Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
import of new ADODB v4.92 library
  • Loading branch information
skodak committed Aug 29, 2006
1 parent a199036 commit c0e3c8d
Show file tree
Hide file tree
Showing 99 changed files with 438 additions and 124 deletions.
8 changes: 7 additions & 1 deletion lib/adodb/adodb-active-record.inc.php
@@ -1,7 +1,7 @@
<?php
/*
@version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
@version V4.92 29 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Latest version is available at http://adodb.sourceforge.net
Released under both BSD license and Lesser GPL library license.
Expand Down Expand Up @@ -102,6 +102,12 @@ function __construct($table = false, $pkeyarr=false, $db=false)
$this->UpdateActiveTable($pkeyarr);
}

function __wakeup()
{
$class = get_class($this);
new $class;
}

function _pluralize($table)
{
$ut = strtoupper($table);
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-csvlib.inc.php
Expand Up @@ -8,7 +8,7 @@

/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-datadict.inc.php
@@ -1,7 +1,7 @@
<?php

/**
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-error.inc.php
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* @version V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-errorhandler.inc.php
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* @version V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-errorpear.inc.php
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* @version V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-exceptions.inc.php
@@ -1,7 +1,7 @@
<?php

/**
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* @version V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-iterator.inc.php
@@ -1,7 +1,7 @@
<?php

/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
78 changes: 68 additions & 10 deletions lib/adodb/adodb-lib.inc.php
Expand Up @@ -7,7 +7,7 @@
$ADODB_INCLUDED_LIB = 1;

/*
@version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim\@natsoft.com.my). All rights reserved.
@version V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand All @@ -16,6 +16,69 @@
Less commonly used functions are placed here to reduce size of adodb.inc.php.
*/

function adodb_probetypes(&$array,&$types,$probe=8)
{
// probe and guess the type
$types = array();
if ($probe > sizeof($array)) $max = sizeof($array);
else $max = $probe;


for ($j=0;$j < $max; $j++) {
$row =& $array[$j];
if (!$row) break;
$i = -1;
foreach($row as $v) {
$i += 1;

if (isset($types[$i]) && $types[$i]=='C') continue;

//print " ($i ".$types[$i]. "$v) ";
$v = trim($v);

if (!preg_match('/^[+-]{0,1}[0-9\.]+$/',$v)) {
$types[$i] = 'C'; // once C, always C

continue;
}
if ($j == 0) {
// If empty string, we presume is character
// test for integer for 1st row only
// after that it is up to testing other rows to prove
// that it is not an integer
if (strlen($v) == 0) $types[$i] = 'C';
if (strpos($v,'.') !== false) $types[$i] = 'N';
else $types[$i] = 'I';
continue;
}

if (strpos($v,'.') !== false) $types[$i] = 'N';

}
}
}

function &adodb_transpose(&$arr, &$newarr, &$hdr)
{
$oldX = sizeof(reset($arr));
$oldY = sizeof($arr);

if ($hdr) {
$startx = 1;
$hdr = array();
for ($y = 0; $y < $oldY; $y++) {
$hdr[] = $arr[$y][0];
}
} else
$startx = 0;

for ($x = $startx; $x < $oldX; $x++) {
$newarr[] = array();
for ($y = 0; $y < $oldY; $y++) {
$newarr[$x-$startx][] = $arr[$y][$x];
}
}
}

// Force key to upper.
// See also http://www.php.net/manual/en/function.array-change-key-case.php
Expand Down Expand Up @@ -297,14 +360,14 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
{
$qryRecs = 0;

if (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+UNION\s+/is',$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);
$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)) {
Expand All @@ -313,12 +376,8 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
$rewritesql = "SELECT COUNT(*) FROM (".$rewritesql.")";

} else if (strncmp($zthis->databaseType,'postgres',8) == 0) {

$info = $zthis->ServerInfo();
if (substr($info['version'],0,3) >= 7.1) { // good till version 999
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
}
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
}
} else {
// now replace SELECT ... FROM with SELECT COUNT(*) FROM
Expand Down Expand Up @@ -383,7 +442,6 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
$rstest->Close();
if ($qryRecs == -1) return 0;
}

return $qryRecs;
}

Expand Down
118 changes: 118 additions & 0 deletions lib/adodb/adodb-memcache.lib.inc.php
@@ -0,0 +1,118 @@
<?php

// security - hide paths
if (!defined('ADODB_DIR')) die();

global $ADODB_INCLUDED_MEMCACHE;
$ADODB_INCLUDED_MEMCACHE = 1;

/*
V4.90 8 June 2006 (c) 2000-2006 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.
Set tabs to 4 for best viewing.
Latest version is available at http://adodb.sourceforge.net
*/

function &getmemcache($key,&$err, $timeout=0, $host, $port)
{
$false = false;
$err = false;

if (!function_exists('memcache_pconnect')) {
$err = 'Memcache module PECL extension not found!';
return $false;
}

$memcache = new Memcache;
if (!@$memcache->pconnect($host, $port)) {
$err = 'Can\'t connect to memcache server on: '.$host.':'.$port;
return $false;
}

$rs = $memcache->get($key);
if (!$rs) {
$err = 'Item with such key doesn\'t exists on the memcached server.';
return $false;
}

$tdiff = intval($rs->timeCreated+$timeout - time());
if ($tdiff <= 2) {
switch($tdiff) {
case 2:
if ((rand() & 15) == 0) {
$err = "Timeout 2";
return $false;
}
break;
case 1:
if ((rand() & 3) == 0) {
$err = "Timeout 1";
return $false;
}
break;
default:
$err = "Timeout 0";
return $false;
}
}
return $rs;
}

function putmemcache($key, $rs, $host, $port, $compress, $debug=false)
{
$false = false;
$true = true;

if (!function_exists('memcache_pconnect')) {
if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
return $false;
}

$memcache = new Memcache;
if (!@$memcache->pconnect($host, $port)) {
if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
return $false;
}

$rs->timeCreated = time();
if (!$memcache->set($key, $rs, $compress, 0)) {
if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n");
return $false;
}
return $true;
}

function flushmemcache($key=false, $host, $port, $debug=false)
{
if (!function_exists('memcache_pconnect')) {
if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
return;
}

$memcache = new Memcache;
if (!@$memcache->pconnect($host, $port)) {
if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
return;
}

if ($key) {
if (!$memcache->delete($key)) {
if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n");
} else {
if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n");
}
} else {
if (!$memcache->flush()) {
if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");
} else {
if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");
}
}
return;
}
?>
2 changes: 1 addition & 1 deletion lib/adodb/adodb-pager.inc.php
@@ -1,7 +1,7 @@
<?php

/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-pear.inc.php
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* @version V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-perf.inc.php
@@ -1,6 +1,6 @@
<?php
/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/adodb/adodb-php4.inc.php
@@ -1,7 +1,7 @@
<?php

/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.92 29 Aug 2006 (c) 2000-2006 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.
Expand Down

0 comments on commit c0e3c8d

Please sign in to comment.