PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #305

_pgFieldFlags() fails for schemas

Details

Submitted2003-11-27 08:28 UTC
Fromsdteffen at web dot de
StatusWont fix
PackageDB
PHP VersionIrrelevant
OSWindows 2000
Roadmaps(Not assigned)

Comments

[2003-11-27 08:28 UTC] sdteffen at web dot de

Description:
------------
_pgFieldFlags() fails when the table name contains a schema,
e.g. test.Table1

Diff against DB-1.5.0RC2.tgz:

--- /c/Program Files/php/pear/DB/pgsql.php 2003-11-27 10:29:52.010464000 +0200
+++ /c/pgsql.php 2003-11-27 10:29:31.991678400 +0200
@@ -571,23 +571,35 @@
function _pgFieldFlags($resource, $num_field, $table_name)
{
$field_name = @pg_fieldname($resource, $num_field);
-
- $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef
- FROM pg_attribute f, pg_class tab, pg_type typ
+ $schema_table = preg_split("/\./", $table_name);
+ if(count($schema_table) == 2) {
+ $table_name_part = $schema_table[1];
+ $schema_name = $schema_table[0];
+ } else {
+ $table_name_part = $table_name;
+ $schema_name = "public";
+ }
+ $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef
+ FROM pg_attribute f, pg_class tab, pg_type typ,
+ pg_namespace schema
WHERE tab.relname = typ.typname
AND typ.typrelid = f.attrelid
AND f.attname = '$field_name'
- AND tab.relname = '$table_name'");
+ AND tab.relname = '$table_name_part'
+ AND tab.relnamespace=schema.oid
+ AND schema.nspname='$schema_name'");
if (@pg_numrows($result) > 0) {
$row = @pg_fetch_row($result, 0);
$flags = ($row[0] == 't') ? 'not_null ' : '';

if ($row[1] == 't') {
$result = @pg_exec($this->connection, "SELECT a.adsrc
- FROM pg_attribute f, pg_class tab, pg_type typ, pg_attrdef a
+ FROM pg_attribute f, pg_class tab, pg_type typ, pg_attrdef a,
+ pg_namespace schema
WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid
AND f.attrelid = a.adrelid AND f.attname = '$field_name'
- AND tab.relname = '$table_name' AND f.attnum = a.adnum");
+ AND tab.relname = '$table_name_part' AND f.attnum = a.adnum
+ AND tab.relnamespace=schema.oid AND schema.nspname='$schema_name'");
$row = @pg_fetch_row($result, 0);
$num = str_replace('\'', '', $row[0]);

@@ -595,12 +607,14 @@
}
}
$result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey
- FROM pg_attribute f, pg_class tab, pg_type typ, pg_index i
+ FROM pg_attribute f, pg_class tab, pg_type typ, pg_index i,
+ pg_namespace schema
WHERE tab.relname = typ.typname
AND typ.typrelid = f.attrelid
AND f.attrelid = i.indrelid
AND f.attname = '$field_name'
- AND tab.relname = '$table_name'");
+ AND tab.relname = '$table_name_part'
+ AND tab.relnamespace=schema.oid AND schema.nspname='$schema_name'");
$count = @pg_numrows($result);

for ($i = 0; $i < $count ; $i++) {

Reproduce code:
---------------
$infoaofa = $dbh->tableInfo("public.test");
print_r($infoaofa);

Expected result:
----------------
Array
(
[0] => Array
(
[table] => public.test
[name] => test
[type] => int4
[len] => 4
[flags] => not_null unique primary
)

)

Actual result:
--------------
testArray
(
[0] => Array
(
[table] => public.test
[name] => test
[type] => int4
[len] => 4
[flags] => not_null
)

)

[2004-06-18 09:21 UTC] s dot ballestrero at firenze dot linux dot it

I STRONGLY disagree with the "Wont fix".
Please see also bug #1607
If you insist on not fixing this in pgsql.php,
please allow me to make a pgsql_schema.php driver that supports schemas on PostgreSQL.