Move overriding method getConstraintsWithFields to the class it really belongs
authorGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Mon, 27 Sep 2010 22:34:33 +0000 (00:34 +0200)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Mon, 27 Sep 2010 22:34:33 +0000 (00:34 +0200)
Method getConstraintsWithFields from Postgres.php is compatible down to 8.1,
so the version from Postgre81 must go to Postgres80 wich is actually not
compatible with the first one.

classes/database/Postgres80.php
classes/database/Postgres81.php

index 860f56b62b3c731c827f2f75b6e89a1bfe3e816e..b6a6b02b0606614208515383a4befdfdc3fba57e 100644 (file)
@@ -165,6 +165,70 @@ class Postgres80 extends Postgres81 {
                return 0;
        }
 
+
+       // Constraint functions
+
+       /**
+        * Returns a list of all constraints on a table,
+        * including constraint name, definition, related col and referenced namespace,
+        * table and col if needed
+        * @param $table the table where we are looking for fk
+        * @return a recordset
+        */
+       function getConstraintsWithFields($table) {
+               global $data;
+
+               $c_schema = $this->_schema;
+               $this->clean($c_schema);
+               $data->clean($table);
+
+               // get the max number of col used in a constraint for the table
+               $sql = "SELECT DISTINCT
+                       max(SUBSTRING(array_dims(c.conkey) FROM '^\\\[.*:(.*)\\\]$')) as nb
+               FROM pg_catalog.pg_constraint AS c
+                       JOIN pg_catalog.pg_class AS r ON (c.conrelid=r.oid)
+                   JOIN pg_catalog.pg_namespace AS ns ON (r.relnamespace=ns.oid)
+               WHERE
+                       r.relname = '{$table}' AND ns.nspname='{$c_schema}'";
+
+               $rs = $this->selectSet($sql);
+
+               if ($rs->EOF) $max_col = 0;
+               else $max_col = $rs->fields['nb'];
+
+               $sql = '
+                       SELECT
+                               c.oid AS conid, c.contype, c.conname, pg_catalog.pg_get_constraintdef(c.oid, true) AS consrc,
+                               ns1.nspname as p_schema, r1.relname as p_table, ns2.nspname as f_schema,
+                               r2.relname as f_table, f1.attname as p_field, f1.attnum AS p_attnum, f2.attname as f_field,
+                               f2.attnum AS f_attnum, pg_catalog.obj_description(c.oid, \'pg_constraint\') AS constcomment,
+                               c.conrelid, c.confrelid
+                       FROM
+                               pg_catalog.pg_constraint AS c
+                               JOIN pg_catalog.pg_class AS r1 ON (c.conrelid=r1.oid)
+                               JOIN pg_catalog.pg_attribute AS f1 ON (f1.attrelid=r1.oid AND (f1.attnum=c.conkey[1]';
+               for ($i = 2; $i <= $rs->fields['nb']; $i++) {
+                       $sql.= " OR f1.attnum=c.conkey[$i]";
+               }
+               $sql.= '))
+                               JOIN pg_catalog.pg_namespace AS ns1 ON r1.relnamespace=ns1.oid
+                               LEFT JOIN (
+                                       pg_catalog.pg_class AS r2 JOIN pg_catalog.pg_namespace AS ns2 ON (r2.relnamespace=ns2.oid)
+                               ) ON (c.confrelid=r2.oid)
+                               LEFT JOIN pg_catalog.pg_attribute AS f2 ON
+                                       (f2.attrelid=r2.oid AND ((c.confkey[1]=f2.attnum AND c.conkey[1]=f1.attnum)';
+               for ($i = 2; $i <= $rs->fields['nb']; $i++)
+                       $sql.= "OR (c.confkey[$i]=f2.attnum AND c.conkey[$i]=f1.attnum)";
+
+               $sql .= sprintf("))
+                       WHERE
+                               r1.relname = '%s' AND ns1.nspname='%s'
+                       ORDER BY 1", $table, $c_schema);
+
+               return $this->selectSet($sql);
+       }
+
+
        // View functions
 
        /**
index 91fa2aa717a39af6016865e607b4bfe39ee83d03..71584d516ccd87f8acffd1a666b51778eb271516 100644 (file)
@@ -134,72 +134,8 @@ class Postgres81 extends Postgres82 {
                if ($status != 0) {
                        $this->rollbackTransaction();
                        return -2;
-       }
-               return $this->endTransaction();
-       }
-
-       // Constraint functions
-
-       /**
-        * Returns a list of all constraints on a table,
-        * including constraint name, definition, related col and referenced namespace,
-        * table and col if needed
-        * @param $table the table where we are looking for fk
-        * @return a recordset
-        */
-       function getConstraintsWithFields($table) {
-               global $data;
-
-               $c_schema = $this->_schema;
-               $this->clean($c_schema);
-               $data->clean($table);
-
-               // get the max number of col used in a constraint for the table
-               $sql = "SELECT DISTINCT
-                               max(SUBSTRING(array_dims(c.conkey) FROM  '^\\\[.*:(.*)\\\]$')) as nb
-               FROM
-                     pg_catalog.pg_constraint AS c
-                 JOIN pg_catalog.pg_class AS r ON (c.conrelid = r.oid)
-                     JOIN pg_catalog.pg_namespace AS ns ON r.relnamespace=ns.oid
-               WHERE
-                       r.relname = '{$table}' AND ns.nspname='{$c_schema}'";
-
-               $rs = $this->selectSet($sql);
-
-               if ($rs->EOF) $max_col = 0;
-               else $max_col = $rs->fields['nb'];
-
-               $sql = '
-                       SELECT
-                               c.oid AS conid, c.contype, c.conname, pg_catalog.pg_get_constraintdef(c.oid,true) AS consrc,
-                               ns1.nspname as p_schema, r1.relname as p_table, ns2.nspname as f_schema,
-                               r2.relname as f_table, f1.attname as p_field, f1.attnum AS p_attnum,
-                               f2.attname as f_field, f2.attnum AS f_attnum,
-                               pg_catalog.obj_description(c.oid, \'pg_constraint\') AS constcomment,
-                               confrelid
-                       FROM
-                               pg_catalog.pg_constraint AS c
-                               JOIN pg_catalog.pg_class AS r1 ON (c.conrelid=r1.oid)
-                               JOIN pg_catalog.pg_attribute AS f1 ON (f1.attrelid=r1.oid AND (f1.attnum=c.conkey[1]';
-               for ($i = 2; $i <= $rs->fields['nb']; $i++) {
-                       $sql.= " OR f1.attnum=c.conkey[$i]";
                }
-               $sql.= '))
-                               JOIN pg_catalog.pg_namespace AS ns1 ON r1.relnamespace=ns1.oid
-                               LEFT JOIN (
-                                       pg_catalog.pg_class AS r2 JOIN pg_catalog.pg_namespace AS ns2 ON (r2.relnamespace=ns2.oid)
-                               ) ON (c.confrelid=r2.oid)
-                               LEFT JOIN pg_catalog.pg_attribute AS f2 ON
-                                       (f2.attrelid=r2.oid AND ((c.confkey[1]=f2.attnum AND c.conkey[1]=f1.attnum)';
-               for ($i = 2; $i <= $rs->fields['nb']; $i++)
-                       $sql.= "OR (c.confkey[$i]=f2.attnum AND c.conkey[$i]=f1.attnum)";
-
-               $sql .= sprintf("))
-                       WHERE
-                               r1.relname = '%s' AND ns1.nspname='%s'
-                       ORDER BY 1", $table, $c_schema);
-
-               return $this->selectSet($sql);
+               return $this->endTransaction();
        }
 
        // Tablespace functions