fix bug in create table, thanks Dew
authorchriskl <chriskl>
Thu, 3 Jun 2004 03:48:21 +0000 (03:48 +0000)
committerchriskl <chriskl>
Thu, 3 Jun 2004 03:48:21 +0000 (03:48 +0000)
HISTORY
classes/database/Postgres.php

diff --git a/HISTORY b/HISTORY
index 80ea9bda657d4fcda86646e8c64d3c7f3d160030..093edf9adde83c00f0af2fae03d0d818969bb7d4 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -44,6 +44,8 @@ Bugs
 * Fix Find for domain constraints
 * Fix popup SQL window so that two different phpPgAdmin instances should
   not want to use the same pop-up.
+* Fix create table if you don't supply as many fields as you originally
+  specified.
 
 Translations
 * Trad. Chinese from Chih-Hsin Lee
index 54a71a7fda461557bfe6c613f1677e7550335654..eb50e44d71e0c48273d6f99cf7992200057cd9c0 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.218 2004/05/28 08:17:22 chriskl Exp $
+ * $Id: Postgres.php,v 1.219 2004/06/03 03:48:22 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1197,6 +1197,7 @@ class Postgres extends BaseDB {
                if ($status != 0) return -1;
 
                $found = false;
+               $first = true;
                $comment_sql = ''; //Accumulate comments for the columns
                $sql = "CREATE TABLE \"{$name}\" (";
                for ($i = 0; $i < $fields; $i++) {
@@ -1207,6 +1208,9 @@ class Postgres extends BaseDB {
 
                        // Skip blank columns - for user convenience
                        if ($field[$i] == '' || $type[$i] == '') continue;
+                       // If not the first column, add a comma
+                       if (!$first) $sql .= ", ";
+                       else $first = false;
                        
                        switch ($type[$i]) {
                                // Have to account for weird placing of length for with/without
@@ -1234,7 +1238,6 @@ class Postgres extends BaseDB {
                        // Add other qualifiers
                        if (isset($notnull[$i])) $sql .= " NOT NULL";
                        if ($default[$i] != '') $sql .= " DEFAULT {$default[$i]}";
-                       if ($i != $fields - 1) $sql .= ", ";
 
                        if ($colcomment[$i] != '') $comment_sql .= "COMMENT ON COLUMN \"{$name}\".\"{$field[$i]}\" IS '{$colcomment[$i]}';\n";