adodb updates
This commit is contained in:
parent
1f44bed8d3
commit
d6392dfd44
@ -8,7 +8,7 @@ $ADODB_INCLUDED_CSV = 1;
|
||||
|
||||
/*
|
||||
|
||||
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. See License.txt.
|
||||
@ -54,7 +54,7 @@ $ADODB_INCLUDED_CSV = 1;
|
||||
$line = "====1,$tt,$sql\n";
|
||||
|
||||
if ($rs->databaseType == 'array') {
|
||||
$rows =& $rs->_array;
|
||||
$rows = $rs->_array;
|
||||
} else {
|
||||
$rows = array();
|
||||
while (!$rs->EOF) {
|
||||
@ -64,13 +64,14 @@ $ADODB_INCLUDED_CSV = 1;
|
||||
}
|
||||
|
||||
for($i=0; $i < $max; $i++) {
|
||||
$o =& $rs->FetchField($i);
|
||||
$o = $rs->FetchField($i);
|
||||
$flds[] = $o;
|
||||
}
|
||||
|
||||
$savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
|
||||
$class = $rs->connection->arrayClass;
|
||||
$rs2 = new $class();
|
||||
$rs2->timeCreated = $rs->timeCreated; # memcache fix
|
||||
$rs2->sql = $rs->sql;
|
||||
$rs2->oldProvider = $rs->dataProvider;
|
||||
$rs2->InitArrayFields($rows,$flds);
|
||||
@ -90,7 +91,7 @@ $ADODB_INCLUDED_CSV = 1;
|
||||
* error occurred in sql INSERT/UPDATE/DELETE,
|
||||
* empty recordset is returned
|
||||
*/
|
||||
function &csv2rs($url,&$err,$timeout=0, $rsclass='ADORecordSet_array')
|
||||
function csv2rs($url,&$err,$timeout=0, $rsclass='ADORecordSet_array')
|
||||
{
|
||||
$false = false;
|
||||
$err = false;
|
||||
@ -261,6 +262,7 @@ $ADODB_INCLUDED_CSV = 1;
|
||||
|
||||
/**
|
||||
* Save a file $filename and its $contents (normally for caching) with file locking
|
||||
* Returns true if ok, false if fopen/fwrite error, 0 if rename error (eg. file is locked)
|
||||
*/
|
||||
function adodb_write_file($filename, $contents,$debug=false)
|
||||
{
|
||||
@ -280,27 +282,31 @@ $ADODB_INCLUDED_CSV = 1;
|
||||
$mtime = substr(str_replace(' ','_',microtime()),2);
|
||||
// getmypid() actually returns 0 on Win98 - never mind!
|
||||
$tmpname = $filename.uniqid($mtime).getmypid();
|
||||
if (!($fd = @fopen($tmpname,'a'))) return false;
|
||||
$ok = ftruncate($fd,0);
|
||||
if (!fwrite($fd,$contents)) $ok = false;
|
||||
if (!($fd = @fopen($tmpname,'w'))) return false;
|
||||
if (fwrite($fd,$contents)) $ok = true;
|
||||
else $ok = false;
|
||||
fclose($fd);
|
||||
chmod($tmpname,0644);
|
||||
// the tricky moment
|
||||
@unlink($filename);
|
||||
if (!@rename($tmpname,$filename)) {
|
||||
unlink($tmpname);
|
||||
$ok = false;
|
||||
}
|
||||
if (!$ok) {
|
||||
if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
|
||||
|
||||
if ($ok) {
|
||||
@chmod($tmpname,0644);
|
||||
// the tricky moment
|
||||
@unlink($filename);
|
||||
if (!@rename($tmpname,$filename)) {
|
||||
unlink($tmpname);
|
||||
$ok = 0;
|
||||
}
|
||||
if (!$ok) {
|
||||
if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
if (!($fd = @fopen($filename, 'a'))) return false;
|
||||
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
|
||||
$ok = fwrite( $fd, $contents );
|
||||
if (fwrite( $fd, $contents )) $ok = true;
|
||||
else $ok = false;
|
||||
fclose($fd);
|
||||
chmod($filename,0644);
|
||||
@chmod($filename,0644);
|
||||
}else {
|
||||
fclose($fd);
|
||||
if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||
* @version V5.06 16 Oct 2008 (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.
|
||||
@ -92,14 +92,14 @@ function adodb_error_pg($errormsg)
|
||||
{
|
||||
if (is_numeric($errormsg)) return (integer) $errormsg;
|
||||
static $error_regexps = array(
|
||||
'/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
|
||||
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
|
||||
'/divide by zero$/' => DB_ERROR_DIVZERO,
|
||||
'/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
|
||||
'/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
|
||||
'/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
|
||||
'/referential integrity violation/' => DB_ERROR_CONSTRAINT,
|
||||
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/'
|
||||
'/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/i' => DB_ERROR_NOSUCHTABLE,
|
||||
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/i' => DB_ERROR_ALREADY_EXISTS,
|
||||
'/divide by zero$/i' => DB_ERROR_DIVZERO,
|
||||
'/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER,
|
||||
'/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/i' => DB_ERROR_NOSUCHFIELD,
|
||||
'/parser: parse error at or near \"/i' => DB_ERROR_SYNTAX,
|
||||
'/referential integrity violation/i' => DB_ERROR_CONSTRAINT,
|
||||
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key.*violates unique constraint/i'
|
||||
=> DB_ERROR_ALREADY_EXISTS
|
||||
);
|
||||
reset($error_regexps);
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||
* @version 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.
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?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.
|
||||
@ -18,68 +18,13 @@
|
||||
|
||||
|
||||
Iterator code based on http://cvs.php.net/cvs.php/php-src/ext/spl/examples/cachingiterator.inc?login=2
|
||||
|
||||
|
||||
Moved to adodb.inc.php to improve performance.
|
||||
*/
|
||||
|
||||
|
||||
class ADODB_Iterator implements Iterator {
|
||||
|
||||
private $rs;
|
||||
|
||||
function __construct($rs)
|
||||
{
|
||||
$this->rs = $rs;
|
||||
}
|
||||
function rewind()
|
||||
{
|
||||
$this->rs->MoveFirst();
|
||||
}
|
||||
|
||||
function valid()
|
||||
{
|
||||
return !$this->rs->EOF;
|
||||
}
|
||||
|
||||
function key()
|
||||
{
|
||||
return $this->rs->_currentRow;
|
||||
}
|
||||
|
||||
function current()
|
||||
{
|
||||
return $this->rs->fields;
|
||||
}
|
||||
|
||||
function next()
|
||||
{
|
||||
$this->rs->MoveNext();
|
||||
}
|
||||
|
||||
function __call($func, $params)
|
||||
{
|
||||
return call_user_func_array(array($this->rs, $func), $params);
|
||||
}
|
||||
|
||||
|
||||
function hasMore()
|
||||
{
|
||||
return !$this->rs->EOF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ADODB_BASE_RS implements IteratorAggregate {
|
||||
function getIterator() {
|
||||
return new ADODB_Iterator($this);
|
||||
}
|
||||
|
||||
/* this is experimental - i don't really know what to return... */
|
||||
function __toString()
|
||||
{
|
||||
include_once(ADODB_DIR.'/toexport.inc.php');
|
||||
return _adodb_export($this,',',',',false,true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
|
||||
// security - hide paths
|
||||
if (!defined('ADODB_DIR')) die();
|
||||
|
||||
@ -7,7 +10,7 @@ global $ADODB_INCLUDED_LIB;
|
||||
$ADODB_INCLUDED_LIB = 1;
|
||||
|
||||
/*
|
||||
@version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim\@natsoft.com.my). All rights reserved.
|
||||
@version V5.06 16 Oct 2008 (c) 2000-2010 John Lim (jlim\@natsoft.com.my). 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. See License.txt.
|
||||
@ -16,6 +19,36 @@ $ADODB_INCLUDED_LIB = 1;
|
||||
Less commonly used functions are placed here to reduce size of adodb.inc.php.
|
||||
*/
|
||||
|
||||
function adodb_strip_order_by($sql)
|
||||
{
|
||||
$rez = preg_match('/(\sORDER\s+BY\s[^)]*)/is',$sql,$arr);
|
||||
if ($arr)
|
||||
if (strpos($arr[0],'(') !== false) {
|
||||
$at = strpos($sql,$arr[0]);
|
||||
$cntin = 0;
|
||||
for ($i=$at, $max=strlen($sql); $i < $max; $i++) {
|
||||
$ch = $sql[$i];
|
||||
if ($ch == '(') {
|
||||
$cntin += 1;
|
||||
} elseif($ch == ')') {
|
||||
$cntin -= 1;
|
||||
if ($cntin < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$sql = substr($sql,0,$at).substr($sql,$i);
|
||||
} else
|
||||
$sql = str_replace($arr[0], '', $sql);
|
||||
return $sql;
|
||||
}
|
||||
|
||||
if (false) {
|
||||
$sql = 'select * from (select a from b order by a(b),b(c) desc)';
|
||||
$sql = '(select * from abc order by 1)';
|
||||
die(adodb_strip_order_by($sql));
|
||||
}
|
||||
|
||||
function adodb_probetypes(&$array,&$types,$probe=8)
|
||||
{
|
||||
// probe and guess the type
|
||||
@ -25,7 +58,7 @@ function adodb_probetypes(&$array,&$types,$probe=8)
|
||||
|
||||
|
||||
for ($j=0;$j < $max; $j++) {
|
||||
$row =& $array[$j];
|
||||
$row = $array[$j];
|
||||
if (!$row) break;
|
||||
$i = -1;
|
||||
foreach($row as $v) {
|
||||
@ -56,16 +89,17 @@ function adodb_probetypes(&$array,&$types,$probe=8)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function &adodb_transpose(&$arr, &$newarr, &$hdr)
|
||||
function adodb_transpose(&$arr, &$newarr, &$hdr, &$fobjs)
|
||||
{
|
||||
$oldX = sizeof(reset($arr));
|
||||
$oldY = sizeof($arr);
|
||||
|
||||
if ($hdr) {
|
||||
$startx = 1;
|
||||
$hdr = array();
|
||||
$hdr = array('Fields');
|
||||
for ($y = 0; $y < $oldY; $y++) {
|
||||
$hdr[] = $arr[$y][0];
|
||||
}
|
||||
@ -73,7 +107,12 @@ function &adodb_transpose(&$arr, &$newarr, &$hdr)
|
||||
$startx = 0;
|
||||
|
||||
for ($x = $startx; $x < $oldX; $x++) {
|
||||
$newarr[] = array();
|
||||
if ($fobjs) {
|
||||
$o = $fobjs[$x];
|
||||
$newarr[] = array($o->name);
|
||||
} else
|
||||
$newarr[] = array();
|
||||
|
||||
for ($y = 0; $y < $oldY; $y++) {
|
||||
$newarr[$x-$startx][] = $arr[$y][$x];
|
||||
}
|
||||
@ -105,7 +144,10 @@ function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_
|
||||
$keyCol = array($keyCol);
|
||||
}
|
||||
foreach($fieldArray as $k => $v) {
|
||||
if ($autoQuote && !is_numeric($v) and strncmp($v,"'",1) !== 0 and strcasecmp($v,$zthis->null2null)!=0) {
|
||||
if ($v === null) {
|
||||
$v = 'NULL';
|
||||
$fieldArray[$k] = $v;
|
||||
} else if ($autoQuote && /*!is_numeric($v) /*and strncmp($v,"'",1) !== 0 -- sql injection risk*/ strcasecmp($v,$zthis->null2null)!=0) {
|
||||
$v = $zthis->qstr($v);
|
||||
$fieldArray[$k] = $v;
|
||||
}
|
||||
@ -117,7 +159,7 @@ function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_
|
||||
} else
|
||||
$uSet .= ",$k=$v";
|
||||
}
|
||||
|
||||
|
||||
$where = false;
|
||||
foreach ($keyCol as $v) {
|
||||
if (isset($fieldArray[$v])) {
|
||||
@ -363,42 +405,35 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
|
||||
if (!empty($zthis->_nestedSQL) || preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) ||
|
||||
preg_match('/\s+GROUP\s+BY\s+/is',$sql) ||
|
||||
preg_match('/\s+UNION\s+/is',$sql)) {
|
||||
|
||||
$rewritesql = adodb_strip_order_by($sql);
|
||||
|
||||
// ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias
|
||||
// but this is only supported by oracle and postgresql...
|
||||
if ($zthis->dataProvider == 'oci8') {
|
||||
|
||||
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
|
||||
|
||||
// Allow Oracle hints to be used for query optimization, Chris Wrye
|
||||
if (preg_match('#/\\*+.*?\\*\\/#', $sql, $hint)) {
|
||||
$rewritesql = "SELECT ".$hint[0]." COUNT(*) FROM (".$rewritesql.")";
|
||||
} else
|
||||
$rewritesql = "SELECT COUNT(*) FROM (".$rewritesql.")";
|
||||
|
||||
} else if (strncmp($zthis->databaseType,'postgres',8) == 0) {
|
||||
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
|
||||
} else if (strncmp($zthis->databaseType,'postgres',8) == 0 || strncmp($zthis->databaseType,'mysql',5) == 0) {
|
||||
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
|
||||
} else {
|
||||
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql)";
|
||||
}
|
||||
} else {
|
||||
// now replace SELECT ... FROM with SELECT COUNT(*) FROM
|
||||
$rewritesql = preg_replace(
|
||||
'/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);
|
||||
|
||||
|
||||
|
||||
// fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails
|
||||
// with mssql, access and postgresql. Also a good speedup optimization - skips sorting!
|
||||
// also see http://phplens.com/lens/lensforum/msgs.php?id=12752
|
||||
if (preg_match('/\sORDER\s+BY\s*\(/i',$rewritesql))
|
||||
$rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql);
|
||||
else
|
||||
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$rewritesql);
|
||||
$rewritesql = adodb_strip_order_by($rewritesql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isset($rewritesql) && $rewritesql != $sql) {
|
||||
if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[1];
|
||||
if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[0];
|
||||
|
||||
if ($secs2cache) {
|
||||
// we only use half the time of secs2cache because the count can quickly
|
||||
@ -416,13 +451,17 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
|
||||
|
||||
// strip off unneeded ORDER BY if no UNION
|
||||
if (preg_match('/\s*UNION\s*/is', $sql)) $rewritesql = $sql;
|
||||
else $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
|
||||
else $rewritesql = $rewritesql = adodb_strip_order_by($sql);
|
||||
|
||||
if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[0];
|
||||
|
||||
$rstest = &$zthis->Execute($rewritesql,$inputarr);
|
||||
if (!$rstest) $rstest = $zthis->Execute($sql,$inputarr);
|
||||
|
||||
if ($secs2cache) {
|
||||
$rstest = $zthis->CacheExecute($secs2cache,$rewritesql,$inputarr);
|
||||
if (!$rstest) $rstest = $zthis->CacheExecute($secs2cache,$sql,$inputarr);
|
||||
} else {
|
||||
$rstest = $zthis->Execute($rewritesql,$inputarr);
|
||||
if (!$rstest) $rstest = $zthis->Execute($sql,$inputarr);
|
||||
}
|
||||
if ($rstest) {
|
||||
$qryRecs = $rstest->RecordCount();
|
||||
if ($qryRecs == -1) {
|
||||
@ -454,7 +493,7 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
|
||||
data will get out of synch. use CachePageExecute() only with tables that
|
||||
rarely change.
|
||||
*/
|
||||
function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
|
||||
function _adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
|
||||
$inputarr=false, $secs2cache=0)
|
||||
{
|
||||
$atfirstpage = false;
|
||||
@ -490,9 +529,9 @@ function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
|
||||
// We get the data we want
|
||||
$offset = $nrows * ($page-1);
|
||||
if ($secs2cache > 0)
|
||||
$rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
|
||||
$rsreturn = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
|
||||
else
|
||||
$rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
|
||||
$rsreturn = $zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
|
||||
|
||||
|
||||
// Before returning the RecordSet, we set the pagination properties we need
|
||||
@ -508,7 +547,7 @@ function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
|
||||
}
|
||||
|
||||
// Iván Oliva version
|
||||
function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0)
|
||||
function _adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0)
|
||||
{
|
||||
|
||||
$atfirstpage = false;
|
||||
@ -524,16 +563,16 @@ function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputar
|
||||
// the last page number.
|
||||
$pagecounter = $page + 1;
|
||||
$pagecounteroffset = ($pagecounter * $nrows) - $nrows;
|
||||
if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
|
||||
else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
|
||||
if ($secs2cache>0) $rstest = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
|
||||
else $rstest = $zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
|
||||
if ($rstest) {
|
||||
while ($rstest && $rstest->EOF && $pagecounter>0) {
|
||||
$atlastpage = true;
|
||||
$pagecounter--;
|
||||
$pagecounteroffset = $nrows * ($pagecounter - 1);
|
||||
$rstest->Close();
|
||||
if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
|
||||
else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
|
||||
if ($secs2cache>0) $rstest = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
|
||||
else $rstest = $zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
|
||||
}
|
||||
if ($rstest) $rstest->Close();
|
||||
}
|
||||
@ -545,8 +584,8 @@ function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputar
|
||||
|
||||
// We get the data we want
|
||||
$offset = $nrows * ($page-1);
|
||||
if ($secs2cache > 0) $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
|
||||
else $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
|
||||
if ($secs2cache > 0) $rsreturn = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
|
||||
else $rsreturn = $zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
|
||||
|
||||
// Before returning the RecordSet, we set the pagination properties we need
|
||||
if ($rsreturn) {
|
||||
@ -560,6 +599,8 @@ function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputar
|
||||
|
||||
function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=2)
|
||||
{
|
||||
global $ADODB_QUOTE_FIELDNAMES;
|
||||
|
||||
if (!$rs) {
|
||||
printf(ADODB_BAD_RS,'GetUpdateSQL');
|
||||
return false;
|
||||
@ -606,7 +647,7 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
|
||||
$type = 'C';
|
||||
}
|
||||
|
||||
if (strpos($upperfname,' ') !== false)
|
||||
if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
|
||||
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
|
||||
else
|
||||
$fnameq = $upperfname;
|
||||
@ -720,6 +761,7 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false,$force=2)
|
||||
static $cacheRS = false;
|
||||
static $cacheSig = 0;
|
||||
static $cacheCols;
|
||||
global $ADODB_QUOTE_FIELDNAMES;
|
||||
|
||||
$tableName = '';
|
||||
$values = '';
|
||||
@ -738,10 +780,10 @@ static $cacheCols;
|
||||
//php can't do a $rsclass::MetaType()
|
||||
$rsclass = $zthis->rsPrefix.$zthis->databaseType;
|
||||
$recordSet = new $rsclass(-1,$zthis->fetchMode);
|
||||
$recordSet->connection = &$zthis;
|
||||
$recordSet->connection = $zthis;
|
||||
|
||||
if (is_string($cacheRS) && $cacheRS == $rs) {
|
||||
$columns =& $cacheCols;
|
||||
$columns = $cacheCols;
|
||||
} else {
|
||||
$columns = $zthis->MetaColumns( $tableName );
|
||||
$cacheRS = $tableName;
|
||||
@ -749,7 +791,7 @@ static $cacheCols;
|
||||
}
|
||||
} else if (is_subclass_of($rs, 'adorecordset')) {
|
||||
if (isset($rs->insertSig) && is_integer($cacheRS) && $cacheRS == $rs->insertSig) {
|
||||
$columns =& $cacheCols;
|
||||
$columns = $cacheCols;
|
||||
} else {
|
||||
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
|
||||
$columns[] = $rs->FetchField($i);
|
||||
@ -757,7 +799,7 @@ static $cacheCols;
|
||||
$cacheCols = $columns;
|
||||
$rs->insertSig = $cacheSig++;
|
||||
}
|
||||
$recordSet =& $rs;
|
||||
$recordSet = $rs;
|
||||
|
||||
} else {
|
||||
printf(ADODB_BAD_RS,'GetInsertSQL');
|
||||
@ -769,7 +811,7 @@ static $cacheCols;
|
||||
$upperfname = strtoupper($field->name);
|
||||
if (adodb_key_exists($upperfname,$arrFields,$force)) {
|
||||
$bad = false;
|
||||
if (strpos($upperfname,' ') !== false)
|
||||
if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
|
||||
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
|
||||
else
|
||||
$fnameq = $upperfname;
|
||||
@ -962,9 +1004,20 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields,
|
||||
case "T":
|
||||
$val = $zthis->DBTimeStamp($arrFields[$fname]);
|
||||
break;
|
||||
|
||||
case "N":
|
||||
$val = $arrFields[$fname];
|
||||
if (!is_numeric($val)) $val = str_replace(',', '.', (float)$val);
|
||||
break;
|
||||
|
||||
case "I":
|
||||
case "R":
|
||||
$val = $arrFields[$fname];
|
||||
if (!is_numeric($val)) $val = (integer) $val;
|
||||
break;
|
||||
|
||||
default:
|
||||
$val = $arrFields[$fname];
|
||||
$val = str_replace(array("'"," ","("),"",$arrFields[$fname]); // basic sql injection defence
|
||||
if (empty($val)) $val = '0';
|
||||
break;
|
||||
}
|
||||
@ -984,7 +1037,8 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
|
||||
if ($inputarr) {
|
||||
foreach($inputarr as $kk=>$vv) {
|
||||
if (is_string($vv) && strlen($vv)>64) $vv = substr($vv,0,64).'...';
|
||||
$ss .= "($kk=>'$vv') ";
|
||||
if (is_null($vv)) $ss .= "($kk=>null) ";
|
||||
else $ss .= "($kk=>'$vv') ";
|
||||
}
|
||||
$ss = "[ $ss ]";
|
||||
}
|
||||
@ -1003,11 +1057,13 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
|
||||
$ss = '<code>'.htmlspecialchars($ss).'</code>';
|
||||
}
|
||||
if ($zthis->debug === -1)
|
||||
ADOConnection::outp( "<br />\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<br />\n",false);
|
||||
else
|
||||
ADOConnection::outp( "<hr />\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<hr />\n",false);
|
||||
ADOConnection::outp( "<br>\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<br>\n",false);
|
||||
else if ($zthis->debug !== -99)
|
||||
ADOConnection::outp( "<hr>\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<hr>\n",false);
|
||||
} else {
|
||||
ADOConnection::outp("-----\n($dbt): ".$sqlTxt."\n-----\n",false);
|
||||
$ss = "\n ".$ss;
|
||||
if ($zthis->debug !== -99)
|
||||
ADOConnection::outp("-----<hr>\n($dbt): ".$sqlTxt." $ss\n-----<hr>\n",false);
|
||||
}
|
||||
|
||||
$qID = $zthis->_query($sql,$inputarr);
|
||||
@ -1018,10 +1074,21 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
|
||||
*/
|
||||
if ($zthis->databaseType == 'mssql') {
|
||||
// ErrorNo is a slow function call in mssql, and not reliable in PHP 4.0.6
|
||||
|
||||
if($emsg = $zthis->ErrorMsg()) {
|
||||
if ($err = $zthis->ErrorNo()) ADOConnection::outp($err.': '.$emsg);
|
||||
if ($err = $zthis->ErrorNo()) {
|
||||
if ($zthis->debug === -99)
|
||||
ADOConnection::outp( "<hr>\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<hr>\n",false);
|
||||
|
||||
ADOConnection::outp($err.': '.$emsg);
|
||||
}
|
||||
}
|
||||
} else if (!$qID) {
|
||||
|
||||
if ($zthis->debug === -99)
|
||||
if ($inBrowser) ADOConnection::outp( "<hr>\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<hr>\n",false);
|
||||
else ADOConnection::outp("-----<hr>\n($dbt): ".$sqlTxt."$ss\n-----<hr>\n",false);
|
||||
|
||||
ADOConnection::outp($zthis->ErrorNo() .': '. $zthis->ErrorMsg());
|
||||
}
|
||||
|
||||
@ -1030,11 +1097,13 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
|
||||
}
|
||||
|
||||
# pretty print the debug_backtrace function
|
||||
function _adodb_backtrace($printOrArr=true,$levels=9999,$skippy=0)
|
||||
function _adodb_backtrace($printOrArr=true,$levels=9999,$skippy=0,$ishtml=null)
|
||||
{
|
||||
if (!function_exists('debug_backtrace')) return '';
|
||||
|
||||
$html = (isset($_SERVER['HTTP_USER_AGENT']));
|
||||
if ($ishtml === null) $html = (isset($_SERVER['HTTP_USER_AGENT']));
|
||||
else $html = $ishtml;
|
||||
|
||||
$fmt = ($html) ? "</font><font color=#808080 size=-1> %% line %4d, file: <a href=\"file:/%s\">%s</a></font>" : "%% line %4d, file: %s";
|
||||
|
||||
$MAXSTRLEN = 128;
|
||||
@ -1065,7 +1134,7 @@ function _adodb_backtrace($printOrArr=true,$levels=9999,$skippy=0)
|
||||
else if (is_bool($v)) $args[] = $v ? 'true' : 'false';
|
||||
else {
|
||||
$v = (string) @$v;
|
||||
$str = htmlspecialchars(substr($v,0,$MAXSTRLEN));
|
||||
$str = htmlspecialchars(str_replace(array("\r","\n"),' ',substr($v,0,$MAXSTRLEN)));
|
||||
if (strlen($v) > $MAXSTRLEN) $str .= '...';
|
||||
$args[] = $str;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?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.
|
||||
|
@ -241,6 +241,24 @@ b. Implement daylight savings, which looks awfully complicated, see
|
||||
|
||||
|
||||
CHANGELOG
|
||||
|
||||
- 11 Feb 2008 0.33
|
||||
* Bug in 0.32 fix for hour handling. Fixed.
|
||||
|
||||
- 1 Feb 2008 0.32
|
||||
* Now adodb_mktime(0,0,0,12+$m,20,2040) works properly.
|
||||
|
||||
- 10 Jan 2008 0.31
|
||||
* Now adodb_mktime(0,0,0,24,1,2037) works correctly.
|
||||
|
||||
- 15 July 2007 0.30
|
||||
Added PHP 5.2.0 compatability fixes.
|
||||
* gmtime behaviour for 1970 has changed. We use the actual date if it is between 1970 to 2038 to get the
|
||||
* timezone, otherwise we use the current year as the baseline to retrieve the timezone.
|
||||
* Also the timezone's in php 5.2.* support historical data better, eg. if timezone today was +8, but
|
||||
in 1970 it was +7:30, then php 5.2 return +7:30, while this library will use +8.
|
||||
*
|
||||
|
||||
- 19 March 2006 0.24
|
||||
Changed strftime() locale detection, because some locales prepend the day of week to the date when %c is used.
|
||||
|
||||
@ -368,7 +386,9 @@ First implementation.
|
||||
/*
|
||||
Version Number
|
||||
*/
|
||||
define('ADODB_DATE_VERSION',0.24);
|
||||
define('ADODB_DATE_VERSION',0.33);
|
||||
|
||||
$ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2);
|
||||
|
||||
/*
|
||||
This code was originally for windows. But apparently this problem happens
|
||||
@ -387,10 +407,13 @@ if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1);
|
||||
|
||||
function adodb_date_test_date($y1,$m,$d=13)
|
||||
{
|
||||
$t = adodb_mktime(0,0,0,$m,$d,$y1);
|
||||
$h = round(rand()% 24);
|
||||
$t = adodb_mktime($h,0,0,$m,$d,$y1);
|
||||
$rez = adodb_date('Y-n-j H:i:s',$t);
|
||||
if ("$y1-$m-$d 00:00:00" != $rez) {
|
||||
print "<b>$y1 error, expected=$y1-$m-$d 00:00:00, adodb=$rez</b><br>";
|
||||
if ($h == 0) $h = '00';
|
||||
else if ($h < 10) $h = '0'.$h;
|
||||
if ("$y1-$m-$d $h:00:00" != $rez) {
|
||||
print "<b>$y1 error, expected=$y1-$m-$d $h:00:00, adodb=$rez</b><br>";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -403,16 +426,19 @@ function adodb_date_test_strftime($fmt)
|
||||
|
||||
if ($s1 == $s2) return true;
|
||||
|
||||
echo "error for $fmt, strftime=$s1, $adodb=$s2<br>";
|
||||
echo "error for $fmt, strftime=$s1, adodb=$s2<br>";
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Test Suite
|
||||
*/
|
||||
*/
|
||||
function adodb_date_test()
|
||||
{
|
||||
|
||||
for ($m=-24; $m<=24; $m++)
|
||||
echo "$m :",adodb_date('d-m-Y',adodb_mktime(0,0,0,1+$m,20,2040)),"<br>";
|
||||
|
||||
error_reporting(E_ALL);
|
||||
print "<h4>Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION.' PHP='.PHP_VERSION."</h4>";
|
||||
@set_time_limit(0);
|
||||
@ -421,6 +447,15 @@ function adodb_date_test()
|
||||
// This flag disables calling of PHP native functions, so we can properly test the code
|
||||
if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1);
|
||||
|
||||
$t = time();
|
||||
|
||||
|
||||
$fmt = 'Y-m-d H:i:s';
|
||||
echo '<pre>';
|
||||
echo 'adodb: ',adodb_date($fmt,$t),'<br>';
|
||||
echo 'php : ',date($fmt,$t),'<br>';
|
||||
echo '</pre>';
|
||||
|
||||
adodb_date_test_strftime('%Y %m %x %X');
|
||||
adodb_date_test_strftime("%A %d %B %Y");
|
||||
adodb_date_test_strftime("%H %M S");
|
||||
@ -480,6 +515,7 @@ function adodb_date_test()
|
||||
|
||||
// Test string formating
|
||||
print "<p>Testing date formating</p>";
|
||||
|
||||
$fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C2822 r s t U w y Y z Z 2003';
|
||||
$s1 = date($fmt,0);
|
||||
$s2 = adodb_date($fmt,0);
|
||||
@ -657,15 +693,45 @@ function adodb_year_digit_check($y)
|
||||
return $y;
|
||||
}
|
||||
|
||||
/**
|
||||
get local time zone offset from GMT
|
||||
*/
|
||||
function adodb_get_gmt_diff()
|
||||
function adodb_get_gmt_diff_ts($ts)
|
||||
{
|
||||
static $TZ;
|
||||
if (isset($TZ)) return $TZ;
|
||||
if (0 <= $ts && $ts <= 0x7FFFFFFF) { // check if number in 32-bit signed range) {
|
||||
$arr = getdate($ts);
|
||||
$y = $arr['year'];
|
||||
$m = $arr['mon'];
|
||||
$d = $arr['mday'];
|
||||
return adodb_get_gmt_diff($y,$m,$d);
|
||||
} else {
|
||||
return adodb_get_gmt_diff(false,false,false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
get local time zone offset from GMT. Does not handle historical timezones before 1970.
|
||||
*/
|
||||
function adodb_get_gmt_diff($y,$m,$d)
|
||||
{
|
||||
static $TZ,$tzo;
|
||||
global $ADODB_DATETIME_CLASS;
|
||||
|
||||
if (!defined('ADODB_TEST_DATES')) $y = false;
|
||||
else if ($y < 1970 || $y >= 2038) $y = false;
|
||||
|
||||
if ($ADODB_DATETIME_CLASS && $y !== false) {
|
||||
$dt = new DateTime();
|
||||
$dt->setISODate($y,$m,$d);
|
||||
if (empty($tzo)) {
|
||||
$tzo = new DateTimeZone(date_default_timezone_get());
|
||||
# $tzt = timezone_transitions_get( $tzo );
|
||||
}
|
||||
return -$tzo->getOffset($dt);
|
||||
} else {
|
||||
if (isset($TZ)) return $TZ;
|
||||
$y = date('Y');
|
||||
$TZ = mktime(0,0,0,12,2,$y,0) - gmmktime(0,0,0,12,2,$y,0);
|
||||
}
|
||||
|
||||
$TZ = mktime(0,0,0,1,2,1970,0) - gmmktime(0,0,0,1,2,1970,0);
|
||||
return $TZ;
|
||||
}
|
||||
|
||||
@ -712,8 +778,8 @@ function adodb_validdate($y,$m,$d)
|
||||
{
|
||||
global $_month_table_normal,$_month_table_leaf;
|
||||
|
||||
if (_adodb_is_leap_year($y)) $marr =& $_month_table_leaf;
|
||||
else $marr =& $_month_table_normal;
|
||||
if (_adodb_is_leap_year($y)) $marr = $_month_table_leaf;
|
||||
else $marr = $_month_table_normal;
|
||||
|
||||
if ($m > 12 || $m < 1) return false;
|
||||
|
||||
@ -736,8 +802,7 @@ function _adodb_getdate($origd=false,$fast=false,$is_gmt=false)
|
||||
static $YRS;
|
||||
global $_month_table_normal,$_month_table_leaf;
|
||||
|
||||
$d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff());
|
||||
|
||||
$d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff_ts($origd));
|
||||
$_day_power = 86400;
|
||||
$_hour_power = 3600;
|
||||
$_min_power = 60;
|
||||
@ -927,6 +992,22 @@ global $_month_table_normal,$_month_table_leaf;
|
||||
0 => $origd
|
||||
);
|
||||
}
|
||||
/*
|
||||
if ($isphp5)
|
||||
$dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
|
||||
else
|
||||
$dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
|
||||
break;*/
|
||||
function adodb_tz_offset($gmt,$isphp5)
|
||||
{
|
||||
$zhrs = abs($gmt)/3600;
|
||||
$hrs = floor($zhrs);
|
||||
if ($isphp5)
|
||||
return sprintf('%s%02d%02d',($gmt<=0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);
|
||||
else
|
||||
return sprintf('%s%02d%02d',($gmt<0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);
|
||||
}
|
||||
|
||||
|
||||
function adodb_gmdate($fmt,$d=false)
|
||||
{
|
||||
@ -958,6 +1039,7 @@ function adodb_date2($fmt, $d=false, $is_gmt=false)
|
||||
function adodb_date($fmt,$d=false,$is_gmt=false)
|
||||
{
|
||||
static $daylight;
|
||||
global $ADODB_DATETIME_CLASS;
|
||||
|
||||
if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt);
|
||||
if (!defined('ADODB_TEST_DATES')) {
|
||||
@ -992,7 +1074,17 @@ static $daylight;
|
||||
*/
|
||||
for ($i=0; $i < $max; $i++) {
|
||||
switch($fmt[$i]) {
|
||||
case 'T': $dates .= date('T');break;
|
||||
case 'e':
|
||||
$dates .= date('e');
|
||||
break;
|
||||
case 'T':
|
||||
if ($ADODB_DATETIME_CLASS) {
|
||||
$dt = new DateTime();
|
||||
$dt->SetDate($year,$month,$day);
|
||||
$dates .= $dt->Format('T');
|
||||
} else
|
||||
$dates .= date('T');
|
||||
break;
|
||||
// YEAR
|
||||
case 'L': $dates .= $arr['leap'] ? '1' : '0'; break;
|
||||
case 'r': // Thu, 21 Dec 2000 16:01:07 +0200
|
||||
@ -1008,13 +1100,11 @@ static $daylight;
|
||||
|
||||
if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs;
|
||||
|
||||
$gmt = adodb_get_gmt_diff();
|
||||
if ($isphp5)
|
||||
$dates .= sprintf(' %s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
|
||||
else
|
||||
$dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
|
||||
$gmt = adodb_get_gmt_diff($year,$month,$day);
|
||||
|
||||
$dates .= ' '.adodb_tz_offset($gmt,$isphp5);
|
||||
break;
|
||||
|
||||
|
||||
case 'Y': $dates .= $year; break;
|
||||
case 'y': $dates .= substr($year,strlen($year)-2,2); break;
|
||||
// MONTH
|
||||
@ -1041,14 +1131,11 @@ static $daylight;
|
||||
|
||||
// HOUR
|
||||
case 'Z':
|
||||
$dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break;
|
||||
$dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff($year,$month,$day); break;
|
||||
case 'O':
|
||||
$gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff();
|
||||
$gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$month,$day);
|
||||
|
||||
if ($isphp5)
|
||||
$dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
|
||||
else
|
||||
$dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
|
||||
$dates .= adodb_tz_offset($gmt,$isphp5);
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
@ -1130,16 +1217,21 @@ function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=fa
|
||||
|
||||
// for windows, we don't check 1970 because with timezone differences,
|
||||
// 1 Jan 1970 could generate negative timestamp, which is illegal
|
||||
if (1971 < $year && $year < 2038
|
||||
$usephpfns = (1970 < $year && $year < 2038
|
||||
|| !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038)
|
||||
) {
|
||||
);
|
||||
|
||||
|
||||
if ($usephpfns && ($year + $mon/12+$day/365.25+$hr/(24*365.25) >= 2038)) $usephpfns = false;
|
||||
|
||||
if ($usephpfns) {
|
||||
return $is_gmt ?
|
||||
@gmmktime($hr,$min,$sec,$mon,$day,$year):
|
||||
@mktime($hr,$min,$sec,$mon,$day,$year);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff();
|
||||
$gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$mon,$day);
|
||||
|
||||
/*
|
||||
# disabled because some people place large values in $sec.
|
||||
@ -1156,7 +1248,7 @@ function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=fa
|
||||
$year = adodb_year_digit_check($year);
|
||||
|
||||
if ($mon > 12) {
|
||||
$y = floor($mon / 12);
|
||||
$y = floor(($mon-1)/ 12);
|
||||
$year += $y;
|
||||
$mon -= $y*12;
|
||||
} else if ($mon < 1) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user