00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 require_once 'creole/metadata/DatabaseInfo.php';
00023
00031 class PgSQLDatabaseInfo extends DatabaseInfo {
00032
00037 protected function initTables()
00038 {
00039 include_once 'creole/drivers/pgsql/metadata/PgSQLTableInfo.php';
00040
00041
00042
00043 $result = pg_query ($this->conn->getResource(), "SELECT version() as ver");
00044
00045 if (!$result)
00046 {
00047 throw new SQLException ("Failed to select database version");
00048 }
00049 $row = pg_fetch_assoc ($result, 0);
00050 $arrVersion = sscanf ($row['ver'], '%*s %d.%d');
00051 $version = sprintf ("%d.%d", $arrVersion[0], $arrVersion[1]);
00052
00053 $arrVersion = null;
00054 $row = null;
00055 pg_free_result ($result);
00056 $result = null;
00057
00058 $result = pg_query($this->conn->getResource(), "SELECT c.oid,
00059 case when n.nspname='public' then c.relname else n.nspname||'.'||c.relname end as relname
00060 FROM pg_class c join pg_namespace n on (c.relnamespace=n.oid)
00061 WHERE c.relkind = 'r'
00062 AND n.nspname NOT IN ('information_schema','pg_catalog')
00063 AND n.nspname NOT LIKE 'pg_temp%'
00064 AND n.nspname NOT LIKE 'pg_toast%'
00065 ORDER BY relname");
00066
00067 if (!$result) {
00068 throw new SQLException("Could not list tables", pg_last_error($this->dblink));
00069 }
00070
00071 while ($row = pg_fetch_assoc($result)) {
00072 $this->tables[strtoupper($row['relname'])] = new PgSQLTableInfo($this, $row['relname'], $version, $row['oid']);
00073 }
00074
00075 $this->tablesLoaded = true;
00076 }
00077
00084 protected function initSequences()
00085 {
00086
00087 $this->sequences = array();
00088
00089 $result = pg_query($this->conn->getResource(), "SELECT c.oid,
00090 case when n.nspname='public' then c.relname else n.nspname||'.'||c.relname end as relname
00091 FROM pg_class c join pg_namespace n on (c.relnamespace=n.oid)
00092 WHERE c.relkind = 'S'
00093 AND n.nspname NOT IN ('information_schema','pg_catalog')
00094 AND n.nspname NOT LIKE 'pg_temp%'
00095 AND n.nspname NOT LIKE 'pg_toast%'
00096 ORDER BY name");
00097
00098 if (!$result) {
00099 throw new SQLException("Could not list sequences", pg_last_error($this->dblink));
00100 }
00101
00102 while ($row = pg_fetch_assoc($result)) {
00103
00104 $obj = new stdClass;
00105 $obj->name = $row['relname'];
00106 $obj->oid = $row['oid'];
00107 $this->sequences[strtoupper($row['relname'])] = $obj;
00108 }
00109
00110 }
00111
00112 }
00113