From 2cfea485a6ac98ec56b298870c74051031a949df Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 1 Oct 2006 15:47:48 +0000 Subject: [PATCH] Added getDefaultValue() for better handling of default values --- .../generators/XMLDBGenerator.class.php | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/xmldb/classes/generators/XMLDBGenerator.class.php b/lib/xmldb/classes/generators/XMLDBGenerator.class.php index 113dd3261f..36f8980300 100644 --- a/lib/xmldb/classes/generators/XMLDBGenerator.class.php +++ b/lib/xmldb/classes/generators/XMLDBGenerator.class.php @@ -428,19 +428,18 @@ class XMLDBgenerator { } /** - * Give one XMLDBField, returns the correct "default clause" for the current configuration + * Give one XMLDBField, returns the correct "default value" for the current configuration */ - function getDefaultClause ($xmldb_field) { + function getDefaultValue ($xmldb_field) { - $default = ''; + $default = null; if ($xmldb_field->getDefault() != NULL) { - $default = ' DEFAULT '; if ($xmldb_field->getType() == XMLDB_TYPE_CHAR || $xmldb_field->getType() == XMLDB_TYPE_TEXT) { - $default .= "'" . addslashes($xmldb_field->getDefault()) . "'"; + $default = "'" . addslashes($xmldb_field->getDefault()) . "'"; } else { - $default .= $xmldb_field->getDefault(); + $default = $xmldb_field->getDefault(); } } else { /// We force default '' for not null char columns without proper default @@ -448,20 +447,34 @@ class XMLDBgenerator { if ($this->default_for_char !== NULL && $xmldb_field->getType() == XMLDB_TYPE_CHAR && $xmldb_field->getNotNull()) { - $default = ' DEFAULT ' . "'" . $this->default_for_char . "'"; + $default = "'" . $this->default_for_char . "'"; } else { /// If the DB requires to explicity define some clause to drop one default, do it here /// never applying defaults to TEXT and BINARY fields if ($this->drop_default_clause_required && $xmldb_field->getType() != XMLDB_TYPE_TEXT && $xmldb_field->getType() != XMLDB_TYPE_BINARY && !$xmldb_field->getNotNull()) { - $default = ' DEFAULT ' . $this->drop_default_clause; + $default = $this->drop_default_clause; } } } return $default; } + /** + * Given one XMLDBField, returns the correct "default clause" for the current configuration + */ + function getDefaultClause ($xmldb_field) { + + $defaultvalue = $this->getDefaultValue ($xmldb_field); + + if ($defaultvalue !== null) { + return ' DEFAULT ' . $defaultvalue; + } else { + return null; + } + } + /** * Given one correct XMLDBTable and the new name, returns the SQL statements * to rename it (inside one array) -- 2.39.5