RES: [PEAR-DEV] Namespace (schema name) in DB (ERROR)

From: Date: Tue, 09 Dec 2003 17:57:17 +0000
Subject: RES: [PEAR-DEV] Namespace (schema name) in DB (ERROR)
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-24313@lists.php.net to get a copy of this message
Another problem : Hello, When I use schema name in DB, occurrs various errors. Then, see the modifications bellow: DB/pgsql.php function _pgFieldFlags($resource, $num_field, $table_name) { /*********************************************/ $table_name_part = explode('.', $table_name); if(sizeof($table_name_part) == 2) { $table_name_nonamespace = $table_name_part[1]; } else { $table_name_nonamespace = $table_name_part[0]; } /*********************************************/ $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 WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid AND f.attname = '$field_name' /*********************************************/ AND tab.relname = '$table_name_nonamespace'"); /*********************************************/ DB/common.php : (Original version replace dot with '_' this is an error, because postgres uses schema.sequence_name) function getSequenceName($sqn) { /*************************************************************************** *********************************/ return sprintf($this->getOption("seqname_format"), preg_replace('/[^a-z0-9._]/i', '_', $sqn)); /*************************************************************************** *********************************/ } DB/pgsql.php : /** * Returns the query needed to get some backend info * @param string $type What kind of info you want to retrieve * @return string The SQL query string */ function getSpecialQuery($type) { switch ($type) { /*************************************************************************** *********************************/ /*START BUG : TOGO MODIFICATION!!! */ case 'tables': { $sql = "SELECT n.nspname || '.' || c.relname as \"Name\" FROM pg_class c, pg_user u, pg_namespace n WHERE c.relnamespace = n.oid AND c.relowner = u.usesysid AND c.relkind = 'r' AND not exists (select 1 from pg_views where viewname = c.relname) AND c.relname !~ '^pg_' UNION SELECT c.relname as \"Name\" FROM pg_class c WHERE c.relkind = 'r' AND not exists (select 1 from pg_views where viewname = c.relname) AND not exists (select 1 from pg_user where usesysid = c.relowner) AND c.relname !~ '^pg_'"; break; } /*END BUG : TOGO MODIFICATION!!! */ /*************************************************************************** *********************************/ case 'views': { // Table cols: viewname | viewowner | definition $sql = "SELECT viewname FROM pg_views"; break; } case 'users': { // cols: usename |usesysid|usecreatedb|usetrace|usesuper|usecatupd|passwd |valuntil $sql = 'SELECT usename FROM pg_user'; break; } case 'databases': { $sql = 'SELECT datname FROM pg_database'; break; } case 'functions': { $sql = 'SELECT proname FROM pg_proc'; break; } default: return null; } return $sql; } // }}} } Thanks, Rodrigo Carvalho Rezende http://www.togoworks.com/ -- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pear.dev (#24313) next »