]> git.mjollnir.org Git - moodle.git/commitdiff
Better approach. Use higher level MetaIndexes() and avoid some MySQL warnings. MDL...
authorstronk7 <stronk7>
Mon, 9 Apr 2007 00:11:22 +0000 (00:11 +0000)
committerstronk7 <stronk7>
Mon, 9 Apr 2007 00:11:22 +0000 (00:11 +0000)
Merged from MOODLE_18_STABLE

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

index f63f753c7e4dbb3756b1021dbc427637da2b7020..9c6b758f3977714158d248b654e2d22c7eca81aa 100644 (file)
@@ -265,6 +265,8 @@ class XMLDBmysql extends XMLDBGenerator {
      */
     function isNameInUse($object_name, $type, $table_name) {
 
+        global $db;
+
     /// Calculate the real table name
         $xmldb_table = new XMLDBTable($table_name);
         $tname = $this->getTableName($xmldb_table);
@@ -272,13 +274,17 @@ class XMLDBmysql extends XMLDBGenerator {
         switch($type) {
             case 'ix':
             case 'uix':
-            /// Fetch all the indexes in the table
-                if ($indexes = get_records_sql("SHOW INDEX FROM $tname")) {
-                    foreach ($indexes as $index) {
+            /// First of all, check table exists
+                $metatables = $db->MetaTables();
+                $metatables = array_flip($metatables);
+                $metatables = array_change_key_case($metatables, CASE_LOWER);
+                if (array_key_exists($tname,  $metatables)) {
+                /// Fetch all the indexes in the table
+                    if ($indexes = $db->MetaIndexes($tname)) {
                     /// Normalize array keys
-                        $index = array_change_key_case((array)$index, CASE_LOWER);
-                    /// Check if the name is being used
-                        if (strtolower($object_name) == $index['key_name']) {
+                        $indexes = array_change_key_case($indexes, CASE_LOWER);
+                    /// Look for existing index in array
+                        if (array_key_exists(strtolower($object_name), $indexes)) {
                             return true;
                         }
                     }