From: stronk7 Date: Sun, 9 Sep 2007 16:09:00 +0000 (+0000) Subject: Now mysql returns getCheckConstraintsFromDB() in a compatible X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4cc68ea1845d9882cc721202f2f25796eb5d7a95;p=moodle.git Now mysql returns getCheckConstraintsFromDB() in a compatible way (array of name & description objects) with the check constraints found in the table --- diff --git a/lib/xmldb/classes/generators/mysql/mysql.class.php b/lib/xmldb/classes/generators/mysql/mysql.class.php index 9c6b758f39..149e0288ec 100644 --- a/lib/xmldb/classes/generators/mysql/mysql.class.php +++ b/lib/xmldb/classes/generators/mysql/mysql.class.php @@ -251,11 +251,34 @@ class XMLDBmysql extends XMLDBGenerator { * in the table (fetched from DB) * Each element contains the name of the constraint and its description * If no check constraints are found, returns an empty array - * MySQL doesn't have check constraints in this implementation + * MySQL doesn't have check constraints in this implementation, but + * we return them based on the enum fields in the table */ function getCheckConstraintsFromDB($xmldb_table) { - return array(); + global $db; + + $results = array(); + + $tablename = $this->getTableName($xmldb_table); + + /// Fetch all the columns in the table + if ($columns = $db->MetaColumns($tablename)) { + /// Normalize array keys + $columns = array_change_key_case($columns, CASE_LOWER); + /// Iterate over columns searching for enums + foreach ($columns as $key => $column) { + /// Enum found, let's add it to the constraints list + if (!empty($column->enums)) { + $result = new object; + $result->name = $key; + $result->description = implode(', ', $column->enums); + $results[$key] = $result; + } + } + } + + return $results; } /**