$this->precision = $type;
$this->unsigned = !empty($unsigned) ? true : false;
$this->notnull = !empty($notnull) ? true : false;
- $this->sequence = !empty($secuence) ? true : false;
+ $this->sequence = !empty($sequence) ? true : false;
$this->enum = !empty($enum) ? true : false;
/// Accept both quoted and non-quoted vales (quoting them)a
if (is_array($enumvalues)) {
}
/// Add enum extra code if needed
if ($this->enum_extra_code) {
- /// Iterate over fields looking for sequences
+ /// Iterate over fields looking for enums
foreach ($xmldb_fields as $xmldb_field) {
if ($xmldb_field->getEnum()) {
$table .= "\n" . $this->getEnumExtraSQL($xmldb_table, $xmldb_field) . ',';
/// TODO, call to getRenameTableExtraSQL() if $rename_table_extra_code is enabled. It will add sequence regeneration code.
if ($this->rename_table_extra_code) {
- $extra_sentences = getDropTableExtraSQL();
+ $extra_sentences = $this->getRenameTableExtraSQL();
$results = array_merge($results, $extra_sentences);
}
$results = array(); //Array where all the sentences will be stored
- $rename = str_replace('TABLENAME', $this->getEncQuoted($this->prefix . $xmldb_table->getName()), $this->drop_table_sql);
+ $drop = str_replace('TABLENAME', $this->getEncQuoted($this->prefix . $xmldb_table->getName()), $this->drop_table_sql);
- $results[] = $rename;
+ $results[] = $drop;
/// TODO, call to getDropTableExtraSQL() if $rename_table_extra_code is enabled. It will add sequence/trigger drop code.
if ($this->drop_table_extra_code) {
- $extra_sentences = getDropTableExtraSQL();
+ $extra_sentences = $this->getDropTableExtraSQL($xmldb_table);
$results = array_merge($results, $extra_sentences);
}
+
return $results;
}
* to create one sequence for the xmldb_table and xmldb_field passes
*/
function getCreateSequenceSQL ($xmldb_table, $xmldb_field) {
- return 'Code for extra sequence SQL goes to getCreateSequenceSQL(). Can be disabled with sequence_extra_code=false';
+ return array('Code for extra sequence SQL goes to getCreateSequenceSQL(). Can be disabled with sequence_extra_code=false');
}
/**
* Returns the code (array of statements) needed to add one comment to the table
*/
function getCommentSQL ($xmldb_table) {
- return 'Code for table comment goes to getCommentSQL(). Can be disabled with add_table_comments=false;';
+ return array('Code for table comment goes to getCommentSQL(). Can be disabled with add_table_comments=false;');
}
/**
* Returns the code (array of statements) needed to execute extra statements on table rename
*/
function getRenameTableExtraSQL ($xmldb_table) {
- return 'Code for table rename goes to getRenameTableExtraSQL(). Can be disabled with rename_table_extra_code=false;';
+ return array('Code for table rename goes to getRenameTableExtraSQL(). Can be disabled with rename_table_extra_code=false;');
}
/**
* Returns the code (array of statements) needed to execute extra statements on table drop
*/
function getDropTableExtraSQL ($xmldb_table) {
- return 'Code for table drop goes to getDropTableExtraSQL(). Can be disabled with drop_table_extra_code=false;';
+ return array('Code for table drop goes to getDropTableExtraSQL(). Can be disabled with drop_table_extra_code=false;');
}
/**
var $sequence_extra_code = true; //Does the generator need to add extra code to generate the sequence fields
var $sequence_name = ''; //Particular name for inline sequences in this generator
+ var $drop_table_extra_code = true; //Does the generatos need to add code after table drop
+
var $enum_inline_code = false; //Does the generator need to add inline code in the column definition
/**
return array($sequence, $trigger);
}
- /**
- * Returns the code (in array) needed to add one comment to the table
- */
- function getCommentSQL ($xmldb_table) {
+ /**
+ * Returns the code needed to drop one sequence for the xmldb_table and xmldb_field passed
+ * Can, optionally, specify if the underlying trigger will be also dropped
+ */
+ function getDropSequenceSQL ($xmldb_table, $xmldb_field, $include_trigger=false) {
+
+ $sequence_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'seq');
+
+ $sequence = "DROP SEQUENCE " . $sequence_name;
+
+ $trigger_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'trg');
+
+ $trigger = "DROP TRIGGER " . $trigger_name;
+
+ if ($include_trigger) {
+ $result = array($sequence, $trigger);
+ } else {
+ $result = array($sequence);
+ }
+ return $result;
+ }
+
+ /**
+ * Returns the code (in array) needed to add one comment to the table
+ */
+ function getCommentSQL ($xmldb_table) {
+
+ $comment = "COMMENT ON TABLE " . $this->getEncQuoted($this->prefix . $xmldb_table->getName());
+ $comment.= " IS '" . substr($xmldb_table->getComment(), 0, 250) . "'";
- $comment = "COMMENT ON TABLE " . $this->getEncQuoted($this->prefix . $xmldb_table->getName());
- $comment.= " IS '" . substr($xmldb_table->getComment(), 0, 250) . "'";
+ return array($comment);
+ }
- return array($comment);
- }
+ /**
+ * Returns the code (array of statements) needed to execute extra statements on table drop
+ */
+ function getDropTableExtraSQL ($xmldb_table) {
+ $xmldb_field = new XMLDBField('id'); // Fields having sequences should be exclusively, id.
+ return $this->getDropSequenceSQL($xmldb_table, $xmldb_field, false);
+ }
/**
* Returns an array of reserved words (lowercase) for this DB