From f075bac4f70d44c9220f65ff080984509076f7fd Mon Sep 17 00:00:00 2001 From: stronk7 Date: Wed, 16 Aug 2006 23:45:18 +0000 Subject: [PATCH] Bah, Oracle requires the default clause BEFORE the not null clause. --- .../generators/XMLDBGenerator.class.php | 61 ++++++++++++------- .../generators/oci8po/oci8po.class.php | 2 + 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/lib/xmldb/classes/generators/XMLDBGenerator.class.php b/lib/xmldb/classes/generators/XMLDBGenerator.class.php index bc90e79ca6..7bcc0c2634 100644 --- a/lib/xmldb/classes/generators/XMLDBGenerator.class.php +++ b/lib/xmldb/classes/generators/XMLDBGenerator.class.php @@ -49,6 +49,8 @@ class XMLDBgenerator { var $unsigned_allowed = true; // To define in the generator must handle unsigned information var $default_for_char = null; // To define the default to set for NOT NULLs CHARs without default (null=do nothing) + var $default_after_null = true; //To decide if the default clause of each field must go after the null clause + var $primary_key_name = null; //To force primary key names to one string (null=no force) var $primary_keys = true; // Does the generator build primary keys @@ -274,9 +276,17 @@ class XMLDBgenerator { $field .= ' unsigned'; } } - /// The not null + /// Calculate the not null clause if ($xmldb_field->getNotNull()) { - $field .= ' NOT NULL'; + $notnull = ' NOT NULL'; + } + /// Calculate the default clause + $default = $this->getDefaultClause($xmldb_field); + /// Based on default_after_null, set both clauses properly + if ($this->default_after_null) { + $field .= $notnull . $default; + } else { + $field .= $default . $notnull; } /// The sequence if ($xmldb_field->getSequence()) { @@ -287,24 +297,6 @@ class XMLDBgenerator { return $this->getEncQuoted($xmldb_field->getName()) . ' ' . $this->sequence_name; } } - /// The default - if ($xmldb_field->getDefault() != NULL) { - $field .= ' default '; - if ($xmldb_field->getType() == XMLDB_TYPE_CHAR || - $xmldb_field->getType() == XMLDB_TYPE_TEXT) { - $field .= "'" . $xmldb_field->getDefault() . "'"; - } else { - $field .= $xmldb_field->getDefault(); - } - } else { - /// We force default '' for not null char columns without proper default - /// some day this should be out! - if ($this->default_for_char !== NULL && - $xmldb_field->getType() == XMLDB_TYPE_CHAR && - $xmldb_field->getNotNull()) { - $field .= ' default ' . "'" . $this->default_for_char . "'"; - } - } return $field; } @@ -337,7 +329,7 @@ class XMLDBgenerator { if ($this->foreign_keys) { $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'fk'); $key .= ' FOREIGN KEY (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')'; - $key .= ' REFERENCES ' . $this->getEncQuoted($xmldb_key->getRefTable()); + $key .= ' REFERENCES ' . $this->getEncQuoted($this->prefix . $xmldb_key->getRefTable()); $key .= ' (' . implode(', ', $this->getEncQuoted($xmldb_key->getRefFields())) . ')'; } break; @@ -346,6 +338,33 @@ class XMLDBgenerator { return $key; } + /** + * Give one XMLDBField, returns the correct "default clause" for the current configuration + */ + function getDefaultClause ($xmldb_field) { + + $default = ''; + + if ($xmldb_field->getDefault() != NULL) { + $default = ' default '; + if ($xmldb_field->getType() == XMLDB_TYPE_CHAR || + $xmldb_field->getType() == XMLDB_TYPE_TEXT) { + $default .= "'" . $xmldb_field->getDefault() . "'"; + } else { + $default .= $xmldb_field->getDefault(); + } + } else { + /// We force default '' for not null char columns without proper default + /// some day this should be out! + if ($this->default_for_char !== NULL && + $xmldb_field->getType() == XMLDB_TYPE_CHAR && + $xmldb_field->getNotNull()) { + $default .= ' default ' . "'" . $this->default_for_char . "'"; + } + } + return $default; + } + /** * Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name */ diff --git a/lib/xmldb/classes/generators/oci8po/oci8po.class.php b/lib/xmldb/classes/generators/oci8po/oci8po.class.php index 396ba32506..769add5c1a 100644 --- a/lib/xmldb/classes/generators/oci8po/oci8po.class.php +++ b/lib/xmldb/classes/generators/oci8po/oci8po.class.php @@ -37,6 +37,8 @@ class XMLDBoci8po 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 $default_after_null = false; //To decide if the default clause of each field must go after the null clause + 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 -- 2.39.5