]> git.mjollnir.org Git - moodle.git/commitdiff
Now all the generators support creating and dropping indexes
authorstronk7 <stronk7>
Tue, 26 Sep 2006 23:15:20 +0000 (23:15 +0000)
committerstronk7 <stronk7>
Tue, 26 Sep 2006 23:15:20 +0000 (23:15 +0000)
lib/xmldb/classes/generators/XMLDBGenerator.class.php
lib/xmldb/classes/generators/mssql/mssql.class.php
lib/xmldb/classes/generators/mysql/mysql.class.php

index 03a797747adedc789485da3259317214a8e42ba0..0c7030fea51533afe5e96673c3a3bfd845f30b95 100644 (file)
@@ -104,6 +104,9 @@ class XMLDBgenerator {
 
     var $alter_column_skip_notnull = false; //The generator will skip the null/notnull clause on alter columns
 
+    var $drop_index_sql = 'DROP INDEX INDEXNAME'; //SQL sentence to drop one index
+                                  //TABLENAME, INDEXNAME are dinamically replaced
+
     var $prefix;         // Prefix to be used for all the DB objects
 
     var $reserved_words; // List of reserved words (in order to quote them properly)
@@ -604,6 +607,34 @@ class XMLDBgenerator {
         }
     }
 
+    /**
+     * Given one XMLDBTable and one XMLDBIndex, return the SQL statements needded to add the index to the table
+     */
+    function getAddIndexSQL($xmldb_table, $xmldb_index) {
+
+    /// Just use the CreateIndexSQL function
+        return $this->getCreateIndexSQL($xmldb_table, $xmldb_index);
+    }
+
+    /**
+     * Given one XMLDBTable and one XMLDBIndex, return the SQL statements needded to drop the index from the table
+     */
+    function getDropIndexSQL($xmldb_table, $xmldb_index) {
+
+        $results = array();
+
+    /// Get the real index name
+        $dbindexname = find_index_name($xmldb_table, $xmldb_index);
+
+    /// Replace TABLENAME and INDEXNAME as needed
+        $dropsql = str_replace('TABLENAME', $this->getEncQuoted($this->prefix . $xmldb_table->getName()), $this->drop_index_sql);
+        $dropsql = str_replace('INDEXNAME', $dbindexname, $dropsql);
+
+        $results[] = $dropsql;
+
+        return $results;
+    }
+
 
     /**
      * Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name
index 3b1d4af7c35562a6b4acd83218d7fd9ae3b01fec..61ba212407dff28d9f04d75b076239996682e3d1 100644 (file)
@@ -60,6 +60,9 @@ class XMLDBmssql extends XMLDBgenerator {
     var $concat_character = '+'; //Characters to be used as concatenation operator. If not defined
                                   //MySQL CONCAT function will be use
 
+    var $drop_index_sql = 'DROP INDEX TABLENAME.INDEXNAME'; //SQL sentence to drop one index
+                                                               //TABLENAME, INDEXNAME are dinamically replaced
+
     /**
      * Creates one new XMLDBmssql
      */
index d0e2dee6396ffa2f004bc869c97aa85ff9505b96..35650677354b927cece2431bfd720b832119a5c0 100644 (file)
@@ -60,6 +60,9 @@ class XMLDBmysql extends XMLDBGenerator {
 
     var $alter_column_sql = 'ALTER TABLE TABLENAME MODIFY COLUMN COLUMNSPECS'; //The SQL template to alter columns
 
+    var $drop_index_sql = 'DROP INDEX INDEXNAME ON TABLENAME'; //SQL sentence to drop one index
+                                                               //TABLENAME, INDEXNAME are dinamically replaced
+
     /**
      * Creates one new XMLDBmysql
      */