13 var
$metaDatabasesSQL =
"select datname from pg_database where datname not in ('template0','template1') order by 1";
14 var
$metaTablesSQL =
"select tablename,'T' from pg_tables where tablename not like 'pg\_%' 15 and tablename not in ('sql_features', 'sql_implementation_info', 'sql_languages', 16 'sql_packages', 'sql_sizing', 'sql_sizing_profiles') 18 select viewname,'V' from pg_views where viewname not like 'pg\_%'";
24 var
$metaColumnsSQL =
"SELECT a.attname,t.typname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,a.attnum 25 FROM pg_class c, pg_attribute a,pg_type t 26 WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) and a.attname not like '....%%' 27 AND a.attnum > 0 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum";
30 var
$metaColumnsSQL1 =
"SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum 31 FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n 32 WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) 33 and c.relnamespace=n.oid and n.nspname='%s' 34 and a.attname not like '....%%' AND a.attnum > 0 35 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum";
38 var
$metaKeySQL =
"SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key 39 FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'";
53 var
$metaDefaultsSQL =
"SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum";
60 $parentDriver->hasTransactions =
false; ## <<< BUG IN PDO pgsql driver
61 $parentDriver->hasInsertID =
true;
62 $parentDriver->_nestedSQL =
true;
67 $arr[
'description'] = ADOConnection::GetOne(
"select version()");
68 $arr[
'version'] = ADOConnection::_findvers($arr[
'description']);
74 $offsetStr = ($offset >= 0) ?
" OFFSET $offset" :
'';
75 $limitStr = ($nrows >= 0) ?
" LIMIT $nrows" :
'';
77 $rs = $this->CacheExecute($secs2cache,
$sql.
"$limitStr$offsetStr",$inputarr);
79 $rs = $this->Execute(
$sql.
"$limitStr$offsetStr",$inputarr);
84 function MetaTables($ttype=
false,$showSchema=
false,$mask=
false)
87 if ($info[
'version'] >= 7.3) {
88 $this->metaTablesSQL =
"select tablename,'T' from pg_tables where tablename not like 'pg\_%' 89 and schemaname not in ( 'pg_catalog','information_schema') 91 select viewname,'V' from pg_views where viewname not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema') ";
95 $mask = $this->qstr(strtolower($mask));
96 if ($info[
'version']>=7.3)
97 $this->metaTablesSQL =
" 98 select tablename,'T' from pg_tables where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema') 100 select viewname,'V' from pg_views where viewname like $mask and schemaname not in ( 'pg_catalog','information_schema') ";
102 $this->metaTablesSQL =
" 103 select tablename,'T' from pg_tables where tablename like $mask 105 select viewname,'V' from pg_views where viewname like $mask";
107 $ret = ADOConnection::MetaTables($ttype,$showSchema);
110 $this->metaTablesSQL = $save;
117 global $ADODB_FETCH_MODE;
120 $this->_findschema($table,$schema);
122 if ($normalize) $table = strtolower($table);
124 $save = $ADODB_FETCH_MODE;
125 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
126 if ($this->fetchMode !==
false) $savem = $this->SetFetchMode(
false);
128 if ($schema)
$rs = $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema));
129 else $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
130 if (isset($savem)) $this->SetFetchMode($savem);
131 $ADODB_FETCH_MODE = $save;
137 if (!empty($this->metaKeySQL)) {
143 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
145 $rskey = $this->Execute(sprintf($this->metaKeySQL,($table)));
147 $keys = $rskey->GetArray();
148 if (isset($savem)) $this->SetFetchMode($savem);
149 $ADODB_FETCH_MODE = $save;
156 if (!empty($this->metaDefaultsSQL)) {
157 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
158 $sql = sprintf($this->metaDefaultsSQL, ($table));
159 $rsdef = $this->Execute(
$sql);
160 if (isset($savem)) $this->SetFetchMode($savem);
161 $ADODB_FETCH_MODE = $save;
164 while (!$rsdef->EOF) {
165 $num = $rsdef->fields[
'num'];
166 $s = $rsdef->fields[
'def'];
167 if (strpos($s,
'::')===
false && substr($s, 0, 1) ==
"'") {
169 $s = substr($s, 0, strlen($s) - 1);
176 ADOConnection::outp(
"==> SQL => " .
$sql);
183 $fld =
new ADOFieldObject();
184 $fld->name =
$rs->fields[0];
185 $fld->type =
$rs->fields[1];
186 $fld->max_length =
$rs->fields[2];
187 if ($fld->max_length <= 0) $fld->max_length =
$rs->fields[3]-4;
188 if ($fld->max_length <= 0) $fld->max_length = -1;
189 if ($fld->type ==
'numeric') {
190 $fld->scale = $fld->max_length & 0xFFFF;
191 $fld->max_length >>= 16;
195 $fld->has_default = (
$rs->fields[5] ==
't');
196 if ($fld->has_default) {
197 $fld->default_value = $rsdefa[
$rs->fields[6]];
201 if (
$rs->fields[4] == $this->true) {
202 $fld->not_null =
true;
206 if (is_array($keys)) {
207 foreach($keys as $key) {
208 if ($fld->name == $key[
'column_name'] AND $key[
'primary_key'] == $this->true)
209 $fld->primary_key =
true;
210 if ($fld->name == $key[
'column_name'] AND $key[
'unique_key'] == $this->true)
215 if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
216 else $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld;
221 if (empty($retarr)) {
224 }
else return $retarr;
$concat_operator
random function
SelectLimit($sql, $nrows=-1, $offset=-1, $inputarr=false, $secs2cache=0)
if(isset($_REQUEST['nrows'])) else $rs
MetaColumns($table, $normalize=true)
MetaTables($ttype=false, $showSchema=false, $mask=false)