forked from Cavemanon/cavepaintings
adodb updates
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||
V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
@@ -58,7 +58,7 @@ class ADODB_mysql extends ADOConnection {
|
||||
}
|
||||
|
||||
|
||||
function &MetaTables($ttype=false,$showSchema=false,$mask=false)
|
||||
function MetaTables($ttype=false,$showSchema=false,$mask=false)
|
||||
{
|
||||
$save = $this->metaTablesSQL;
|
||||
if ($showSchema && is_string($showSchema)) {
|
||||
@@ -69,14 +69,14 @@ class ADODB_mysql extends ADOConnection {
|
||||
$mask = $this->qstr($mask);
|
||||
$this->metaTablesSQL .= " like $mask";
|
||||
}
|
||||
$ret =& ADOConnection::MetaTables($ttype,$showSchema);
|
||||
$ret = ADOConnection::MetaTables($ttype,$showSchema);
|
||||
|
||||
$this->metaTablesSQL = $save;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
function &MetaIndexes ($table, $primary = FALSE, $owner=false)
|
||||
function MetaIndexes ($table, $primary = FALSE, $owner=false)
|
||||
{
|
||||
// save old fetch mode
|
||||
global $ADODB_FETCH_MODE;
|
||||
@@ -132,6 +132,7 @@ class ADODB_mysql extends ADOConnection {
|
||||
// if magic quotes disabled, use mysql_real_escape_string()
|
||||
function qstr($s,$magic_quotes=false)
|
||||
{
|
||||
if (is_null($s)) return 'NULL';
|
||||
if (!$magic_quotes) {
|
||||
|
||||
if (ADODB_PHPVER >= 0x4300) {
|
||||
@@ -157,11 +158,12 @@ class ADODB_mysql extends ADOConnection {
|
||||
|
||||
function GetOne($sql,$inputarr=false)
|
||||
{
|
||||
global $ADODB_GETONE_EOF;
|
||||
if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
|
||||
$rs =& $this->SelectLimit($sql,1,-1,$inputarr);
|
||||
$rs = $this->SelectLimit($sql,1,-1,$inputarr);
|
||||
if ($rs) {
|
||||
$rs->Close();
|
||||
if ($rs->EOF) return false;
|
||||
if ($rs->EOF) return $ADODB_GETONE_EOF;
|
||||
return reset($rs->fields);
|
||||
}
|
||||
} else {
|
||||
@@ -180,10 +182,11 @@ class ADODB_mysql extends ADOConnection {
|
||||
return mysql_affected_rows($this->_connectionID);
|
||||
}
|
||||
|
||||
// See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
|
||||
// See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
|
||||
// Reference on Last_Insert_ID on the recommended way to simulate sequences
|
||||
var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
|
||||
var $_genSeqSQL = "create table %s (id int not null)";
|
||||
var $_genSeqCountSQL = "select count(*) from %s";
|
||||
var $_genSeq2SQL = "insert into %s values (%s)";
|
||||
var $_dropSeqSQL = "drop table %s";
|
||||
|
||||
@@ -212,18 +215,22 @@ class ADODB_mysql extends ADOConnection {
|
||||
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
|
||||
$u = strtoupper($seqname);
|
||||
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
|
||||
$this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
|
||||
$cnt = $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
|
||||
if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
|
||||
$rs = $this->Execute($getnext);
|
||||
}
|
||||
$this->genID = mysql_insert_id($this->_connectionID);
|
||||
|
||||
if ($rs) $rs->Close();
|
||||
if ($rs) {
|
||||
$this->genID = mysql_insert_id($this->_connectionID);
|
||||
$rs->Close();
|
||||
} else
|
||||
$this->genID = 0;
|
||||
|
||||
$this->_logsql = $savelog;
|
||||
return $this->genID;
|
||||
}
|
||||
|
||||
function &MetaDatabases()
|
||||
function MetaDatabases()
|
||||
{
|
||||
$qid = mysql_list_dbs($this->_connectionID);
|
||||
$arr = array();
|
||||
@@ -343,7 +350,7 @@ class ADODB_mysql extends ADOConnection {
|
||||
if (!$date) $date = $this->sysDate;
|
||||
|
||||
$fraction = $dayFraction * 24 * 3600;
|
||||
return $date . ' + INTERVAL ' . $fraction.' SECOND';
|
||||
return '('. $date . ' + INTERVAL ' . $fraction.' SECOND)';
|
||||
|
||||
// return "from_unixtime(unix_timestamp($date)+$fraction)";
|
||||
}
|
||||
@@ -388,7 +395,7 @@ class ADODB_mysql extends ADOConnection {
|
||||
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
|
||||
}
|
||||
|
||||
function &MetaColumns($table)
|
||||
function MetaColumns($table, $normalize=true)
|
||||
{
|
||||
$this->_findschema($table,$schema);
|
||||
if ($schema) {
|
||||
@@ -441,9 +448,10 @@ class ADODB_mysql extends ADOConnection {
|
||||
$fld->not_null = ($rs->fields[2] != 'YES');
|
||||
$fld->primary_key = ($rs->fields[3] == 'PRI');
|
||||
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
|
||||
$fld->binary = (strpos($type,'blob') !== false);
|
||||
$fld->binary = (strpos($type,'blob') !== false || strpos($type,'binary') !== false);
|
||||
$fld->unsigned = (strpos($type,'unsigned') !== false);
|
||||
|
||||
$fld->zerofill = (strpos($type,'zerofill') !== false);
|
||||
|
||||
if (!$fld->binary) {
|
||||
$d = $rs->fields[4];
|
||||
if ($d != '' && $d != 'NULL') {
|
||||
@@ -478,21 +486,21 @@ class ADODB_mysql extends ADOConnection {
|
||||
}
|
||||
|
||||
// parameters use PostgreSQL convention, not MySQL
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
|
||||
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
|
||||
{
|
||||
$offsetStr =($offset>=0) ? ((integer)$offset)."," : '';
|
||||
// jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
|
||||
if ($nrows < 0) $nrows = '18446744073709551615';
|
||||
|
||||
if ($secs)
|
||||
$rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
||||
$rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
||||
else
|
||||
$rs =& $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
||||
$rs = $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
||||
return $rs;
|
||||
}
|
||||
|
||||
// returns queryID or false
|
||||
function _query($sql,$inputarr)
|
||||
function _query($sql,$inputarr=false)
|
||||
{
|
||||
//global $ADODB_COUNTRECS;
|
||||
//if($ADODB_COUNTRECS)
|
||||
@@ -552,8 +560,9 @@ class ADODB_mysql extends ADOConnection {
|
||||
$table = "$owner.$table";
|
||||
}
|
||||
$a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
|
||||
if ($associative) $create_sql = $a_create_table["Create Table"];
|
||||
else $create_sql = $a_create_table[1];
|
||||
if ($associative) {
|
||||
$create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"];
|
||||
} else $create_sql = $a_create_table[1];
|
||||
|
||||
$matches = array();
|
||||
|
||||
@@ -569,9 +578,12 @@ class ADODB_mysql extends ADOConnection {
|
||||
$ref_table = strtoupper($ref_table);
|
||||
}
|
||||
|
||||
$foreign_keys[$ref_table] = array();
|
||||
$num_fields = count($my_field);
|
||||
for ( $j = 0; $j < $num_fields; $j ++ ) {
|
||||
// see https://sourceforge.net/tracker/index.php?func=detail&aid=2287278&group_id=42718&atid=433976
|
||||
if (!isset($foreign_keys[$ref_table])) {
|
||||
$foreign_keys[$ref_table] = array();
|
||||
}
|
||||
$num_fields = count($my_field);
|
||||
for ( $j = 0; $j < $num_fields; $j ++ ) {
|
||||
if ( $associative ) {
|
||||
$foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
|
||||
} else {
|
||||
@@ -623,28 +635,28 @@ class ADORecordSet_mysql extends ADORecordSet{
|
||||
$this->_numOfFields = @mysql_num_fields($this->_queryID);
|
||||
}
|
||||
|
||||
function &FetchField($fieldOffset = -1)
|
||||
function FetchField($fieldOffset = -1)
|
||||
{
|
||||
if ($fieldOffset != -1) {
|
||||
$o = @mysql_fetch_field($this->_queryID, $fieldOffset);
|
||||
$f = @mysql_field_flags($this->_queryID,$fieldOffset);
|
||||
$o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)
|
||||
if ($o) $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich#att.com)
|
||||
//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
|
||||
$o->binary = (strpos($f,'binary')!== false);
|
||||
if ($o) $o->binary = (strpos($f,'binary')!== false);
|
||||
}
|
||||
else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
|
||||
$o = @mysql_fetch_field($this->_queryID);
|
||||
$o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)
|
||||
if ($o) $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich#att.com)
|
||||
//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
function &GetRowAssoc($upper=true)
|
||||
function GetRowAssoc($upper=true)
|
||||
{
|
||||
if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
|
||||
else $row =& ADORecordSet::GetRowAssoc($upper);
|
||||
else $row = ADORecordSet::GetRowAssoc($upper);
|
||||
return $row;
|
||||
}
|
||||
|
||||
@@ -726,6 +738,7 @@ class ADORecordSet_mysql extends ADORecordSet{
|
||||
case 'LONGBLOB':
|
||||
case 'BLOB':
|
||||
case 'MEDIUMBLOB':
|
||||
case 'BINARY':
|
||||
return !empty($fieldobj->binary) ? 'B' : 'X';
|
||||
|
||||
case 'YEAR':
|
||||
|
14
lib/adodb/drivers/adodb-postgres.inc.php
Normal file
14
lib/adodb/drivers/adodb-postgres.inc.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/*
|
||||
V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4.
|
||||
|
||||
NOTE: Since 3.31, this file is no longer used, and the "postgres" driver is
|
||||
remapped to "postgres7". Maintaining multiple postgres drivers is no easy
|
||||
job, so hopefully this will ensure greater consistency and fewer bugs.
|
||||
*/
|
||||
|
||||
?>
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||
V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
@@ -104,7 +104,8 @@ WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s'))
|
||||
var $random = 'random()'; /// random function
|
||||
var $autoRollback = true; // apparently pgsql does not autorollback properly before php 4.3.4
|
||||
// http://bugs.php.net/bug.php?id=25404
|
||||
|
||||
|
||||
var $uniqueIisR = true;
|
||||
var $_bindInputArray = false; // requires postgresql 7.3+ and ability to modify database
|
||||
var $disableBlobs = false; // set to true to disable blob checking, resulting in 2-5% improvement in performance.
|
||||
|
||||
@@ -177,10 +178,10 @@ a different OID if a database must be reloaded. */
|
||||
return @pg_Exec($this->_connectionID, "begin ".$this->_transmode);
|
||||
}
|
||||
|
||||
function RowLock($tables,$where,$flds='1 as ignore')
|
||||
function RowLock($tables,$where,$col='1 as adodbignore')
|
||||
{
|
||||
if (!$this->transCnt) $this->BeginTrans();
|
||||
return $this->GetOne("select $flds from $tables where $where for update");
|
||||
return $this->GetOne("select $col from $tables where $where for update");
|
||||
}
|
||||
|
||||
// returns true/false.
|
||||
@@ -201,7 +202,7 @@ a different OID if a database must be reloaded. */
|
||||
return @pg_Exec($this->_connectionID, "rollback");
|
||||
}
|
||||
|
||||
function &MetaTables($ttype=false,$showSchema=false,$mask=false)
|
||||
function MetaTables($ttype=false,$showSchema=false,$mask=false)
|
||||
{
|
||||
$info = $this->ServerInfo();
|
||||
if ($info['version'] >= 7.3) {
|
||||
@@ -224,7 +225,7 @@ select tablename,'T' from pg_tables where tablename like $mask
|
||||
union
|
||||
select viewname,'V' from pg_views where viewname like $mask";
|
||||
}
|
||||
$ret =& ADOConnection::MetaTables($ttype,$showSchema);
|
||||
$ret = ADOConnection::MetaTables($ttype,$showSchema);
|
||||
|
||||
if ($mask) {
|
||||
$this->metaTablesSQL = $save;
|
||||
@@ -236,6 +237,8 @@ select viewname,'V' from pg_views where viewname like $mask";
|
||||
// if magic quotes disabled, use pg_escape_string()
|
||||
function qstr($s,$magic_quotes=false)
|
||||
{
|
||||
if (is_bool($s)) return $s ? 'true' : 'false';
|
||||
|
||||
if (!$magic_quotes) {
|
||||
if (ADODB_PHPVER >= 0x5200) {
|
||||
return "'".pg_escape_string($this->_connectionID,$s)."'";
|
||||
@@ -457,14 +460,17 @@ select viewname,'V' from pg_views where viewname like $mask";
|
||||
if (10 <= $len && $len <= 12) $date = 'date '.$date;
|
||||
else $date = 'timestamp '.$date;
|
||||
}
|
||||
return "($date+interval'$dayFraction days')";
|
||||
|
||||
|
||||
return "($date+interval'".($dayFraction * 1440)." minutes')";
|
||||
#return "($date+interval'$dayFraction days')";
|
||||
}
|
||||
|
||||
|
||||
// for schema support, pass in the $table param "$schema.$tabname".
|
||||
// converts field names to lowercase, $upper is ignored
|
||||
// see http://phplens.com/lens/lensforum/msgs.php?id=14018 for more info
|
||||
function &MetaColumns($table,$normalize=true)
|
||||
function MetaColumns($table,$normalize=true)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
@@ -478,8 +484,8 @@ select viewname,'V' from pg_views where viewname like $mask";
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
||||
|
||||
if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema));
|
||||
else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
|
||||
if ($schema) $rs = $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema));
|
||||
else $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
|
||||
if (isset($savem)) $this->SetFetchMode($savem);
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
|
||||
@@ -496,7 +502,7 @@ select viewname,'V' from pg_views where viewname like $mask";
|
||||
|
||||
$rskey = $this->Execute(sprintf($this->metaKeySQL,($table)));
|
||||
// fetch all result in once for performance.
|
||||
$keys =& $rskey->GetArray();
|
||||
$keys = $rskey->GetArray();
|
||||
if (isset($savem)) $this->SetFetchMode($savem);
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
|
||||
@@ -578,7 +584,7 @@ select viewname,'V' from pg_views where viewname like $mask";
|
||||
|
||||
}
|
||||
|
||||
function &MetaIndexes ($table, $primary = FALSE)
|
||||
function MetaIndexes ($table, $primary = FALSE, $owner = false)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
@@ -659,7 +665,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
|
||||
if (strlen($db) == 0) $db = 'template1';
|
||||
$db = adodb_addslashes($db);
|
||||
if ($str) {
|
||||
$host = split(":", $str);
|
||||
$host = explode(":", $str);
|
||||
if ($host[0]) $str = "host=".adodb_addslashes($host[0]);
|
||||
else $str = '';
|
||||
if (isset($host[1])) $str .= " port=$host[1]";
|
||||
@@ -713,7 +719,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
|
||||
|
||||
|
||||
// returns queryID or false
|
||||
function _query($sql,$inputarr)
|
||||
function _query($sql,$inputarr=false)
|
||||
{
|
||||
$this->_errorMsg = false;
|
||||
if ($inputarr) {
|
||||
@@ -886,10 +892,10 @@ class ADORecordSet_postgres64 extends ADORecordSet{
|
||||
$this->ADORecordSet($queryID);
|
||||
}
|
||||
|
||||
function &GetRowAssoc($upper=true)
|
||||
function GetRowAssoc($upper=true)
|
||||
{
|
||||
if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields;
|
||||
$row =& ADORecordSet::GetRowAssoc($upper);
|
||||
$row = ADORecordSet::GetRowAssoc($upper);
|
||||
return $row;
|
||||
}
|
||||
|
||||
@@ -925,7 +931,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
|
||||
return $this->fields[$this->bind[strtoupper($colname)]];
|
||||
}
|
||||
|
||||
function &FetchField($off = 0)
|
||||
function FetchField($off = 0)
|
||||
{
|
||||
// offsets begin at 0
|
||||
|
||||
@@ -943,6 +949,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
|
||||
|
||||
function _decode($blob)
|
||||
{
|
||||
if ($blob === NULL) return NULL;
|
||||
eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";');
|
||||
return $realblob;
|
||||
}
|
||||
@@ -1049,7 +1056,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
|
||||
case 'INT4':
|
||||
case 'INT2':
|
||||
if (isset($fieldobj) &&
|
||||
empty($fieldobj->primary_key) && empty($fieldobj->unique)) return 'I';
|
||||
empty($fieldobj->primary_key) && (!$this->connection->uniqueIisR || empty($fieldobj->unique))) return 'I';
|
||||
|
||||
case 'OID':
|
||||
case 'SERIAL':
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||
V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
@@ -34,14 +34,14 @@ class ADODB_postgres7 extends ADODB_postgres64 {
|
||||
|
||||
// the following should be compat with postgresql 7.2,
|
||||
// which makes obsolete the LIMIT limit,offset syntax
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
|
||||
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
|
||||
{
|
||||
$offsetStr = ($offset >= 0) ? " OFFSET ".((integer)$offset) : '';
|
||||
$limitStr = ($nrows >= 0) ? " LIMIT ".((integer)$nrows) : '';
|
||||
if ($secs2cache)
|
||||
$rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
||||
$rs = $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
||||
else
|
||||
$rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
||||
$rs = $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
||||
|
||||
return $rs;
|
||||
}
|
||||
@@ -56,9 +56,58 @@ class ADODB_postgres7 extends ADODB_postgres64 {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// from Edward Jaramilla, improved version - works on pg 7.4
|
||||
/*
|
||||
I discovered that the MetaForeignKeys method no longer worked for Postgres 8.3.
|
||||
I went ahead and modified it to work for both 8.2 and 8.3.
|
||||
Please feel free to include this change in your next release of adodb.
|
||||
William Kolodny [William.Kolodny#gt-t.net]
|
||||
*/
|
||||
function MetaForeignKeys($table, $owner=false, $upper=false)
|
||||
{
|
||||
$sql="
|
||||
SELECT fum.ftblname AS lookup_table, split_part(fum.rf, ')'::text, 1) AS lookup_field,
|
||||
fum.ltable AS dep_table, split_part(fum.lf, ')'::text, 1) AS dep_field
|
||||
FROM (
|
||||
SELECT fee.ltable, fee.ftblname, fee.consrc, split_part(fee.consrc,'('::text, 2) AS lf,
|
||||
split_part(fee.consrc, '('::text, 3) AS rf
|
||||
FROM (
|
||||
SELECT foo.relname AS ltable, foo.ftblname,
|
||||
pg_get_constraintdef(foo.oid) AS consrc
|
||||
FROM (
|
||||
SELECT c.oid, c.conname AS name, t.relname, ft.relname AS ftblname
|
||||
FROM pg_constraint c
|
||||
JOIN pg_class t ON (t.oid = c.conrelid)
|
||||
JOIN pg_class ft ON (ft.oid = c.confrelid)
|
||||
JOIN pg_namespace nft ON (nft.oid = ft.relnamespace)
|
||||
LEFT JOIN pg_description ds ON (ds.objoid = c.oid)
|
||||
JOIN pg_namespace n ON (n.oid = t.relnamespace)
|
||||
WHERE c.contype = 'f'::\"char\"
|
||||
ORDER BY t.relname, n.nspname, c.conname, c.oid
|
||||
) foo
|
||||
) fee) fum
|
||||
WHERE fum.ltable='".strtolower($table)."'
|
||||
ORDER BY fum.ftblname, fum.ltable, split_part(fum.lf, ')'::text, 1)
|
||||
";
|
||||
$rs = $this->Execute($sql);
|
||||
|
||||
if (!$rs || $rs->EOF) return false;
|
||||
|
||||
$a = array();
|
||||
while (!$rs->EOF) {
|
||||
if ($upper) {
|
||||
$a[strtoupper($rs->Fields('lookup_table'))][] = strtoupper(str_replace('"','',$rs->Fields('dep_field').'='.$rs->Fields('lookup_field')));
|
||||
} else {
|
||||
$a[$rs->Fields('lookup_table')][] = str_replace('"','',$rs->Fields('dep_field').'='.$rs->Fields('lookup_field'));
|
||||
}
|
||||
$rs->MoveNext();
|
||||
}
|
||||
|
||||
return $a;
|
||||
|
||||
}
|
||||
|
||||
// from Edward Jaramilla, improved version - works on pg 7.4
|
||||
function _old_MetaForeignKeys($table, $owner=false, $upper=false)
|
||||
{
|
||||
$sql = 'SELECT t.tgargs as args
|
||||
FROM
|
||||
@@ -72,11 +121,11 @@ class ADODB_postgres7 extends ADODB_postgres64 {
|
||||
ORDER BY
|
||||
t.tgrelid';
|
||||
|
||||
$rs =& $this->Execute($sql);
|
||||
$rs = $this->Execute($sql);
|
||||
|
||||
if (!$rs || $rs->EOF) return false;
|
||||
|
||||
$arr =& $rs->GetArray();
|
||||
$arr = $rs->GetArray();
|
||||
$a = array();
|
||||
foreach($arr as $v) {
|
||||
$data = explode(chr(0), $v['args']);
|
||||
@@ -91,7 +140,7 @@ class ADODB_postgres7 extends ADODB_postgres64 {
|
||||
return $a;
|
||||
}
|
||||
|
||||
function _query($sql,$inputarr)
|
||||
function _query($sql,$inputarr=false)
|
||||
{
|
||||
if (! $this->_bindInputArray) {
|
||||
// We don't have native support for parameterized queries, so let's emulate it at the parent
|
||||
|
12
lib/adodb/drivers/adodb-postgres8.inc.php
Normal file
12
lib/adodb/drivers/adodb-postgres8.inc.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4.
|
||||
|
||||
NOTE: The "postgres8" driver is remapped to "postgres7".
|
||||
*/
|
||||
|
||||
?>
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||
V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
@@ -78,14 +78,14 @@ class ADODB_sqlite extends ADOConnection {
|
||||
}
|
||||
|
||||
// mark newnham
|
||||
function &MetaColumns($tab)
|
||||
function MetaColumns($table, $normalize=true)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
$false = false;
|
||||
$save = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
||||
$rs = $this->Execute("PRAGMA table_info('$tab')");
|
||||
$rs = $this->Execute("PRAGMA table_info('$table')");
|
||||
if (isset($savem)) $this->SetFetchMode($savem);
|
||||
if (!$rs) {
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
@@ -190,14 +190,14 @@ class ADODB_sqlite extends ADOConnection {
|
||||
return $rez;
|
||||
}
|
||||
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
|
||||
function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
|
||||
{
|
||||
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
|
||||
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : '');
|
||||
if ($secs2cache)
|
||||
$rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
||||
$rs = $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
||||
else
|
||||
$rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
||||
$rs = $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
||||
|
||||
return $rs;
|
||||
}
|
||||
@@ -261,7 +261,7 @@ class ADODB_sqlite extends ADOConnection {
|
||||
return @sqlite_close($this->_connectionID);
|
||||
}
|
||||
|
||||
function &MetaIndexes($table, $primary = FALSE, $owner=false)
|
||||
function MetaIndexes($table, $primary = FALSE, $owner=false, $owner = false)
|
||||
{
|
||||
$false = false;
|
||||
// save old fetch mode
|
||||
@@ -350,7 +350,7 @@ class ADORecordset_sqlite extends ADORecordSet {
|
||||
}
|
||||
|
||||
|
||||
function &FetchField($fieldOffset = -1)
|
||||
function FetchField($fieldOffset = -1)
|
||||
{
|
||||
$fld = new ADOFieldObject;
|
||||
$fld->name = sqlite_field_name($this->_queryID, $fieldOffset);
|
||||
@@ -393,5 +393,6 @@ class ADORecordset_sqlite extends ADORecordSet {
|
||||
function _close()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
62
lib/adodb/drivers/adodb-sqlitepo.inc.php
Normal file
62
lib/adodb/drivers/adodb-sqlitepo.inc.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*
|
||||
V5.11 5 May 2010 (c) 2000-2010 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
|
||||
Portable version of sqlite driver, to make it more similar to other database drivers.
|
||||
The main differences are
|
||||
|
||||
1. When selecting (joining) multiple tables, in assoc mode the table
|
||||
names are included in the assoc keys in the "sqlite" driver.
|
||||
|
||||
In "sqlitepo" driver, the table names are stripped from the returned column names.
|
||||
When this results in a conflict, the first field get preference.
|
||||
|
||||
Contributed by Herman Kuiper herman#ozuzo.net
|
||||
*/
|
||||
|
||||
if (!defined('ADODB_DIR')) die();
|
||||
|
||||
include_once(ADODB_DIR.'/drivers/adodb-sqlite.inc.php');
|
||||
|
||||
class ADODB_sqlitepo extends ADODB_sqlite {
|
||||
var $databaseType = 'sqlitepo';
|
||||
|
||||
function ADODB_sqlitepo()
|
||||
{
|
||||
$this->ADODB_sqlite();
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordset_sqlitepo extends ADORecordset_sqlite {
|
||||
|
||||
var $databaseType = 'sqlitepo';
|
||||
|
||||
function ADORecordset_sqlitepo($queryID,$mode=false)
|
||||
{
|
||||
$this->ADORecordset_sqlite($queryID,$mode);
|
||||
}
|
||||
|
||||
// Modified to strip table names from returned fields
|
||||
function _fetch($ignore_fields=false)
|
||||
{
|
||||
$this->fields = array();
|
||||
$fields = @sqlite_fetch_array($this->_queryID,$this->fetchMode);
|
||||
if(is_array($fields))
|
||||
foreach($fields as $n => $v)
|
||||
{
|
||||
if(($p = strpos($n, ".")) !== false)
|
||||
$n = substr($n, $p+1);
|
||||
$this->fields[$n] = $v;
|
||||
}
|
||||
|
||||
return !empty($this->fields);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user