Several small cleanups found while working on selenium tests
authorGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Sun, 14 Dec 2008 19:28:36 +0000 (14:28 -0500)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Sun, 14 Dec 2008 19:28:36 +0000 (14:28 -0500)
- 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

classes/database/Postgres.php
classes/database/Postgres74.php
tblproperties.php
tests/selenium/testBuilder.class.php

index 0f64514ecfbc6361918c5dd604dca6ac03069c71..2a1cf27df7862646b4ec22c8071b4afe63765df6 100755 (executable)
@@ -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; }
+       
 }
 ?>
index bb65c084b97fbc52a0064cb9da36bddf4fb07ba7..894e1a0cd649f931c098f8bce2573f0aa5a37d2f 100644 (file)
@@ -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; }
 }
 ?>
index a6fa31b98701c6ffa390683ed3481288f2eb9143..e3f6b704f1882ac61579af3509aefa2a97497d67 100644 (file)
                                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";
index 564163a3caf0e70c1511b830b306da438600073f..65a9423faac9417312d7a6faa45d142daa9a188e 100644 (file)
                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