From: stronk7 Date: Mon, 10 Sep 2007 22:00:24 +0000 (+0000) Subject: Preparing getCheckConstraintsFromDB() to retrieve the check constraint X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a347e5e4398e4c2219920fd6a9782cef69668f01;p=moodle.git Preparing getCheckConstraintsFromDB() to retrieve the check constraint defined for one field. Not used yet but I need it in CVS now. --- diff --git a/lib/xmldb/classes/generators/mssql/mssql.class.php b/lib/xmldb/classes/generators/mssql/mssql.class.php index 4552deb261..09e4e0a60e 100644 --- a/lib/xmldb/classes/generators/mssql/mssql.class.php +++ b/lib/xmldb/classes/generators/mssql/mssql.class.php @@ -470,6 +470,22 @@ class XMLDBmssql extends XMLDBgenerator { } } + /// Filter by the required field if specified + if ($xmldb_field) { + $filtered_results = array(); + $filter = $xmldb_field->getName(); + /// Lets clean a bit each constraint description, looking for the filtered field + foreach ($results as $key => $result) { + $description = trim(preg_replace('/[\(\)]/', '', $result->description)); // Parenthesis out & trim + /// description starts by [$filter] assume it's a constraint beloging to the field + if (preg_match("/^\[{$filter}\]/i", $description)) { + $filtered_results[$key] = $result; + } + } + /// Assign filtered results to the final results array + $results = $filtered_results; + } + return $results; } diff --git a/lib/xmldb/classes/generators/mysql/mysql.class.php b/lib/xmldb/classes/generators/mysql/mysql.class.php index 98c39cae34..a7c0a83dac 100644 --- a/lib/xmldb/classes/generators/mysql/mysql.class.php +++ b/lib/xmldb/classes/generators/mysql/mysql.class.php @@ -280,6 +280,17 @@ class XMLDBmysql extends XMLDBGenerator { } } + /// Filter by the required field if specified + if ($xmldb_field) { + $filter = $xmldb_field->getName(); + /// Check if some of the checks belong to the field (easy under MySQL) + if (array_key_exists($filter, $results)) { + $results = array($filter => $results[$filter]); + } else { + $results = array(); + } + } + return $results; } diff --git a/lib/xmldb/classes/generators/oci8po/oci8po.class.php b/lib/xmldb/classes/generators/oci8po/oci8po.class.php index 694d6003d5..5ff92a5801 100644 --- a/lib/xmldb/classes/generators/oci8po/oci8po.class.php +++ b/lib/xmldb/classes/generators/oci8po/oci8po.class.php @@ -500,6 +500,12 @@ class XMLDBoci8po extends XMLDBgenerator { } } + /// Filter by the required field if specified + if ($xmldb_field) { + $filter = $xmldb_field->getName(); + /// Lets clean a bit each constraint description, looking for the filtered fiel + } + return $results; } diff --git a/lib/xmldb/classes/generators/postgres7/postgres7.class.php b/lib/xmldb/classes/generators/postgres7/postgres7.class.php index 8f7fb6a033..e9c3832358 100644 --- a/lib/xmldb/classes/generators/postgres7/postgres7.class.php +++ b/lib/xmldb/classes/generators/postgres7/postgres7.class.php @@ -455,6 +455,26 @@ class XMLDBpostgres7 extends XMLDBgenerator { } } + /// Filter by the required field if specified + if ($xmldb_field) { + $filtered_results = array(); + $filter = $xmldb_field->getName(); + /// Lets clean a bit each constraint description, looking for the filtered field + foreach ($results as $key => $result) { + $description = preg_replace('/\("(.*?)"\)/', '($1)', $result->description);// Double quotes out + $description = preg_replace('/[\(\)]/', '', $description); // Parenthesis out + $description = preg_replace('/::[a-z]+/i', '', $description); // Casts out + $description = preg_replace("/({$filter})/i", '@$1@', $description); + $description = trim(preg_replace('/ or /i', ' OR ', $description)); // Uppercase or & trim + /// description starts by @$filter@ assume it's a constraint beloging to the field + if (preg_match("/^@{$filter}@/i", $description)) { + $filtered_results[$key] = $result; + } + } + /// Assign filtered results to the final results array + $results = $filtered_results; + } + return $results; }