$commands = array('Fields',
$optionspacer . 'add_field',
$optionspacer . 'drop_field',
- $optionspacer . 'rename_field (not imp!)',
+ $optionspacer . 'rename_field',
$optionspacer . 'change_field_type',
$optionspacer . 'change_field_precision',
$optionspacer . 'change_field_unsigned',
$optionspacer . 'change_field_notnull',
- $optionspacer . 'change_field_sequence (not imp!)',
- $optionspacer . 'change_field_enum (not imp!)',
+ $optionspacer . 'change_field_enum',
$optionspacer . 'change_field_default',
'Keys',
$optionspacer . 'add_key',
$o.= $this->str['mustselectonefield'];
}
break;
+ case 'change_field_enum':
+ if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
+ $o.= s($this->change_field_enum_php($structure, $tableparam, $fieldkeyindexparam));
+ } else {
+ $o.= $this->str['mustselectonefield'];
+ }
+ break;
case 'change_field_default':
if ($fieldkeyindexinitial == 'f') { //Only if we have got one field
$o.= s($this->change_field_default_php($structure, $tableparam, $fieldkeyindexparam));
return $result;
}
+ /**
+ * This function will generate all the PHP code needed to
+ * change the enum values (check constraint) of one field
+ * using XMLDB objects and functions
+ *
+ * @param XMLDBStructure structure object containing all the info
+ * @param string table table name
+ * @param string field field name to change its enum
+ */
+ function change_field_enum_php($structure, $table, $field) {
+
+ $result = '';
+ /// Validate if we can do it
+ if (!$table = $structure->getTable($table)) {
+ return false;
+ }
+ if (!$field = $table->getField($field)) {
+ return false;
+ }
+ if ($table->getAllErrors()) {
+ return false;
+ }
+
+ /// Calculate the enum tip text
+ $enum = $field->getEnum() ? implode(', ', $field->getEnumValues()) : 'none';
+
+ /// Add the standard PHP header
+ $result .= XMLDB_PHP_HEADER;
+
+ /// Add contents
+ $result .= XMLDB_LINEFEED;
+ $result .= ' /// Changing list of values (enum) of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $enum . XMLDB_LINEFEED;
+ $result .= ' $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;
+ $result .= ' $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED;
+ $result .= ' $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED;
+
+ /// Launch the proper DDL
+ $result .= XMLDB_LINEFEED;
+ $result .= ' /// Launch change of list of values for field ' . $field->getName() . XMLDB_LINEFEED;
+ $result .= ' $status = $status && change_field_enum($table, $field);' . XMLDB_LINEFEED;
+
+ /// Add standard PHP footer
+ $result .= XMLDB_PHP_FOOTER;
+
+ return $result;
+ }
+
/**
* This function will generate all the PHP code needed to
* change the default of one field using XMLDB objects and functions
return false;
}
+ /// Prepend warning. This function isn't usable!
+ $result .= 'DON\'T USE THIS FUNCTION (IT\'S ONLY EXPERIMENTAL). SOME DBs DON\'T SUPPORT IT!' . XMLDB_LINEFEED . XMLDB_LINEFEED;
+
/// Add the standard PHP header
$result .= XMLDB_PHP_HEADER;
return false;
}
+ /// Prepend warning. This function isn't usable!
+ $result .= 'DON\'T USE THIS FUNCTION (IT\'S ONLY EXPERIMENTAL). SOME DBs DON\'T SUPPORT IT!' . XMLDB_LINEFEED . XMLDB_LINEFEED;
+
/// Add the standard PHP header
$result .= XMLDB_PHP_HEADER;