From: stronk7 Date: Tue, 12 Sep 2006 22:15:00 +0000 (+0000) Subject: Added functions to retrieve the proper add and drop field SQL. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3ab2610037e11da73eab9e0175709e05f1bfde0d;p=moodle.git Added functions to retrieve the proper add and drop field SQL. --- diff --git a/lib/xmldb/classes/generators/XMLDBGenerator.class.php b/lib/xmldb/classes/generators/XMLDBGenerator.class.php index 9fa7d1f475..7c7b6c7553 100644 --- a/lib/xmldb/classes/generators/XMLDBGenerator.class.php +++ b/lib/xmldb/classes/generators/XMLDBGenerator.class.php @@ -453,6 +453,47 @@ class XMLDBgenerator { return $results; } + /** + * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to add the field to the table + */ + function getAddFieldSQL($xmldb_table, $xmldb_field) { + + $results = array(); + + /// Get the quoted name of the table and field + $tablename = $this->getEncQuoted($this->prefix . $xmldb_table->getName()); + + /// Build the standard alter table add + $results[] = 'ALTER TABLE ' . $tablename . ' ADD ' . $this->getFieldSQL($xmldb_field); + + /// If the DB has extra enum code + if ($this->enum_extra_code) { + /// If it's enum add the extra code + if ($xmldb_field->getEnum()) { + $results[] = 'ALTER TABLE ' . $tablename . ' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field); + } + } + + return $results; + } + + /** + * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop the field from the table + */ + function getDropFieldSQL($xmldb_table, $xmldb_field) { + + $results = array(); + + /// Get the quoted name of the table and field + $tablename = $this->getEncQuoted($this->prefix . $xmldb_table->getName()); + $fieldname = $this->getEncQuoted($xmldb_field->getName()); + + /// Build the standard alter table drop + $results[] = 'ALTER TABLE ' . $tablename . ' DROP COLUMN ' . $fieldname; + + return $results; + } + /** * Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name * quoting it if necessary