fix bug where default and not null clauses were being ignored in add column for 8.0
authorchriskl <chriskl>
Tue, 2 Nov 2004 03:33:35 +0000 (03:33 +0000)
committerchriskl <chriskl>
Tue, 2 Nov 2004 03:33:35 +0000 (03:33 +0000)
classes/database/Postgres.php
tblproperties.php

index c897b49cbced7fba5ef960ea7dc009d40dd51ecf..4d07fe43affbcb6b50c5c1d46424f0a9f5633d3b 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.248 2004/10/11 10:27:33 jollytoad Exp $
+ * $Id: Postgres.php,v 1.249 2004/11/02 03:33:35 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1302,10 +1302,12 @@ class Postgres extends ADODB_base {
         * @param $column The name of the new column
         * @param $type The type of the column
         * @param $array True if array type, false otherwise
+        * @param $notnull True if NOT NULL, false otherwise
+        * @param $default The default for the column.  '' for none.
         * @param $length The optional size of the column (ie. 30 for varchar(30))
         * @return 0 success
         */
-       function addColumn($table, $column, $type, $array, $length, $comment) {
+       function addColumn($table, $column, $type, $array, $length, $notnull, $default, $comment) {
                $this->fieldClean($table);
                $this->fieldClean($column);
                $this->clean($type);
@@ -1335,6 +1337,15 @@ class Postgres extends ADODB_base {
                
                // Add array qualifier, if requested
                if ($array) $sql .= '[]';
+               
+               // If we have advanced column adding, add the extra qualifiers
+               if ($this->hasAlterColumnType()) {
+                       // NOT NULL clause
+                       if ($notnull) $sql .= ' NOT NULL';
+                       
+                       // DEFAULT clause
+                       if ($default != '') $sql .= ' DEFAULT ' . $default;
+               }
 
                $status = $this->beginTransaction();
                if ($status != 0) return -1;
index d89d42ec00f897c98833356a02cc0dd95fb334af..a11982dd524dfaae3a7443bc8492bcae11824a95 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tblproperties.php,v 1.61 2004/09/07 13:58:21 jollytoad Exp $
+        * $Id: tblproperties.php,v 1.62 2004/11/02 03:33:35 chriskl Exp $
         */
 
        // Include application functions
                                        echo "<td><input name=\"default\" size=\"20\" value=\"",
                                                htmlspecialchars($_POST['default']), "\" /></td>";
                                }
+                               else {
+                                       echo "<input type=\"hidden\" name=\"default\" value=\"\" />\n"; 
+                               }
                                echo "<td><input name=\"comment\" size=\"40\" value=\"",
                                        htmlspecialchars($_POST['comment']), "\" /></td></tr>";
                                echo "</table>\n";
                                        doAddColumn($lang['strcolneedsname']);
                                        return;
                                }
-                               
+
                                $status = $data->addColumn($_POST['table'], $_POST['field'],
-                                                          $_POST['type'], $_POST['array'] != '', $_POST['length'], $_POST['comment']);
+                                                          $_POST['type'], $_POST['array'] != '', $_POST['length'], isset($_POST['notnull']),
+                                                          $_POST['default'], $_POST['comment']);
                                if ($status == 0)
                                        doDefault($lang['strcolumnadded']);
                                else {