]> git.mjollnir.org Git - moodle.git/commitdiff
Prevent Unique Keys generation. Instead use unique indexes at DB level.
authorstronk7 <stronk7>
Sun, 24 Sep 2006 09:38:56 +0000 (09:38 +0000)
committerstronk7 <stronk7>
Sun, 24 Sep 2006 09:38:56 +0000 (09:38 +0000)
With this, all we'll have are PRIMARY KEYS + INDEXES, that are pretty
well supported by ADODB MetaXXX functions.
Both Unique and Foreign Keys will be used once ADODB support them and
the relational mode was enforced.

lib/xmldb/classes/generators/mssql/mssql.class.php
lib/xmldb/classes/generators/mysql/mysql.class.php
lib/xmldb/classes/generators/oci8po/oci8po.class.php
lib/xmldb/classes/generators/postgres7/postgres7.class.php

index 1cd5c5aa078bcc7d3db61c7c9c0dd7f70fd84d45..05551c0c3838b52ba1012728576f4601f02bb324 100644 (file)
@@ -42,10 +42,11 @@ class XMLDBmssql extends XMLDBgenerator {
     var $specify_nulls = true;  //To force the generator if NULL clauses must be specified. It shouldn't be necessary
                                      //but some mssql drivers require them or everything is created as NOT NULL :-(
 
+    var $unique_keys = false; // Does the generator build unique keys
     var $foreign_keys = false; // Does the generator build foreign keys
 
     var $primary_index = false;// Does the generator need to build one index for primary keys
-    var $unique_index = false;  // Does the generator need to build one index for unique keys
+    var $unique_index = true;  // Does the generator need to build one index for unique keys
     var $foreign_index = true; // Does the generator need to build one index for foreign keys
 
     var $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields
index ebaef7a290ed8d997e1a61b0fe171412a661ec1d..19a0cec795f539ca54a48e3d5ba398c9b1b54750 100644 (file)
@@ -38,10 +38,12 @@ class XMLDBmysql extends XMLDBGenerator {
 
     var $primary_key_name = ''; //To force primary key names to one string (null=no force)
 
+    var $unique_keys = false; // Does the generator build unique key
     var $foreign_keys = false; // Does the generator build foreign keys
 
     var $primary_index = false;// Does the generator need to build one index for primary keys
-    var $unique_index = false;  // Does the generator need to build one index for unique keys
+    var $unique_index = true;  // Does the generator need to build one index for unique keys
+    var $foreign_index = true;  // Does the generator need to build one index for foreign keys
 
     var $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields
     var $sequence_name = 'auto_increment'; //Particular name for inline sequences in this generator
index 3de7a1777b5b6de1dea23cfd24be589f9dacca2a..f16981eff5d0d7e9037fd0802b98de814abda768 100644 (file)
@@ -43,10 +43,11 @@ class XMLDBoci8po extends XMLDBgenerator {
 
     var $default_after_null = false;  //To decide if the default clause of each field must go after the null clause
 
+    var $unique_keys = false; // Does the generator build unique keys
     var $foreign_keys = false; // Does the generator build foreign keys
 
     var $primary_index = false;// Does the generator need to build one index for primary keys
-    var $unique_index = false;  // Does the generator need to build one index for unique keys
+    var $unique_index = true;  // Does the generator need to build one index for unique keys
     var $foreign_index = true; // Does the generator need to build one index for foreign keys
 
     var $sequence_extra_code = true; //Does the generator need to add extra code to generate the sequence fields
index c2440dc485ffc4e8f3b5988823130d950be11a4b..542f71f52b278e40fd9c6bd0a5eeff50d406c651 100644 (file)
@@ -37,10 +37,11 @@ class XMLDBpostgres7 extends XMLDBgenerator {
     var $unsigned_allowed = false;    // To define in the generator must handle unsigned information
     var $default_for_char = '';      // To define the default to set for NOT NULLs CHARs without default (null=do nothing)
 
+    var $unique_keys = false; // Does the generator build unique keys
     var $foreign_keys = false; // Does the generator build foreign keys
 
     var $primary_index = false;// Does the generator need to build one index for primary keys
-    var $unique_index = false;  // Does the generator need to build one index for unique keys
+    var $unique_index = true;  // Does the generator need to build one index for unique keys
     var $foreign_index = true; // Does the generator need to build one index for foreign keys
 
     var $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields
@@ -136,6 +137,53 @@ class XMLDBpostgres7 extends XMLDBgenerator {
          return array($comment);
      }
 
+     /**
+      * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to alter the field in the table
+      * PostgreSQL has some severe limits:
+      *     - Any change of type or precision requires a new temporary column to be created, values to
+      *       be transfered potentially casting them, to apply defaults if the column is not null and 
+      *       finally, to rename it
+      *     - Changes in null/not null require the SET/DROP NOT NULL clause
+      *     - Changes in default require the SET/DROP DEFAULT clause
+      */
+     function getAlterFieldSQL($xmldb_table, $xmldb_field) {
+
+         global $db;
+
+     /// Get the quoted name of the table and field
+         $tablename = $this->getEncQuoted($this->prefix . $xmldb_table->getName());
+         $fieldname = $this->getEncQuoted($xmldb_field->getName());
+
+     /// Take a look to field metadata
+         $meta = array_change_key_case($db->MetaColumns($tablename));
+         $metac = $meta[$fieldname];
+         print_object($metac);
+         $oldtype = strtolower($metac->type);
+         $oldlength = $metac->max_length;
+         $olddecimals = empty($metac->scale) ? null : $metac->scale;
+         $oldnotnull = empty($metac->not_null) ? false : $metac->not_null;
+         $olddefault = empty($metac->default_value) ? null : $metac->default_value;
+                                                                                                                                   /// If field is CLOB and new one is also XMLDB_TYPE_TEXT or 
+     /// if fiels is BLOB and new one is also XMLDB_TYPE_BINARY
+     /// prevent type to be specified, so only NULL and DEFAULT clauses are allowed
+         if (($oldtype = 'clob' && $xmldb_field->getType() == XMLDB_TYPE_TEXT) ||
+             ($oldtype = 'blob' && $xmldb_field->getType() == XMLDB_TYPE_BINARY)) {
+             $this->alter_column_skip_type = true;
+             $islob = true;
+         }
+
+     /// If field is NOT NULL and the new one too or
+     /// if field is NULL and the new one too
+     /// prevent null clause to be specified
+         if (($oldnotnull && $xmldb_field->getNotnull()) ||
+             (!$oldnotnull && !$xmldb_field->getNotnull())) {
+             $this->alter_column_skip_notnull = true;
+         }
+
+     /// In the rest of cases, use the general generator
+         return parent::getAlterFieldSQL($xmldb_table, $xmldb_field);
+     }
+
     /**
      * Returns an array of reserved words (lowercase) for this DB
      */