some fix from Kristoffer `spq` Janke
authorioguix <ioguix>
Wed, 20 Feb 2008 21:06:18 +0000 (21:06 +0000)
committerioguix <ioguix>
Wed, 20 Feb 2008 21:06:18 +0000 (21:06 +0000)
CREDITS
classes/database/Postgres74.php
tables.php

diff --git a/CREDITS b/CREDITS
index e93f503c36347f39a5c4174fce573df758b658b5..0092bb5f46cf626bdfbf1ff3fcafb1c8c23bc274 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -64,6 +64,7 @@ Contributors
 - Karl O. Pinc  
 - Tomasz Pala
 - Ivan Zolotukhin 
+- Kristoffer `spq` Janke
 
 Third Party Libraries
 
index 0b87f0adaa02bfcfb01dbacfa56ea72aff145849..1502c21c166ab28411a445b5d5e345a4a7348776 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres74.php,v 1.71 2007/12/28 16:21:25 ioguix Exp $
+ * $Id: Postgres74.php,v 1.72 2008/02/20 21:06:18 ioguix Exp $
  */
 
 include_once('./classes/database/Postgres73.php');
@@ -252,14 +252,21 @@ class Postgres74 extends Postgres73 {
        /**
         * Creates a new table in the database copying attribs and other properties from another table
         * @param $name The name of the table
-        * @param $like The name of the table from which attribs are copying from
+        * @param $like an array giving the schema ans the name of the table from which attribs are copying from:
+        *              array(
+        *                      'table' => table name,
+        *                      'schema' => the schema name,
+        *              )
         * @param $defaults if true, copy the defaults values as well
         * @param $constraints if true, copy the constraints as well (CHECK on table & attr)
         * @param $tablespace The tablespace name ('' means none/default)
         */
        function createTableLike($name, $like, $defaults = false, $constraints = false, $idx = false, $tablespace = '') {
                $this->fieldClean($name);
-               $this->fieldClean($like);
+
+               $this->fieldClean($like['schema']);
+               $this->fieldClean($like['table']);
+               $like = "\"{$like['schema']}\".\"{$like['table']}\"";
 
                $status = $this->beginTransaction();
                if ($status != 0) return -1;
index c9190261cb1e91f3f27f8ba38940376bb62d8f0a..24d0c660819db19182b53058926bec05e68eee81 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.109 2008/01/14 17:55:01 ioguix Exp $
+        * $Id: tables.php,v 1.110 2008/02/20 21:06:18 ioguix Exp $
         */
 
        // Include application functions
@@ -62,7 +62,7 @@
                                        while (!$tablespaces->EOF) {
                                                $spcname = htmlspecialchars($tablespaces->fields['spcname']);
                                                echo "\t\t\t\t<option value=\"{$spcname}\"",
-                                                       ($spcname == $_REQUEST['spcname']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
+                                                       ($tablespaces->fields['spcname'] == $_REQUEST['spcname']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
                                                $tablespaces->moveNext();
                                        }
                                        echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
 
        /**
         * Dsiplay a screen where user can create a table from an existing one.
+        * We don't have to check if pg supports schema cause create table like
+        * is available under pg 7.4+ which has schema.
         */
        function doCreateLike($confirm, $msg = '') {
                global $data, $misc, $lang;
                        $tbltmp = $tbltmp->getArray();
 
                        $tables = array();
-                       if ( $data->hasSchemas() )
-                               foreach ($tbltmp as $a) $tables["{$a['nspname']}.{$a['relname']}"] = "{$a['nspname']}.{$a['relname']}";
-                       else
-                               foreach ($tbltmp as $a) $tables[$a['relname']] = $a['relname'];
+                       foreach ($tbltmp as $a) {
+                               $data->fieldClean($a['nspname']);
+                               $data->fieldClean($a['relname']);
+                               $tables["\"{$a['nspname']}\".\"{$a['relname']}\""] = serialize(array('schema' => $a['nspname'], 'table' => $a['relname']));
+                       }
 
                        unset($tbltmp);
 
                                isset($_REQUEST['withdefaults']) ? ' checked="checked"' : '',
                                "/>{$lang['strcreatelikewithdefaults']}</label>";
                        if ($data->hasCreateTableLikeWithConstraints()) {
-                               echo "<label for=\"withconstraints\"><input type=\"checkbox\" id=\"withconstraints\" name=\"withconstraints\"",
+                               echo "<br /><label for=\"withconstraints\"><input type=\"checkbox\" id=\"withconstraints\" name=\"withconstraints\"",
                                        isset($_REQUEST['withconstraints']) ? ' checked="checked"' : '',
                                        "/>{$lang['strcreatelikewithconstraints']}</label>";
                        }
                        if ($data->hasCreateTableLikeWithIndexes()) {
-                               echo "<label for=\"withindexes\"><input type=\"checkbox\" id=\"withindexes\" name=\"withindexes\"",
+                               echo "<br /><label for=\"withindexes\"><input type=\"checkbox\" id=\"withindexes\" name=\"withindexes\"",
                                        isset($_REQUEST['withindexes']) ? ' checked="checked"' : '',
                                        "/>{$lang['strcreatelikewithindexes']}</label>";
                        }
 
                        if (!isset($_REQUEST['tablespace'])) $_REQUEST['tablespace'] = '';
 
-                       $status = $data->createTableLike($_REQUEST['name'], $_REQUEST['like'], isset($_REQUEST['withdefaults']),
-                               isset($_REQUEST['withconstraints']), isset($_REQUEST['withindexes']), $_REQUEST['tablespace']);
+                       $status = $data->createTableLike($_REQUEST['name'], unserialize($_REQUEST['like']), isset($_REQUEST['withdefaults']),
+                               isset($_REQUEST['withconstraints']), isset($_REQUEST['withindexes']), $_REQUEST['tablespace']);
+                               
                        if ($status == 0) {
                                $_reload_browser = true;
                                doDefault($lang['strtablecreated']);