if ($array) $sql .= '[]';
// If we have advanced column adding, add the extra qualifiers
- if ($this->hasAlterColumnType()) {
+ if ($this->hasCreateFieldWithConstraints()) {
// NOT NULL clause
if ($notnull) $sql .= ' NOT NULL';
* @param $comment Comment for the column
* @return 0 success
* @return -1 batch alteration failed
- * @return -3 rename column error
- * @return -4 comment error
+ * @return -4 rename column error
+ * @return -5 comment error
* @return -6 transaction error
*/
function alterColumn($table, $column, $name, $notnull, $oldnotnull, $default, $olddefault,
- $type, $length, $array, $oldtype, $comment) {
+ $type, $length, $array, $oldtype, $comment)
+ {
$this->fieldClean($table);
$this->fieldClean($column);
$this->clean($comment);
- // Initialise an empty SQL string
- $sql = '';
-
+ $toAlter = array();
// Create the command for changing nullability
if ($notnull != $oldnotnull) {
- $sql .= "ALTER TABLE \"{$this->_schema}\".\"{$table}\" ALTER COLUMN \"{$column}\" " . (($notnull) ? 'SET' : 'DROP') . " NOT NULL";
- }
+ $toAlter[] = "ALTER COLUMN \"{$column}\" ". (($notnull) ? 'SET' : 'DROP') . " NOT NULL";
+ }
// Add default, if it has changed
if ($default != $olddefault) {
if ($default == '') {
- if ($sql == '') $sql = "ALTER TABLE \"{$this->_schema}\".\"{$table}\" ";
- else $sql .= ", ";
- $sql .= "ALTER COLUMN \"{$column}\" DROP DEFAULT";
+ $toAlter[] = "ALTER COLUMN \"{$column}\" DROP DEFAULT";
}
else {
- if ($sql == '') $sql = "ALTER TABLE \"{$this->_schema}\".\"{$table}\" ";
- else $sql .= ", ";
- $sql .= "ALTER COLUMN \"{$column}\" SET DEFAULT {$default}";
+ $toAlter[] = "ALTER COLUMN \"{$column}\" SET DEFAULT {$default}";
}
}
if ($array) $ftype .= '[]';
if ($ftype != $oldtype) {
- if ($sql == '') $sql = "ALTER TABLE \"{$this->_schema}\".\"{$table}\" ";
- else $sql .= ", ";
- $sql .= "ALTER COLUMN \"{$column}\" TYPE {$ftype}";
+ $toAlter[] = "ALTER COLUMN \"{$column}\" TYPE {$ftype}";
}
// Begin transaction
}
// Attempt to process the batch alteration, if anything has been changed
- if ($sql != '') {
+ if (!empty($toAlter)) {
+ // Initialise an empty SQL string
+ $sql = "ALTER TABLE \"{$this->_schema}\".\"{$table}\" "
+ . implode(',', $toAlter);
$status = $this->execute($sql);
if ($status != 0) {
$this->rollbackTransaction();
// Update the comment on the column
$status = $this->setComment('COLUMN', $column, $table, $comment);
if ($status != 0) {
- $this->rollbackTransaction();
- return -4;
+ $this->rollbackTransaction();
+ return -5;
}
// Rename the column, if it has been changed
$status = $this->renameColumn($table, $column, $name);
if ($status != 0) {
$this->rollbackTransaction();
- return -3;
+ return -4;
}
}
function hasCreateTableLike() { return true; }
function hasCreateTableLikeWithConstraints() { return true; }
function hasCreateTableLikeWithIndexes() { return true; }
+ function hasCreateFieldWithConstraints() { return true; }
function hasDisableTriggers() { return true; }
function hasAlterDomains() { return true; }
function hasDomainConstraints() { return true; }
function hasWithoutOIDs() { return true; }
function hasAlterDatabase() { return $this->hasAlterDatabaseRename(); }
function hasForeignKeysInfo() { return $this->hasConstraintsInfo(); }
+ function hasMagicTypes() { return true; }
+
}
?>
* @param $oldtype The old type for the column
* @param $comment Comment for the column
* @return 0 success
- * @return -1 set not null error
- * @return -2 set default error
- * @return -3 rename column error
- * @return -4 comment error
+ * @return -2 set not null error
+ * @return -3 set default error
+ * @return -4 rename column error
+ * @return -5 comment error
+ * @return -6 transaction error
*/
function alterColumn($table, $column, $name, $notnull, $oldnotnull, $default, $olddefault,
- $type, $length, $array, $oldtype, $comment) {
- $this->beginTransaction();
+ $type, $length, $array, $oldtype, $comment)
+ {
+ $status = $this->beginTransaction();
+ if ($status != 0) return -1;
// @@ NEED TO HANDLE "NESTED" TRANSACTION HERE
if ($notnull != $oldnotnull) {
$status = $this->setColumnNull($table, $column, !$notnull);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -1;
- }
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -2;
+ }
}
// Set default, if it has changed
if ($default != $olddefault) {
if ($default == '')
$status = $this->dropColumnDefault($table, $column);
- else
+ else
$status = $this->setColumnDefault($table, $column, $default);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -2;
- }
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -3;
+ }
}
// Rename the column, if it has been changed
if ($column != $name) {
$status = $this->renameColumn($table, $column, $name);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -3;
- }
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -4;
+ }
}
// Parameters must be cleaned for the setComment function. It's ok to do
$status = $this->setComment('COLUMN', $name, $table, $comment);
if ($status != 0) {
$this->rollbackTransaction();
- return -4;
+ return -5;
}
return $this->endTransaction();
// Capabilities
function hasAlterColumnType() { return false; }
+ function hasCreateFieldWithConstraints() { return false; }
function hasAlterDatabaseOwner() { return false; }
function hasAlterSchemaOwner() { return false; }
function hasFunctionAlterOwner() { return false; }
function hasNamedParams() { return false; }
function hasSignals() { return false; }
function hasTablespaces() { return false; }
+ function hasMagicTypes() { return false; }
}
?>
echo "<table>\n";
echo "<tr><th class=\"data required\">{$lang['strname']}</th>\n<th colspan=\"2\" class=\"data required\">{$lang['strtype']}</th>\n";
echo "<th class=\"data\">{$lang['strlength']}</th>\n";
- if ($data->hasAlterColumnType())
+ if ($data->hasCreateFieldWithConstraints())
echo "<th class=\"data\">{$lang['strnotnull']}</th>\n<th class=\"data\">{$lang['strdefault']}</th>\n";
echo "<th class=\"data\">{$lang['strcomment']}</th></tr>\n";
htmlspecialchars($_POST['field']), "\" /></td>\n";
echo "<td><select name=\"type\" id=\"type\" onchange=\"checkLengths(document.getElementById('type').value,'');\">\n";
// Output any "magic" types. This came in with the alter column type so we'll check that
- if ($data->hasAlterColumnType()) {
+ if ($data->hasMagicTypes()) {
foreach ($data->extraTypes as $v) {
$types_for_js[] = strtolower($v);
echo "\t<option value=\"", htmlspecialchars($v), "\"",
echo "<td><input name=\"length\" id=\"lengths\" size=\"8\" value=\"",
htmlspecialchars($_POST['length']), "\" /></td>\n";
// Support for adding column with not null and default
- if ($data->hasAlterColumnType()) {
+ if ($data->hasCreateFieldWithConstraints()) {
echo "<td><input type=\"checkbox\" name=\"notnull\"",
(isset($_REQUEST['notnull'])) ? ' checked="checked"' : '', " /></td>\n";
echo "<td><input name=\"default\" size=\"20\" value=\"",
echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
echo $misc->form;
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
- if (!$data->hasAlterColumnType()) {
+ if (!$data->hasCreateFieldWithConstraints()) {
echo "<input type=\"hidden\" name=\"default\" value=\"\" />\n";
}
echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
public function select($selector, $value) {
$this->test('select', $selector, $value);
}
+
+ /**
+ * Add a selenium addSelection test to the file
+ * @param $selector the selector to select the object to work on (second column)
+ * @param $value (optional) the expected (or not) value (third column)
+ */
+ public function addSelection($selector, $value) {
+ $this->test('addSelection', $selector, $value);
+ }
/**
* Add a selenium click test to the file