From d761c224b8c134e08e3b6d6d3dc226043f8dddf7 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 15 Feb 2008 07:02:02 +0000 Subject: [PATCH] Merged Adodb 4.98 from 1.9 MDL-13474 --- lib/adodb/adodb-active-record.inc.php | 73 +- lib/adodb/adodb-csvlib.inc.php | 33 +- lib/adodb/adodb-datadict.inc.php | 9 +- lib/adodb/adodb-error.inc.php | 18 +- lib/adodb/adodb-errorhandler.inc.php | 2 +- lib/adodb/adodb-errorpear.inc.php | 2 +- lib/adodb/adodb-exceptions.inc.php | 2 +- lib/adodb/adodb-iterator.inc.php | 2 +- lib/adodb/adodb-lib.inc.php | 33 +- lib/adodb/adodb-memcache.lib.inc.php | 236 ++--- lib/adodb/adodb-pager.inc.php | 2 +- lib/adodb/adodb-pear.inc.php | 2 +- lib/adodb/adodb-perf.inc.php | 14 +- lib/adodb/adodb-php4.inc.php | 2 +- lib/adodb/adodb-time.inc.php | 43 +- lib/adodb/adodb-xmlschema.inc.php | 4 +- lib/adodb/adodb-xmlschema03.inc.php | 4 +- lib/adodb/adodb.inc.php | 49 +- lib/adodb/datadict/datadict-access.inc.php | 2 +- lib/adodb/datadict/datadict-db2.inc.php | 2 +- lib/adodb/datadict/datadict-firebird.inc.php | 2 +- lib/adodb/datadict/datadict-generic.inc.php | 2 +- lib/adodb/datadict/datadict-ibase.inc.php | 2 +- lib/adodb/datadict/datadict-informix.inc.php | 2 +- lib/adodb/datadict/datadict-mssql.inc.php | 2 +- lib/adodb/datadict/datadict-mysql.inc.php | 2 +- lib/adodb/datadict/datadict-oci8.inc.php | 2 +- lib/adodb/datadict/datadict-postgres.inc.php | 8 +- lib/adodb/datadict/datadict-sapdb.inc.php | 240 ++--- lib/adodb/datadict/datadict-sybase.inc.php | 2 +- lib/adodb/drivers/adodb-access.inc.php | 2 +- lib/adodb/drivers/adodb-ado.inc.php | 2 +- lib/adodb/drivers/adodb-ado5.inc.php | 2 +- lib/adodb/drivers/adodb-ado_access.inc.php | 2 +- lib/adodb/drivers/adodb-ado_mssql.inc.php | 2 +- lib/adodb/drivers/adodb-borland_ibase.inc.php | 2 +- lib/adodb/drivers/adodb-csv.inc.php | 2 +- lib/adodb/drivers/adodb-db2.inc.php | 2 +- lib/adodb/drivers/adodb-fbsql.inc.php | 2 +- lib/adodb/drivers/adodb-firebird.inc.php | 2 +- lib/adodb/drivers/adodb-ibase.inc.php | 2 +- lib/adodb/drivers/adodb-informix.inc.php | 2 +- lib/adodb/drivers/adodb-informix72.inc.php | 2 +- lib/adodb/drivers/adodb-ldap.inc.php | 2 +- lib/adodb/drivers/adodb-mssql.inc.php | 4 +- lib/adodb/drivers/adodb-mssql_n.inc.php | 2 +- lib/adodb/drivers/adodb-mssqlpo.inc.php | 2 +- lib/adodb/drivers/adodb-mysql.inc.php | 2 +- lib/adodb/drivers/adodb-mysqli.inc.php | 12 +- lib/adodb/drivers/adodb-mysqlt.inc.php | 2 +- lib/adodb/drivers/adodb-netezza.inc.php | 2 +- lib/adodb/drivers/adodb-oci8.inc.php | 17 +- lib/adodb/drivers/adodb-oci805.inc.php | 2 +- lib/adodb/drivers/adodb-oci8po.inc.php | 2 +- lib/adodb/drivers/adodb-odbc.inc.php | 2 +- lib/adodb/drivers/adodb-odbc_db2.inc.php | 2 +- lib/adodb/drivers/adodb-odbc_mssql.inc.php | 2 +- lib/adodb/drivers/adodb-odbc_oracle.inc.php | 2 +- lib/adodb/drivers/adodb-odbtp.inc.php | 2 +- lib/adodb/drivers/adodb-odbtp_unicode.inc.php | 2 +- lib/adodb/drivers/adodb-oracle.inc.php | 2 +- lib/adodb/drivers/adodb-pdo.inc.php | 74 +- lib/adodb/drivers/adodb-pdo_mssql.inc.php | 2 +- lib/adodb/drivers/adodb-pdo_mysql.inc.php | 6 +- lib/adodb/drivers/adodb-pdo_oci.inc.php | 2 +- lib/adodb/drivers/adodb-pdo_pgsql.inc.php | 2 +- lib/adodb/drivers/adodb-postgres.inc.php | 2 +- lib/adodb/drivers/adodb-postgres64.inc.php | 2 +- lib/adodb/drivers/adodb-postgres7.inc.php | 2 +- lib/adodb/drivers/adodb-postgres8.inc.php | 2 +- lib/adodb/drivers/adodb-proxy.inc.php | 2 +- lib/adodb/drivers/adodb-sapdb.inc.php | 2 +- lib/adodb/drivers/adodb-sqlanywhere.inc.php | 2 +- lib/adodb/drivers/adodb-sqlite.inc.php | 2 +- lib/adodb/drivers/adodb-sqlitepo.inc.php | 2 +- lib/adodb/drivers/adodb-sybase.inc.php | 2 +- lib/adodb/drivers/adodb-sybase_ase.inc.php | 2 +- lib/adodb/drivers/adodb-vfp.inc.php | 2 +- lib/adodb/lang/adodb-ar.inc.php | 2 +- lib/adodb/lang/adodb-bgutf8.inc.php | 4 +- lib/adodb/lang/adodb-ca.inc.php | 69 +- lib/adodb/lang/adodb-pt-br.inc.php | 70 +- lib/adodb/lang/adodb-ro.inc.php | 2 +- lib/adodb/lang/adodb-uk1251.inc.php | 2 +- lib/adodb/lang/adodb_th.inc.php | 2 +- lib/adodb/perf/perf-db2.inc.php | 2 +- lib/adodb/perf/perf-informix.inc.php | 2 +- lib/adodb/perf/perf-mssql.inc.php | 2 +- lib/adodb/perf/perf-mysql.inc.php | 2 +- lib/adodb/perf/perf-oci8.inc.php | 2 +- lib/adodb/perf/perf-postgres.inc.php | 2 +- lib/adodb/pivottable.inc.php | 372 ++++---- lib/adodb/readme_moodle.txt | 11 +- lib/adodb/rsfilter.inc.php | 120 +-- lib/adodb/session/adodb-compress-bzip2.php | 2 +- lib/adodb/session/adodb-compress-gzip.php | 2 +- lib/adodb/session/adodb-cryptsession.php | 2 +- lib/adodb/session/adodb-cryptsession2.php | 2 +- lib/adodb/session/adodb-encrypt-mcrypt.php | 2 +- lib/adodb/session/adodb-encrypt-md5.php | 2 +- lib/adodb/session/adodb-encrypt-secret.php | 2 +- lib/adodb/session/adodb-session-clob.php | 2 +- lib/adodb/session/adodb-session-clob2.php | 2 +- lib/adodb/session/adodb-session.php | 2 +- lib/adodb/session/adodb-session2.php | 2 +- lib/adodb/session/old/adodb-cryptsession.php | 2 +- lib/adodb/session/old/adodb-session-clob.php | 896 +++++++++--------- lib/adodb/session/old/adodb-session.php | 876 ++++++++--------- lib/adodb/toexport.inc.php | 264 +++--- lib/adodb/tohtml.inc.php | 388 ++++---- 110 files changed, 2107 insertions(+), 2004 deletions(-) diff --git a/lib/adodb/adodb-active-record.inc.php b/lib/adodb/adodb-active-record.inc.php index a67b55e40c..0654828c00 100644 --- a/lib/adodb/adodb-active-record.inc.php +++ b/lib/adodb/adodb-active-record.inc.php @@ -1,7 +1,7 @@ _dbat $_ADODB_ACTIVE_DBS = array(); $ACTIVE_RECORD_SAFETY = true; +$ADODB_ACTIVE_DEFVALS = false; class ADODB_Active_DB { var $db; // ADOConnection @@ -69,6 +71,14 @@ class ADODB_Active_Record { var $_lasterr = false; // last error message var $_original = false; // the original values loaded or inserted, refreshed on update + // should be static + function UseDefaultValues($bool=null) + { + global $ADODB_ACTIVE_DEFVALS; + if (isset($bool)) $ADODB_ACTIVE_DEFVALS = $bool; + return $ADODB_ACTIVE_DEFVALS; + } + // should be static function SetDatabaseAdapter(&$db) { @@ -141,7 +151,8 @@ class ADODB_Active_Record { function UpdateActiveTable($pkeys=false,$forceUpdate=false) { global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS; - + global $ADODB_ACTIVE_DEFVALS; + $activedb =& $_ADODB_ACTIVE_DBS[$this->_dbat]; $table = $this->_table; @@ -149,8 +160,12 @@ class ADODB_Active_Record { $tableat = $this->_tableat; if (!$forceUpdate && !empty($tables[$tableat])) { $tobj =& $tables[$tableat]; - foreach($tobj->flds as $name => $fld) - $this->$name = null; + foreach($tobj->flds as $name => $fld) { + if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) + $this->$name = $fld->default_value; + else + $this->$name = null; + } return; } @@ -203,7 +218,10 @@ class ADODB_Active_Record { case 0: foreach($cols as $name => $fldobj) { $name = strtolower($name); - $this->$name = null; + if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) + $this->$name = $fldobj->default_value; + else + $this->$name = null; $attr[$name] = $fldobj; } foreach($pkeys as $k => $name) { @@ -214,7 +232,11 @@ class ADODB_Active_Record { case 1: foreach($cols as $name => $fldobj) { $name = strtoupper($name); - $this->$name = null; + + if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) + $this->$name = $fldobj->default_value; + else + $this->$name = null; $attr[$name] = $fldobj; } @@ -225,7 +247,11 @@ class ADODB_Active_Record { default: foreach($cols as $name => $fldobj) { $name = ($fldobj->name); - $this->$name = null; + + if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) + $this->$name = $fldobj->default_value; + else + $this->$name = null; $attr[$name] = $fldobj; } foreach($pkeys as $k => $name) { @@ -336,17 +362,30 @@ class ADODB_Active_Record { $table =& $this->TableInfo(); if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) { - $this->Error("Table structure of $this->_table has changed","Load"); - return false; + $bad_size = TRUE; + if (sizeof($row) == 2 * sizeof($table->flds)) { + // Only keep string keys + $keys = array_filter(array_keys($row), 'is_string'); + if (sizeof($keys) == sizeof($table->flds)) + $bad_size = FALSE; + } + if ($bad_size) { + $this->Error("Table structure of $this->_table has changed","Load"); + return false; + } } - - $keys = array_keys($row); - $cnt = 0; + else + $keys = array_keys($row); + + reset($keys); + $this->_original = array(); foreach($table->flds as $name=>$fld) { - $this->$name = $row[$keys[$cnt]]; - $cnt += 1; + $value = $row[current($keys)]; + $this->$name = $value; + $this->_original[] = $value; + next($keys); } - $this->_original = $row; + # return true; } @@ -533,7 +572,7 @@ class ADODB_Active_Record { if ($ADODB_ASSOC_CASE == 0) foreach($pkey as $k => $v) $pkey[$k] = strtolower($v); - elseif ($ADODB_ASSOC_CASE == 0) + elseif ($ADODB_ASSOC_CASE == 1) foreach($pkey as $k => $v) $pkey[$k] = strtoupper($v); diff --git a/lib/adodb/adodb-csvlib.inc.php b/lib/adodb/adodb-csvlib.inc.php index 77c4cc4bde..c82c965582 100644 --- a/lib/adodb/adodb-csvlib.inc.php +++ b/lib/adodb/adodb-csvlib.inc.php @@ -8,7 +8,7 @@ $ADODB_INCLUDED_CSV = 1; /* - V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. + V4.98 13 Feb 2008 (c) 2000-2008 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. @@ -261,6 +261,7 @@ $ADODB_INCLUDED_CSV = 1; /** * Save a file $filename and its $contents (normally for caching) with file locking + * Returns true if ok, false if fopen/fwrite error, 0 if rename error (eg. file is locked) */ function adodb_write_file($filename, $contents,$debug=false) { @@ -280,25 +281,29 @@ $ADODB_INCLUDED_CSV = 1; $mtime = substr(str_replace(' ','_',microtime()),2); // getmypid() actually returns 0 on Win98 - never mind! $tmpname = $filename.uniqid($mtime).getmypid(); - if (!($fd = @fopen($tmpname,'a'))) return false; - $ok = ftruncate($fd,0); - if (!fwrite($fd,$contents)) $ok = false; + if (!($fd = @fopen($tmpname,'w'))) return false; + if (fwrite($fd,$contents)) $ok = true; + else $ok = false; fclose($fd); - chmod($tmpname,0644); - // the tricky moment - @unlink($filename); - if (!@rename($tmpname,$filename)) { - unlink($tmpname); - $ok = false; - } - if (!$ok) { - if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed')); + + if ($ok) { + chmod($tmpname,0644); + // the tricky moment + @unlink($filename); + if (!@rename($tmpname,$filename)) { + unlink($tmpname); + $ok = 0; + } + if (!$ok) { + if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed')); + } } return $ok; } if (!($fd = @fopen($filename, 'a'))) return false; if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) { - $ok = fwrite( $fd, $contents ); + if (fwrite( $fd, $contents )) $ok = true; + else $ok = false; fclose($fd); chmod($filename,0644); }else { diff --git a/lib/adodb/adodb-datadict.inc.php b/lib/adodb/adodb-datadict.inc.php index 9761763a91..86961a2bfc 100644 --- a/lib/adodb/adodb-datadict.inc.php +++ b/lib/adodb/adodb-datadict.inc.php @@ -1,7 +1,7 @@ invalidResizeTypes4)) { - echo "

$this->alterCol cannot be changed to $flds currently

"; + // $flds[1] holds the type, $flds[2] holds the size -postnuke addition + if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4) + && (isset($flds[0][2]) && is_numeric($flds[0][2]))) { + if ($this->debug) ADOConnection::outp(sprintf("

%s cannot be changed to %s currently

", $flds[0][0], $flds[0][1])); + #echo "

$this->alterCol cannot be changed to $flds currently

"; continue; } $sql[] = $alter . $this->alterCol . ' ' . $v; diff --git a/lib/adodb/adodb-error.inc.php b/lib/adodb/adodb-error.inc.php index 48e46ff2a3..f55516116b 100644 --- a/lib/adodb/adodb-error.inc.php +++ b/lib/adodb/adodb-error.inc.php @@ -1,6 +1,6 @@ DB_ERROR_NOSUCHTABLE, - '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS, - '/divide by zero$/' => DB_ERROR_DIVZERO, - '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER, - '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD, - '/parser: parse error at or near \"/' => DB_ERROR_SYNTAX, - '/referential integrity violation/' => DB_ERROR_CONSTRAINT, - '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/' + '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/i' => DB_ERROR_NOSUCHTABLE, + '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/i' => DB_ERROR_ALREADY_EXISTS, + '/divide by zero$/i' => DB_ERROR_DIVZERO, + '/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER, + '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/i' => DB_ERROR_NOSUCHFIELD, + '/parser: parse error at or near \"/i' => DB_ERROR_SYNTAX, + '/referential integrity violation/i' => DB_ERROR_CONSTRAINT, + '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/i' => DB_ERROR_ALREADY_EXISTS ); reset($error_regexps); diff --git a/lib/adodb/adodb-errorhandler.inc.php b/lib/adodb/adodb-errorhandler.inc.php index 3c844b7d59..779cf7f473 100644 --- a/lib/adodb/adodb-errorhandler.inc.php +++ b/lib/adodb/adodb-errorhandler.inc.php @@ -1,6 +1,6 @@ databaseType,'postgres',8) == 0) { + } else if (strncmp($zthis->databaseType,'postgres',8) == 0 || strncmp($zthis->databaseType,'mysql',5) == 0) { $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_"; + } else { + $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) "; } } else { // now replace SELECT ... FROM with SELECT COUNT(*) FROM @@ -537,7 +539,7 @@ function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page, return $rsreturn; } -// Iv�n Oliva version +// Iván Oliva version function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0) { @@ -991,24 +993,23 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, case "D": $val = $zthis->DBDate($arrFields[$fname]); break; - - - case "T": + + case "T": $val = $zthis->DBTimeStamp($arrFields[$fname]); - break; - -// moodle change start - see readme_moodle.txt - case "F": //Floating point number - case "N": //Numeric or decimal number - $val = (float)$arrFields[$fname]; break; - case "L": //Integer field suitable for storing booleans (0 or 1) + case "F": //Floating point number // Moodle added + case "N": + $val = $arrFields[$fname]; + if (!is_numeric($val)) $val = str_replace(',', '.', (float)$val); + break; + + case "L": //Integer field suitable for storing booleans (0 or 1) // Moodle added case "I": case "R": - $val = (int) $arrFields[$fname]; + $val = $arrFields[$fname]; + if (!is_numeric($val)) $val = (integer) $val; break; -// moodle change end default: $val = str_replace(array("'"," ","("),"",$arrFields[$fname]); // basic sql injection defence @@ -1177,4 +1178,4 @@ function _adodb_find_from($sql) } */ -?> \ No newline at end of file +?> diff --git a/lib/adodb/adodb-memcache.lib.inc.php b/lib/adodb/adodb-memcache.lib.inc.php index bc6b420bc6..31a1c247f3 100644 --- a/lib/adodb/adodb-memcache.lib.inc.php +++ b/lib/adodb/adodb-memcache.lib.inc.php @@ -1,118 +1,118 @@ -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!
\n"); - return $false; - } - - $memcache = new Memcache; - if (!@$memcache->pconnect($host, $port)) { - if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\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!
\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!
\n"); - return; - } - - $memcache = new Memcache; - if (!@$memcache->pconnect($host, $port)) { - if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\n"); - return; - } - - if ($key) { - if (!$memcache->delete($key)) { - if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!
\n"); - } else { - if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!
\n"); - } - } else { - if (!$memcache->flush()) { - if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!
\n"); - } else { - if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!
\n"); - } - } - return; - } -?> +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!
\n"); + return $false; + } + + $memcache = new Memcache; + if (!@$memcache->pconnect($host, $port)) { + if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\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!
\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!
\n"); + return; + } + + $memcache = new Memcache; + if (!@$memcache->pconnect($host, $port)) { + if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\n"); + return; + } + + if ($key) { + if (!$memcache->delete($key)) { + if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!
\n"); + } else { + if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!
\n"); + } + } else { + if (!$memcache->flush()) { + if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!
\n"); + } else { + if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!
\n"); + } + } + return; + } +?> diff --git a/lib/adodb/adodb-pager.inc.php b/lib/adodb/adodb-pager.inc.php index f7f6ba0e74..fe6bab543c 100644 --- a/lib/adodb/adodb-pager.inc.php +++ b/lib/adodb/adodb-pager.inc.php @@ -1,7 +1,7 @@ = minimum number of secs to run + define( 'ADODB_OPT_HIGH', 2); define( 'ADODB_OPT_LOW', 1); @@ -165,7 +168,12 @@ function& adodb_log_sql(&$connx,$sql,$inputarr) if ($dbT == 'db2') $arr['f'] = (float) $arr['f']; $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)"; } - $ok = $conn->Execute($isql,$arr); + global $ADODB_PERF_MIN; + if ($errN != 0 || $time >= $ADODB_PERF_MIN) { + $ok = $conn->Execute($isql,$arr); + } else { + $ok = true; + } $conn->debug = $saved; if ($ok) { @@ -695,6 +703,8 @@ Committed_AS: 348732 kB else $form = " "; $allowsql = !defined('ADODB_PERF_NO_RUN_SQL'); + global $ADODB_PERF_MIN; + $app .= " (Min sql timing \$ADODB_PERF_MIN=$ADODB_PERF_MIN secs)"; if (empty($_GET['hidem'])) echo "
diff --git a/lib/adodb/adodb-php4.inc.php b/lib/adodb/adodb-php4.inc.php index a609770bcc..140d28ae87 100644 --- a/lib/adodb/adodb-php4.inc.php +++ b/lib/adodb/adodb-php4.inc.php @@ -1,7 +1,7 @@ = 5.2); @@ -401,7 +411,7 @@ function adodb_date_test_date($y1,$m,$d=13) $t = adodb_mktime($h,0,0,$m,$d,$y1); $rez = adodb_date('Y-n-j H:i:s',$t); if ($h == 0) $h = '00'; - else if ($h < 10) $h = '0'.$h; + else if ($h < 10) $h = '0'.$h; if ("$y1-$m-$d $h:00:00" != $rez) { print "$y1 error, expected=$y1-$m-$d $h:00:00, adodb=$rez
"; return false; @@ -422,10 +432,13 @@ function adodb_date_test_strftime($fmt) /** Test Suite -*/ +*/ function adodb_date_test() { + for ($m=-24; $m<=24; $m++) + echo "$m :",adodb_date('d-m-Y',adodb_mktime(0,0,0,1+$m,20,2040)),"
"; + error_reporting(E_ALL); print "

Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION.' PHP='.PHP_VERSION."

"; @set_time_limit(0); @@ -688,7 +701,7 @@ function adodb_get_gmt_diff_ts($ts) $m = $arr['mon']; $d = $arr['mday']; return adodb_get_gmt_diff($y,$m,$d); -} else { + } else { return adodb_get_gmt_diff(false,false,false); } @@ -714,9 +727,9 @@ global $ADODB_DATETIME_CLASS; } 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); + 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); } return $TZ; @@ -1089,7 +1102,7 @@ global $ADODB_DATETIME_CLASS; $dates .= ' '.adodb_tz_offset($gmt,$isphp5); break; - + case 'Y': $dates .= $year; break; case 'y': $dates .= substr($year,strlen($year)-2,2); break; // MONTH @@ -1202,13 +1215,18 @@ function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=fa // for windows, we don't check 1970 because with timezone differences, // 1 Jan 1970 could generate negative timestamp, which is illegal - if (1971 < $year && $year < 2038 + $usephpfns = (1971 < $year && $year < 2038 || !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038) - ) { + ); + + + if ($usephpfns && ($year + $mon/12+$day/365.25+$hr/(24*365.25) >= 2038)) $usephpfns = false; + + if ($usephpfns) { return $is_gmt ? @gmmktime($hr,$min,$sec,$mon,$day,$year): @mktime($hr,$min,$sec,$mon,$day,$year); - } + } } $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$mon,$day); @@ -1228,7 +1246,7 @@ function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=fa $year = adodb_year_digit_check($year); if ($mon > 12) { - $y = floor($mon / 12); + $y = floor(($mon-1)/ 12); $year += $y; $mon -= $y*12; } else if ($mon < 1) { @@ -1405,5 +1423,4 @@ global $ADODB_DATE_LOCALE; return $ret; } - ?> \ No newline at end of file diff --git a/lib/adodb/adodb-xmlschema.inc.php b/lib/adodb/adodb-xmlschema.inc.php index 5648c364a2..c925f0b53d 100644 --- a/lib/adodb/adodb-xmlschema.inc.php +++ b/lib/adodb/adodb-xmlschema.inc.php @@ -12,7 +12,7 @@ * * Last Editor: $Author$ * @author Richard Tango-Lowy & Dan Cech - * @version $Id$ + * @version $Revision$ * * @package axmls * @tutorial getting_started.pkg @@ -1209,7 +1209,7 @@ class dbQuerySet extends dbObject { * @tutorial getting_started.pkg * * @author Richard Tango-Lowy & Dan Cech -* @version $Id$ +* @version $Revision$ * * @package axmls */ diff --git a/lib/adodb/adodb-xmlschema03.inc.php b/lib/adodb/adodb-xmlschema03.inc.php index 8ba28969d8..cc98bec6bb 100644 --- a/lib/adodb/adodb-xmlschema03.inc.php +++ b/lib/adodb/adodb-xmlschema03.inc.php @@ -12,7 +12,7 @@ * * Last Editor: $Author$ * @author Richard Tango-Lowy & Dan Cech - * @version $Id$ + * @version $Revision$ * * @package axmls * @tutorial getting_started.pkg @@ -1309,7 +1309,7 @@ class dbQuerySet extends dbObject { * @tutorial getting_started.pkg * * @author Richard Tango-Lowy & Dan Cech -* @version $Id$ +* @version $Revision$ * * @package axmls */ diff --git a/lib/adodb/adodb.inc.php b/lib/adodb/adodb.inc.php index cb969e92b2..092e46ee91 100644 --- a/lib/adodb/adodb.inc.php +++ b/lib/adodb/adodb.inc.php @@ -1,4 +1,4 @@ -RecordCount() is used. @@ -1329,7 +1329,7 @@ function GetCol($sql, $inputarr = false, $trim = false) { - $rv = false; + $rs = &$this->Execute($sql, $inputarr); if ($rs) { $rv = array(); @@ -1345,15 +1345,16 @@ } } $rs->Close(); - } + } else + $rv = false; return $rv; } function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false) { - $rv = false; $rs = &$this->CacheExecute($secs, $sql, $inputarr); if ($rs) { + $rv = array(); if ($trim) { while (!$rs->EOF) { $rv[] = trim(reset($rs->fields)); @@ -1366,8 +1367,10 @@ } } $rs->Close(); - } - return $rv; + } else + $rv = false; + + return $rv; } function &Transpose(&$rs,$addfieldnames=true) @@ -1485,7 +1488,7 @@ { $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr); if ($rs) { - $arr = false; + $arr = array(); if (!$rs->EOF) $arr = $rs->fields; $rs->Close(); return $arr; @@ -1697,8 +1700,8 @@ if ($createdir && $notSafeMode && !file_exists($dir)) { $oldu = umask(0); - if (!mkdir($dir,0771)) - if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql"); + if (!@mkdir($dir,0771)) + if(!is_dir($dir) && $this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql"); umask($oldu); } return $dir.'/adodb_'.$m.'.cache'; @@ -1771,17 +1774,27 @@ $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this); if ($this->debug) ADOConnection::outp( " Cache write error"); } - } else - if ($rs) { + } else if ($rs) { $eof = $rs->EOF; $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately $txt = _rs2serialize($rs,false,$sql); // serialize - if (!adodb_write_file($md5file,$txt,$this->debug)) { - if ($fn = $this->raiseErrorFn) { - $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this); + $ok = adodb_write_file($md5file,$txt,$this->debug); + if (!$ok) { + if ($ok === false) { + $em = 'Cache write error'; + $en = -32000; + + if ($fn = $this->raiseErrorFn) { + $fn($this->databaseType,'CacheExecute', $en, $em, $md5file,$sql,$this); + } + } else { + $em = 'Cache file locked warning'; + $en = -32001; + // do not call error handling for just a warning } - if ($this->debug) ADOConnection::outp( " Cache write error"); + + if ($this->debug) ADOConnection::outp( " ".$em); } if ($rs->EOF && !$eof) { $rs->MoveFirst(); @@ -3853,7 +3866,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 $mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode; if ($mode & ADODB_FETCH_ASSOC) { - if (!isset($this->fields[$colname])) $colname = strtolower($colname); + if (!isset($this->fields[$colname]) && !is_null($this->fields[$colname])) $colname = strtolower($colname); return $this->fields[$colname]; } if (!$this->bind) { diff --git a/lib/adodb/datadict/datadict-access.inc.php b/lib/adodb/datadict/datadict-access.inc.php index 908d6917e0..3ec194e3bf 100644 --- a/lib/adodb/datadict/datadict-access.inc.php +++ b/lib/adodb/datadict/datadict-access.inc.php @@ -1,7 +1,7 @@ dropIndex, $this->TableName($idxname), $this->TableName($tabname))); + } + /** * Change the definition of one column * diff --git a/lib/adodb/datadict/datadict-sapdb.inc.php b/lib/adodb/datadict/datadict-sapdb.inc.php index 37de29ed61..bf52455476 100644 --- a/lib/adodb/datadict/datadict-sapdb.inc.php +++ b/lib/adodb/datadict/datadict-sapdb.inc.php @@ -1,121 +1,121 @@ -type; - $len = $fieldobj->max_length; - } - static $maxdb_type2adodb = array( - 'VARCHAR' => 'C', - 'CHARACTER' => 'C', - 'LONG' => 'X', // no way to differ between 'X' and 'B' :-( - 'DATE' => 'D', - 'TIMESTAMP' => 'T', - 'BOOLEAN' => 'L', - 'INTEGER' => 'I4', - 'SMALLINT' => 'I2', - 'FLOAT' => 'F', - 'FIXED' => 'N', - ); - $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C'; - - // convert integer-types simulated with fixed back to integer - if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) { - $type = $len == 20 ? 'I8' : 'I1'; - } - if ($fieldobj->auto_increment) $type = 'R'; - - return $type; - } - - // return string must begin with space - function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) - { - $suffix = ''; - if ($funsigned) $suffix .= ' UNSIGNED'; - if ($fnotnull) $suffix .= ' NOT NULL'; - if ($fautoinc) $suffix .= ' DEFAULT SERIAL'; - elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; - if ($fconstraint) $suffix .= ' '.$fconstraint; - return $suffix; - } - - function AddColumnSQL($tabname, $flds) - { - $tabname = $this->TableName ($tabname); - $sql = array(); - list($lines,$pkey) = $this->_GenFields($flds); - return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' ); - } - - function AlterColumnSQL($tabname, $flds) - { - $tabname = $this->TableName ($tabname); - $sql = array(); - list($lines,$pkey) = $this->_GenFields($flds); - return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' ); - } - - function DropColumnSQL($tabname, $flds) - { - $tabname = $this->TableName ($tabname); - if (!is_array($flds)) $flds = explode(',',$flds); - foreach($flds as $k => $v) { - $flds[$k] = $this->NameQuote($v); - } - return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' ); - } -} - +type; + $len = $fieldobj->max_length; + } + static $maxdb_type2adodb = array( + 'VARCHAR' => 'C', + 'CHARACTER' => 'C', + 'LONG' => 'X', // no way to differ between 'X' and 'B' :-( + 'DATE' => 'D', + 'TIMESTAMP' => 'T', + 'BOOLEAN' => 'L', + 'INTEGER' => 'I4', + 'SMALLINT' => 'I2', + 'FLOAT' => 'F', + 'FIXED' => 'N', + ); + $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C'; + + // convert integer-types simulated with fixed back to integer + if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) { + $type = $len == 20 ? 'I8' : 'I1'; + } + if ($fieldobj->auto_increment) $type = 'R'; + + return $type; + } + + // return string must begin with space + function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) + { + $suffix = ''; + if ($funsigned) $suffix .= ' UNSIGNED'; + if ($fnotnull) $suffix .= ' NOT NULL'; + if ($fautoinc) $suffix .= ' DEFAULT SERIAL'; + elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; + if ($fconstraint) $suffix .= ' '.$fconstraint; + return $suffix; + } + + function AddColumnSQL($tabname, $flds) + { + $tabname = $this->TableName ($tabname); + $sql = array(); + list($lines,$pkey) = $this->_GenFields($flds); + return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' ); + } + + function AlterColumnSQL($tabname, $flds) + { + $tabname = $this->TableName ($tabname); + $sql = array(); + list($lines,$pkey) = $this->_GenFields($flds); + return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' ); + } + + function DropColumnSQL($tabname, $flds) + { + $tabname = $this->TableName ($tabname); + if (!is_array($flds)) $flds = explode(',',$flds); + foreach($flds as $k => $v) { + $flds[$k] = $this->NameQuote($v); + } + return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' ); + } +} + ?> \ No newline at end of file diff --git a/lib/adodb/datadict/datadict-sybase.inc.php b/lib/adodb/datadict/datadict-sybase.inc.php index 50300944ff..2adbe0035f 100644 --- a/lib/adodb/datadict/datadict-sybase.inc.php +++ b/lib/adodb/datadict/datadict-sybase.inc.php @@ -1,7 +1,7 @@ debug) ADOConnection::outp("Could't connect : " . $this->ErrorMsg()); + $this->_connectionID = null; return false; } } @@ -611,16 +612,15 @@ class ADODB_mysqli extends ADOConnection { $nrows = -1, $offset = -1, $inputarr = false, - $arg3 = false, $secs = 0) { $offsetStr = ($offset >= 0) ? "$offset," : ''; if ($nrows < 0) $nrows = '18446744073709551615'; if ($secs) - $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3); + $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr); else - $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3); + $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr); return $rs; } @@ -944,7 +944,7 @@ class ADORecordSet_mysqli extends ADORecordSet{ case 'SET': case MYSQLI_TYPE_TINY_BLOB : - case MYSQLI_TYPE_CHAR : + #case MYSQLI_TYPE_CHAR : case MYSQLI_TYPE_STRING : case MYSQLI_TYPE_ENUM : case MYSQLI_TYPE_SET : @@ -1051,7 +1051,7 @@ class ADORecordSet_array_mysqli extends ADORecordSet_array { case 'SET': case MYSQLI_TYPE_TINY_BLOB : - case MYSQLI_TYPE_CHAR : + #case MYSQLI_TYPE_CHAR : case MYSQLI_TYPE_STRING : case MYSQLI_TYPE_ENUM : case MYSQLI_TYPE_SET : diff --git a/lib/adodb/drivers/adodb-mysqlt.inc.php b/lib/adodb/drivers/adodb-mysqlt.inc.php index fe05a174dc..6badabdf1e 100644 --- a/lib/adodb/drivers/adodb-mysqlt.inc.php +++ b/lib/adodb/drivers/adodb-mysqlt.inc.php @@ -1,7 +1,7 @@ name =OCIcolumnname($this->_queryID, $fieldOffset); $fld->type = OCIcolumntype($this->_queryID, $fieldOffset); $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset); - if ($fld->type == 'NUMBER') { + switch($fld->type) { + case 'NUMBER': $p = OCIColumnPrecision($this->_queryID, $fieldOffset); $sc = OCIColumnScale($this->_queryID, $fieldOffset); if ($p != 0 && $sc == 0) $fld->type = 'INT'; - //echo " $this->name ($p.$sc) "; - } + break; + + case 'CLOB': + case 'NCLOB': + case 'BLOB': + $fld->max_length = -1; + break; + } return $fld; } diff --git a/lib/adodb/drivers/adodb-oci805.inc.php b/lib/adodb/drivers/adodb-oci805.inc.php index 8d3513fb7b..3528c7b062 100644 --- a/lib/adodb/drivers/adodb-oci805.inc.php +++ b/lib/adodb/drivers/adodb-oci805.inc.php @@ -1,6 +1,6 @@ _bindInputArray = true; - #$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true); - } - - function ServerInfo() - { - return ADOConnection::ServerInfo(); - } - - function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) - { - $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - return $ret; - } - - function MetaTables() - { - return false; - } - - function MetaColumns() - { - return false; - } -} - - class ADODB_pdo extends ADOConnection { var $databaseType = "pdo"; var $dataProvider = "pdo"; @@ -390,6 +355,43 @@ class ADODB_pdo extends ADOConnection { } } + + +class ADODB_pdo_base extends ADODB_pdo { + + var $sysDate = "'?'"; + var $sysTimeStamp = "'?'"; + + + function _init($parentDriver) + { + $parentDriver->_bindInputArray = true; + #$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true); + } + + function ServerInfo() + { + return ADOConnection::ServerInfo(); + } + + function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) + { + $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + return $ret; + } + + function MetaTables() + { + return false; + } + + function MetaColumns() + { + return false; + } +} + + class ADOPDOStatement { var $databaseType = "pdo"; diff --git a/lib/adodb/drivers/adodb-pdo_mssql.inc.php b/lib/adodb/drivers/adodb-pdo_mssql.inc.php index 3450b4b05b..2a9958c7fe 100644 --- a/lib/adodb/drivers/adodb-pdo_mssql.inc.php +++ b/lib/adodb/drivers/adodb-pdo_mssql.inc.php @@ -2,7 +2,7 @@ /* -V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. +V4.98 13 Feb 2008 (c) 2000-2008 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. diff --git a/lib/adodb/drivers/adodb-pdo_mysql.inc.php b/lib/adodb/drivers/adodb-pdo_mysql.inc.php index 701d7f30ba..c24c010519 100644 --- a/lib/adodb/drivers/adodb-pdo_mysql.inc.php +++ b/lib/adodb/drivers/adodb-pdo_mysql.inc.php @@ -2,7 +2,7 @@ /* -V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. +V4.98 13 Feb 2008 (c) 2000-2008 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. @@ -15,6 +15,10 @@ class ADODB_pdo_mysql extends ADODB_pdo { var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`"; var $sysDate = 'CURDATE()'; var $sysTimeStamp = 'NOW()'; + var $hasGenID = true; + var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);"; + var $_dropSeqSQL = "drop table %s"; + var $nameQuote = '`'; function _init($parentDriver) diff --git a/lib/adodb/drivers/adodb-pdo_oci.inc.php b/lib/adodb/drivers/adodb-pdo_oci.inc.php index 50112db25f..c3a016d385 100644 --- a/lib/adodb/drivers/adodb-pdo_oci.inc.php +++ b/lib/adodb/drivers/adodb-pdo_oci.inc.php @@ -2,7 +2,7 @@ /* -V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. +V4.98 13 Feb 2008 (c) 2000-2008 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. diff --git a/lib/adodb/drivers/adodb-pdo_pgsql.inc.php b/lib/adodb/drivers/adodb-pdo_pgsql.inc.php index 039bd83f16..1215ad8a06 100644 --- a/lib/adodb/drivers/adodb-pdo_pgsql.inc.php +++ b/lib/adodb/drivers/adodb-pdo_pgsql.inc.php @@ -1,7 +1,7 @@ 'áíÓ åäÇáß ÞÇÚÏÉ ÈíÇäÇÊ ÈåÐÇ ÇáÇÓã', DB_ERROR_ACCESS_VIOLATION => 'ÓãÇÍíÇÊ ÛíÑ ßÇÝíÉ' ); -?> +?> \ No newline at end of file diff --git a/lib/adodb/lang/adodb-bgutf8.inc.php b/lib/adodb/lang/adodb-bgutf8.inc.php index d5c7155c60..5281ed53b6 100644 --- a/lib/adodb/lang/adodb-bgutf8.inc.php +++ b/lib/adodb/lang/adodb-bgutf8.inc.php @@ -1,4 +1,4 @@ - @@ -34,4 +34,4 @@ $ADODB_LANG_ARRAY = array ( DB_ERROR_NOSUCHDB => 'несъществуваща база данни', DB_ERROR_ACCESS_VIOLATION => 'нямате достатъчно права' ); -?> +?> \ No newline at end of file diff --git a/lib/adodb/lang/adodb-ca.inc.php b/lib/adodb/lang/adodb-ca.inc.php index 3e6a4496bd..3640ebd0bb 100644 --- a/lib/adodb/lang/adodb-ca.inc.php +++ b/lib/adodb/lang/adodb-ca.inc.php @@ -1,35 +1,34 @@ - 'ca', - DB_ERROR => 'error desconegut', - DB_ERROR_ALREADY_EXISTS => 'ja existeix', - DB_ERROR_CANNOT_CREATE => 'no es pot crear', - DB_ERROR_CANNOT_DELETE => 'no es pot esborrar', - DB_ERROR_CANNOT_DROP => 'no es pot eliminar', - DB_ERROR_CONSTRAINT => 'violació de constraint', - DB_ERROR_DIVZERO => 'divisió per zero', - DB_ERROR_INVALID => 'no és vàlid', - DB_ERROR_INVALID_DATE => 'la data o l\'hora no són vàlides', - DB_ERROR_INVALID_NUMBER => 'el nombre no és vàlid', - DB_ERROR_MISMATCH => 'no hi ha coincidència', - DB_ERROR_NODBSELECTED => 'cap base de dades seleccionada', - DB_ERROR_NOSUCHFIELD => 'camp inexistent', - DB_ERROR_NOSUCHTABLE => 'taula inexistent', - DB_ERROR_NOT_CAPABLE => 'l\'execució secundària de DB no pot', - DB_ERROR_NOT_FOUND => 'no trobat', - DB_ERROR_NOT_LOCKED => 'no blocat', - DB_ERROR_SYNTAX => 'error de sintaxi', - DB_ERROR_UNSUPPORTED => 'no suportat', - DB_ERROR_VALUE_COUNT_ON_ROW => 'el nombre de columnes no coincideix amb el nombre de valors en la fila', - DB_ERROR_INVALID_DSN => 'el DSN no és vàlid', - DB_ERROR_CONNECT_FAILED => 'connexió fallida', - 0 => 'cap error', // DB_OK - DB_ERROR_NEED_MORE_DATA => 'les dades subministrades són insuficients', - DB_ERROR_EXTENSION_NOT_FOUND=> 'extensió no trobada', - DB_ERROR_NOSUCHDB => 'base de dades inexistent', - DB_ERROR_ACCESS_VIOLATION => 'permisos insuficients' -); -?> - \ No newline at end of file + 'ca', + DB_ERROR => 'error desconegut', + DB_ERROR_ALREADY_EXISTS => 'ja existeix', + DB_ERROR_CANNOT_CREATE => 'no es pot crear', + DB_ERROR_CANNOT_DELETE => 'no es pot esborrar', + DB_ERROR_CANNOT_DROP => 'no es pot eliminar', + DB_ERROR_CONSTRAINT => 'violació de constraint', + DB_ERROR_DIVZERO => 'divisió per zero', + DB_ERROR_INVALID => 'no és vàlid', + DB_ERROR_INVALID_DATE => 'la data o l\'hora no són vàlides', + DB_ERROR_INVALID_NUMBER => 'el nombre no és vàlid', + DB_ERROR_MISMATCH => 'no hi ha coincidència', + DB_ERROR_NODBSELECTED => 'cap base de dades seleccionada', + DB_ERROR_NOSUCHFIELD => 'camp inexistent', + DB_ERROR_NOSUCHTABLE => 'taula inexistent', + DB_ERROR_NOT_CAPABLE => 'l\'execució secundària de DB no pot', + DB_ERROR_NOT_FOUND => 'no trobat', + DB_ERROR_NOT_LOCKED => 'no blocat', + DB_ERROR_SYNTAX => 'error de sintaxi', + DB_ERROR_UNSUPPORTED => 'no suportat', + DB_ERROR_VALUE_COUNT_ON_ROW => 'el nombre de columnes no coincideix amb el nombre de valors en la fila', + DB_ERROR_INVALID_DSN => 'el DSN no és vàlid', + DB_ERROR_CONNECT_FAILED => 'connexió fallida', + 0 => 'cap error', // DB_OK + DB_ERROR_NEED_MORE_DATA => 'les dades subministrades són insuficients', + DB_ERROR_EXTENSION_NOT_FOUND=> 'extensió no trobada', + DB_ERROR_NOSUCHDB => 'base de dades inexistent', + DB_ERROR_ACCESS_VIOLATION => 'permisos insuficients' +); +?> \ No newline at end of file diff --git a/lib/adodb/lang/adodb-pt-br.inc.php b/lib/adodb/lang/adodb-pt-br.inc.php index 3424099a5c..cd28f7e55c 100644 --- a/lib/adodb/lang/adodb-pt-br.inc.php +++ b/lib/adodb/lang/adodb-pt-br.inc.php @@ -1,35 +1,35 @@ - 'pt-br', - DB_ERROR => 'erro desconhecido', - DB_ERROR_ALREADY_EXISTS => 'já existe', - DB_ERROR_CANNOT_CREATE => 'impossível criar', - DB_ERROR_CANNOT_DELETE => 'impossível excluír', - DB_ERROR_CANNOT_DROP => 'impossível remover', - DB_ERROR_CONSTRAINT => 'violação do confinamente', - DB_ERROR_DIVZERO => 'divisão por zero', - DB_ERROR_INVALID => 'inválido', - DB_ERROR_INVALID_DATE => 'data ou hora inválida', - DB_ERROR_INVALID_NUMBER => 'número inválido', - DB_ERROR_MISMATCH => 'erro', - DB_ERROR_NODBSELECTED => 'nenhum banco de dados selecionado', - DB_ERROR_NOSUCHFIELD => 'campo inválido', - DB_ERROR_NOSUCHTABLE => 'tabela inexistente', - DB_ERROR_NOT_CAPABLE => 'capacidade inválida para este BD', - DB_ERROR_NOT_FOUND => 'não encontrado', - DB_ERROR_NOT_LOCKED => 'não bloqueado', - DB_ERROR_SYNTAX => 'erro de sintaxe', - DB_ERROR_UNSUPPORTED => -'não suportado', - DB_ERROR_VALUE_COUNT_ON_ROW => 'a quantidade de colunas não corresponde ao de valores', - DB_ERROR_INVALID_DSN => 'DSN inválido', - DB_ERROR_CONNECT_FAILED => 'falha na conexão', - 0 => 'sem erro', // DB_OK - DB_ERROR_NEED_MORE_DATA => 'dados insuficientes', - DB_ERROR_EXTENSION_NOT_FOUND=> 'extensão não encontrada', - DB_ERROR_NOSUCHDB => 'banco de dados não encontrado', - DB_ERROR_ACCESS_VIOLATION => 'permissão insuficiente' -); -?> + 'pt-br', + DB_ERROR => 'erro desconhecido', + DB_ERROR_ALREADY_EXISTS => 'já existe', + DB_ERROR_CANNOT_CREATE => 'impossível criar', + DB_ERROR_CANNOT_DELETE => 'impossível excluír', + DB_ERROR_CANNOT_DROP => 'impossível remover', + DB_ERROR_CONSTRAINT => 'violação do confinamente', + DB_ERROR_DIVZERO => 'divisão por zero', + DB_ERROR_INVALID => 'inválido', + DB_ERROR_INVALID_DATE => 'data ou hora inválida', + DB_ERROR_INVALID_NUMBER => 'número inválido', + DB_ERROR_MISMATCH => 'erro', + DB_ERROR_NODBSELECTED => 'nenhum banco de dados selecionado', + DB_ERROR_NOSUCHFIELD => 'campo inválido', + DB_ERROR_NOSUCHTABLE => 'tabela inexistente', + DB_ERROR_NOT_CAPABLE => 'capacidade inválida para este BD', + DB_ERROR_NOT_FOUND => 'não encontrado', + DB_ERROR_NOT_LOCKED => 'não bloqueado', + DB_ERROR_SYNTAX => 'erro de sintaxe', + DB_ERROR_UNSUPPORTED => +'não suportado', + DB_ERROR_VALUE_COUNT_ON_ROW => 'a quantidade de colunas não corresponde ao de valores', + DB_ERROR_INVALID_DSN => 'DSN inválido', + DB_ERROR_CONNECT_FAILED => 'falha na conexão', + 0 => 'sem erro', // DB_OK + DB_ERROR_NEED_MORE_DATA => 'dados insuficientes', + DB_ERROR_EXTENSION_NOT_FOUND=> 'extensão não encontrada', + DB_ERROR_NOSUCHDB => 'banco de dados não encontrado', + DB_ERROR_ACCESS_VIOLATION => 'permissão insuficiente' +); +?> \ No newline at end of file diff --git a/lib/adodb/lang/adodb-ro.inc.php b/lib/adodb/lang/adodb-ro.inc.php index 8263d822b4..bcd7d13228 100644 --- a/lib/adodb/lang/adodb-ro.inc.php +++ b/lib/adodb/lang/adodb-ro.inc.php @@ -32,4 +32,4 @@ $ADODB_LANG_ARRAY = array ( DB_ERROR_NOSUCHDB => 'nu exista baza de date', DB_ERROR_ACCESS_VIOLATION => 'permisiuni insuficiente' ); -?> +?> \ No newline at end of file diff --git a/lib/adodb/lang/adodb-uk1251.inc.php b/lib/adodb/lang/adodb-uk1251.inc.php index 9fa32ed5b4..675016d125 100644 --- a/lib/adodb/lang/adodb-uk1251.inc.php +++ b/lib/adodb/lang/adodb-uk1251.inc.php @@ -32,4 +32,4 @@ $ADODB_LANG_ARRAY = array ( DB_ERROR_NOSUCHDB => 'íå ³ñíóº ÁÄ', DB_ERROR_ACCESS_VIOLATION => 'íåäîñòàòíüî ïðàâ äîñòóïà' ); -?> +?> \ No newline at end of file diff --git a/lib/adodb/lang/adodb_th.inc.php b/lib/adodb/lang/adodb_th.inc.php index a7288efb57..3fdd99705f 100644 --- a/lib/adodb/lang/adodb_th.inc.php +++ b/lib/adodb/lang/adodb_th.inc.php @@ -30,4 +30,4 @@ $ADODB_LANG_ARRAY = array ( DB_ERROR_NOSUCHDB => 'ไม่มีข้อมูลนี้', DB_ERROR_ACCESS_VIOLATION => 'permissions ไม่พอ' ); -?> +?> \ No newline at end of file diff --git a/lib/adodb/perf/perf-db2.inc.php b/lib/adodb/perf/perf-db2.inc.php index ca02cb554e..ea6d3b4c93 100644 --- a/lib/adodb/perf/perf-db2.inc.php +++ b/lib/adodb/perf/perf-db2.inc.php @@ -1,6 +1,6 @@ databaseType,'access') !== false; - // note - vfp 6 still doesn' work even with IIF enabled || $db->databaseType == 'vfp'; - - //$hidecnt = false; - - if ($where) $where = "\nWHERE $where"; - if (!is_array($colfield)) $colarr = $db->GetCol("select distinct $colfield from $tables $where order by 1"); - if (!$aggfield) $hidecnt = false; - - $sel = "$rowfields, "; - if (is_array($colfield)) { - foreach ($colfield as $k => $v) { - $k = trim($k); - if (!$hidecnt) { - $sel .= $iif ? - "\n\t$aggfn(IIF($v,1,0)) AS \"$k\", " - : - "\n\t$aggfn(CASE WHEN $v THEN 1 ELSE 0 END) AS \"$k\", "; - } - if ($aggfield) { - $sel .= $iif ? - "\n\t$aggfn(IIF($v,$aggfield,0)) AS \"$sumlabel$k\", " - : - "\n\t$aggfn(CASE WHEN $v THEN $aggfield ELSE 0 END) AS \"$sumlabel$k\", "; - } - } - } else { - foreach ($colarr as $v) { - if (!is_numeric($v)) $vq = $db->qstr($v); - else $vq = $v; - $v = trim($v); - if (strlen($v) == 0 ) $v = 'null'; - if (!$hidecnt) { - $sel .= $iif ? - "\n\t$aggfn(IIF($colfield=$vq,1,0)) AS \"$v\", " - : - "\n\t$aggfn(CASE WHEN $colfield=$vq THEN 1 ELSE 0 END) AS \"$v\", "; - } - if ($aggfield) { - if ($hidecnt) $label = $v; - else $label = "{$v}_$aggfield"; - $sel .= $iif ? - "\n\t$aggfn(IIF($colfield=$vq,$aggfield,0)) AS \"$label\", " - : - "\n\t$aggfn(CASE WHEN $colfield=$vq THEN $aggfield ELSE 0 END) AS \"$label\", "; - } - } - } - if ($aggfield && $aggfield != '1'){ - $agg = "$aggfn($aggfield)"; - $sel .= "\n\t$agg as \"$sumlabel$aggfield\", "; - } - - if ($showcount) - $sel .= "\n\tSUM(1) as Total"; - else - $sel = substr($sel,0,strlen($sel)-2); - - - // Strip aliases - $rowfields = preg_replace('/ AS (\w+)/i', '', $rowfields); - - $sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields"; - - return $sql; - } - -/* EXAMPLES USING MS NORTHWIND DATABASE */ -if (0) { - -# example1 -# -# Query the main "product" table -# Set the rows to CompanyName and QuantityPerUnit -# and the columns to the Categories -# and define the joins to link to lookup tables -# "categories" and "suppliers" -# - - $sql = PivotTableSQL( - $gDB, # adodb connection - 'products p ,categories c ,suppliers s', # tables - 'CompanyName,QuantityPerUnit', # row fields - 'CategoryName', # column fields - 'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where -); - print "
$sql";
- $rs = $gDB->Execute($sql);
- rs2html($rs);
- 
-/*
-Generated SQL:
-
-SELECT CompanyName,QuantityPerUnit, 
-	SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS "Beverages", 
-	SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS "Condiments", 
-	SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS "Confections", 
-	SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS "Dairy Products", 
-	SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS "Grains/Cereals", 
-	SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS "Meat/Poultry", 
-	SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS "Produce", 
-	SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS "Seafood", 
-	SUM(1) as Total 
-FROM products p ,categories c ,suppliers s  WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
-GROUP BY CompanyName,QuantityPerUnit
-*/
-//=====================================================================
-
-# example2
-#
-# Query the main "product" table
-# Set the rows to CompanyName and QuantityPerUnit
-# and the columns to the UnitsInStock for diiferent ranges
-# and define the joins to link to lookup tables 
-# "categories" and "suppliers"
-#
- $sql = PivotTableSQL(
- 	$gDB,										# adodb connection
- 	'products p ,categories c ,suppliers s',	# tables
-	'CompanyName,QuantityPerUnit',				# row fields
-												# column ranges
-array(										
-' 0 ' => 'UnitsInStock <= 0',
-"1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5',
-"6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10',
-"11 to 15"  => '10 < UnitsInStock and UnitsInStock <= 15',
-"16+" =>'15 < UnitsInStock'
-),
-	' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where
-	'UnitsInStock', 							# sum this field
-	'Sum'										# sum label prefix
-);
- print "
$sql";
- $rs = $gDB->Execute($sql);
- rs2html($rs);
- /*
- Generated SQL:
- 
-SELECT CompanyName,QuantityPerUnit, 
-	SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum  0 ", 
-	SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock ELSE 0 END) AS "Sum 1 to 5", 
-	SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock ELSE 0 END) AS "Sum 6 to 10", 
-	SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock ELSE 0 END) AS "Sum 11 to 15", 
-	SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 16+",
-	SUM(UnitsInStock) AS "Sum UnitsInStock", 
-	SUM(1) as Total 
-FROM products p ,categories c ,suppliers s  WHERE  p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
-GROUP BY CompanyName,QuantityPerUnit
- */
-}
+databaseType,'access') !== false; 
+		// note - vfp 6 still doesn' work even with IIF enabled || $db->databaseType == 'vfp';
+	
+	//$hidecnt = false;
+	
+ 	if ($where) $where = "\nWHERE $where";
+	if (!is_array($colfield)) $colarr = $db->GetCol("select distinct $colfield from $tables $where order by 1");
+	if (!$aggfield) $hidecnt = false;
+	
+	$sel = "$rowfields, ";
+	if (is_array($colfield)) {
+		foreach ($colfield as $k => $v) {
+			$k = trim($k);
+			if (!$hidecnt) {
+				$sel .= $iif ? 
+					"\n\t$aggfn(IIF($v,1,0)) AS \"$k\", "
+					:
+					"\n\t$aggfn(CASE WHEN $v THEN 1 ELSE 0 END) AS \"$k\", ";
+			}
+			if ($aggfield) {
+				$sel .= $iif ?
+					"\n\t$aggfn(IIF($v,$aggfield,0)) AS \"$sumlabel$k\", "
+					:
+					"\n\t$aggfn(CASE WHEN $v THEN $aggfield ELSE 0 END) AS \"$sumlabel$k\", ";
+			}
+		} 
+	} else {
+		foreach ($colarr as $v) {
+			if (!is_numeric($v)) $vq = $db->qstr($v);
+			else $vq = $v;
+			$v = trim($v);
+			if (strlen($v) == 0	) $v = 'null';
+			if (!$hidecnt) {
+				$sel .= $iif ?
+					"\n\t$aggfn(IIF($colfield=$vq,1,0)) AS \"$v\", "
+					:
+					"\n\t$aggfn(CASE WHEN $colfield=$vq THEN 1 ELSE 0 END) AS \"$v\", ";
+			}
+			if ($aggfield) {
+				if ($hidecnt) $label = $v;
+				else $label = "{$v}_$aggfield";
+				$sel .= $iif ?
+					"\n\t$aggfn(IIF($colfield=$vq,$aggfield,0)) AS \"$label\", "
+					:
+					"\n\t$aggfn(CASE WHEN $colfield=$vq THEN $aggfield ELSE 0 END) AS \"$label\", ";
+			}
+		}
+	}
+	if ($aggfield && $aggfield != '1'){
+		$agg = "$aggfn($aggfield)";
+		$sel .= "\n\t$agg as \"$sumlabel$aggfield\", ";		
+	}
+	
+	if ($showcount)
+		$sel .= "\n\tSUM(1) as Total";
+	else
+		$sel = substr($sel,0,strlen($sel)-2);
+	
+	
+	// Strip aliases
+	$rowfields = preg_replace('/ AS (\w+)/i', '', $rowfields);
+	
+	$sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields";
+	
+	return $sql;
+ }
+
+/* EXAMPLES USING MS NORTHWIND DATABASE */
+if (0) {
+
+# example1
+#
+# Query the main "product" table
+# Set the rows to CompanyName and QuantityPerUnit
+# and the columns to the Categories
+# and define the joins to link to lookup tables 
+# "categories" and "suppliers"
+#
+
+ $sql = PivotTableSQL(
+ 	$gDB,  											# adodb connection
+ 	'products p ,categories c ,suppliers s',  		# tables
+	'CompanyName,QuantityPerUnit',					# row fields
+	'CategoryName',									# column fields 
+	'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where
+);
+ print "
$sql";
+ $rs = $gDB->Execute($sql);
+ rs2html($rs);
+ 
+/*
+Generated SQL:
+
+SELECT CompanyName,QuantityPerUnit, 
+	SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS "Beverages", 
+	SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS "Condiments", 
+	SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS "Confections", 
+	SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS "Dairy Products", 
+	SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS "Grains/Cereals", 
+	SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS "Meat/Poultry", 
+	SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS "Produce", 
+	SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS "Seafood", 
+	SUM(1) as Total 
+FROM products p ,categories c ,suppliers s  WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
+GROUP BY CompanyName,QuantityPerUnit
+*/
+//=====================================================================
+
+# example2
+#
+# Query the main "product" table
+# Set the rows to CompanyName and QuantityPerUnit
+# and the columns to the UnitsInStock for diiferent ranges
+# and define the joins to link to lookup tables 
+# "categories" and "suppliers"
+#
+ $sql = PivotTableSQL(
+ 	$gDB,										# adodb connection
+ 	'products p ,categories c ,suppliers s',	# tables
+	'CompanyName,QuantityPerUnit',				# row fields
+												# column ranges
+array(										
+' 0 ' => 'UnitsInStock <= 0',
+"1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5',
+"6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10',
+"11 to 15"  => '10 < UnitsInStock and UnitsInStock <= 15',
+"16+" =>'15 < UnitsInStock'
+),
+	' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where
+	'UnitsInStock', 							# sum this field
+	'Sum'										# sum label prefix
+);
+ print "
$sql";
+ $rs = $gDB->Execute($sql);
+ rs2html($rs);
+ /*
+ Generated SQL:
+ 
+SELECT CompanyName,QuantityPerUnit, 
+	SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum  0 ", 
+	SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock ELSE 0 END) AS "Sum 1 to 5", 
+	SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock ELSE 0 END) AS "Sum 6 to 10", 
+	SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock ELSE 0 END) AS "Sum 11 to 15", 
+	SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 16+",
+	SUM(UnitsInStock) AS "Sum UnitsInStock", 
+	SUM(1) as Total 
+FROM products p ,categories c ,suppliers s  WHERE  p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
+GROUP BY CompanyName,QuantityPerUnit
+ */
+}
 ?>
\ No newline at end of file
diff --git a/lib/adodb/readme_moodle.txt b/lib/adodb/readme_moodle.txt
index 45d08c4edd..f96e9023ad 100644
--- a/lib/adodb/readme_moodle.txt
+++ b/lib/adodb/readme_moodle.txt
@@ -1,4 +1,4 @@
-Description of ADODB v4.96a library import into Moodle
+Description of ADODB v4.98 library import into Moodle
 
 Removed:
  * contrib/
@@ -13,16 +13,13 @@ Added:
  * readme_moodle.txt - this file ;-)
 
 Our changes:
- * adodb-lib.inc.php - forced conversion to proper numeric type in _adodb_column_sql()
+ * adodb-lib.inc.php - added support for "F" and "L" types in  _adodb_column_sql()
  * adodb-lib.inc.php - modify some debug output to be correct XHTML. MDL-12378.
        Reported to ADOdb at: http://phplens.com/lens/lensforum/msgs.php?id=17133
        Once fixed by adodb guys, we'll return to their official distro.
- * lang/adodb-ar.inc.php lang/adodb-bg.inc.php lang/adodb-bgutf8.inc.php 
-   lang/adodb-en.inc.php lang/adodb-pl.inc.php lang/adodb-ro.inc.php
-   lang/adodb_th.inc.php - Removed leading white space outside PHP open/close tags
-   (see http://tracker.moodle.org/browse/MDL-11632).
+
+skodak, iarenaza, moodler
 
 
-skodak, iarenaza
 
 $Id$
diff --git a/lib/adodb/rsfilter.inc.php b/lib/adodb/rsfilter.inc.php
index 29662a215e..cf705c9073 100644
--- a/lib/adodb/rsfilter.inc.php
+++ b/lib/adodb/rsfilter.inc.php
@@ -1,61 +1,61 @@
- $v) {
-			$arr[$k] = ucwords($v);
-		}
-	}
-	$rs = RSFilter($rs,'do_ucwords');
- */
-function &RSFilter($rs,$fn)
-{
-	if ($rs->databaseType != 'array') {
-		if (!$rs->connection) return false;
-		
-		$rs = &$rs->connection->_rs2rs($rs);
-	}
-	$rows = $rs->RecordCount();
-	for ($i=0; $i < $rows; $i++) {
-		if (is_array ($fn)) {
-        	$obj = $fn[0];
-        	$method = $fn[1];
-        	$obj->$method ($rs->_array[$i],$rs);
-      } else {
-			$fn($rs->_array[$i],$rs);
-      }
-	  
-	}
-	if (!$rs->EOF) {
-		$rs->_currentRow = 0;
-		$rs->fields = $rs->_array[0];
-	}
-	
-	return $rs;
-}
+ $v) {
+			$arr[$k] = ucwords($v);
+		}
+	}
+	$rs = RSFilter($rs,'do_ucwords');
+ */
+function &RSFilter($rs,$fn)
+{
+	if ($rs->databaseType != 'array') {
+		if (!$rs->connection) return false;
+		
+		$rs = &$rs->connection->_rs2rs($rs);
+	}
+	$rows = $rs->RecordCount();
+	for ($i=0; $i < $rows; $i++) {
+		if (is_array ($fn)) {
+        	$obj = $fn[0];
+        	$method = $fn[1];
+        	$obj->$method ($rs->_array[$i],$rs);
+      } else {
+			$fn($rs->_array[$i],$rs);
+      }
+	  
+	}
+	if (!$rs->EOF) {
+		$rs->_currentRow = 0;
+		$rs->fields = $rs->_array[0];
+	}
+	
+	return $rs;
+}
 ?>
\ No newline at end of file
diff --git a/lib/adodb/session/adodb-compress-bzip2.php b/lib/adodb/session/adodb-compress-bzip2.php
index cbb5c4e16f..c58428b4ff 100644
--- a/lib/adodb/session/adodb-compress-bzip2.php
+++ b/lib/adodb/session/adodb-compress-bzip2.php
@@ -1,7 +1,7 @@
 ";
-	
-To force non-persistent connections, call adodb_session_open first before session_start():
-
-	include('adodb.inc.php');
-	include('adodb-session.php');
-	adodb_session_open(false,false,false);
-	session_start();
-	session_register('AVAR');
-	$_SESSION['AVAR'] += 1;
-	print "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}

"; - - - Installation - ============ - 1. Create this table in your database (syntax might vary depending on your db): - - create table sessions ( - SESSKEY char(32) not null, - EXPIRY int(11) unsigned not null, - EXPIREREF varchar(64), - DATA CLOB, - primary key (sesskey) - ); - - - 2. Then define the following parameters in this file: - $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase'; - $ADODB_SESSION_CONNECT='server to connect to'; - $ADODB_SESSION_USER ='user'; - $ADODB_SESSION_PWD ='password'; - $ADODB_SESSION_DB ='database'; - $ADODB_SESSION_TBL = 'sessions' - $ADODB_SESSION_USE_LOBS = false; (or, if you wanna use CLOBS (= 'CLOB') or ( = 'BLOB') - - 3. Recommended is PHP 4.1.0 or later. There are documented - session bugs in earlier versions of PHP. - - 4. If you want to receive notifications when a session expires, then - you can tag a session with an EXPIREREF, and before the session - record is deleted, we can call a function that will pass the EXPIREREF - as the first parameter, and the session key as the second parameter. - - To do this, define a notification function, say NotifyFn: - - function NotifyFn($expireref, $sesskey) - { - } - - Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY. - This is an array with 2 elements, the first being the name of the variable - you would like to store in the EXPIREREF field, and the 2nd is the - notification function's name. - - In this example, we want to be notified when a user's session - has expired, so we store the user id in the global variable $USERID, - store this value in the EXPIREREF field: - - $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn'); - - Then when the NotifyFn is called, we are passed the $USERID as the first - parameter, eg. NotifyFn($userid, $sesskey). -*/ - -if (!defined('_ADODB_LAYER')) { - include (dirname(__FILE__).'/adodb.inc.php'); -} - -if (!defined('ADODB_SESSION')) { - - define('ADODB_SESSION',1); - - /* if database time and system time is difference is greater than this, then give warning */ - define('ADODB_SESSION_SYNCH_SECS',60); - -/****************************************************************************************\ - Global definitions -\****************************************************************************************/ -GLOBAL $ADODB_SESSION_CONNECT, - $ADODB_SESSION_DRIVER, - $ADODB_SESSION_USER, - $ADODB_SESSION_PWD, - $ADODB_SESSION_DB, - $ADODB_SESS_CONN, - $ADODB_SESS_LIFE, - $ADODB_SESS_DEBUG, - $ADODB_SESSION_EXPIRE_NOTIFY, - $ADODB_SESSION_CRC, - $ADODB_SESSION_USE_LOBS, - $ADODB_SESSION_TBL; - - if (!isset($ADODB_SESSION_USE_LOBS)) $ADODB_SESSION_USE_LOBS = 'CLOB'; - - $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime'); - if ($ADODB_SESS_LIFE <= 1) { - // bug in PHP 4.0.3 pl 1 -- how about other versions? - //print "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; - $ADODB_SESS_LIFE=1440; - } - $ADODB_SESSION_CRC = false; - //$ADODB_SESS_DEBUG = true; - - ////////////////////////////////// - /* SET THE FOLLOWING PARAMETERS */ - ////////////////////////////////// - - if (empty($ADODB_SESSION_DRIVER)) { - $ADODB_SESSION_DRIVER='mysql'; - $ADODB_SESSION_CONNECT='localhost'; - $ADODB_SESSION_USER ='root'; - $ADODB_SESSION_PWD =''; - $ADODB_SESSION_DB ='xphplens_2'; - } - - if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) { - $ADODB_SESSION_EXPIRE_NOTIFY = false; - } - // Made table name configurable - by David Johnson djohnson@inpro.net - if (empty($ADODB_SESSION_TBL)){ - $ADODB_SESSION_TBL = 'sessions'; - } - - - // defaulting $ADODB_SESSION_USE_LOBS - if (!isset($ADODB_SESSION_USE_LOBS) || empty($ADODB_SESSION_USE_LOBS)) { - $ADODB_SESSION_USE_LOBS = false; - } - - /* - $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER; - $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT; - $ADODB_SESS['user'] = $ADODB_SESSION_USER; - $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD; - $ADODB_SESS['db'] = $ADODB_SESSION_DB; - $ADODB_SESS['life'] = $ADODB_SESS_LIFE; - $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; - - $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; - $ADODB_SESS['table'] = $ADODB_SESS_TBL; - */ - -/****************************************************************************************\ - Create the connection to the database. - - If $ADODB_SESS_CONN already exists, reuse that connection -\****************************************************************************************/ -function adodb_sess_open($save_path, $session_name,$persist=true) -{ -GLOBAL $ADODB_SESS_CONN; - if (isset($ADODB_SESS_CONN)) return true; - -GLOBAL $ADODB_SESSION_CONNECT, - $ADODB_SESSION_DRIVER, - $ADODB_SESSION_USER, - $ADODB_SESSION_PWD, - $ADODB_SESSION_DB, - $ADODB_SESS_DEBUG; - - // cannot use & below - do not know why... - $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER); - if (!empty($ADODB_SESS_DEBUG)) { - $ADODB_SESS_CONN->debug = true; - ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB "); - } - if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT, - $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); - else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT, - $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); - - if (!$ok) ADOConnection::outp( " --- Session: connection failed

",false); -} - -/****************************************************************************************\ - Close the connection -\****************************************************************************************/ -function adodb_sess_close() -{ -global $ADODB_SESS_CONN; - - if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close(); - return true; -} - -/****************************************************************************************\ - Slurp in the session variables and return the serialized string -\****************************************************************************************/ -function adodb_sess_read($key) -{ -global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC; - - $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time()); - if ($rs) { - if ($rs->EOF) { - $v = ''; - } else - $v = rawurldecode(reset($rs->fields)); - - $rs->Close(); - - // new optimization adodb 2.1 - $ADODB_SESSION_CRC = strlen($v).crc32($v); - - return $v; - } - - return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com -} - -/****************************************************************************************\ - Write the serialized data to a database. - - If the data has not been modified since adodb_sess_read(), we do not write. -\****************************************************************************************/ -function adodb_sess_write($key, $val) -{ - global - $ADODB_SESS_CONN, - $ADODB_SESS_LIFE, - $ADODB_SESSION_TBL, - $ADODB_SESS_DEBUG, - $ADODB_SESSION_CRC, - $ADODB_SESSION_EXPIRE_NOTIFY, - $ADODB_SESSION_DRIVER, // added - $ADODB_SESSION_USE_LOBS; // added - - $expiry = time() + $ADODB_SESS_LIFE; - - // crc32 optimization since adodb 2.1 - // now we only update expiry date, thx to sebastian thom in adodb 2.32 - if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) { - if ($ADODB_SESS_DEBUG) echo " --- Session: Only updating date - crc32 not changed

"; - $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time(); - $rs = $ADODB_SESS_CONN->Execute($qry); - return true; - } - $val = rawurlencode($val); - - $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val); - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - $var = reset($ADODB_SESSION_EXPIRE_NOTIFY); - global $$var; - $arr['expireref'] = $$var; - } - - - if ($ADODB_SESSION_USE_LOBS === false) { // no lobs, simply use replace() - $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, 'sesskey',$autoQuote = true); - if (!$rs) { - $err = $ADODB_SESS_CONN->ErrorMsg(); - } - } else { - // what value shall we insert/update for lob row? - switch ($ADODB_SESSION_DRIVER) { - // empty_clob or empty_lob for oracle dbs - case "oracle": - case "oci8": - case "oci8po": - case "oci805": - $lob_value = sprintf("empty_%s()", strtolower($ADODB_SESSION_USE_LOBS)); - break; - - // null for all other - default: - $lob_value = "null"; - break; - } - - // do we insert or update? => as for sesskey - $res = $ADODB_SESS_CONN->Execute("select count(*) as cnt from $ADODB_SESSION_TBL where sesskey = '$key'"); - if ($res && reset($res->fields) > 0) { - $qry = sprintf("update %s set expiry = %d, data = %s where sesskey = '%s'", $ADODB_SESSION_TBL, $expiry, $lob_value, $key); - } else { - // insert - $qry = sprintf("insert into %s (sesskey, expiry, data) values ('%s', %d, %s)", $ADODB_SESSION_TBL, $key, $expiry, $lob_value); - } - - $err = ""; - $rs1 = $ADODB_SESS_CONN->Execute($qry); - if (!$rs1) { - $err .= $ADODB_SESS_CONN->ErrorMsg()."\n"; - } - $rs2 = $ADODB_SESS_CONN->UpdateBlob($ADODB_SESSION_TBL, 'data', $val, "sesskey='$key'", strtoupper($ADODB_SESSION_USE_LOBS)); - if (!$rs2) { - $err .= $ADODB_SESS_CONN->ErrorMsg()."\n"; - } - $rs = ($rs1 && $rs2) ? true : false; - } - - if (!$rs) { - ADOConnection::outp( ' --- Session Replace: '.nl2br($err).'

',false); - } else { - // bug in access driver (could be odbc?) means that info is not commited - // properly unless select statement executed in Win2000 - if ($ADODB_SESS_CONN->databaseType == 'access') - $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); - } - return !empty($rs); -} - -function adodb_sess_destroy($key) -{ - global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; - - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - reset($ADODB_SESSION_EXPIRE_NOTIFY); - $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); - $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); - $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $ADODB_SESS_CONN->SetFetchMode($savem); - if ($rs) { - $ADODB_SESS_CONN->BeginTrans(); - while (!$rs->EOF) { - $ref = $rs->fields[0]; - $key = $rs->fields[1]; - $fn($ref,$key); - $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $rs->MoveNext(); - } - $ADODB_SESS_CONN->CommitTrans(); - } - } else { - $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'"; - $rs = $ADODB_SESS_CONN->Execute($qry); - } - return $rs ? true : false; -} - -function adodb_sess_gc($maxlifetime) -{ - global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; - - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - reset($ADODB_SESSION_EXPIRE_NOTIFY); - $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); - $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); - $t = time(); - $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t"); - $ADODB_SESS_CONN->SetFetchMode($savem); - if ($rs) { - $ADODB_SESS_CONN->BeginTrans(); - while (!$rs->EOF) { - $ref = $rs->fields[0]; - $key = $rs->fields[1]; - $fn($ref,$key); - $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $rs->MoveNext(); - } - $rs->Close(); - - //$ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < $t"); - $ADODB_SESS_CONN->CommitTrans(); - - } - } else { - $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time()); - - if ($ADODB_SESS_DEBUG) ADOConnection::outp(" --- Garbage Collection: $qry

"); - } - // suggested by Cameron, "GaM3R" - if (defined('ADODB_SESSION_OPTIMIZE')) { - global $ADODB_SESSION_DRIVER; - - switch( $ADODB_SESSION_DRIVER ) { - case 'mysql': - case 'mysqlt': - $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL; - break; - case 'postgresql': - case 'postgresql7': - $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; - break; - } - if (!empty($opt_qry)) { - $ADODB_SESS_CONN->Execute($opt_qry); - } - } - if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL; - else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL; - - $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1); - if ($rs && !$rs->EOF) { - - $dbts = reset($rs->fields); - $rs->Close(); - $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts); - $t = time(); - if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) { - $msg = - __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)"; - error_log($msg); - if ($ADODB_SESS_DEBUG) ADOConnection::outp(" --- $msg

"); - } - } - - return true; -} - -session_module_name('user'); -session_set_save_handler( - "adodb_sess_open", - "adodb_sess_close", - "adodb_sess_read", - "adodb_sess_write", - "adodb_sess_destroy", - "adodb_sess_gc"); -} - -/* TEST SCRIPT -- UNCOMMENT */ - -if (0) { - - session_start(); - session_register('AVAR'); - $_SESSION['AVAR'] += 1; - ADOConnection::outp( " --- \$_SESSION['AVAR']={$_SESSION['AVAR']}

",false); -} - -?> +"; + +To force non-persistent connections, call adodb_session_open first before session_start(): + + include('adodb.inc.php'); + include('adodb-session.php'); + adodb_session_open(false,false,false); + session_start(); + session_register('AVAR'); + $_SESSION['AVAR'] += 1; + print " +-- \$_SESSION['AVAR']={$_SESSION['AVAR']}

"; + + + Installation + ============ + 1. Create this table in your database (syntax might vary depending on your db): + + create table sessions ( + SESSKEY char(32) not null, + EXPIRY int(11) unsigned not null, + EXPIREREF varchar(64), + DATA CLOB, + primary key (sesskey) + ); + + + 2. Then define the following parameters in this file: + $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase'; + $ADODB_SESSION_CONNECT='server to connect to'; + $ADODB_SESSION_USER ='user'; + $ADODB_SESSION_PWD ='password'; + $ADODB_SESSION_DB ='database'; + $ADODB_SESSION_TBL = 'sessions' + $ADODB_SESSION_USE_LOBS = false; (or, if you wanna use CLOBS (= 'CLOB') or ( = 'BLOB') + + 3. Recommended is PHP 4.1.0 or later. There are documented + session bugs in earlier versions of PHP. + + 4. If you want to receive notifications when a session expires, then + you can tag a session with an EXPIREREF, and before the session + record is deleted, we can call a function that will pass the EXPIREREF + as the first parameter, and the session key as the second parameter. + + To do this, define a notification function, say NotifyFn: + + function NotifyFn($expireref, $sesskey) + { + } + + Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY. + This is an array with 2 elements, the first being the name of the variable + you would like to store in the EXPIREREF field, and the 2nd is the + notification function's name. + + In this example, we want to be notified when a user's session + has expired, so we store the user id in the global variable $USERID, + store this value in the EXPIREREF field: + + $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn'); + + Then when the NotifyFn is called, we are passed the $USERID as the first + parameter, eg. NotifyFn($userid, $sesskey). +*/ + +if (!defined('_ADODB_LAYER')) { + include (dirname(__FILE__).'/adodb.inc.php'); +} + +if (!defined('ADODB_SESSION')) { + + define('ADODB_SESSION',1); + + /* if database time and system time is difference is greater than this, then give warning */ + define('ADODB_SESSION_SYNCH_SECS',60); + +/****************************************************************************************\ + Global definitions +\****************************************************************************************/ +GLOBAL $ADODB_SESSION_CONNECT, + $ADODB_SESSION_DRIVER, + $ADODB_SESSION_USER, + $ADODB_SESSION_PWD, + $ADODB_SESSION_DB, + $ADODB_SESS_CONN, + $ADODB_SESS_LIFE, + $ADODB_SESS_DEBUG, + $ADODB_SESSION_EXPIRE_NOTIFY, + $ADODB_SESSION_CRC, + $ADODB_SESSION_USE_LOBS, + $ADODB_SESSION_TBL; + + if (!isset($ADODB_SESSION_USE_LOBS)) $ADODB_SESSION_USE_LOBS = 'CLOB'; + + $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime'); + if ($ADODB_SESS_LIFE <= 1) { + // bug in PHP 4.0.3 pl 1 -- how about other versions? + //print "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; + $ADODB_SESS_LIFE=1440; + } + $ADODB_SESSION_CRC = false; + //$ADODB_SESS_DEBUG = true; + + ////////////////////////////////// + /* SET THE FOLLOWING PARAMETERS */ + ////////////////////////////////// + + if (empty($ADODB_SESSION_DRIVER)) { + $ADODB_SESSION_DRIVER='mysql'; + $ADODB_SESSION_CONNECT='localhost'; + $ADODB_SESSION_USER ='root'; + $ADODB_SESSION_PWD =''; + $ADODB_SESSION_DB ='xphplens_2'; + } + + if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) { + $ADODB_SESSION_EXPIRE_NOTIFY = false; + } + // Made table name configurable - by David Johnson djohnson@inpro.net + if (empty($ADODB_SESSION_TBL)){ + $ADODB_SESSION_TBL = 'sessions'; + } + + + // defaulting $ADODB_SESSION_USE_LOBS + if (!isset($ADODB_SESSION_USE_LOBS) || empty($ADODB_SESSION_USE_LOBS)) { + $ADODB_SESSION_USE_LOBS = false; + } + + /* + $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER; + $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT; + $ADODB_SESS['user'] = $ADODB_SESSION_USER; + $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD; + $ADODB_SESS['db'] = $ADODB_SESSION_DB; + $ADODB_SESS['life'] = $ADODB_SESS_LIFE; + $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; + + $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; + $ADODB_SESS['table'] = $ADODB_SESS_TBL; + */ + +/****************************************************************************************\ + Create the connection to the database. + + If $ADODB_SESS_CONN already exists, reuse that connection +\****************************************************************************************/ +function adodb_sess_open($save_path, $session_name,$persist=true) +{ +GLOBAL $ADODB_SESS_CONN; + if (isset($ADODB_SESS_CONN)) return true; + +GLOBAL $ADODB_SESSION_CONNECT, + $ADODB_SESSION_DRIVER, + $ADODB_SESSION_USER, + $ADODB_SESSION_PWD, + $ADODB_SESSION_DB, + $ADODB_SESS_DEBUG; + + // cannot use & below - do not know why... + $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER); + if (!empty($ADODB_SESS_DEBUG)) { + $ADODB_SESS_CONN->debug = true; + ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB "); + } + if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT, + $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); + else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT, + $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); + + if (!$ok) ADOConnection::outp( " +-- Session: connection failed

",false); +} + +/****************************************************************************************\ + Close the connection +\****************************************************************************************/ +function adodb_sess_close() +{ +global $ADODB_SESS_CONN; + + if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close(); + return true; +} + +/****************************************************************************************\ + Slurp in the session variables and return the serialized string +\****************************************************************************************/ +function adodb_sess_read($key) +{ +global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC; + + $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time()); + if ($rs) { + if ($rs->EOF) { + $v = ''; + } else + $v = rawurldecode(reset($rs->fields)); + + $rs->Close(); + + // new optimization adodb 2.1 + $ADODB_SESSION_CRC = strlen($v).crc32($v); + + return $v; + } + + return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com +} + +/****************************************************************************************\ + Write the serialized data to a database. + + If the data has not been modified since adodb_sess_read(), we do not write. +\****************************************************************************************/ +function adodb_sess_write($key, $val) +{ + global + $ADODB_SESS_CONN, + $ADODB_SESS_LIFE, + $ADODB_SESSION_TBL, + $ADODB_SESS_DEBUG, + $ADODB_SESSION_CRC, + $ADODB_SESSION_EXPIRE_NOTIFY, + $ADODB_SESSION_DRIVER, // added + $ADODB_SESSION_USE_LOBS; // added + + $expiry = time() + $ADODB_SESS_LIFE; + + // crc32 optimization since adodb 2.1 + // now we only update expiry date, thx to sebastian thom in adodb 2.32 + if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) { + if ($ADODB_SESS_DEBUG) echo " +-- Session: Only updating date - crc32 not changed

"; + $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time(); + $rs = $ADODB_SESS_CONN->Execute($qry); + return true; + } + $val = rawurlencode($val); + + $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val); + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + $var = reset($ADODB_SESSION_EXPIRE_NOTIFY); + global $$var; + $arr['expireref'] = $$var; + } + + + if ($ADODB_SESSION_USE_LOBS === false) { // no lobs, simply use replace() + $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, 'sesskey',$autoQuote = true); + if (!$rs) { + $err = $ADODB_SESS_CONN->ErrorMsg(); + } + } else { + // what value shall we insert/update for lob row? + switch ($ADODB_SESSION_DRIVER) { + // empty_clob or empty_lob for oracle dbs + case "oracle": + case "oci8": + case "oci8po": + case "oci805": + $lob_value = sprintf("empty_%s()", strtolower($ADODB_SESSION_USE_LOBS)); + break; + + // null for all other + default: + $lob_value = "null"; + break; + } + + // do we insert or update? => as for sesskey + $res = $ADODB_SESS_CONN->Execute("select count(*) as cnt from $ADODB_SESSION_TBL where sesskey = '$key'"); + if ($res && reset($res->fields) > 0) { + $qry = sprintf("update %s set expiry = %d, data = %s where sesskey = '%s'", $ADODB_SESSION_TBL, $expiry, $lob_value, $key); + } else { + // insert + $qry = sprintf("insert into %s (sesskey, expiry, data) values ('%s', %d, %s)", $ADODB_SESSION_TBL, $key, $expiry, $lob_value); + } + + $err = ""; + $rs1 = $ADODB_SESS_CONN->Execute($qry); + if (!$rs1) { + $err .= $ADODB_SESS_CONN->ErrorMsg()."\n"; + } + $rs2 = $ADODB_SESS_CONN->UpdateBlob($ADODB_SESSION_TBL, 'data', $val, "sesskey='$key'", strtoupper($ADODB_SESSION_USE_LOBS)); + if (!$rs2) { + $err .= $ADODB_SESS_CONN->ErrorMsg()."\n"; + } + $rs = ($rs1 && $rs2) ? true : false; + } + + if (!$rs) { + ADOConnection::outp( ' +-- Session Replace: '.nl2br($err).'

',false); + } else { + // bug in access driver (could be odbc?) means that info is not commited + // properly unless select statement executed in Win2000 + if ($ADODB_SESS_CONN->databaseType == 'access') + $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); + } + return !empty($rs); +} + +function adodb_sess_destroy($key) +{ + global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; + + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + reset($ADODB_SESSION_EXPIRE_NOTIFY); + $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); + $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); + $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $ADODB_SESS_CONN->SetFetchMode($savem); + if ($rs) { + $ADODB_SESS_CONN->BeginTrans(); + while (!$rs->EOF) { + $ref = $rs->fields[0]; + $key = $rs->fields[1]; + $fn($ref,$key); + $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $rs->MoveNext(); + } + $ADODB_SESS_CONN->CommitTrans(); + } + } else { + $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'"; + $rs = $ADODB_SESS_CONN->Execute($qry); + } + return $rs ? true : false; +} + +function adodb_sess_gc($maxlifetime) +{ + global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; + + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + reset($ADODB_SESSION_EXPIRE_NOTIFY); + $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); + $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); + $t = time(); + $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t"); + $ADODB_SESS_CONN->SetFetchMode($savem); + if ($rs) { + $ADODB_SESS_CONN->BeginTrans(); + while (!$rs->EOF) { + $ref = $rs->fields[0]; + $key = $rs->fields[1]; + $fn($ref,$key); + $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $rs->MoveNext(); + } + $rs->Close(); + + //$ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < $t"); + $ADODB_SESS_CONN->CommitTrans(); + + } + } else { + $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time()); + + if ($ADODB_SESS_DEBUG) ADOConnection::outp(" +-- Garbage Collection: $qry

"); + } + // suggested by Cameron, "GaM3R" + if (defined('ADODB_SESSION_OPTIMIZE')) { + global $ADODB_SESSION_DRIVER; + + switch( $ADODB_SESSION_DRIVER ) { + case 'mysql': + case 'mysqlt': + $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL; + break; + case 'postgresql': + case 'postgresql7': + $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; + break; + } + if (!empty($opt_qry)) { + $ADODB_SESS_CONN->Execute($opt_qry); + } + } + if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL; + else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL; + + $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1); + if ($rs && !$rs->EOF) { + + $dbts = reset($rs->fields); + $rs->Close(); + $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts); + $t = time(); + if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) { + $msg = + __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)"; + error_log($msg); + if ($ADODB_SESS_DEBUG) ADOConnection::outp(" +-- $msg

"); + } + } + + return true; +} + +session_module_name('user'); +session_set_save_handler( + "adodb_sess_open", + "adodb_sess_close", + "adodb_sess_read", + "adodb_sess_write", + "adodb_sess_destroy", + "adodb_sess_gc"); +} + +/* TEST SCRIPT -- UNCOMMENT */ + +if (0) { + + session_start(); + session_register('AVAR'); + $_SESSION['AVAR'] += 1; + ADOConnection::outp( " +-- \$_SESSION['AVAR']={$_SESSION['AVAR']}

",false); +} + +?> diff --git a/lib/adodb/session/old/adodb-session.php b/lib/adodb/session/old/adodb-session.php index 6fc9b2fe05..deec3105a0 100644 --- a/lib/adodb/session/old/adodb-session.php +++ b/lib/adodb/session/old/adodb-session.php @@ -1,439 +1,439 @@ -"; - -To force non-persistent connections, call adodb_session_open first before session_start(): - - include('adodb.inc.php'); - include('adodb-session.php'); - adodb_sess_open(false,false,false); - session_start(); - session_register('AVAR'); - $_SESSION['AVAR'] += 1; - print " --- \$_SESSION['AVAR']={$_SESSION['AVAR']}

"; - - - Installation - ============ - 1. Create this table in your database (syntax might vary depending on your db): - - create table sessions ( - SESSKEY char(32) not null, - EXPIRY int(11) unsigned not null, - EXPIREREF varchar(64), - DATA text not null, - primary key (sesskey) - ); - - For oracle: - create table sessions ( - SESSKEY char(32) not null, - EXPIRY DECIMAL(16) not null, - EXPIREREF varchar(64), - DATA varchar(4000) not null, - primary key (sesskey) - ); - - - 2. Then define the following parameters. You can either modify - this file, or define them before this file is included: - - $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase'; - $ADODB_SESSION_CONNECT='server to connect to'; - $ADODB_SESSION_USER ='user'; - $ADODB_SESSION_PWD ='password'; - $ADODB_SESSION_DB ='database'; - $ADODB_SESSION_TBL = 'sessions' - - 3. Recommended is PHP 4.1.0 or later. There are documented - session bugs in earlier versions of PHP. - - 4. If you want to receive notifications when a session expires, then - you can tag a session with an EXPIREREF, and before the session - record is deleted, we can call a function that will pass the EXPIREREF - as the first parameter, and the session key as the second parameter. - - To do this, define a notification function, say NotifyFn: - - function NotifyFn($expireref, $sesskey) - { - } - - Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY. - This is an array with 2 elements, the first being the name of the variable - you would like to store in the EXPIREREF field, and the 2nd is the - notification function's name. - - In this example, we want to be notified when a user's session - has expired, so we store the user id in the global variable $USERID, - store this value in the EXPIREREF field: - - $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn'); - - Then when the NotifyFn is called, we are passed the $USERID as the first - parameter, eg. NotifyFn($userid, $sesskey). -*/ - -if (!defined('_ADODB_LAYER')) { - include (dirname(__FILE__).'/adodb.inc.php'); -} - -if (!defined('ADODB_SESSION')) { - - define('ADODB_SESSION',1); - - /* if database time and system time is difference is greater than this, then give warning */ - define('ADODB_SESSION_SYNCH_SECS',60); - - /* - Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 -*/ -function adodb_session_regenerate_id() -{ - $conn =& ADODB_Session::_conn(); - if (!$conn) return false; - - $old_id = session_id(); - if (function_exists('session_regenerate_id')) { - session_regenerate_id(); - } else { - session_id(md5(uniqid(rand(), true))); - $ck = session_get_cookie_params(); - setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); - //@session_start(); - } - $new_id = session_id(); - $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); - - /* it is possible that the update statement fails due to a collision */ - if (!$ok) { - session_id($old_id); - if (empty($ck)) $ck = session_get_cookie_params(); - setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); - return false; - } - - return true; -} - -/****************************************************************************************\ - Global definitions -\****************************************************************************************/ -GLOBAL $ADODB_SESSION_CONNECT, - $ADODB_SESSION_DRIVER, - $ADODB_SESSION_USER, - $ADODB_SESSION_PWD, - $ADODB_SESSION_DB, - $ADODB_SESS_CONN, - $ADODB_SESS_LIFE, - $ADODB_SESS_DEBUG, - $ADODB_SESSION_EXPIRE_NOTIFY, - $ADODB_SESSION_CRC, - $ADODB_SESSION_TBL; - - - $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime'); - if ($ADODB_SESS_LIFE <= 1) { - // bug in PHP 4.0.3 pl 1 -- how about other versions? - //print "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; - $ADODB_SESS_LIFE=1440; - } - $ADODB_SESSION_CRC = false; - //$ADODB_SESS_DEBUG = true; - - ////////////////////////////////// - /* SET THE FOLLOWING PARAMETERS */ - ////////////////////////////////// - - if (empty($ADODB_SESSION_DRIVER)) { - $ADODB_SESSION_DRIVER='mysql'; - $ADODB_SESSION_CONNECT='localhost'; - $ADODB_SESSION_USER ='root'; - $ADODB_SESSION_PWD =''; - $ADODB_SESSION_DB ='xphplens_2'; - } - - if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) { - $ADODB_SESSION_EXPIRE_NOTIFY = false; - } - // Made table name configurable - by David Johnson djohnson@inpro.net - if (empty($ADODB_SESSION_TBL)){ - $ADODB_SESSION_TBL = 'sessions'; - } - - /* - $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER; - $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT; - $ADODB_SESS['user'] = $ADODB_SESSION_USER; - $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD; - $ADODB_SESS['db'] = $ADODB_SESSION_DB; - $ADODB_SESS['life'] = $ADODB_SESS_LIFE; - $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; - - $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; - $ADODB_SESS['table'] = $ADODB_SESS_TBL; - */ - -/****************************************************************************************\ - Create the connection to the database. - - If $ADODB_SESS_CONN already exists, reuse that connection -\****************************************************************************************/ -function adodb_sess_open($save_path, $session_name,$persist=true) -{ -GLOBAL $ADODB_SESS_CONN; - if (isset($ADODB_SESS_CONN)) return true; - -GLOBAL $ADODB_SESSION_CONNECT, - $ADODB_SESSION_DRIVER, - $ADODB_SESSION_USER, - $ADODB_SESSION_PWD, - $ADODB_SESSION_DB, - $ADODB_SESS_DEBUG; - - // cannot use & below - do not know why... - $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER); - if (!empty($ADODB_SESS_DEBUG)) { - $ADODB_SESS_CONN->debug = true; - ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB "); - } - if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT, - $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); - else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT, - $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); - - if (!$ok) ADOConnection::outp( " --- Session: connection failed

",false); -} - -/****************************************************************************************\ - Close the connection -\****************************************************************************************/ -function adodb_sess_close() -{ -global $ADODB_SESS_CONN; - - if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close(); - return true; -} - -/****************************************************************************************\ - Slurp in the session variables and return the serialized string -\****************************************************************************************/ -function adodb_sess_read($key) -{ -global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC; - - $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time()); - if ($rs) { - if ($rs->EOF) { - $v = ''; - } else - $v = rawurldecode(reset($rs->fields)); - - $rs->Close(); - - // new optimization adodb 2.1 - $ADODB_SESSION_CRC = strlen($v).crc32($v); - - return $v; - } - - return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com -} - -/****************************************************************************************\ - Write the serialized data to a database. - - If the data has not been modified since adodb_sess_read(), we do not write. -\****************************************************************************************/ -function adodb_sess_write($key, $val) -{ - global - $ADODB_SESS_CONN, - $ADODB_SESS_LIFE, - $ADODB_SESSION_TBL, - $ADODB_SESS_DEBUG, - $ADODB_SESSION_CRC, - $ADODB_SESSION_EXPIRE_NOTIFY; - - $expiry = time() + $ADODB_SESS_LIFE; - - // crc32 optimization since adodb 2.1 - // now we only update expiry date, thx to sebastian thom in adodb 2.32 - if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) { - if ($ADODB_SESS_DEBUG) echo " --- Session: Only updating date - crc32 not changed

"; - $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time(); - $rs = $ADODB_SESS_CONN->Execute($qry); - return true; - } - $val = rawurlencode($val); - - $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val); - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - $var = reset($ADODB_SESSION_EXPIRE_NOTIFY); - global $$var; - $arr['expireref'] = $$var; - } - $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, - 'sesskey',$autoQuote = true); - - if (!$rs) { - ADOConnection::outp( ' --- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'

',false); - } else { - // bug in access driver (could be odbc?) means that info is not commited - // properly unless select statement executed in Win2000 - if ($ADODB_SESS_CONN->databaseType == 'access') - $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); - } - return !empty($rs); -} - -function adodb_sess_destroy($key) -{ - global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; - - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - reset($ADODB_SESSION_EXPIRE_NOTIFY); - $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); - $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); - $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $ADODB_SESS_CONN->SetFetchMode($savem); - if ($rs) { - $ADODB_SESS_CONN->BeginTrans(); - while (!$rs->EOF) { - $ref = $rs->fields[0]; - $key = $rs->fields[1]; - $fn($ref,$key); - $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $rs->MoveNext(); - } - $ADODB_SESS_CONN->CommitTrans(); - } - } else { - $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'"; - $rs = $ADODB_SESS_CONN->Execute($qry); - } - return $rs ? true : false; -} - -function adodb_sess_gc($maxlifetime) -{ - global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; - - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - reset($ADODB_SESSION_EXPIRE_NOTIFY); - $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); - $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); - $t = time(); - $rs =& $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t"); - $ADODB_SESS_CONN->SetFetchMode($savem); - if ($rs) { - $ADODB_SESS_CONN->BeginTrans(); - while (!$rs->EOF) { - $ref = $rs->fields[0]; - $key = $rs->fields[1]; - $fn($ref,$key); - $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $rs->MoveNext(); - } - $rs->Close(); - - $ADODB_SESS_CONN->CommitTrans(); - - } - } else { - $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time(); - $ADODB_SESS_CONN->Execute($qry); - - if ($ADODB_SESS_DEBUG) ADOConnection::outp(" --- Garbage Collection: $qry

"); - } - // suggested by Cameron, "GaM3R" - if (defined('ADODB_SESSION_OPTIMIZE')) { - global $ADODB_SESSION_DRIVER; - - switch( $ADODB_SESSION_DRIVER ) { - case 'mysql': - case 'mysqlt': - $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL; - break; - case 'postgresql': - case 'postgresql7': - $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; - break; - } - if (!empty($opt_qry)) { - $ADODB_SESS_CONN->Execute($opt_qry); - } - } - if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL; - else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL; - - $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1); - if ($rs && !$rs->EOF) { - - $dbts = reset($rs->fields); - $rs->Close(); - $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts); - $t = time(); - - if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) { - - $msg = - __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)"; - error_log($msg); - if ($ADODB_SESS_DEBUG) ADOConnection::outp(" --- $msg

"); - } - } - - return true; -} - -session_module_name('user'); -session_set_save_handler( - "adodb_sess_open", - "adodb_sess_close", - "adodb_sess_read", - "adodb_sess_write", - "adodb_sess_destroy", - "adodb_sess_gc"); -} - -/* TEST SCRIPT -- UNCOMMENT */ - -if (0) { - - session_start(); - session_register('AVAR'); - $_SESSION['AVAR'] += 1; - ADOConnection::outp( " --- \$_SESSION['AVAR']={$_SESSION['AVAR']}

",false); -} - +"; + +To force non-persistent connections, call adodb_session_open first before session_start(): + + include('adodb.inc.php'); + include('adodb-session.php'); + adodb_sess_open(false,false,false); + session_start(); + session_register('AVAR'); + $_SESSION['AVAR'] += 1; + print " +-- \$_SESSION['AVAR']={$_SESSION['AVAR']}

"; + + + Installation + ============ + 1. Create this table in your database (syntax might vary depending on your db): + + create table sessions ( + SESSKEY char(32) not null, + EXPIRY int(11) unsigned not null, + EXPIREREF varchar(64), + DATA text not null, + primary key (sesskey) + ); + + For oracle: + create table sessions ( + SESSKEY char(32) not null, + EXPIRY DECIMAL(16) not null, + EXPIREREF varchar(64), + DATA varchar(4000) not null, + primary key (sesskey) + ); + + + 2. Then define the following parameters. You can either modify + this file, or define them before this file is included: + + $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase'; + $ADODB_SESSION_CONNECT='server to connect to'; + $ADODB_SESSION_USER ='user'; + $ADODB_SESSION_PWD ='password'; + $ADODB_SESSION_DB ='database'; + $ADODB_SESSION_TBL = 'sessions' + + 3. Recommended is PHP 4.1.0 or later. There are documented + session bugs in earlier versions of PHP. + + 4. If you want to receive notifications when a session expires, then + you can tag a session with an EXPIREREF, and before the session + record is deleted, we can call a function that will pass the EXPIREREF + as the first parameter, and the session key as the second parameter. + + To do this, define a notification function, say NotifyFn: + + function NotifyFn($expireref, $sesskey) + { + } + + Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY. + This is an array with 2 elements, the first being the name of the variable + you would like to store in the EXPIREREF field, and the 2nd is the + notification function's name. + + In this example, we want to be notified when a user's session + has expired, so we store the user id in the global variable $USERID, + store this value in the EXPIREREF field: + + $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn'); + + Then when the NotifyFn is called, we are passed the $USERID as the first + parameter, eg. NotifyFn($userid, $sesskey). +*/ + +if (!defined('_ADODB_LAYER')) { + include (dirname(__FILE__).'/adodb.inc.php'); +} + +if (!defined('ADODB_SESSION')) { + + define('ADODB_SESSION',1); + + /* if database time and system time is difference is greater than this, then give warning */ + define('ADODB_SESSION_SYNCH_SECS',60); + + /* + Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 +*/ +function adodb_session_regenerate_id() +{ + $conn =& ADODB_Session::_conn(); + if (!$conn) return false; + + $old_id = session_id(); + if (function_exists('session_regenerate_id')) { + session_regenerate_id(); + } else { + session_id(md5(uniqid(rand(), true))); + $ck = session_get_cookie_params(); + setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); + //@session_start(); + } + $new_id = session_id(); + $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); + + /* it is possible that the update statement fails due to a collision */ + if (!$ok) { + session_id($old_id); + if (empty($ck)) $ck = session_get_cookie_params(); + setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); + return false; + } + + return true; +} + +/****************************************************************************************\ + Global definitions +\****************************************************************************************/ +GLOBAL $ADODB_SESSION_CONNECT, + $ADODB_SESSION_DRIVER, + $ADODB_SESSION_USER, + $ADODB_SESSION_PWD, + $ADODB_SESSION_DB, + $ADODB_SESS_CONN, + $ADODB_SESS_LIFE, + $ADODB_SESS_DEBUG, + $ADODB_SESSION_EXPIRE_NOTIFY, + $ADODB_SESSION_CRC, + $ADODB_SESSION_TBL; + + + $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime'); + if ($ADODB_SESS_LIFE <= 1) { + // bug in PHP 4.0.3 pl 1 -- how about other versions? + //print "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; + $ADODB_SESS_LIFE=1440; + } + $ADODB_SESSION_CRC = false; + //$ADODB_SESS_DEBUG = true; + + ////////////////////////////////// + /* SET THE FOLLOWING PARAMETERS */ + ////////////////////////////////// + + if (empty($ADODB_SESSION_DRIVER)) { + $ADODB_SESSION_DRIVER='mysql'; + $ADODB_SESSION_CONNECT='localhost'; + $ADODB_SESSION_USER ='root'; + $ADODB_SESSION_PWD =''; + $ADODB_SESSION_DB ='xphplens_2'; + } + + if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) { + $ADODB_SESSION_EXPIRE_NOTIFY = false; + } + // Made table name configurable - by David Johnson djohnson@inpro.net + if (empty($ADODB_SESSION_TBL)){ + $ADODB_SESSION_TBL = 'sessions'; + } + + /* + $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER; + $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT; + $ADODB_SESS['user'] = $ADODB_SESSION_USER; + $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD; + $ADODB_SESS['db'] = $ADODB_SESSION_DB; + $ADODB_SESS['life'] = $ADODB_SESS_LIFE; + $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; + + $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; + $ADODB_SESS['table'] = $ADODB_SESS_TBL; + */ + +/****************************************************************************************\ + Create the connection to the database. + + If $ADODB_SESS_CONN already exists, reuse that connection +\****************************************************************************************/ +function adodb_sess_open($save_path, $session_name,$persist=true) +{ +GLOBAL $ADODB_SESS_CONN; + if (isset($ADODB_SESS_CONN)) return true; + +GLOBAL $ADODB_SESSION_CONNECT, + $ADODB_SESSION_DRIVER, + $ADODB_SESSION_USER, + $ADODB_SESSION_PWD, + $ADODB_SESSION_DB, + $ADODB_SESS_DEBUG; + + // cannot use & below - do not know why... + $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER); + if (!empty($ADODB_SESS_DEBUG)) { + $ADODB_SESS_CONN->debug = true; + ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB "); + } + if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT, + $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); + else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT, + $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); + + if (!$ok) ADOConnection::outp( " +-- Session: connection failed

",false); +} + +/****************************************************************************************\ + Close the connection +\****************************************************************************************/ +function adodb_sess_close() +{ +global $ADODB_SESS_CONN; + + if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close(); + return true; +} + +/****************************************************************************************\ + Slurp in the session variables and return the serialized string +\****************************************************************************************/ +function adodb_sess_read($key) +{ +global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC; + + $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time()); + if ($rs) { + if ($rs->EOF) { + $v = ''; + } else + $v = rawurldecode(reset($rs->fields)); + + $rs->Close(); + + // new optimization adodb 2.1 + $ADODB_SESSION_CRC = strlen($v).crc32($v); + + return $v; + } + + return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com +} + +/****************************************************************************************\ + Write the serialized data to a database. + + If the data has not been modified since adodb_sess_read(), we do not write. +\****************************************************************************************/ +function adodb_sess_write($key, $val) +{ + global + $ADODB_SESS_CONN, + $ADODB_SESS_LIFE, + $ADODB_SESSION_TBL, + $ADODB_SESS_DEBUG, + $ADODB_SESSION_CRC, + $ADODB_SESSION_EXPIRE_NOTIFY; + + $expiry = time() + $ADODB_SESS_LIFE; + + // crc32 optimization since adodb 2.1 + // now we only update expiry date, thx to sebastian thom in adodb 2.32 + if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) { + if ($ADODB_SESS_DEBUG) echo " +-- Session: Only updating date - crc32 not changed

"; + $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time(); + $rs = $ADODB_SESS_CONN->Execute($qry); + return true; + } + $val = rawurlencode($val); + + $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val); + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + $var = reset($ADODB_SESSION_EXPIRE_NOTIFY); + global $$var; + $arr['expireref'] = $$var; + } + $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, + 'sesskey',$autoQuote = true); + + if (!$rs) { + ADOConnection::outp( ' +-- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'

',false); + } else { + // bug in access driver (could be odbc?) means that info is not commited + // properly unless select statement executed in Win2000 + if ($ADODB_SESS_CONN->databaseType == 'access') + $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); + } + return !empty($rs); +} + +function adodb_sess_destroy($key) +{ + global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; + + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + reset($ADODB_SESSION_EXPIRE_NOTIFY); + $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); + $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); + $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $ADODB_SESS_CONN->SetFetchMode($savem); + if ($rs) { + $ADODB_SESS_CONN->BeginTrans(); + while (!$rs->EOF) { + $ref = $rs->fields[0]; + $key = $rs->fields[1]; + $fn($ref,$key); + $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $rs->MoveNext(); + } + $ADODB_SESS_CONN->CommitTrans(); + } + } else { + $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'"; + $rs = $ADODB_SESS_CONN->Execute($qry); + } + return $rs ? true : false; +} + +function adodb_sess_gc($maxlifetime) +{ + global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; + + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + reset($ADODB_SESSION_EXPIRE_NOTIFY); + $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); + $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); + $t = time(); + $rs =& $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t"); + $ADODB_SESS_CONN->SetFetchMode($savem); + if ($rs) { + $ADODB_SESS_CONN->BeginTrans(); + while (!$rs->EOF) { + $ref = $rs->fields[0]; + $key = $rs->fields[1]; + $fn($ref,$key); + $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $rs->MoveNext(); + } + $rs->Close(); + + $ADODB_SESS_CONN->CommitTrans(); + + } + } else { + $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time(); + $ADODB_SESS_CONN->Execute($qry); + + if ($ADODB_SESS_DEBUG) ADOConnection::outp(" +-- Garbage Collection: $qry

"); + } + // suggested by Cameron, "GaM3R" + if (defined('ADODB_SESSION_OPTIMIZE')) { + global $ADODB_SESSION_DRIVER; + + switch( $ADODB_SESSION_DRIVER ) { + case 'mysql': + case 'mysqlt': + $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL; + break; + case 'postgresql': + case 'postgresql7': + $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; + break; + } + if (!empty($opt_qry)) { + $ADODB_SESS_CONN->Execute($opt_qry); + } + } + if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL; + else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL; + + $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1); + if ($rs && !$rs->EOF) { + + $dbts = reset($rs->fields); + $rs->Close(); + $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts); + $t = time(); + + if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) { + + $msg = + __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)"; + error_log($msg); + if ($ADODB_SESS_DEBUG) ADOConnection::outp(" +-- $msg

"); + } + } + + return true; +} + +session_module_name('user'); +session_set_save_handler( + "adodb_sess_open", + "adodb_sess_close", + "adodb_sess_read", + "adodb_sess_write", + "adodb_sess_destroy", + "adodb_sess_gc"); +} + +/* TEST SCRIPT -- UNCOMMENT */ + +if (0) { + + session_start(); + session_register('AVAR'); + $_SESSION['AVAR'] += 1; + ADOConnection::outp( " +-- \$_SESSION['AVAR']={$_SESSION['AVAR']}

",false); +} + ?> \ No newline at end of file diff --git a/lib/adodb/toexport.inc.php b/lib/adodb/toexport.inc.php index ba3f37a21c..8be7d2e3d3 100644 --- a/lib/adodb/toexport.inc.php +++ b/lib/adodb/toexport.inc.php @@ -1,133 +1,133 @@ -FieldTypesArray(); - reset($fieldTypes); - while(list(,$o) = each($fieldTypes)) { - - $v = $o->name; - if ($escquote) $v = str_replace($quote,$escquotequote,$v); - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); - $elements[] = $v; - - } - $s .= implode($sep, $elements).$NEWLINE; - } - $hasNumIndex = isset($rs->fields[0]); - - $line = 0; - $max = $rs->FieldCount(); - - while (!$rs->EOF) { - $elements = array(); - $i = 0; - - if ($hasNumIndex) { - for ($j=0; $j < $max; $j++) { - $v = $rs->fields[$j]; - if (!is_object($v)) $v = trim($v); - else $v = 'Object'; - if ($escquote) $v = str_replace($quote,$escquotequote,$v); - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); - - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; - else $elements[] = $v; - } - } else { // ASSOCIATIVE ARRAY - foreach($rs->fields as $v) { - if ($escquote) $v = str_replace($quote,$escquotequote,trim($v)); - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); - - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; - else $elements[] = $v; - } - } - $s .= implode($sep, $elements).$NEWLINE; - $rs->MoveNext(); - $line += 1; - if ($fp && ($line % $BUFLINES) == 0) { - if ($fp === true) echo $s; - else fwrite($fp,$s); - $s = ''; - } - } - - if ($fp) { - if ($fp === true) echo $s; - else fwrite($fp,$s); - $s = ''; - } - - return $s; -} +FieldTypesArray(); + reset($fieldTypes); + while(list(,$o) = each($fieldTypes)) { + + $v = $o->name; + if ($escquote) $v = str_replace($quote,$escquotequote,$v); + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); + $elements[] = $v; + + } + $s .= implode($sep, $elements).$NEWLINE; + } + $hasNumIndex = isset($rs->fields[0]); + + $line = 0; + $max = $rs->FieldCount(); + + while (!$rs->EOF) { + $elements = array(); + $i = 0; + + if ($hasNumIndex) { + for ($j=0; $j < $max; $j++) { + $v = $rs->fields[$j]; + if (!is_object($v)) $v = trim($v); + else $v = 'Object'; + if ($escquote) $v = str_replace($quote,$escquotequote,$v); + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); + + if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; + else $elements[] = $v; + } + } else { // ASSOCIATIVE ARRAY + foreach($rs->fields as $v) { + if ($escquote) $v = str_replace($quote,$escquotequote,trim($v)); + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); + + if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; + else $elements[] = $v; + } + } + $s .= implode($sep, $elements).$NEWLINE; + $rs->MoveNext(); + $line += 1; + if ($fp && ($line % $BUFLINES) == 0) { + if ($fp === true) echo $s; + else fwrite($fp,$s); + $s = ''; + } + } + + if ($fp) { + if ($fp === true) echo $s; + else fwrite($fp,$s); + $s = ''; + } + + return $s; +} ?> \ No newline at end of file diff --git a/lib/adodb/tohtml.inc.php b/lib/adodb/tohtml.inc.php index b9bef03f57..44267d2a6f 100644 --- a/lib/adodb/tohtml.inc.php +++ b/lib/adodb/tohtml.inc.php @@ -1,195 +1,195 @@ - -*/ - -// specific code for tohtml -GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; - -$ADODB_ROUND=4; // rounding -$gSQLMaxRows = 1000; // max no of rows to download -$gSQLBlockRows=20; // max no of rows per table block - -// RecordSet to HTML Table -//------------------------------------------------------------ -// Convert a recordset to a html table. Multiple tables are generated -// if the number of rows is > $gSQLBlockRows. This is because -// web browsers normally require the whole table to be downloaded -// before it can be rendered, so we break the output into several -// smaller faster rendering tables. -// -// $rs: the recordset -// $ztabhtml: the table tag attributes (optional) -// $zheaderarray: contains the replacement strings for the headers (optional) -// -// USAGE: -// include('adodb.inc.php'); -// $db = ADONewConnection('mysql'); -// $db->Connect('mysql','userid','password','database'); -// $rs = $db->Execute('select col1,col2,col3 from table'); -// rs2html($rs, 'BORDER=2', array('Title1', 'Title2', 'Title3')); -// $rs->Close(); -// -// RETURNS: number of rows displayed - - -function rs2html(&$rs,$ztabhtml=false,$zheaderarray=false,$htmlspecialchars=true,$echo = true) -{ -$s ='';$rows=0;$docnt = false; -GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; - - if (!$rs) { - printf(ADODB_BAD_RS,'rs2html'); - return false; - } - - if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'"; - //else $docnt = true; - $typearr = array(); - $ncols = $rs->FieldCount(); - $hdr = "\n\n"; - for ($i=0; $i < $ncols; $i++) { - $field = $rs->FetchField($i); - if ($field) { - if ($zheaderarray) $fname = $zheaderarray[$i]; - else $fname = htmlspecialchars($field->name); - $typearr[$i] = $rs->MetaType($field->type,$field->max_length); - //print " $field->name $field->type $typearr[$i] "; - } else { - $fname = 'Field '.($i+1); - $typearr[$i] = 'C'; - } - if (strlen($fname)==0) $fname = ' '; - $hdr .= ""; - } - $hdr .= "\n"; - if ($echo) print $hdr."\n\n"; - else $html = $hdr; - - // smart algorithm - handles ADODB_FETCH_MODE's correctly by probing... - $numoffset = isset($rs->fields[0]) ||isset($rs->fields[1]) || isset($rs->fields[2]); - while (!$rs->EOF) { - - $s .= "\n"; - - for ($i=0; $i < $ncols; $i++) { - if ($i===0) $v=($numoffset) ? $rs->fields[0] : reset($rs->fields); - else $v = ($numoffset) ? $rs->fields[$i] : next($rs->fields); - - $type = $typearr[$i]; - switch($type) { - case 'D': - if (empty($v)) $s .= "\n"; - else if (!strpos($v,':')) { - $s .= " \n"; - } - break; - case 'T': - if (empty($v)) $s .= "\n"; - else $s .= " \n"; - break; - - case 'N': - if (abs(abs($v) - round($v,0)) < 0.00000001) - $v = round($v); - else - $v = round($v,$ADODB_ROUND); - case 'I': - $s .= " \n"; - - break; - /* - case 'B': - if (substr($v,8,2)=="BM" ) $v = substr($v,8); - $mtime = substr(str_replace(' ','_',microtime()),2); - $tmpname = "tmp/".uniqid($mtime).getmypid(); - $fd = @fopen($tmpname,'a'); - @ftruncate($fd,0); - @fwrite($fd,$v); - @fclose($fd); - if (!function_exists ("mime_content_type")) { - function mime_content_type ($file) { - return exec("file -bi ".escapeshellarg($file)); - } - } - $t = mime_content_type($tmpname); - $s .= (substr($t,0,5)=="image") ? " \\n" : " \\n"; - break; - */ - - default: - if ($htmlspecialchars) $v = htmlspecialchars(trim($v)); - $v = trim($v); - if (strlen($v) == 0) $v = ' '; - $s .= " \n"; - - } - } // for - $s .= "\n\n"; - - $rows += 1; - if ($rows >= $gSQLMaxRows) { - $rows = "

Truncated at $gSQLMaxRows

"; - break; - } // switch - - $rs->MoveNext(); - - // additional EOF check to prevent a widow header - if (!$rs->EOF && $rows % $gSQLBlockRows == 0) { - - //if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP - if ($echo) print $s . "
$fname
  ".$rs->UserDate($v,"D d, M Y") ."    ".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ." ".stripslashes((trim($v))) ." $t$t". str_replace("\n",'
',stripslashes($v)) ."
\n\n"; - else $html .= $s ."
\n\n"; - $s = $hdr; - } - } // while - - if ($echo) print $s."\n\n"; - else $html .= $s."\n\n"; - - if ($docnt) if ($echo) print "

".$rows." Rows

"; - - return ($echo) ? $rows : $html; - } - -// pass in 2 dimensional array -function arr2html(&$arr,$ztabhtml='',$zheaderarray='') -{ - if (!$ztabhtml) $ztabhtml = 'BORDER=1'; - - $s = "";//';print_r($arr); - - if ($zheaderarray) { - $s .= ''; - for ($i=0; $i\n"; - } else $s .= " \n"; - $s .= "\n\n"; - } - $s .= '
 
'; - print $s; -} - + +*/ + +// specific code for tohtml +GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; + +$ADODB_ROUND=4; // rounding +$gSQLMaxRows = 1000; // max no of rows to download +$gSQLBlockRows=20; // max no of rows per table block + +// RecordSet to HTML Table +//------------------------------------------------------------ +// Convert a recordset to a html table. Multiple tables are generated +// if the number of rows is > $gSQLBlockRows. This is because +// web browsers normally require the whole table to be downloaded +// before it can be rendered, so we break the output into several +// smaller faster rendering tables. +// +// $rs: the recordset +// $ztabhtml: the table tag attributes (optional) +// $zheaderarray: contains the replacement strings for the headers (optional) +// +// USAGE: +// include('adodb.inc.php'); +// $db = ADONewConnection('mysql'); +// $db->Connect('mysql','userid','password','database'); +// $rs = $db->Execute('select col1,col2,col3 from table'); +// rs2html($rs, 'BORDER=2', array('Title1', 'Title2', 'Title3')); +// $rs->Close(); +// +// RETURNS: number of rows displayed + + +function rs2html(&$rs,$ztabhtml=false,$zheaderarray=false,$htmlspecialchars=true,$echo = true) +{ +$s ='';$rows=0;$docnt = false; +GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; + + if (!$rs) { + printf(ADODB_BAD_RS,'rs2html'); + return false; + } + + if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'"; + //else $docnt = true; + $typearr = array(); + $ncols = $rs->FieldCount(); + $hdr = "\n\n"; + for ($i=0; $i < $ncols; $i++) { + $field = $rs->FetchField($i); + if ($field) { + if ($zheaderarray) $fname = $zheaderarray[$i]; + else $fname = htmlspecialchars($field->name); + $typearr[$i] = $rs->MetaType($field->type,$field->max_length); + //print " $field->name $field->type $typearr[$i] "; + } else { + $fname = 'Field '.($i+1); + $typearr[$i] = 'C'; + } + if (strlen($fname)==0) $fname = ' '; + $hdr .= ""; + } + $hdr .= "\n"; + if ($echo) print $hdr."\n\n"; + else $html = $hdr; + + // smart algorithm - handles ADODB_FETCH_MODE's correctly by probing... + $numoffset = isset($rs->fields[0]) ||isset($rs->fields[1]) || isset($rs->fields[2]); + while (!$rs->EOF) { + + $s .= "\n"; + + for ($i=0; $i < $ncols; $i++) { + if ($i===0) $v=($numoffset) ? $rs->fields[0] : reset($rs->fields); + else $v = ($numoffset) ? $rs->fields[$i] : next($rs->fields); + + $type = $typearr[$i]; + switch($type) { + case 'D': + if (empty($v)) $s .= "\n"; + else if (!strpos($v,':')) { + $s .= " \n"; + } + break; + case 'T': + if (empty($v)) $s .= "\n"; + else $s .= " \n"; + break; + + case 'N': + if (abs(abs($v) - round($v,0)) < 0.00000001) + $v = round($v); + else + $v = round($v,$ADODB_ROUND); + case 'I': + $s .= " \n"; + + break; + /* + case 'B': + if (substr($v,8,2)=="BM" ) $v = substr($v,8); + $mtime = substr(str_replace(' ','_',microtime()),2); + $tmpname = "tmp/".uniqid($mtime).getmypid(); + $fd = @fopen($tmpname,'a'); + @ftruncate($fd,0); + @fwrite($fd,$v); + @fclose($fd); + if (!function_exists ("mime_content_type")) { + function mime_content_type ($file) { + return exec("file -bi ".escapeshellarg($file)); + } + } + $t = mime_content_type($tmpname); + $s .= (substr($t,0,5)=="image") ? " \\n" : " \\n"; + break; + */ + + default: + if ($htmlspecialchars) $v = htmlspecialchars(trim($v)); + $v = trim($v); + if (strlen($v) == 0) $v = ' '; + $s .= " \n"; + + } + } // for + $s .= "\n\n"; + + $rows += 1; + if ($rows >= $gSQLMaxRows) { + $rows = "

Truncated at $gSQLMaxRows

"; + break; + } // switch + + $rs->MoveNext(); + + // additional EOF check to prevent a widow header + if (!$rs->EOF && $rows % $gSQLBlockRows == 0) { + + //if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP + if ($echo) print $s . "
$fname
  ".$rs->UserDate($v,"D d, M Y") ."    ".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ." ".stripslashes((trim($v))) ." $t$t". str_replace("\n",'
',stripslashes($v)) ."
\n\n"; + else $html .= $s ."\n\n"; + $s = $hdr; + } + } // while + + if ($echo) print $s."\n\n"; + else $html .= $s."\n\n"; + + if ($docnt) if ($echo) print "

".$rows." Rows

"; + + return ($echo) ? $rows : $html; + } + +// pass in 2 dimensional array +function arr2html(&$arr,$ztabhtml='',$zheaderarray='') +{ + if (!$ztabhtml) $ztabhtml = 'BORDER=1'; + + $s = "";//';print_r($arr); + + if ($zheaderarray) { + $s .= ''; + for ($i=0; $i\n"; + } else $s .= " \n"; + $s .= "\n\n"; + } + $s .= '
 
'; + print $s; +} + ?> \ No newline at end of file -- 2.39.5