From 7c07a932236079a82b11d23b9eb8ecc582d796dc Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 1 Oct 2006 22:54:51 +0000 Subject: [PATCH] Added rename_field() support. TODO: Sync sequences, triggers and check constraints --- .../generators/XMLDBGenerator.class.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/xmldb/classes/generators/XMLDBGenerator.class.php b/lib/xmldb/classes/generators/XMLDBGenerator.class.php index 36f8980300..2a6959adb0 100644 --- a/lib/xmldb/classes/generators/XMLDBGenerator.class.php +++ b/lib/xmldb/classes/generators/XMLDBGenerator.class.php @@ -110,6 +110,11 @@ class XMLDBgenerator { var $alter_column_skip_notnull = false; //The generator will skip the null/notnull clause on alter columns + var $rename_column_sql = 'ALTER TABLE TABLENAME RENAME COLUMN OLDFIELDNAME TO NEWFIELDNAME'; + ///TABLENAME, OLDFIELDNAME and NEWFIELDNAME are dianmically replaced + + var $rename_column_extra_code = false; //Does the generator need to add code after column rename + var $drop_index_sql = 'DROP INDEX INDEXNAME'; //SQL sentence to drop one index //TABLENAME, INDEXNAME are dinamically replaced @@ -642,6 +647,29 @@ class XMLDBgenerator { return $results; } + /** + * Given one correct XMLDBField and the new name, returns the SQL statements + * to rename it (inside one array) + */ + function getRenameFieldSQL($xmldb_table, $xmldb_field, $newname) { + + $results = array(); //Array where all the sentences will be stored + + $rename = str_replace('TABLENAME', $this->getTableName($xmldb_table), $this->rename_column_sql); + $rename = str_replace('OLDFIELDNAME', $xmldb_field->getName(), $rename); + $rename = str_replace('NEWFIELDNAME', $newname, $rename); + + $results[] = $rename; + + /// Call to getRenameFieldExtraSQL() if $rename_column_extra_code is enabled (will add some required sentences) + if ($this->rename_column_extra_code) { + $extra_sentences = $this->getRenameFieldExtraSQL($xmldb_table, $xmldb_field, $newname); + $results = array_merge($results, $extra_sentences); + } + + return $results; + } + /** * Given one XMLDBTable and one XMLDBKey, return the SQL statements needded to add the key to the table * note that undelying indexes will be added as parametrised by $xxxx_keys and $xxxx_index parameters @@ -1041,6 +1069,13 @@ class XMLDBgenerator { return 'Code for extra enum SQL goes to getEnumExtraSQL(). Can be disabled with enum_extra_code=false'; } + /** + * Returns the code (array of statements) needed to execute extra statements on field rename + */ + function getRenameFieldExtraSQL ($xmldb_table, $xmldb_field) { + return array('Code for field rename goes to getRenameFieldExtraSQL(). Can be disabled with rename_column_extra_code=false;'); + } + /** * Returns the code (array of statements) needed * to create one sequence for the xmldb_table and xmldb_field passes -- 2.39.5