diff options
author | Guillaume (ioguix) de Rorthais | 2008-12-14 19:28:36 +0000 |
---|---|---|
committer | Guillaume (ioguix) de Rorthais | 2008-12-14 19:28:36 +0000 |
commit | 860e07d6dd52ae5e9015decb54ae5f95605cf415 (patch) | |
tree | 02d6fb4594548cf602d6d3fa8ddf2e2e4022b584 | |
parent | ea3f6cdbfe43b5d7d357b7e8d8258db25ba90a7b (diff) |
Several small cleanups found while working on selenium tests
- add method hasMagicTypes instead of using confusing hasAlterColumnType
- add method hasCreateFieldWithConstraints insead of using confusing hasAlterColumnType
- fix some bad indentation
- fix non uniform values returned from alterColumn
- refactor the way alterColumn is bulding its request
- add method addSelection the the testBuilder class
-rwxr-xr-x | classes/database/Postgres.php | 43 | ||||
-rw-r--r-- | classes/database/Postgres74.php | 45 | ||||
-rw-r--r-- | tblproperties.php | 8 | ||||
-rw-r--r-- | tests/selenium/testBuilder.class.php | 9 |
4 files changed, 59 insertions, 46 deletions
diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 0f64514e..2a1cf27d 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -2054,7 +2054,7 @@ class Postgres extends ADODB_base { 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'; @@ -2096,35 +2096,30 @@ class Postgres extends ADODB_base { * @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}"; } } @@ -2154,9 +2149,7 @@ class Postgres extends ADODB_base { 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 @@ -2167,7 +2160,10 @@ class Postgres extends ADODB_base { } // 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(); @@ -2178,8 +2174,8 @@ class Postgres extends ADODB_base { // 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 @@ -2187,7 +2183,7 @@ class Postgres extends ADODB_base { $status = $this->renameColumn($table, $column, $name); if ($status != 0) { $this->rollbackTransaction(); - return -3; + return -4; } } @@ -7400,6 +7396,7 @@ class Postgres extends ADODB_base { 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; } @@ -7440,5 +7437,7 @@ class Postgres extends ADODB_base { function hasWithoutOIDs() { return true; } function hasAlterDatabase() { return $this->hasAlterDatabaseRename(); } function hasForeignKeysInfo() { return $this->hasConstraintsInfo(); } + function hasMagicTypes() { return true; } + } ?> diff --git a/classes/database/Postgres74.php b/classes/database/Postgres74.php index bb65c084..894e1a0c 100644 --- a/classes/database/Postgres74.php +++ b/classes/database/Postgres74.php @@ -156,44 +156,47 @@ class Postgres74 extends Postgres80 { * @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 @@ -204,7 +207,7 @@ class Postgres74 extends Postgres80 { $status = $this->setComment('COLUMN', $name, $table, $comment); if ($status != 0) { $this->rollbackTransaction(); - return -4; + return -5; } return $this->endTransaction(); @@ -333,11 +336,13 @@ class Postgres74 extends Postgres80 { // 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; } } ?> diff --git a/tblproperties.php b/tblproperties.php index a6fa31b9..e3f6b704 100644 --- a/tblproperties.php +++ b/tblproperties.php @@ -270,7 +270,7 @@ 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"; @@ -278,7 +278,7 @@ 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), "\"", @@ -309,7 +309,7 @@ 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=\"", @@ -322,7 +322,7 @@ 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"; diff --git a/tests/selenium/testBuilder.class.php b/tests/selenium/testBuilder.class.php index 564163a3..65a9423f 100644 --- a/tests/selenium/testBuilder.class.php +++ b/tests/selenium/testBuilder.class.php @@ -108,6 +108,15 @@ 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 |