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.
|
Released under both BSD license and Lesser GPL library license.
|
||||||
Whenever there is any discrepancy between the two licenses,
|
Whenever there is any discrepancy between the two licenses,
|
||||||
the BSD license will take precedence. See License.txt.
|
the BSD license will take precedence. See License.txt.
|
||||||
@ -54,7 +54,7 @@ $ADODB_INCLUDED_CSV = 1;
|
|||||||
$line = "====1,$tt,$sql\n";
|
$line = "====1,$tt,$sql\n";
|
||||||
|
|
||||||
if ($rs->databaseType == 'array') {
|
if ($rs->databaseType == 'array') {
|
||||||
$rows =& $rs->_array;
|
$rows = $rs->_array;
|
||||||
} else {
|
} else {
|
||||||
$rows = array();
|
$rows = array();
|
||||||
while (!$rs->EOF) {
|
while (!$rs->EOF) {
|
||||||
@ -64,13 +64,14 @@ $ADODB_INCLUDED_CSV = 1;
|
|||||||
}
|
}
|
||||||
|
|
||||||
for($i=0; $i < $max; $i++) {
|
for($i=0; $i < $max; $i++) {
|
||||||
$o =& $rs->FetchField($i);
|
$o = $rs->FetchField($i);
|
||||||
$flds[] = $o;
|
$flds[] = $o;
|
||||||
}
|
}
|
||||||
|
|
||||||
$savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
|
$savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
|
||||||
$class = $rs->connection->arrayClass;
|
$class = $rs->connection->arrayClass;
|
||||||
$rs2 = new $class();
|
$rs2 = new $class();
|
||||||
|
$rs2->timeCreated = $rs->timeCreated; # memcache fix
|
||||||
$rs2->sql = $rs->sql;
|
$rs2->sql = $rs->sql;
|
||||||
$rs2->oldProvider = $rs->dataProvider;
|
$rs2->oldProvider = $rs->dataProvider;
|
||||||
$rs2->InitArrayFields($rows,$flds);
|
$rs2->InitArrayFields($rows,$flds);
|
||||||
@ -90,7 +91,7 @@ $ADODB_INCLUDED_CSV = 1;
|
|||||||
* error occurred in sql INSERT/UPDATE/DELETE,
|
* error occurred in sql INSERT/UPDATE/DELETE,
|
||||||
* empty recordset is returned
|
* empty recordset is returned
|
||||||
*/
|
*/
|
||||||
function &csv2rs($url,&$err,$timeout=0, $rsclass='ADORecordSet_array')
|
function csv2rs($url,&$err,$timeout=0, $rsclass='ADORecordSet_array')
|
||||||
{
|
{
|
||||||
$false = false;
|
$false = false;
|
||||||
$err = false;
|
$err = false;
|
||||||
@ -261,6 +262,7 @@ $ADODB_INCLUDED_CSV = 1;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a file $filename and its $contents (normally for caching) with file locking
|
* 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)
|
function adodb_write_file($filename, $contents,$debug=false)
|
||||||
{
|
{
|
||||||
@ -280,27 +282,31 @@ $ADODB_INCLUDED_CSV = 1;
|
|||||||
$mtime = substr(str_replace(' ','_',microtime()),2);
|
$mtime = substr(str_replace(' ','_',microtime()),2);
|
||||||
// getmypid() actually returns 0 on Win98 - never mind!
|
// getmypid() actually returns 0 on Win98 - never mind!
|
||||||
$tmpname = $filename.uniqid($mtime).getmypid();
|
$tmpname = $filename.uniqid($mtime).getmypid();
|
||||||
if (!($fd = @fopen($tmpname,'a'))) return false;
|
if (!($fd = @fopen($tmpname,'w'))) return false;
|
||||||
$ok = ftruncate($fd,0);
|
if (fwrite($fd,$contents)) $ok = true;
|
||||||
if (!fwrite($fd,$contents)) $ok = false;
|
else $ok = false;
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
chmod($tmpname,0644);
|
|
||||||
|
if ($ok) {
|
||||||
|
@chmod($tmpname,0644);
|
||||||
// the tricky moment
|
// the tricky moment
|
||||||
@unlink($filename);
|
@unlink($filename);
|
||||||
if (!@rename($tmpname,$filename)) {
|
if (!@rename($tmpname,$filename)) {
|
||||||
unlink($tmpname);
|
unlink($tmpname);
|
||||||
$ok = false;
|
$ok = 0;
|
||||||
}
|
}
|
||||||
if (!$ok) {
|
if (!$ok) {
|
||||||
if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
|
if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
if (!($fd = @fopen($filename, 'a'))) return false;
|
if (!($fd = @fopen($filename, 'a'))) return false;
|
||||||
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
|
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
|
||||||
$ok = fwrite( $fd, $contents );
|
if (fwrite( $fd, $contents )) $ok = true;
|
||||||
|
else $ok = false;
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
chmod($filename,0644);
|
@chmod($filename,0644);
|
||||||
}else {
|
}else {
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
|
if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?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.
|
* Released under both BSD license and Lesser GPL library license.
|
||||||
* Whenever there is any discrepancy between the two licenses,
|
* Whenever there is any discrepancy between the two licenses,
|
||||||
* the BSD license will take precedence.
|
* the BSD license will take precedence.
|
||||||
@ -92,14 +92,14 @@ function adodb_error_pg($errormsg)
|
|||||||
{
|
{
|
||||||
if (is_numeric($errormsg)) return (integer) $errormsg;
|
if (is_numeric($errormsg)) return (integer) $errormsg;
|
||||||
static $error_regexps = array(
|
static $error_regexps = array(
|
||||||
'/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
|
'/(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.*/' => DB_ERROR_ALREADY_EXISTS,
|
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/i' => DB_ERROR_ALREADY_EXISTS,
|
||||||
'/divide by zero$/' => DB_ERROR_DIVZERO,
|
'/divide by zero$/i' => DB_ERROR_DIVZERO,
|
||||||
'/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
|
'/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER,
|
||||||
'/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
|
'/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/i' => DB_ERROR_NOSUCHFIELD,
|
||||||
'/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
|
'/parser: parse error at or near \"/i' => DB_ERROR_SYNTAX,
|
||||||
'/referential integrity violation/' => DB_ERROR_CONSTRAINT,
|
'/referential integrity violation/i' => DB_ERROR_CONSTRAINT,
|
||||||
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/'
|
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key.*violates unique constraint/i'
|
||||||
=> DB_ERROR_ALREADY_EXISTS
|
=> DB_ERROR_ALREADY_EXISTS
|
||||||
);
|
);
|
||||||
reset($error_regexps);
|
reset($error_regexps);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?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.
|
* Released under both BSD license and Lesser GPL library license.
|
||||||
* Whenever there is any discrepancy between the two licenses,
|
* Whenever there is any discrepancy between the two licenses,
|
||||||
* the BSD license will take precedence.
|
* the BSD license will take precedence.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?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.
|
Released under both BSD license and Lesser GPL library license.
|
||||||
Whenever there is any discrepancy between the two licenses,
|
Whenever there is any discrepancy between the two licenses,
|
||||||
the BSD license will take precedence.
|
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
|
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
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// security - hide paths
|
// security - hide paths
|
||||||
if (!defined('ADODB_DIR')) die();
|
if (!defined('ADODB_DIR')) die();
|
||||||
|
|
||||||
@ -7,7 +10,7 @@ global $ADODB_INCLUDED_LIB;
|
|||||||
$ADODB_INCLUDED_LIB = 1;
|
$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.
|
Released under both BSD license and Lesser GPL library license.
|
||||||
Whenever there is any discrepancy between the two licenses,
|
Whenever there is any discrepancy between the two licenses,
|
||||||
the BSD license will take precedence. See License.txt.
|
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.
|
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)
|
function adodb_probetypes(&$array,&$types,$probe=8)
|
||||||
{
|
{
|
||||||
// probe and guess the type
|
// probe and guess the type
|
||||||
@ -25,7 +58,7 @@ function adodb_probetypes(&$array,&$types,$probe=8)
|
|||||||
|
|
||||||
|
|
||||||
for ($j=0;$j < $max; $j++) {
|
for ($j=0;$j < $max; $j++) {
|
||||||
$row =& $array[$j];
|
$row = $array[$j];
|
||||||
if (!$row) break;
|
if (!$row) break;
|
||||||
$i = -1;
|
$i = -1;
|
||||||
foreach($row as $v) {
|
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));
|
$oldX = sizeof(reset($arr));
|
||||||
$oldY = sizeof($arr);
|
$oldY = sizeof($arr);
|
||||||
|
|
||||||
if ($hdr) {
|
if ($hdr) {
|
||||||
$startx = 1;
|
$startx = 1;
|
||||||
$hdr = array();
|
$hdr = array('Fields');
|
||||||
for ($y = 0; $y < $oldY; $y++) {
|
for ($y = 0; $y < $oldY; $y++) {
|
||||||
$hdr[] = $arr[$y][0];
|
$hdr[] = $arr[$y][0];
|
||||||
}
|
}
|
||||||
@ -73,7 +107,12 @@ function &adodb_transpose(&$arr, &$newarr, &$hdr)
|
|||||||
$startx = 0;
|
$startx = 0;
|
||||||
|
|
||||||
for ($x = $startx; $x < $oldX; $x++) {
|
for ($x = $startx; $x < $oldX; $x++) {
|
||||||
|
if ($fobjs) {
|
||||||
|
$o = $fobjs[$x];
|
||||||
|
$newarr[] = array($o->name);
|
||||||
|
} else
|
||||||
$newarr[] = array();
|
$newarr[] = array();
|
||||||
|
|
||||||
for ($y = 0; $y < $oldY; $y++) {
|
for ($y = 0; $y < $oldY; $y++) {
|
||||||
$newarr[$x-$startx][] = $arr[$y][$x];
|
$newarr[$x-$startx][] = $arr[$y][$x];
|
||||||
}
|
}
|
||||||
@ -105,7 +144,10 @@ function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_
|
|||||||
$keyCol = array($keyCol);
|
$keyCol = array($keyCol);
|
||||||
}
|
}
|
||||||
foreach($fieldArray as $k => $v) {
|
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);
|
$v = $zthis->qstr($v);
|
||||||
$fieldArray[$k] = $v;
|
$fieldArray[$k] = $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) ||
|
if (!empty($zthis->_nestedSQL) || preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) ||
|
||||||
preg_match('/\s+GROUP\s+BY\s+/is',$sql) ||
|
preg_match('/\s+GROUP\s+BY\s+/is',$sql) ||
|
||||||
preg_match('/\s+UNION\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
|
// 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...
|
// but this is only supported by oracle and postgresql...
|
||||||
if ($zthis->dataProvider == 'oci8') {
|
if ($zthis->dataProvider == 'oci8') {
|
||||||
|
|
||||||
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
|
|
||||||
|
|
||||||
// Allow Oracle hints to be used for query optimization, Chris Wrye
|
// Allow Oracle hints to be used for query optimization, Chris Wrye
|
||||||
if (preg_match('#/\\*+.*?\\*\\/#', $sql, $hint)) {
|
if (preg_match('#/\\*+.*?\\*\\/#', $sql, $hint)) {
|
||||||
$rewritesql = "SELECT ".$hint[0]." COUNT(*) FROM (".$rewritesql.")";
|
$rewritesql = "SELECT ".$hint[0]." COUNT(*) FROM (".$rewritesql.")";
|
||||||
} else
|
} else
|
||||||
$rewritesql = "SELECT COUNT(*) FROM (".$rewritesql.")";
|
$rewritesql = "SELECT COUNT(*) FROM (".$rewritesql.")";
|
||||||
|
|
||||||
} else if (strncmp($zthis->databaseType,'postgres',8) == 0) {
|
} else if (strncmp($zthis->databaseType,'postgres',8) == 0 || strncmp($zthis->databaseType,'mysql',5) == 0) {
|
||||||
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
|
|
||||||
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
|
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
|
||||||
|
} else {
|
||||||
|
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql)";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// now replace SELECT ... FROM with SELECT COUNT(*) FROM
|
// now replace SELECT ... FROM with SELECT COUNT(*) FROM
|
||||||
$rewritesql = preg_replace(
|
$rewritesql = preg_replace(
|
||||||
'/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);
|
'/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails
|
// 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!
|
// with mssql, access and postgresql. Also a good speedup optimization - skips sorting!
|
||||||
// also see http://phplens.com/lens/lensforum/msgs.php?id=12752
|
// also see http://phplens.com/lens/lensforum/msgs.php?id=12752
|
||||||
if (preg_match('/\sORDER\s+BY\s*\(/i',$rewritesql))
|
$rewritesql = adodb_strip_order_by($rewritesql);
|
||||||
$rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql);
|
|
||||||
else
|
|
||||||
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$rewritesql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (isset($rewritesql) && $rewritesql != $sql) {
|
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) {
|
if ($secs2cache) {
|
||||||
// we only use half the time of secs2cache because the count can quickly
|
// 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
|
// strip off unneeded ORDER BY if no UNION
|
||||||
if (preg_match('/\s*UNION\s*/is', $sql)) $rewritesql = $sql;
|
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];
|
if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[0];
|
||||||
|
|
||||||
$rstest = &$zthis->Execute($rewritesql,$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) $rstest = $zthis->Execute($sql,$inputarr);
|
||||||
|
}
|
||||||
if ($rstest) {
|
if ($rstest) {
|
||||||
$qryRecs = $rstest->RecordCount();
|
$qryRecs = $rstest->RecordCount();
|
||||||
if ($qryRecs == -1) {
|
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
|
data will get out of synch. use CachePageExecute() only with tables that
|
||||||
rarely change.
|
rarely change.
|
||||||
*/
|
*/
|
||||||
function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
|
function _adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
|
||||||
$inputarr=false, $secs2cache=0)
|
$inputarr=false, $secs2cache=0)
|
||||||
{
|
{
|
||||||
$atfirstpage = false;
|
$atfirstpage = false;
|
||||||
@ -490,9 +529,9 @@ function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
|
|||||||
// We get the data we want
|
// We get the data we want
|
||||||
$offset = $nrows * ($page-1);
|
$offset = $nrows * ($page-1);
|
||||||
if ($secs2cache > 0)
|
if ($secs2cache > 0)
|
||||||
$rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
|
$rsreturn = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
|
||||||
else
|
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
|
// 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
|
// 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;
|
$atfirstpage = false;
|
||||||
@ -524,16 +563,16 @@ function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputar
|
|||||||
// the last page number.
|
// the last page number.
|
||||||
$pagecounter = $page + 1;
|
$pagecounter = $page + 1;
|
||||||
$pagecounteroffset = ($pagecounter * $nrows) - $nrows;
|
$pagecounteroffset = ($pagecounter * $nrows) - $nrows;
|
||||||
if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
|
if ($secs2cache>0) $rstest = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
|
||||||
else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
|
else $rstest = $zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
|
||||||
if ($rstest) {
|
if ($rstest) {
|
||||||
while ($rstest && $rstest->EOF && $pagecounter>0) {
|
while ($rstest && $rstest->EOF && $pagecounter>0) {
|
||||||
$atlastpage = true;
|
$atlastpage = true;
|
||||||
$pagecounter--;
|
$pagecounter--;
|
||||||
$pagecounteroffset = $nrows * ($pagecounter - 1);
|
$pagecounteroffset = $nrows * ($pagecounter - 1);
|
||||||
$rstest->Close();
|
$rstest->Close();
|
||||||
if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
|
if ($secs2cache>0) $rstest = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
|
||||||
else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
|
else $rstest = $zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
|
||||||
}
|
}
|
||||||
if ($rstest) $rstest->Close();
|
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
|
// We get the data we want
|
||||||
$offset = $nrows * ($page-1);
|
$offset = $nrows * ($page-1);
|
||||||
if ($secs2cache > 0) $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
|
if ($secs2cache > 0) $rsreturn = $zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
|
||||||
else $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
|
else $rsreturn = $zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
|
||||||
|
|
||||||
// Before returning the RecordSet, we set the pagination properties we need
|
// Before returning the RecordSet, we set the pagination properties we need
|
||||||
if ($rsreturn) {
|
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)
|
function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=2)
|
||||||
{
|
{
|
||||||
|
global $ADODB_QUOTE_FIELDNAMES;
|
||||||
|
|
||||||
if (!$rs) {
|
if (!$rs) {
|
||||||
printf(ADODB_BAD_RS,'GetUpdateSQL');
|
printf(ADODB_BAD_RS,'GetUpdateSQL');
|
||||||
return false;
|
return false;
|
||||||
@ -606,7 +647,7 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
|
|||||||
$type = 'C';
|
$type = 'C';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($upperfname,' ') !== false)
|
if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
|
||||||
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
|
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
|
||||||
else
|
else
|
||||||
$fnameq = $upperfname;
|
$fnameq = $upperfname;
|
||||||
@ -720,6 +761,7 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false,$force=2)
|
|||||||
static $cacheRS = false;
|
static $cacheRS = false;
|
||||||
static $cacheSig = 0;
|
static $cacheSig = 0;
|
||||||
static $cacheCols;
|
static $cacheCols;
|
||||||
|
global $ADODB_QUOTE_FIELDNAMES;
|
||||||
|
|
||||||
$tableName = '';
|
$tableName = '';
|
||||||
$values = '';
|
$values = '';
|
||||||
@ -738,10 +780,10 @@ static $cacheCols;
|
|||||||
//php can't do a $rsclass::MetaType()
|
//php can't do a $rsclass::MetaType()
|
||||||
$rsclass = $zthis->rsPrefix.$zthis->databaseType;
|
$rsclass = $zthis->rsPrefix.$zthis->databaseType;
|
||||||
$recordSet = new $rsclass(-1,$zthis->fetchMode);
|
$recordSet = new $rsclass(-1,$zthis->fetchMode);
|
||||||
$recordSet->connection = &$zthis;
|
$recordSet->connection = $zthis;
|
||||||
|
|
||||||
if (is_string($cacheRS) && $cacheRS == $rs) {
|
if (is_string($cacheRS) && $cacheRS == $rs) {
|
||||||
$columns =& $cacheCols;
|
$columns = $cacheCols;
|
||||||
} else {
|
} else {
|
||||||
$columns = $zthis->MetaColumns( $tableName );
|
$columns = $zthis->MetaColumns( $tableName );
|
||||||
$cacheRS = $tableName;
|
$cacheRS = $tableName;
|
||||||
@ -749,7 +791,7 @@ static $cacheCols;
|
|||||||
}
|
}
|
||||||
} else if (is_subclass_of($rs, 'adorecordset')) {
|
} else if (is_subclass_of($rs, 'adorecordset')) {
|
||||||
if (isset($rs->insertSig) && is_integer($cacheRS) && $cacheRS == $rs->insertSig) {
|
if (isset($rs->insertSig) && is_integer($cacheRS) && $cacheRS == $rs->insertSig) {
|
||||||
$columns =& $cacheCols;
|
$columns = $cacheCols;
|
||||||
} else {
|
} else {
|
||||||
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
|
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
|
||||||
$columns[] = $rs->FetchField($i);
|
$columns[] = $rs->FetchField($i);
|
||||||
@ -757,7 +799,7 @@ static $cacheCols;
|
|||||||
$cacheCols = $columns;
|
$cacheCols = $columns;
|
||||||
$rs->insertSig = $cacheSig++;
|
$rs->insertSig = $cacheSig++;
|
||||||
}
|
}
|
||||||
$recordSet =& $rs;
|
$recordSet = $rs;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf(ADODB_BAD_RS,'GetInsertSQL');
|
printf(ADODB_BAD_RS,'GetInsertSQL');
|
||||||
@ -769,7 +811,7 @@ static $cacheCols;
|
|||||||
$upperfname = strtoupper($field->name);
|
$upperfname = strtoupper($field->name);
|
||||||
if (adodb_key_exists($upperfname,$arrFields,$force)) {
|
if (adodb_key_exists($upperfname,$arrFields,$force)) {
|
||||||
$bad = false;
|
$bad = false;
|
||||||
if (strpos($upperfname,' ') !== false)
|
if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
|
||||||
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
|
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
|
||||||
else
|
else
|
||||||
$fnameq = $upperfname;
|
$fnameq = $upperfname;
|
||||||
@ -963,8 +1005,19 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields,
|
|||||||
$val = $zthis->DBTimeStamp($arrFields[$fname]);
|
$val = $zthis->DBTimeStamp($arrFields[$fname]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case "N":
|
||||||
$val = $arrFields[$fname];
|
$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 = str_replace(array("'"," ","("),"",$arrFields[$fname]); // basic sql injection defence
|
||||||
if (empty($val)) $val = '0';
|
if (empty($val)) $val = '0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -984,7 +1037,8 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
|
|||||||
if ($inputarr) {
|
if ($inputarr) {
|
||||||
foreach($inputarr as $kk=>$vv) {
|
foreach($inputarr as $kk=>$vv) {
|
||||||
if (is_string($vv) && strlen($vv)>64) $vv = substr($vv,0,64).'...';
|
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 ]";
|
$ss = "[ $ss ]";
|
||||||
}
|
}
|
||||||
@ -1003,11 +1057,13 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
|
|||||||
$ss = '<code>'.htmlspecialchars($ss).'</code>';
|
$ss = '<code>'.htmlspecialchars($ss).'</code>';
|
||||||
}
|
}
|
||||||
if ($zthis->debug === -1)
|
if ($zthis->debug === -1)
|
||||||
ADOConnection::outp( "<br />\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<br />\n",false);
|
ADOConnection::outp( "<br>\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<br>\n",false);
|
||||||
else
|
else if ($zthis->debug !== -99)
|
||||||
ADOConnection::outp( "<hr />\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<hr />\n",false);
|
ADOConnection::outp( "<hr>\n($dbt): ".htmlspecialchars($sqlTxt)." $ss\n<hr>\n",false);
|
||||||
} else {
|
} 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);
|
$qID = $zthis->_query($sql,$inputarr);
|
||||||
@ -1018,10 +1074,21 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
|
|||||||
*/
|
*/
|
||||||
if ($zthis->databaseType == 'mssql') {
|
if ($zthis->databaseType == 'mssql') {
|
||||||
// ErrorNo is a slow function call in mssql, and not reliable in PHP 4.0.6
|
// ErrorNo is a slow function call in mssql, and not reliable in PHP 4.0.6
|
||||||
|
|
||||||
if($emsg = $zthis->ErrorMsg()) {
|
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) {
|
} 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());
|
ADOConnection::outp($zthis->ErrorNo() .': '. $zthis->ErrorMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1030,11 +1097,13 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
# pretty print the debug_backtrace function
|
# 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 '';
|
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";
|
$fmt = ($html) ? "</font><font color=#808080 size=-1> %% line %4d, file: <a href=\"file:/%s\">%s</a></font>" : "%% line %4d, file: %s";
|
||||||
|
|
||||||
$MAXSTRLEN = 128;
|
$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 if (is_bool($v)) $args[] = $v ? 'true' : 'false';
|
||||||
else {
|
else {
|
||||||
$v = (string) @$v;
|
$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 .= '...';
|
if (strlen($v) > $MAXSTRLEN) $str .= '...';
|
||||||
$args[] = $str;
|
$args[] = $str;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?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.
|
Released under both BSD license and Lesser GPL library license.
|
||||||
Whenever there is any discrepancy between the two licenses,
|
Whenever there is any discrepancy between the two licenses,
|
||||||
the BSD license will take precedence.
|
the BSD license will take precedence.
|
||||||
|
@ -241,6 +241,24 @@ b. Implement daylight savings, which looks awfully complicated, see
|
|||||||
|
|
||||||
|
|
||||||
CHANGELOG
|
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
|
- 19 March 2006 0.24
|
||||||
Changed strftime() locale detection, because some locales prepend the day of week to the date when %c is used.
|
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
|
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
|
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)
|
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);
|
$rez = adodb_date('Y-n-j H:i:s',$t);
|
||||||
if ("$y1-$m-$d 00:00:00" != $rez) {
|
if ($h == 0) $h = '00';
|
||||||
print "<b>$y1 error, expected=$y1-$m-$d 00:00:00, adodb=$rez</b><br>";
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -403,7 +426,7 @@ function adodb_date_test_strftime($fmt)
|
|||||||
|
|
||||||
if ($s1 == $s2) return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,6 +436,9 @@ function adodb_date_test_strftime($fmt)
|
|||||||
function adodb_date_test()
|
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);
|
error_reporting(E_ALL);
|
||||||
print "<h4>Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION.' PHP='.PHP_VERSION."</h4>";
|
print "<h4>Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION.' PHP='.PHP_VERSION."</h4>";
|
||||||
@set_time_limit(0);
|
@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
|
// 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);
|
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('%Y %m %x %X');
|
||||||
adodb_date_test_strftime("%A %d %B %Y");
|
adodb_date_test_strftime("%A %d %B %Y");
|
||||||
adodb_date_test_strftime("%H %M S");
|
adodb_date_test_strftime("%H %M S");
|
||||||
@ -480,6 +515,7 @@ function adodb_date_test()
|
|||||||
|
|
||||||
// Test string formating
|
// Test string formating
|
||||||
print "<p>Testing date formating</p>";
|
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';
|
$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);
|
$s1 = date($fmt,0);
|
||||||
$s2 = adodb_date($fmt,0);
|
$s2 = adodb_date($fmt,0);
|
||||||
@ -657,15 +693,45 @@ function adodb_year_digit_check($y)
|
|||||||
return $y;
|
return $y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function adodb_get_gmt_diff_ts($ts)
|
||||||
get local time zone offset from GMT
|
|
||||||
*/
|
|
||||||
function adodb_get_gmt_diff()
|
|
||||||
{
|
{
|
||||||
static $TZ;
|
if (0 <= $ts && $ts <= 0x7FFFFFFF) { // check if number in 32-bit signed range) {
|
||||||
if (isset($TZ)) return $TZ;
|
$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;
|
return $TZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -712,8 +778,8 @@ function adodb_validdate($y,$m,$d)
|
|||||||
{
|
{
|
||||||
global $_month_table_normal,$_month_table_leaf;
|
global $_month_table_normal,$_month_table_leaf;
|
||||||
|
|
||||||
if (_adodb_is_leap_year($y)) $marr =& $_month_table_leaf;
|
if (_adodb_is_leap_year($y)) $marr = $_month_table_leaf;
|
||||||
else $marr =& $_month_table_normal;
|
else $marr = $_month_table_normal;
|
||||||
|
|
||||||
if ($m > 12 || $m < 1) return false;
|
if ($m > 12 || $m < 1) return false;
|
||||||
|
|
||||||
@ -736,8 +802,7 @@ function _adodb_getdate($origd=false,$fast=false,$is_gmt=false)
|
|||||||
static $YRS;
|
static $YRS;
|
||||||
global $_month_table_normal,$_month_table_leaf;
|
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;
|
$_day_power = 86400;
|
||||||
$_hour_power = 3600;
|
$_hour_power = 3600;
|
||||||
$_min_power = 60;
|
$_min_power = 60;
|
||||||
@ -927,6 +992,22 @@ global $_month_table_normal,$_month_table_leaf;
|
|||||||
0 => $origd
|
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)
|
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)
|
function adodb_date($fmt,$d=false,$is_gmt=false)
|
||||||
{
|
{
|
||||||
static $daylight;
|
static $daylight;
|
||||||
|
global $ADODB_DATETIME_CLASS;
|
||||||
|
|
||||||
if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt);
|
if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt);
|
||||||
if (!defined('ADODB_TEST_DATES')) {
|
if (!defined('ADODB_TEST_DATES')) {
|
||||||
@ -992,7 +1074,17 @@ static $daylight;
|
|||||||
*/
|
*/
|
||||||
for ($i=0; $i < $max; $i++) {
|
for ($i=0; $i < $max; $i++) {
|
||||||
switch($fmt[$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
|
// YEAR
|
||||||
case 'L': $dates .= $arr['leap'] ? '1' : '0'; break;
|
case 'L': $dates .= $arr['leap'] ? '1' : '0'; break;
|
||||||
case 'r': // Thu, 21 Dec 2000 16:01:07 +0200
|
case 'r': // Thu, 21 Dec 2000 16:01:07 +0200
|
||||||
@ -1008,11 +1100,9 @@ static $daylight;
|
|||||||
|
|
||||||
if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs;
|
if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs;
|
||||||
|
|
||||||
$gmt = adodb_get_gmt_diff();
|
$gmt = adodb_get_gmt_diff($year,$month,$day);
|
||||||
if ($isphp5)
|
|
||||||
$dates .= sprintf(' %s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
|
$dates .= ' '.adodb_tz_offset($gmt,$isphp5);
|
||||||
else
|
|
||||||
$dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Y': $dates .= $year; break;
|
case 'Y': $dates .= $year; break;
|
||||||
@ -1041,14 +1131,11 @@ static $daylight;
|
|||||||
|
|
||||||
// HOUR
|
// HOUR
|
||||||
case 'Z':
|
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':
|
case 'O':
|
||||||
$gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff();
|
$gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$month,$day);
|
||||||
|
|
||||||
if ($isphp5)
|
$dates .= adodb_tz_offset($gmt,$isphp5);
|
||||||
$dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
|
|
||||||
else
|
|
||||||
$dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'H':
|
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,
|
// for windows, we don't check 1970 because with timezone differences,
|
||||||
// 1 Jan 1970 could generate negative timestamp, which is illegal
|
// 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)
|
|| !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 ?
|
return $is_gmt ?
|
||||||
@gmmktime($hr,$min,$sec,$mon,$day,$year):
|
@gmmktime($hr,$min,$sec,$mon,$day,$year):
|
||||||
@mktime($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.
|
# 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);
|
$year = adodb_year_digit_check($year);
|
||||||
|
|
||||||
if ($mon > 12) {
|
if ($mon > 12) {
|
||||||
$y = floor($mon / 12);
|
$y = floor(($mon-1)/ 12);
|
||||||
$year += $y;
|
$year += $y;
|
||||||
$mon -= $y*12;
|
$mon -= $y*12;
|
||||||
} else if ($mon < 1) {
|
} else if ($mon < 1) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?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.
|
Released under both BSD license and Lesser GPL library license.
|
||||||
Whenever there is any discrepancy between the two licenses,
|
Whenever there is any discrepancy between the two licenses,
|
||||||
the BSD license will take precedence.
|
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;
|
$save = $this->metaTablesSQL;
|
||||||
if ($showSchema && is_string($showSchema)) {
|
if ($showSchema && is_string($showSchema)) {
|
||||||
@ -69,14 +69,14 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
$mask = $this->qstr($mask);
|
$mask = $this->qstr($mask);
|
||||||
$this->metaTablesSQL .= " like $mask";
|
$this->metaTablesSQL .= " like $mask";
|
||||||
}
|
}
|
||||||
$ret =& ADOConnection::MetaTables($ttype,$showSchema);
|
$ret = ADOConnection::MetaTables($ttype,$showSchema);
|
||||||
|
|
||||||
$this->metaTablesSQL = $save;
|
$this->metaTablesSQL = $save;
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function &MetaIndexes ($table, $primary = FALSE, $owner=false)
|
function MetaIndexes ($table, $primary = FALSE, $owner=false)
|
||||||
{
|
{
|
||||||
// save old fetch mode
|
// save old fetch mode
|
||||||
global $ADODB_FETCH_MODE;
|
global $ADODB_FETCH_MODE;
|
||||||
@ -132,6 +132,7 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
// if magic quotes disabled, use mysql_real_escape_string()
|
// if magic quotes disabled, use mysql_real_escape_string()
|
||||||
function qstr($s,$magic_quotes=false)
|
function qstr($s,$magic_quotes=false)
|
||||||
{
|
{
|
||||||
|
if (is_null($s)) return 'NULL';
|
||||||
if (!$magic_quotes) {
|
if (!$magic_quotes) {
|
||||||
|
|
||||||
if (ADODB_PHPVER >= 0x4300) {
|
if (ADODB_PHPVER >= 0x4300) {
|
||||||
@ -157,11 +158,12 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
|
|
||||||
function GetOne($sql,$inputarr=false)
|
function GetOne($sql,$inputarr=false)
|
||||||
{
|
{
|
||||||
|
global $ADODB_GETONE_EOF;
|
||||||
if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
|
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) {
|
if ($rs) {
|
||||||
$rs->Close();
|
$rs->Close();
|
||||||
if ($rs->EOF) return false;
|
if ($rs->EOF) return $ADODB_GETONE_EOF;
|
||||||
return reset($rs->fields);
|
return reset($rs->fields);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -184,6 +186,7 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
// Reference on Last_Insert_ID on the recommended way to simulate sequences
|
// Reference on Last_Insert_ID on the recommended way to simulate sequences
|
||||||
var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
|
var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
|
||||||
var $_genSeqSQL = "create table %s (id int not null)";
|
var $_genSeqSQL = "create table %s (id int not null)";
|
||||||
|
var $_genSeqCountSQL = "select count(*) from %s";
|
||||||
var $_genSeq2SQL = "insert into %s values (%s)";
|
var $_genSeq2SQL = "insert into %s values (%s)";
|
||||||
var $_dropSeqSQL = "drop table %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
|
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
|
||||||
$u = strtoupper($seqname);
|
$u = strtoupper($seqname);
|
||||||
$this->Execute(sprintf($this->_genSeqSQL,$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);
|
$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;
|
$this->_logsql = $savelog;
|
||||||
return $this->genID;
|
return $this->genID;
|
||||||
}
|
}
|
||||||
|
|
||||||
function &MetaDatabases()
|
function MetaDatabases()
|
||||||
{
|
{
|
||||||
$qid = mysql_list_dbs($this->_connectionID);
|
$qid = mysql_list_dbs($this->_connectionID);
|
||||||
$arr = array();
|
$arr = array();
|
||||||
@ -343,7 +350,7 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
if (!$date) $date = $this->sysDate;
|
if (!$date) $date = $this->sysDate;
|
||||||
|
|
||||||
$fraction = $dayFraction * 24 * 3600;
|
$fraction = $dayFraction * 24 * 3600;
|
||||||
return $date . ' + INTERVAL ' . $fraction.' SECOND';
|
return '('. $date . ' + INTERVAL ' . $fraction.' SECOND)';
|
||||||
|
|
||||||
// return "from_unixtime(unix_timestamp($date)+$fraction)";
|
// return "from_unixtime(unix_timestamp($date)+$fraction)";
|
||||||
}
|
}
|
||||||
@ -388,7 +395,7 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
|
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
|
||||||
}
|
}
|
||||||
|
|
||||||
function &MetaColumns($table)
|
function MetaColumns($table, $normalize=true)
|
||||||
{
|
{
|
||||||
$this->_findschema($table,$schema);
|
$this->_findschema($table,$schema);
|
||||||
if ($schema) {
|
if ($schema) {
|
||||||
@ -441,8 +448,9 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
$fld->not_null = ($rs->fields[2] != 'YES');
|
$fld->not_null = ($rs->fields[2] != 'YES');
|
||||||
$fld->primary_key = ($rs->fields[3] == 'PRI');
|
$fld->primary_key = ($rs->fields[3] == 'PRI');
|
||||||
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
|
$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->unsigned = (strpos($type,'unsigned') !== false);
|
||||||
|
$fld->zerofill = (strpos($type,'zerofill') !== false);
|
||||||
|
|
||||||
if (!$fld->binary) {
|
if (!$fld->binary) {
|
||||||
$d = $rs->fields[4];
|
$d = $rs->fields[4];
|
||||||
@ -478,21 +486,21 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parameters use PostgreSQL convention, not MySQL
|
// 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)."," : '';
|
$offsetStr =($offset>=0) ? ((integer)$offset)."," : '';
|
||||||
// jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
|
// jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
|
||||||
if ($nrows < 0) $nrows = '18446744073709551615';
|
if ($nrows < 0) $nrows = '18446744073709551615';
|
||||||
|
|
||||||
if ($secs)
|
if ($secs)
|
||||||
$rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
$rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
||||||
else
|
else
|
||||||
$rs =& $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
$rs = $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
||||||
return $rs;
|
return $rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns queryID or false
|
// returns queryID or false
|
||||||
function _query($sql,$inputarr)
|
function _query($sql,$inputarr=false)
|
||||||
{
|
{
|
||||||
//global $ADODB_COUNTRECS;
|
//global $ADODB_COUNTRECS;
|
||||||
//if($ADODB_COUNTRECS)
|
//if($ADODB_COUNTRECS)
|
||||||
@ -552,8 +560,9 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
$table = "$owner.$table";
|
$table = "$owner.$table";
|
||||||
}
|
}
|
||||||
$a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
|
$a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
|
||||||
if ($associative) $create_sql = $a_create_table["Create Table"];
|
if ($associative) {
|
||||||
else $create_sql = $a_create_table[1];
|
$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();
|
$matches = array();
|
||||||
|
|
||||||
@ -569,7 +578,10 @@ class ADODB_mysql extends ADOConnection {
|
|||||||
$ref_table = strtoupper($ref_table);
|
$ref_table = strtoupper($ref_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
$foreign_keys[$ref_table] = array();
|
||||||
|
}
|
||||||
$num_fields = count($my_field);
|
$num_fields = count($my_field);
|
||||||
for ( $j = 0; $j < $num_fields; $j ++ ) {
|
for ( $j = 0; $j < $num_fields; $j ++ ) {
|
||||||
if ( $associative ) {
|
if ( $associative ) {
|
||||||
@ -623,28 +635,28 @@ class ADORecordSet_mysql extends ADORecordSet{
|
|||||||
$this->_numOfFields = @mysql_num_fields($this->_queryID);
|
$this->_numOfFields = @mysql_num_fields($this->_queryID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function &FetchField($fieldOffset = -1)
|
function FetchField($fieldOffset = -1)
|
||||||
{
|
{
|
||||||
if ($fieldOffset != -1) {
|
if ($fieldOffset != -1) {
|
||||||
$o = @mysql_fetch_field($this->_queryID, $fieldOffset);
|
$o = @mysql_fetch_field($this->_queryID, $fieldOffset);
|
||||||
$f = @mysql_field_flags($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->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 */
|
else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
|
||||||
$o = @mysql_fetch_field($this->_queryID);
|
$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
|
//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
|
||||||
}
|
}
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
}
|
}
|
||||||
|
|
||||||
function &GetRowAssoc($upper=true)
|
function GetRowAssoc($upper=true)
|
||||||
{
|
{
|
||||||
if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
|
if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
|
||||||
else $row =& ADORecordSet::GetRowAssoc($upper);
|
else $row = ADORecordSet::GetRowAssoc($upper);
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,6 +738,7 @@ class ADORecordSet_mysql extends ADORecordSet{
|
|||||||
case 'LONGBLOB':
|
case 'LONGBLOB':
|
||||||
case 'BLOB':
|
case 'BLOB':
|
||||||
case 'MEDIUMBLOB':
|
case 'MEDIUMBLOB':
|
||||||
|
case 'BINARY':
|
||||||
return !empty($fieldobj->binary) ? 'B' : 'X';
|
return !empty($fieldobj->binary) ? 'B' : 'X';
|
||||||
|
|
||||||
case 'YEAR':
|
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
|
<?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.
|
Released under both BSD license and Lesser GPL library license.
|
||||||
Whenever there is any discrepancy between the two licenses,
|
Whenever there is any discrepancy between the two licenses,
|
||||||
the BSD license will take precedence.
|
the BSD license will take precedence.
|
||||||
@ -105,6 +105,7 @@ WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s'))
|
|||||||
var $autoRollback = true; // apparently pgsql does not autorollback properly before php 4.3.4
|
var $autoRollback = true; // apparently pgsql does not autorollback properly before php 4.3.4
|
||||||
// http://bugs.php.net/bug.php?id=25404
|
// http://bugs.php.net/bug.php?id=25404
|
||||||
|
|
||||||
|
var $uniqueIisR = true;
|
||||||
var $_bindInputArray = false; // requires postgresql 7.3+ and ability to modify database
|
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.
|
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);
|
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();
|
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.
|
// returns true/false.
|
||||||
@ -201,7 +202,7 @@ a different OID if a database must be reloaded. */
|
|||||||
return @pg_Exec($this->_connectionID, "rollback");
|
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();
|
$info = $this->ServerInfo();
|
||||||
if ($info['version'] >= 7.3) {
|
if ($info['version'] >= 7.3) {
|
||||||
@ -224,7 +225,7 @@ select tablename,'T' from pg_tables where tablename like $mask
|
|||||||
union
|
union
|
||||||
select viewname,'V' from pg_views where viewname like $mask";
|
select viewname,'V' from pg_views where viewname like $mask";
|
||||||
}
|
}
|
||||||
$ret =& ADOConnection::MetaTables($ttype,$showSchema);
|
$ret = ADOConnection::MetaTables($ttype,$showSchema);
|
||||||
|
|
||||||
if ($mask) {
|
if ($mask) {
|
||||||
$this->metaTablesSQL = $save;
|
$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()
|
// if magic quotes disabled, use pg_escape_string()
|
||||||
function qstr($s,$magic_quotes=false)
|
function qstr($s,$magic_quotes=false)
|
||||||
{
|
{
|
||||||
|
if (is_bool($s)) return $s ? 'true' : 'false';
|
||||||
|
|
||||||
if (!$magic_quotes) {
|
if (!$magic_quotes) {
|
||||||
if (ADODB_PHPVER >= 0x5200) {
|
if (ADODB_PHPVER >= 0x5200) {
|
||||||
return "'".pg_escape_string($this->_connectionID,$s)."'";
|
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;
|
if (10 <= $len && $len <= 12) $date = 'date '.$date;
|
||||||
else $date = 'timestamp '.$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".
|
// for schema support, pass in the $table param "$schema.$tabname".
|
||||||
// converts field names to lowercase, $upper is ignored
|
// converts field names to lowercase, $upper is ignored
|
||||||
// see http://phplens.com/lens/lensforum/msgs.php?id=14018 for more info
|
// 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;
|
global $ADODB_FETCH_MODE;
|
||||||
|
|
||||||
@ -478,8 +484,8 @@ select viewname,'V' from pg_views where viewname like $mask";
|
|||||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||||
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
||||||
|
|
||||||
if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema));
|
if ($schema) $rs = $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema));
|
||||||
else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
|
else $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
|
||||||
if (isset($savem)) $this->SetFetchMode($savem);
|
if (isset($savem)) $this->SetFetchMode($savem);
|
||||||
$ADODB_FETCH_MODE = $save;
|
$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)));
|
$rskey = $this->Execute(sprintf($this->metaKeySQL,($table)));
|
||||||
// fetch all result in once for performance.
|
// fetch all result in once for performance.
|
||||||
$keys =& $rskey->GetArray();
|
$keys = $rskey->GetArray();
|
||||||
if (isset($savem)) $this->SetFetchMode($savem);
|
if (isset($savem)) $this->SetFetchMode($savem);
|
||||||
$ADODB_FETCH_MODE = $save;
|
$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;
|
global $ADODB_FETCH_MODE;
|
||||||
|
|
||||||
@ -659,7 +665,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
|
|||||||
if (strlen($db) == 0) $db = 'template1';
|
if (strlen($db) == 0) $db = 'template1';
|
||||||
$db = adodb_addslashes($db);
|
$db = adodb_addslashes($db);
|
||||||
if ($str) {
|
if ($str) {
|
||||||
$host = split(":", $str);
|
$host = explode(":", $str);
|
||||||
if ($host[0]) $str = "host=".adodb_addslashes($host[0]);
|
if ($host[0]) $str = "host=".adodb_addslashes($host[0]);
|
||||||
else $str = '';
|
else $str = '';
|
||||||
if (isset($host[1])) $str .= " port=$host[1]";
|
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
|
// returns queryID or false
|
||||||
function _query($sql,$inputarr)
|
function _query($sql,$inputarr=false)
|
||||||
{
|
{
|
||||||
$this->_errorMsg = false;
|
$this->_errorMsg = false;
|
||||||
if ($inputarr) {
|
if ($inputarr) {
|
||||||
@ -886,10 +892,10 @@ class ADORecordSet_postgres64 extends ADORecordSet{
|
|||||||
$this->ADORecordSet($queryID);
|
$this->ADORecordSet($queryID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function &GetRowAssoc($upper=true)
|
function GetRowAssoc($upper=true)
|
||||||
{
|
{
|
||||||
if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields;
|
if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields;
|
||||||
$row =& ADORecordSet::GetRowAssoc($upper);
|
$row = ADORecordSet::GetRowAssoc($upper);
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,7 +931,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
|
|||||||
return $this->fields[$this->bind[strtoupper($colname)]];
|
return $this->fields[$this->bind[strtoupper($colname)]];
|
||||||
}
|
}
|
||||||
|
|
||||||
function &FetchField($off = 0)
|
function FetchField($off = 0)
|
||||||
{
|
{
|
||||||
// offsets begin at 0
|
// offsets begin at 0
|
||||||
|
|
||||||
@ -943,6 +949,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
|
|||||||
|
|
||||||
function _decode($blob)
|
function _decode($blob)
|
||||||
{
|
{
|
||||||
|
if ($blob === NULL) return NULL;
|
||||||
eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";');
|
eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";');
|
||||||
return $realblob;
|
return $realblob;
|
||||||
}
|
}
|
||||||
@ -1049,7 +1056,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
|
|||||||
case 'INT4':
|
case 'INT4':
|
||||||
case 'INT2':
|
case 'INT2':
|
||||||
if (isset($fieldobj) &&
|
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 'OID':
|
||||||
case 'SERIAL':
|
case 'SERIAL':
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?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.
|
Released under both BSD license and Lesser GPL library license.
|
||||||
Whenever there is any discrepancy between the two licenses,
|
Whenever there is any discrepancy between the two licenses,
|
||||||
the BSD license will take precedence.
|
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,
|
// the following should be compat with postgresql 7.2,
|
||||||
// which makes obsolete the LIMIT limit,offset syntax
|
// 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) : '';
|
$offsetStr = ($offset >= 0) ? " OFFSET ".((integer)$offset) : '';
|
||||||
$limitStr = ($nrows >= 0) ? " LIMIT ".((integer)$nrows) : '';
|
$limitStr = ($nrows >= 0) ? " LIMIT ".((integer)$nrows) : '';
|
||||||
if ($secs2cache)
|
if ($secs2cache)
|
||||||
$rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
$rs = $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
||||||
else
|
else
|
||||||
$rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
$rs = $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
||||||
|
|
||||||
return $rs;
|
return $rs;
|
||||||
}
|
}
|
||||||
@ -56,9 +56,58 @@ class ADODB_postgres7 extends ADODB_postgres64 {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
// from Edward Jaramilla, improved version - works on pg 7.4
|
||||||
function MetaForeignKeys($table, $owner=false, $upper=false)
|
function _old_MetaForeignKeys($table, $owner=false, $upper=false)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT t.tgargs as args
|
$sql = 'SELECT t.tgargs as args
|
||||||
FROM
|
FROM
|
||||||
@ -72,11 +121,11 @@ class ADODB_postgres7 extends ADODB_postgres64 {
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
t.tgrelid';
|
t.tgrelid';
|
||||||
|
|
||||||
$rs =& $this->Execute($sql);
|
$rs = $this->Execute($sql);
|
||||||
|
|
||||||
if (!$rs || $rs->EOF) return false;
|
if (!$rs || $rs->EOF) return false;
|
||||||
|
|
||||||
$arr =& $rs->GetArray();
|
$arr = $rs->GetArray();
|
||||||
$a = array();
|
$a = array();
|
||||||
foreach($arr as $v) {
|
foreach($arr as $v) {
|
||||||
$data = explode(chr(0), $v['args']);
|
$data = explode(chr(0), $v['args']);
|
||||||
@ -91,7 +140,7 @@ class ADODB_postgres7 extends ADODB_postgres64 {
|
|||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _query($sql,$inputarr)
|
function _query($sql,$inputarr=false)
|
||||||
{
|
{
|
||||||
if (! $this->_bindInputArray) {
|
if (! $this->_bindInputArray) {
|
||||||
// We don't have native support for parameterized queries, so let's emulate it at the parent
|
// 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
|
<?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.
|
Released under both BSD license and Lesser GPL library license.
|
||||||
Whenever there is any discrepancy between the two licenses,
|
Whenever there is any discrepancy between the two licenses,
|
||||||
the BSD license will take precedence.
|
the BSD license will take precedence.
|
||||||
@ -78,14 +78,14 @@ class ADODB_sqlite extends ADOConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mark newnham
|
// mark newnham
|
||||||
function &MetaColumns($tab)
|
function MetaColumns($table, $normalize=true)
|
||||||
{
|
{
|
||||||
global $ADODB_FETCH_MODE;
|
global $ADODB_FETCH_MODE;
|
||||||
$false = false;
|
$false = false;
|
||||||
$save = $ADODB_FETCH_MODE;
|
$save = $ADODB_FETCH_MODE;
|
||||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||||
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
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 (isset($savem)) $this->SetFetchMode($savem);
|
||||||
if (!$rs) {
|
if (!$rs) {
|
||||||
$ADODB_FETCH_MODE = $save;
|
$ADODB_FETCH_MODE = $save;
|
||||||
@ -190,14 +190,14 @@ class ADODB_sqlite extends ADOConnection {
|
|||||||
return $rez;
|
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" : '';
|
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
|
||||||
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : '');
|
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : '');
|
||||||
if ($secs2cache)
|
if ($secs2cache)
|
||||||
$rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
$rs = $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
||||||
else
|
else
|
||||||
$rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
$rs = $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
||||||
|
|
||||||
return $rs;
|
return $rs;
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ class ADODB_sqlite extends ADOConnection {
|
|||||||
return @sqlite_close($this->_connectionID);
|
return @sqlite_close($this->_connectionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function &MetaIndexes($table, $primary = FALSE, $owner=false)
|
function MetaIndexes($table, $primary = FALSE, $owner=false, $owner = false)
|
||||||
{
|
{
|
||||||
$false = false;
|
$false = false;
|
||||||
// save old fetch mode
|
// 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 = new ADOFieldObject;
|
||||||
$fld->name = sqlite_field_name($this->_queryID, $fieldOffset);
|
$fld->name = sqlite_field_name($this->_queryID, $fieldOffset);
|
||||||
@ -393,5 +393,6 @@ class ADORecordset_sqlite extends ADORecordSet {
|
|||||||
function _close()
|
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