]> git.mjollnir.org Git - moodle.git/commitdiff
Initial, unfinished, not working, simple version of rename_table generator.
authorstronk7 <stronk7>
Wed, 6 Sep 2006 23:04:13 +0000 (23:04 +0000)
committerstronk7 <stronk7>
Wed, 6 Sep 2006 23:04:13 +0000 (23:04 +0000)
More coming soon, but I needed it in CVS now!

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

index 39a301404730e7629bce9a8442576d1ea3435ad3..6a2492578fbefc599b334ed06e82de3ee09ab102 100644 (file)
@@ -78,6 +78,10 @@ class XMLDBgenerator {
 
     var $concat_character = '||'; //Characters to be used as concatenation operator. If not defined
                                   //MySQL CONCAT function will be used
+    var $rename_table_sql = 'ALTER TABLE OLDNAME RENAME TO NEWNAME'; //SQL sentence to rename one table, both
+                                  //OLDNAME and NEWNAME are dinamically replaced
+
+    var $rename_table_extra_code = false; //Does the generatos need to add code after table renaming
 
     var $prefix;         // Prefix to be used for all the DB objects
 
@@ -400,6 +404,24 @@ class XMLDBgenerator {
         return $default;
     }
 
+    /**
+     * Given one correct XMLDBTable and the new name, returns the SQL statements
+     * to rename it (inside one array)
+     */ 
+    function getRenameTableSQL($xmldb_table, $newname) {
+
+        $results = array();  //Array where all the sentences will be stored
+
+        $rename = str_replace('OLDNAME', $this->getEncQuoted($this->prefix . $xmldb_table->getName), $rename_table_sql);
+        $rename = str_replace('NEWNAME', $this->getEncQuoted($this->prefix . $newname), $rename_table_sql);
+
+        $results[] = $rename;
+
+    /// TODO, call to getRenameTableExtraSQL() if $rename_table_extra_code is enabled. It will add sequence regeneration code.
+
+        return $results;
+    }
+
     /**
      * Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name
      * quoting it if necessary
@@ -617,6 +639,13 @@ class XMLDBgenerator {
         return 'Code for table comment goes to getCommentSQL(). Can be disabled with add_table_comments=false;';
     }
 
+    /**
+     * Returns the code (array of statements) needed to execute extra statements on table rename
+     */
+    function getRenameTableExtraSQL ($xmldb_table) {
+        return 'Code for table comment goes to getCommentSQL(). Can be disabled with add_table_comments=false;';
+    }
+
     /**
      * Returns an array of reserved words (lowercase) for this DB
      * You MUST provide the real list for each DB inside every XMLDB class