]> git.mjollnir.org Git - moodle.git/commitdiff
Now mysql returns getCheckConstraintsFromDB() in a compatible
authorstronk7 <stronk7>
Sun, 9 Sep 2007 16:09:00 +0000 (16:09 +0000)
committerstronk7 <stronk7>
Sun, 9 Sep 2007 16:09:00 +0000 (16:09 +0000)
way (array of name & description objects) with the check
constraints found in the table

lib/xmldb/classes/generators/mysql/mysql.class.php

index 9c6b758f3977714158d248b654e2d22c7eca81aa..149e0288ec4f2705da8ecf0b16f421fe107e430f 100644 (file)
@@ -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;
     }
 
     /**