]> git.mjollnir.org Git - moodle.git/commitdiff
Typos + drop table fully supported.
authorstronk7 <stronk7>
Thu, 7 Sep 2006 18:39:43 +0000 (18:39 +0000)
committerstronk7 <stronk7>
Thu, 7 Sep 2006 18:39:43 +0000 (18:39 +0000)
lib/xmldb/classes/XMLDBField.class.php
lib/xmldb/classes/generators/XMLDBGenerator.class.php
lib/xmldb/classes/generators/oci8po/oci8po.class.php

index 35a3d20ddaf662082eba865c50a773f5592d7642..ffa3e1a4d96bd339b39430930078d70035c0d593 100644 (file)
@@ -80,7 +80,7 @@ class XMLDBField extends XMLDBObject {
         $this->precision = $type;
         $this->unsigned = !empty($unsigned) ? true : false;
         $this->notnull = !empty($notnull) ? true : false;
-        $this->sequence = !empty($secuence) ? true : false;
+        $this->sequence = !empty($sequence) ? true : false;
         $this->enum = !empty($enum) ? true : false;
     /// Accept both quoted and non-quoted vales (quoting them)a
         if (is_array($enumvalues)) {
index 7404c1e8daa4f142db15a4b79d0d19bbae9f7eb4..e89e998bd67f749993ab44f01fc8fdc82979672b 100644 (file)
@@ -157,7 +157,7 @@ class XMLDBgenerator {
         }
     /// Add enum extra code if needed
         if ($this->enum_extra_code) {
-        /// Iterate over fields looking for sequences
+        /// Iterate over fields looking for enums
             foreach ($xmldb_fields as $xmldb_field) {
                 if ($xmldb_field->getEnum()) {
                     $table .= "\n" . $this->getEnumExtraSQL($xmldb_table, $xmldb_field) . ',';
@@ -424,7 +424,7 @@ class XMLDBgenerator {
 
     /// TODO, call to getRenameTableExtraSQL() if $rename_table_extra_code is enabled. It will add sequence regeneration code.
         if ($this->rename_table_extra_code) {
-            $extra_sentences = getDropTableExtraSQL();
+            $extra_sentences = $this->getRenameTableExtraSQL();
             $results = array_merge($results, $extra_sentences);
         }
 
@@ -439,16 +439,17 @@ class XMLDBgenerator {
 
         $results = array();  //Array where all the sentences will be stored
 
-        $rename = str_replace('TABLENAME', $this->getEncQuoted($this->prefix . $xmldb_table->getName()), $this->drop_table_sql);
+        $drop = str_replace('TABLENAME', $this->getEncQuoted($this->prefix . $xmldb_table->getName()), $this->drop_table_sql);
 
-        $results[] = $rename;
+        $results[] = $drop;
 
     /// TODO, call to getDropTableExtraSQL() if $rename_table_extra_code is enabled. It will add sequence/trigger drop code.
         if ($this->drop_table_extra_code) {
-            $extra_sentences = getDropTableExtraSQL();
+            $extra_sentences = $this->getDropTableExtraSQL($xmldb_table);
             $results = array_merge($results, $extra_sentences);
         }
 
+
         return $results;
     }
 
@@ -659,28 +660,28 @@ class XMLDBgenerator {
      * to create one sequence for the xmldb_table and xmldb_field passes
      */
     function getCreateSequenceSQL ($xmldb_table, $xmldb_field) {
-        return 'Code for extra sequence SQL goes to getCreateSequenceSQL(). Can be disabled with sequence_extra_code=false';
+        return array('Code for extra sequence SQL goes to getCreateSequenceSQL(). Can be disabled with sequence_extra_code=false');
     }
 
     /**
      * Returns the code (array of statements) needed to add one comment to the table
      */
     function getCommentSQL ($xmldb_table) {
-        return 'Code for table comment goes to getCommentSQL(). Can be disabled with add_table_comments=false;';
+        return array('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 rename goes to getRenameTableExtraSQL(). Can be disabled with rename_table_extra_code=false;';
+        return array('Code for table rename goes to getRenameTableExtraSQL(). Can be disabled with rename_table_extra_code=false;');
     }
 
     /**
      * Returns the code (array of statements) needed to execute extra statements on table drop
      */
     function getDropTableExtraSQL ($xmldb_table) {
-        return 'Code for table drop goes to getDropTableExtraSQL(). Can be disabled with drop_table_extra_code=false;';
+        return array('Code for table drop goes to getDropTableExtraSQL(). Can be disabled with drop_table_extra_code=false;');
     }
 
     /**
index 3055ae5a89077c8fd8bdde88998cbfc2cf72e42f..5c2198e29ae20f8328be9d06ec5245c7db3e724f 100644 (file)
@@ -52,6 +52,8 @@ class XMLDBoci8po extends XMLDBgenerator {
     var $sequence_extra_code = true; //Does the generator need to add extra code to generate the sequence fields
     var $sequence_name = ''; //Particular name for inline sequences in this generator
 
+    var $drop_table_extra_code = true; //Does the generatos need to add code after table drop
+
     var $enum_inline_code = false; //Does the generator need to add inline code in the column definition
 
     /**
@@ -149,16 +151,46 @@ class XMLDBoci8po extends XMLDBgenerator {
         return array($sequence, $trigger);
     }
 
-     /**
-      * Returns the code (in array) needed to add one comment to the table
-      */
-     function getCommentSQL ($xmldb_table) {
+    /**
+     * Returns the code needed to drop one sequence for the xmldb_table and xmldb_field passed
+     * Can, optionally, specify if the underlying trigger will be also dropped
+     */
+    function getDropSequenceSQL ($xmldb_table, $xmldb_field, $include_trigger=false) {
+
+        $sequence_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'seq');
+        
+        $sequence = "DROP SEQUENCE " . $sequence_name;
+
+        $trigger_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'trg');
+        $trigger = "DROP TRIGGER " . $trigger_name;
+
+        if ($include_trigger) {
+            $result =  array($sequence, $trigger);
+        } else {
+            $result = array($sequence);
+        }
+        return $result;
+    }
+
+    /**
+     * Returns the code (in array) needed to add one comment to the table
+     */
+    function getCommentSQL ($xmldb_table) {
+
+        $comment = "COMMENT ON TABLE " . $this->getEncQuoted($this->prefix . $xmldb_table->getName());
+        $comment.= " IS '" . substr($xmldb_table->getComment(), 0, 250) . "'";
 
-         $comment = "COMMENT ON TABLE " . $this->getEncQuoted($this->prefix . $xmldb_table->getName());
-         $comment.= " IS '" . substr($xmldb_table->getComment(), 0, 250) . "'";
+        return array($comment);
+    }
 
-         return array($comment);
-     }
+    /**
+     * Returns the code (array of statements) needed to execute extra statements on table drop
+     */
+    function getDropTableExtraSQL ($xmldb_table) {
+        $xmldb_field = new XMLDBField('id'); // Fields having sequences should be exclusively, id.
+        return $this->getDropSequenceSQL($xmldb_table, $xmldb_field, false);
+    }
 
     /**
      * Returns an array of reserved words (lowercase) for this DB