Page MenuHomePhabricator

adodb505.patch

Authored By
bzimport
Nov 21 2014, 9:38 PM
Size
107 KB
Referenced Files
None
Subscribers
None

adodb505.patch

This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
Index: adodb.inc.php
===================================================================
--- adodb.inc.php (revision 1)
+++ adodb.inc.php (working copy)
@@ -1,9 +1,9 @@
-<?php
+<?php
/*
* Set tabs to 4 for best viewing.
- *
+ *
* Latest version is available at http://adodb.sourceforge.net
- *
+ *
* This is the main include file for ADOdb.
* Database specific drivers are stored in the adodb/drivers/adodb-*.inc.php
*
@@ -12,15 +12,15 @@
*/
/**
- \mainpage
-
+ \mainpage
+
@version V5.05 11 July 2008 (c) 2000-2008 John Lim (jlim#natsoft.com). All rights reserved.
Released under both BSD license and Lesser GPL library license. You can choose which license
you prefer.
-
- PHP's database access functions are not standardised. This creates a need for a database
- class library to hide the differences between the different database API's (encapsulate
+
+ PHP's database access functions are not standardised. This creates a need for a database
+ class library to hide the differences between the different database API's (encapsulate
the differences) so we can easily switch databases.
We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, DB2,
@@ -29,28 +29,28 @@
other databases via ODBC.
Latest Download at http://adodb.sourceforge.net/
-
+
*/
-
+
if (!defined('_ADODB_LAYER')) {
define('_ADODB_LAYER',1);
-
- //==============================================================================================
+
+ //==============================================================================================
// CONSTANT DEFINITIONS
- //==============================================================================================
+ //==============================================================================================
- /**
+ /**
* Set ADODB_DIR to the directory where this file resides...
* This constant was formerly called $ADODB_RootPath
*/
if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));
-
- //==============================================================================================
+
+ //==============================================================================================
// GLOBAL VARIABLES
- //==============================================================================================
+ //==============================================================================================
- GLOBAL
+ GLOBAL
$ADODB_vers, // database version
$ADODB_COUNTRECS, // count number of records returned - slows down query
$ADODB_CACHE_DIR, // directory to cache recordsets
@@ -59,14 +59,14 @@
$ADODB_EXTENSION, // ADODB extension installed
$ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF
$ADODB_FETCH_MODE, // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
- $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql.
-
- //==============================================================================================
+ $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql.
+
+ //==============================================================================================
// GLOBAL SETUP
- //==============================================================================================
-
+ //==============================================================================================
+
$ADODB_EXTENSION = defined('ADODB_EXTENSION');
-
+
//********************************************************//
/*
Controls $ADODB_FORCE_TYPE mode. Default is ADODB_FORCE_VALUE (3).
@@ -85,52 +85,52 @@
if (!$ADODB_EXTENSION || ADODB_EXTENSION < 4.0) {
-
+
define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>');
-
+
// allow [ ] @ ` " and . in table names
define('ADODB_TABLE_REGEX','([]0-9a-z_\:\"\`\.\@\[-]*)');
-
+
// prefetching used by oracle
if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);
-
-
+
+
/*
Controls ADODB_FETCH_ASSOC field-name case. Default is 2, use native case-names.
This currently works only with mssql, odbc, oci8po and ibase derived drivers.
-
+
0 = assoc lowercase field names. $rs->fields['orderid']
1 = assoc uppercase field names. $rs->fields['ORDERID']
2 = use native-case field names. $rs->fields['OrderID']
*/
-
+
define('ADODB_FETCH_DEFAULT',0);
define('ADODB_FETCH_NUM',1);
define('ADODB_FETCH_ASSOC',2);
define('ADODB_FETCH_BOTH',3);
-
+
if (!defined('TIMESTAMP_FIRST_YEAR')) define('TIMESTAMP_FIRST_YEAR',100);
-
+
// PHP's version scheme makes converting to numbers difficult - workaround
$_adodb_ver = (float) PHP_VERSION;
if ($_adodb_ver >= 5.2) {
define('ADODB_PHPVER',0x5200);
} else if ($_adodb_ver >= 5.0) {
define('ADODB_PHPVER',0x5000);
- } else
+ } else
die("PHP5 or later required. You are running ".PHP_VERSION);
}
-
+
//if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);
-
+
/**
Accepts $src and $dest arrays, replacing string $data
*/
function ADODB_str_replace($src, $dest, $data)
{
if (ADODB_PHPVER >= 0x4050) return str_replace($src,$dest,$data);
-
+
$s = reset($src);
$d = reset($dest);
while ($s !== false) {
@@ -140,10 +140,10 @@
}
return $data;
}
-
+
function ADODB_Setup()
{
- GLOBAL
+ GLOBAL
$ADODB_vers, // database version
$ADODB_COUNTRECS, // count number of records returned - slows down query
$ADODB_CACHE_DIR, // directory to cache recordsets
@@ -152,7 +152,7 @@
$ADODB_CACHE_CLASS,
$ADODB_FORCE_TYPE,
$ADODB_QUOTE_FIELDNAMES;
-
+
$ADODB_CACHE_CLASS = 'ADODB_Cache_File';
$ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;
$ADODB_FORCE_TYPE = ADODB_FORCE_VALUE;
@@ -162,59 +162,59 @@
$ADODB_CACHE_DIR = '/tmp'; //(isset($_ENV['TMP'])) ? $_ENV['TMP'] : '/tmp';
} else {
// do not accept url based paths, eg. http:/ or ftp:/
- if (strpos($ADODB_CACHE_DIR,'://') !== false)
+ if (strpos($ADODB_CACHE_DIR,'://') !== false)
die("Illegal path http:// or ftp://");
}
-
-
+
+
// Initialize random number generator for randomizing cache flushes
// -- note Since PHP 4.2.0, the seed becomes optional and defaults to a random value if omitted.
srand(((double)microtime())*1000000);
-
+
/**
* ADODB version as a string.
*/
$ADODB_vers = 'V5.05 11 July 2008 (c) 2000-2008 John Lim (jlim#natsoft.com). All rights reserved. Released BSD & LGPL.';
-
+
/**
- * Determines whether recordset->RecordCount() is used.
+ * Determines whether recordset->RecordCount() is used.
* Set to false for highest performance -- RecordCount() will always return -1 then
* for databases that provide "virtual" recordcounts...
*/
- if (!isset($ADODB_COUNTRECS)) $ADODB_COUNTRECS = true;
+ if (!isset($ADODB_COUNTRECS)) $ADODB_COUNTRECS = true;
}
-
-
- //==============================================================================================
+
+
+ //==============================================================================================
// CHANGE NOTHING BELOW UNLESS YOU ARE DESIGNING ADODB
- //==============================================================================================
-
+ //==============================================================================================
+
ADODB_Setup();
- //==============================================================================================
+ //==============================================================================================
// CLASS ADOFieldObject
- //==============================================================================================
+ //==============================================================================================
/**
* Helper class for FetchFields -- holds info on a column
*/
- class ADOFieldObject {
+ class ADOFieldObject {
var $name = '';
var $max_length=0;
var $type="";
/*
// additional fields by dannym... (danny_milo@yahoo.com)
- var $not_null = false;
+ var $not_null = false;
// actually, this has already been built-in in the postgres, fbsql AND mysql module? ^-^
// so we can as well make not_null standard (leaving it at "false" does not harm anyways)
- var $has_default = false; // this one I have done only in mysql and postgres for now ...
+ var $has_default = false; // this one I have done only in mysql and postgres for now ...
// others to come (dannym)
var $default_value; // default, if any, and supported. Check has_default first.
*/
}
-
+
// for transaction handling
-
+
function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)
{
//print "Errorno ($fn errno=$errno m=$errmsg) ";
@@ -224,46 +224,46 @@
$fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection);
}
}
-
+
//------------------
// class for caching
class ADODB_Cache_File {
-
+
var $createdir = true; // requires creation of temp dirs
-
+
function ADODB_Cache_File()
{
global $ADODB_INCLUDED_CSV;
if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');
}
-
+
// write serialised recordset to cache item/file
function writecache($filename, $contents, $debug, $secs2cache)
{
return adodb_write_file($filename, $contents,$debug);
}
-
+
// load serialised recordset and unserialise it
function &readcache($filename, &$err, $secs2cache, $rsClass)
{
$rs = csv2rs($filename,$err,$secs2cache,$rsClass);
return $rs;
}
-
+
// flush all items in cache
function flushall($debug=false)
{
global $ADODB_CACHE_DIR;
$rez = false;
-
+
if (strlen($ADODB_CACHE_DIR) > 1) {
$rez = $this->_dirFlush($ADODB_CACHE_DIR);
if ($debug) DOConnection::outp( "flushall: $dir<br><pre>\n". $rez."</pre>");
}
return $rez;
}
-
+
// flush one file in cache
function flushcache($f, $debug=false)
{
@@ -271,14 +271,14 @@
if ($debug) ADOConnection::outp( "flushcache: failed for $f");
}
}
-
+
function getdirname($hash)
{
global $ADODB_CACHE_DIR;
if (!isset($this->notSafeMode)) $this->notSafeMode = !ini_get('safe_mode');
return ($this->notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($hash,0,2) : $ADODB_CACHE_DIR;
}
-
+
// create temp directories
function createdir($hash, $debug)
{
@@ -288,24 +288,24 @@
if (!@mkdir($dir,0771)) if(!is_dir($dir) && $debug) ADOConnection::outp("Cannot create $dir");
umask($oldu);
}
-
+
return $dir;
}
-
+
/**
* Private function to erase all of the files and subdirectories in a directory.
*
* Just specify the directory, and tell it if you want to delete the directory or just clear it out.
* Note: $kill_top_level is used internally in the function to flush subdirectories.
*/
- function _dirFlush($dir, $kill_top_level = false)
+ function _dirFlush($dir, $kill_top_level = false)
{
if(!$dh = @opendir($dir)) return;
-
+
while (($obj = readdir($dh))) {
if($obj=='.' || $obj=='..') continue;
$f = $dir.'/'.$obj;
-
+
if (strpos($obj,'.cache')) @unlink($f);
if (is_dir($f)) $this->_dirFlush($f, true);
}
@@ -313,27 +313,27 @@
return true;
}
}
-
- //==============================================================================================
+
+ //==============================================================================================
// CLASS ADOConnection
- //==============================================================================================
-
+ //==============================================================================================
+
/**
* Connection object. For connecting to databases, and executing queries.
- */
+ */
class ADOConnection {
//
- // PUBLIC VARS
+ // PUBLIC VARS
//
var $dataProvider = 'native';
- var $databaseType = ''; /// RDBMS currently in use, eg. odbc, mysql, mssql
- var $database = ''; /// Name of database to be used.
- var $host = ''; /// The hostname of the database server
- var $user = ''; /// The username which is used to connect to the database server.
+ var $databaseType = ''; /// RDBMS currently in use, eg. odbc, mysql, mssql
+ var $database = ''; /// Name of database to be used.
+ var $host = ''; /// The hostname of the database server
+ var $user = ''; /// The username which is used to connect to the database server.
var $password = ''; /// Password for the username. For security, we no longer store it.
var $debug = false; /// if set to true will output sql statements
var $maxblobsize = 262144; /// maximum size of blobs or large text fields (262144 = 256K)-- some db's die otherwise like foxpro
- var $concat_operator = '+'; /// default concat operator -- change to || for Oracle/Interbase
+ var $concat_operator = '+'; /// default concat operator -- change to || for Oracle/Interbase
var $substr = 'substr'; /// substring operator
var $length = 'length'; /// string length ofperator
var $random = 'rand()'; /// random function
@@ -375,9 +375,9 @@
var $sysDate = false; /// name of function that returns the current date
var $sysTimeStamp = false; /// name of function that returns the current timestamp
var $arrayClass = 'ADORecordSet_array'; /// name of class used to generate array recordsets, which are pre-downloaded recordsets
-
+
var $noNullStrings = false; /// oracle specific stuff - if true ensures that '' is converted to ' '
- var $numCacheHits = 0;
+ var $numCacheHits = 0;
var $numCacheMisses = 0;
var $pageExecuteCountRows = true;
var $uniqueSort = false; /// indicates that all fields in order by must be unique
@@ -386,76 +386,76 @@
var $ansiOuter = false; /// whether ansi outer join syntax supported
var $autoRollback = false; // autoRollback on PConnect().
var $poorAffectedRows = false; // affectedRows not working or unreliable
-
+
var $fnExecute = false;
var $fnCacheExecute = false;
var $blobEncodeType = false; // false=not required, 'I'=encode to integer, 'C'=encode to char
var $rsPrefix = "ADORecordSet_";
-
+
var $autoCommit = true; /// do not modify this yourself - actually private
var $transOff = 0; /// temporarily disable transactions
var $transCnt = 0; /// count of nested transactions
-
+
var $fetchMode=false;
-
+
var $null2null = 'null'; // in autoexecute/getinsertsql/getupdatesql, this value will be converted to a null
//
// PRIVATE VARS
//
var $_oldRaiseFn = false;
var $_transOK = null;
- var $_connectionID = false; /// The returned link identifier whenever a successful database connection is made.
+ var $_connectionID = false; /// The returned link identifier whenever a successful database connection is made.
var $_errorMsg = false; /// A variable which was used to keep the returned last error message. The value will
- /// then returned by the errorMsg() function
- var $_errorCode = false; /// Last error code, not guaranteed to be used - only by oci8
+ /// then returned by the errorMsg() function
+ var $_errorCode = false; /// Last error code, not guaranteed to be used - only by oci8
var $_queryID = false; /// This variable keeps the last created result link identifier
-
+
var $_isPersistentConnection = false; /// A boolean variable to state whether its a persistent connection or normal connection. */
var $_bindInputArray = false; /// set to true if ADOConnection.Execute() permits binding of array parameters.
var $_evalAll = false;
var $_affected = false;
var $_logsql = false;
var $_transmode = ''; // transaction mode
-
-
+
+
/**
* Constructor
*/
- function ADOConnection()
+ function ADOConnection()
{
die('Virtual Class -- cannot instantiate');
}
-
+
static function Version()
{
global $ADODB_vers;
-
+
return (float) substr($ADODB_vers,1);
}
-
+
/**
Get server version info...
-
- @returns An array with 2 elements: $arr['string'] is the description string,
+
+ @returns An array with 2 elements: $arr['string'] is the description string,
and $arr[version] is the version (also a string).
*/
function ServerInfo()
{
return array('description' => '', 'version' => '');
}
-
+
function IsConnected()
{
return !empty($this->_connectionID);
}
-
+
function _findvers($str)
{
if (preg_match('/([0-9]+\.([0-9\.])+)/',$str, $arr)) return $arr[1];
else return '';
}
-
+
/**
* All error messages go through this bottleneck function.
* You can define your own handler by defining the function name in ADODB_OUTP.
@@ -463,7 +463,7 @@
static function outp($msg,$newline=true)
{
global $ADODB_FLUSH,$ADODB_OUTP;
-
+
if (defined('ADODB_OUTP')) {
$fn = ADODB_OUTP;
$fn($msg,$newline);
@@ -473,25 +473,25 @@
$fn($msg,$newline);
return;
}
-
+
if ($newline) $msg .= "<br>\n";
-
+
if (isset($_SERVER['HTTP_USER_AGENT']) || !$newline) echo $msg;
else echo strip_tags($msg);
-
-
- if (!empty($ADODB_FLUSH) && ob_get_length() !== false) flush(); // do not flush if output buffering enabled - useless - thx to Jesse Mullan
-
+
+
+ if (!empty($ADODB_FLUSH) && ob_get_length() !== false) flush(); // do not flush if output buffering enabled - useless - thx to Jesse Mullan
+
}
-
+
function Time()
{
$rs = $this->_Execute("select $this->sysTimeStamp");
if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields));
-
+
return false;
}
-
+
/**
* Connect to database
*
@@ -502,19 +502,19 @@
* @param [forceNew] force new connection
*
* @return true or false
- */
- function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "", $forceNew = false)
+ */
+ function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "", $forceNew = false)
{
if ($argHostname != "") $this->host = $argHostname;
if ($argUsername != "") $this->user = $argUsername;
if ($argPassword != "") $this->password = $argPassword; // not stored for security reasons
- if ($argDatabaseName != "") $this->database = $argDatabaseName;
-
- $this->_isPersistentConnection = false;
-
+ if ($argDatabaseName != "") $this->database = $argDatabaseName;
+
+ $this->_isPersistentConnection = false;
+
global $ADODB_CACHE;
if (empty($ADODB_CACHE)) $this->_CreateCache();
-
+
if ($forceNew) {
if ($rez=$this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;
} else {
@@ -528,21 +528,21 @@
$err = "Missing extension for ".$this->dataProvider;
$ret = 0;
}
- if ($fn = $this->raiseErrorFn)
+ if ($fn = $this->raiseErrorFn)
$fn($this->databaseType,'CONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);
-
-
+
+
$this->_connectionID = false;
if ($this->debug) ADOConnection::outp( $this->host.': '.$err);
return $ret;
- }
-
+ }
+
function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName)
{
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName);
}
-
-
+
+
/**
* Always force a new connection to database - currently only works with oracle
*
@@ -552,12 +552,12 @@
* @param [argDatabaseName] database
*
* @return true or false
- */
- function NConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "")
+ */
+ function NConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "")
{
return $this->Connect($argHostname, $argUsername, $argPassword, $argDatabaseName, true);
}
-
+
/**
* Establish persistent connect to database
*
@@ -567,23 +567,23 @@
* @param [argDatabaseName] database
*
* @return return true or false
- */
+ */
function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "")
{
-
- if (defined('ADODB_NEVER_PERSIST'))
+
+ if (defined('ADODB_NEVER_PERSIST'))
return $this->Connect($argHostname,$argUsername,$argPassword,$argDatabaseName);
-
+
if ($argHostname != "") $this->host = $argHostname;
if ($argUsername != "") $this->user = $argUsername;
if ($argPassword != "") $this->password = $argPassword;
- if ($argDatabaseName != "") $this->database = $argDatabaseName;
-
- $this->_isPersistentConnection = true;
-
+ if ($argDatabaseName != "") $this->database = $argDatabaseName;
+
+ $this->_isPersistentConnection = true;
+
global $ADODB_CACHE;
if (empty($ADODB_CACHE)) $this->_CreateCache();
-
+
if ($rez = $this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;
if (isset($rez)) {
$err = $this->ErrorMsg();
@@ -596,7 +596,7 @@
if ($fn = $this->raiseErrorFn) {
$fn($this->databaseType,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);
}
-
+
$this->_connectionID = false;
if ($this->debug) ADOConnection::outp( $this->host.': '.$err);
return $ret;
@@ -607,32 +607,32 @@
if (defined('ADODB_ERROR_HANDLER') && ADODB_ERROR_HANDLER == 'adodb_throw') {
adodb_throw($this->databaseType,$src,-9999,$msg,$sql,false,$this);
return;
- }
+ }
ADOConnection::outp($msg);
}
-
+
// create cache class. Code is backward compat with old memcache implementation
function _CreateCache()
{
global $ADODB_CACHE, $ADODB_CACHE_CLASS;
-
+
if ($this->memCache) {
global $ADODB_INCLUDED_MEMCACHE;
-
+
if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php');
$ADODB_CACHE = new ADODB_Cache_MemCache($this);
} else
$ADODB_CACHE = new $ADODB_CACHE_CLASS($this);
-
+
}
-
+
// Format date column in sql string given an input format that understands Y M D
function SQLDate($fmt, $col=false)
- {
+ {
if (!$col) $col = $this->sysDate;
return $col; // child class implement
}
-
+
/**
* Should prepare the sql statement and return the stmt resource.
* For databases that do not support this, we return the $sql. To ensure
@@ -647,7 +647,7 @@
* @return return FALSE, or the prepared statement, or the original sql if
* if the database does not support prepare.
*
- */
+ */
function Prepare($sql)
{
return $sql;
@@ -666,7 +666,7 @@
* @return return FALSE, or the prepared statement, or the original sql if
* if the database does not support prepare.
*
- */
+ */
function PrepareSP($sql,$param=true)
{
return $this->Prepare($sql,$param);
@@ -679,7 +679,7 @@
{
return $this->qstr($s,false);
}
-
+
/**
Requested by "Karsten Dambekalns" <k.dambekalns@fishfarm.de>
*/
@@ -693,18 +693,18 @@
#if (!empty($this->qNull)) if ($s == 'null') return $s;
$s = $this->qstr($s,false);
}
-
+
/**
- * PEAR DB Compat - do not use internally.
+ * PEAR DB Compat - do not use internally.
*/
function ErrorNative()
{
return $this->ErrorNo();
}
-
+
/**
- * PEAR DB Compat - do not use internally.
+ * PEAR DB Compat - do not use internally.
*/
function nextId($seq_name)
{
@@ -722,19 +722,19 @@
{
return false;
}
-
+
function CommitLock($table)
{
return $this->CommitTrans();
}
-
+
function RollbackLock($table)
{
return $this->RollbackTrans();
}
-
+
/**
- * PEAR DB Compat - do not use internally.
+ * PEAR DB Compat - do not use internally.
*
* The fetch modes for NUMERIC and ASSOC for PEAR DB and ADODB are identical
* for easy porting :-)
@@ -743,20 +743,20 @@
* @returns The previous fetch mode
*/
function SetFetchMode($mode)
- {
+ {
$old = $this->fetchMode;
$this->fetchMode = $mode;
-
+
if ($old === false) {
global $ADODB_FETCH_MODE;
return $ADODB_FETCH_MODE;
}
return $old;
}
-
+
/**
- * PEAR DB Compat - do not use internally.
+ * PEAR DB Compat - do not use internally.
*/
function Query($sql, $inputarr=false)
{
@@ -765,18 +765,18 @@
return $rs;
}
-
+
/**
* PEAR DB Compat - do not use internally
*/
function LimitQuery($sql, $offset, $count, $params=false)
{
- $rs = $this->SelectLimit($sql, $count, $offset, $params);
+ $rs = $this->SelectLimit($sql, $count, $offset, $params);
if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();
return $rs;
}
-
+
/**
* PEAR DB Compat - do not use internally
*/
@@ -784,13 +784,13 @@
{
return $this->Close();
}
-
+
/*
Returns placeholder for parameter, eg.
$DB->Param('a')
-
+
will return ':a' for Oracle, and '?' for most other databases...
-
+
For databases that require positioned params, eg $1, $2, $3 for postgresql,
pass in Param(false) before setting the first parameter.
*/
@@ -798,7 +798,7 @@
{
return '?';
}
-
+
/*
InParameter and OutParameter are self-documenting versions of Parameter().
*/
@@ -806,23 +806,23 @@
{
return $this->Parameter($stmt,$var,$name,false,$maxLen,$type);
}
-
+
/*
*/
function OutParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
{
return $this->Parameter($stmt,$var,$name,true,$maxLen,$type);
-
+
}
-
- /*
+
+ /*
Usage in oracle
$stmt = $db->Prepare('select * from table where id =:myid and group=:group');
$db->Parameter($stmt,$id,'myid');
$db->Parameter($stmt,$group,'group',64);
$db->Execute();
-
+
@param $stmt Statement returned by Prepare() or PrepareSP().
@param $var PHP variable to bind to
@param $name Name of stored procedure variable name to bind to.
@@ -835,8 +835,8 @@
{
return false;
}
-
-
+
+
function IgnoreErrors($saveErrs=false)
{
if (!$saveErrs) {
@@ -848,11 +848,11 @@
$this->_transOK = $saveErrs[1];
}
}
-
+
/**
Improved method of initiating a transaction. Used together with CompleteTrans().
Advantages include:
-
+
a. StartTrans/CompleteTrans is nestable, unlike BeginTrans/CommitTrans/RollbackTrans.
Only the outermost block is treated as a transaction.<br>
b. CompleteTrans auto-detects SQL errors, and will rollback on errors, commit otherwise.<br>
@@ -865,22 +865,22 @@
$this->transOff += 1;
return;
}
-
+
$this->_oldRaiseFn = $this->raiseErrorFn;
$this->raiseErrorFn = $errfn;
$this->_transOK = true;
-
+
if ($this->debug && $this->transCnt > 0) ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans");
$this->BeginTrans();
$this->transOff = 1;
}
-
-
+
+
/**
Used together with StartTrans() to end a transaction. Monitors connection
for sql errors, and will commit or rollback as appropriate.
-
- @autoComplete if true, monitor sql errors and commit and rollback as appropriate,
+
+ @autoComplete if true, monitor sql errors and commit and rollback as appropriate,
and if set to false force rollback even if no SQL error detected.
@returns true on commit, false on rollback.
*/
@@ -891,7 +891,7 @@
return true;
}
$this->raiseErrorFn = $this->_oldRaiseFn;
-
+
$this->transOff = 0;
if ($this->_transOK && $autoComplete) {
if (!$this->CommitTrans()) {
@@ -904,16 +904,16 @@
$this->RollbackTrans();
if ($this->debug) ADOCOnnection::outp("Smart Rollback occurred");
}
-
+
return $this->_transOK;
}
-
+
/*
At the end of a StartTrans/CompleteTrans block, perform a rollback.
*/
function FailTrans()
{
- if ($this->debug)
+ if ($this->debug)
if ($this->transOff == 0) {
ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans");
} else {
@@ -922,7 +922,7 @@
}
$this->_transOK = false;
}
-
+
/**
Check if transaction has failed, only for Smart Transactions.
*/
@@ -931,15 +931,15 @@
if ($this->transOff > 0) return $this->_transOK == false;
return false;
}
-
+
/**
- * Execute SQL
+ * Execute SQL
*
* @param sql SQL statement to execute, or possibly an array holding prepared statement ($sql[0] will hold sql text)
* @param [inputarr] holds the input data to bind to. Null elements will be set to null.
* @return RecordSet or false
*/
- function Execute($sql,$inputarr=false)
+ function Execute($sql,$inputarr=false)
{
if ($this->fnExecute) {
$fn = $this->fnExecute;
@@ -948,16 +948,16 @@
}
if ($inputarr) {
if (!is_array($inputarr)) $inputarr = array($inputarr);
-
+
$element0 = reset($inputarr);
# is_object check because oci8 descriptors can be passed in
- $array_2d = is_array($element0) && !is_object(reset($element0));
+ $array_2d = is_array($element0);// && !is_object(reset($element0));// Removed this check 30 JUL 2008 to reduce breakage BY: djb
//remove extra memory copy of input -mikefedyk
unset($element0);
-
+
if (!is_array($sql) && !$this->_bindInputArray) {
$sqlarr = explode('?',$sql);
-
+
if (!$array_2d) $inputarr = array($inputarr);
foreach($inputarr as $arr) {
$sql = ''; $i = 0;
@@ -965,7 +965,7 @@
while(list(, $v) = each($arr)) {
$sql .= $sqlarr[$i];
// from Ron Baldwin <ron.baldwin#sourceprose.com>
- // Only quote string types
+ // Only quote string types
$typ = gettype($v);
if ($typ == 'string')
//New memory copy of input created here -mikefedyk
@@ -986,19 +986,19 @@
if (isset($sqlarr[$i])) {
$sql .= $sqlarr[$i];
if ($i+1 != sizeof($sqlarr)) $this->outp_throw( "Input Array does not match ?: ".htmlspecialchars($sql),'Execute');
- } else if ($i != sizeof($sqlarr))
+ } else if ($i != sizeof($sqlarr))
$this->outp_throw( "Input array does not match ?: ".htmlspecialchars($sql),'Execute');
-
+
$ret = $this->_Execute($sql);
if (!$ret) return $ret;
- }
+ }
} else {
if ($array_2d) {
if (is_string($sql))
$stmt = $this->Prepare($sql);
else
$stmt = $sql;
-
+
foreach($inputarr as $arr) {
$ret = $this->_Execute($stmt,$arr);
if (!$ret) return $ret;
@@ -1013,8 +1013,8 @@
return $ret;
}
-
-
+
+
function _Execute($sql,$inputarr=false)
{
if ($this->debug) {
@@ -1024,28 +1024,28 @@
} else {
$this->_queryID = @$this->_query($sql,$inputarr);
}
-
+
/************************
// OK, query executed
*************************/
if ($this->_queryID === false) { // error handling if query fails
- if ($this->debug == 99) adodb_backtrace(true,5);
+ if ($this->debug == 99) adodb_backtrace(true,5);
$fn = $this->raiseErrorFn;
if ($fn) {
$fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr,$this);
- }
+ }
$false = false;
return $false;
- }
-
+ }
+
if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead
$rsclass = $this->rsPrefix.'empty';
$rs = (class_exists($rsclass)) ? new $rsclass(): new ADORecordSet_empty();
-
+
return $rs;
}
-
+
// return real recordset from select statement
$rsclass = $this->rsPrefix.$this->databaseType;
$rs = new $rsclass($this->_queryID,$this->fetchMode);
@@ -1056,7 +1056,7 @@
if ($rs->_numOfRows <= 0) {
global $ADODB_COUNTRECS;
if ($ADODB_COUNTRECS) {
- if (!$rs->EOF) {
+ if (!$rs->EOF) {
$rs = $this->_rs2rs($rs,-1,-1,!is_array($sql));
$rs->_queryID = $this->_queryID;
} else
@@ -1091,16 +1091,16 @@
if (!$this->hasGenID) {
return 0; // formerly returns false pre 1.60
}
-
+
$getnext = sprintf($this->_genIDSQL,$seqname);
-
+
$holdtransOK = $this->_transOK;
-
+
$save_handler = $this->raiseErrorFn;
$this->raiseErrorFn = '';
@($rs = $this->Execute($getnext));
$this->raiseErrorFn = $save_handler;
-
+
if (!$rs) {
$this->_transOK = $holdtransOK; //if the status was ok before reset
$createseq = $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID));
@@ -1108,17 +1108,17 @@
}
if ($rs && !$rs->EOF) $this->genID = reset($rs->fields);
else $this->genID = 0; // false
-
+
if ($rs) $rs->Close();
return $this->genID;
- }
+ }
/**
* @param $table string name of the table, not needed by all databases (eg. mysql), default ''
* @param $column string name of the column, not needed by all databases (eg. mysql), default ''
* @return the last inserted ID. Not all databases support this.
- */
+ */
function Insert_ID($table='',$column='')
{
if ($this->_logsql && $this->lastInsID) return $this->lastInsID;
@@ -1136,8 +1136,8 @@
*
* @return the last inserted ID. All databases support this. But aware possible
* problems in multiuser environments. Heavy test this before deploying.
- */
- function PO_Insert_ID($table="", $id="")
+ */
+ function PO_Insert_ID($table="", $id="")
{
if ($this->hasInsertID){
return $this->Insert_ID($table,$id);
@@ -1148,7 +1148,7 @@
/**
* @return # rows affected by UPDATE/DELETE
- */
+ */
function Affected_Rows()
{
if ($this->hasAffectedRows) {
@@ -1158,12 +1158,12 @@
$val = $this->_affectedrows();
return ($val < 0) ? false : $val;
}
-
+
if ($this->debug) ADOConnection::outp( '<p>Affected_Rows error</p>',false);
return false;
}
-
-
+
+
/**
* @return the last error message
*/
@@ -1172,29 +1172,29 @@
if ($this->_errorMsg) return '!! '.strtoupper($this->dataProvider.' '.$this->databaseType).': '.$this->_errorMsg;
else return '';
}
-
-
+
+
/**
* @return the last error number. Normally 0 means no error.
*/
- function ErrorNo()
+ function ErrorNo()
{
return ($this->_errorMsg) ? -1 : 0;
}
-
+
function MetaError($err=false)
{
include_once(ADODB_DIR."/adodb-error.inc.php");
if ($err === false) $err = $this->ErrorNo();
return adodb_error($this->dataProvider,$this->databaseType,$err);
}
-
+
function MetaErrorMsg($errno)
{
include_once(ADODB_DIR."/adodb-error.inc.php");
return adodb_errormsg($errno);
}
-
+
/**
* @returns an array with the primary key columns in it.
*/
@@ -1214,7 +1214,7 @@
return ADODB_VIEW_PRIMARYKEYS($this->databaseType, $this->database, $table, $owner);
return false;
}
-
+
/**
* @returns assoc array where keys are tables, and values are foreign keys
*/
@@ -1228,16 +1228,16 @@
* @param dbName is the name of the database to select
* @return true or false
*/
- function SelectDB($dbName)
+ function SelectDB($dbName)
{return false;}
-
-
+
+
/**
- * Will select, getting rows from $offset (1-based), for $nrows.
+ * Will select, getting rows from $offset (1-based), for $nrows.
* This simulates the MySQL "select * from table limit $offset,$nrows" , and
* the PostgreSQL "select * from table limit $nrows offset $offset". Note that
* MySQL and PostgreSQL parameter ordering is the opposite of the other.
- * eg.
+ * eg.
* SelectLimit('select * from table',3); will return rows 1 to 3 (1-based)
* SelectLimit('select * from table',3,2); will return rows 3 to 5 (1-based)
*
@@ -1254,14 +1254,14 @@
function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)
{
if ($this->hasTop && $nrows > 0) {
- // suggested by Reinhard Balling. Access requires top after distinct
+ // suggested by Reinhard Balling. Access requires top after distinct
// Informix requires first before distinct - F Riosa
$ismssql = (strpos($this->databaseType,'mssql') !== false);
if ($ismssql) $isaccess = false;
else $isaccess = (strpos($this->databaseType,'access') !== false);
-
+
if ($offset <= 0) {
-
+
// access includes ties in result
if ($isaccess) {
$sql = preg_replace(
@@ -1291,18 +1291,18 @@
}
}
}
-
+
// if $offset>0, we want to skip rows, and $ADODB_COUNTRECS is set, we buffer rows
// 0 to offset-1 which will be discarded anyway. So we disable $ADODB_COUNTRECS.
global $ADODB_COUNTRECS;
-
+
$savec = $ADODB_COUNTRECS;
$ADODB_COUNTRECS = false;
-
+
if ($secs2cache != 0) $rs = $this->CacheExecute($secs2cache,$sql,$inputarr);
else $rs = $this->Execute($sql,$inputarr);
-
+
$ADODB_COUNTRECS = $savec;
if ($rs && !$rs->EOF) {
$rs = $this->_rs2rs($rs,$nrows,$offset);
@@ -1310,7 +1310,7 @@
//print_r($rs);
return $rs;
}
-
+
/**
* Create serializable recordset. Breaks rs link to connection.
*
@@ -1321,10 +1321,10 @@
$rs2 = $this->_rs2rs($rs);
$ignore = false;
$rs2->connection = $ignore;
-
+
return $rs2;
}
-
+
/**
* Convert database recordset to an array recordset
* input recordset's cursor should be at beginning, and
@@ -1359,9 +1359,9 @@
$arr = $rs->GetArrayLimit($nrows,$offset);
//print_r($arr);
if ($close) $rs->Close();
-
+
$arrayClass = $this->arrayClass;
-
+
$rs2 = new $arrayClass();
$rs2->connection = $this;
$rs2->sql = $rs->sql;
@@ -1370,7 +1370,7 @@
$rs2->fetchMode = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
return $rs2;
}
-
+
/*
* Return all rows. Compat with PEAR DB
*/
@@ -1379,7 +1379,7 @@
$arr = $this->GetArray($sql,$inputarr);
return $arr;
}
-
+
function GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false)
{
$rs = $this->Execute($sql, $inputarr);
@@ -1390,7 +1390,7 @@
$arr = $rs->GetAssoc($force_array,$first2cols);
return $arr;
}
-
+
function CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false)
{
if (!is_numeric($secs2cache)) {
@@ -1405,7 +1405,7 @@
$arr = $rs->GetAssoc($force_array,$first2cols);
return $arr;
}
-
+
/**
* Return first element of first row of sql statement. Recordset is disposed
* for you.
@@ -1418,19 +1418,19 @@
global $ADODB_COUNTRECS;
$crecs = $ADODB_COUNTRECS;
$ADODB_COUNTRECS = false;
-
+
$ret = false;
$rs = $this->Execute($sql,$inputarr);
- if ($rs) {
+ if ($rs) {
if ($rs->EOF) $ret = null;
else $ret = reset($rs->fields);
-
+
$rs->Close();
}
$ADODB_COUNTRECS = $crecs;
return $ret;
}
-
+
function CacheGetOne($secs2cache,$sql=false,$inputarr=false)
{
$ret = false;
@@ -1439,14 +1439,14 @@
if ($rs->EOF) $ret = null;
else $ret = reset($rs->fields);
$rs->Close();
- }
-
+ }
+
return $ret;
}
-
+
function GetCol($sql, $inputarr = false, $trim = false)
{
-
+
$rs = $this->Execute($sql, $inputarr);
if ($rs) {
$rv = array();
@@ -1466,7 +1466,7 @@
$rv = false;
return $rv;
}
-
+
function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false)
{
$rs = $this->CacheExecute($secs, $sql, $inputarr);
@@ -1486,34 +1486,34 @@
$rs->Close();
} else
$rv = false;
-
+
return $rv;
}
-
+
function Transpose(&$rs,$addfieldnames=true)
{
$rs2 = $this->_rs2rs($rs);
$false = false;
if (!$rs2) return $false;
-
+
$rs2->_transpose($addfieldnames);
return $rs2;
}
-
+
/*
Calculate the offset of a date for a particular database and generate
appropriate SQL. Useful for calculating future/past dates and storing
in a database.
-
+
If dayFraction=1.5 means 1.5 days from now, 1.0/24 for 1 hour.
*/
function OffsetDate($dayFraction,$date=false)
- {
+ {
if (!$date) $date = $this->sysDate;
return '('.$date.'+'.$dayFraction.')';
}
-
-
+
+
/**
*
* @param sql SQL statement
@@ -1522,12 +1522,12 @@
function GetArray($sql,$inputarr=false)
{
global $ADODB_COUNTRECS;
-
+
$savec = $ADODB_COUNTRECS;
$ADODB_COUNTRECS = false;
$rs = $this->Execute($sql,$inputarr);
$ADODB_COUNTRECS = $savec;
- if (!$rs)
+ if (!$rs)
if (defined('ADODB_PEAR')) {
$cls = ADODB_PEAR_Error();
return $cls;
@@ -1539,23 +1539,23 @@
$rs->Close();
return $arr;
}
-
+
function CacheGetAll($secs2cache,$sql=false,$inputarr=false)
{
$arr = $this->CacheGetArray($secs2cache,$sql,$inputarr);
return $arr;
}
-
+
function CacheGetArray($secs2cache,$sql=false,$inputarr=false)
{
global $ADODB_COUNTRECS;
-
+
$savec = $ADODB_COUNTRECS;
$ADODB_COUNTRECS = false;
$rs = $this->CacheExecute($secs2cache,$sql,$inputarr);
$ADODB_COUNTRECS = $savec;
-
- if (!$rs)
+
+ if (!$rs)
if (defined('ADODB_PEAR')) {
$cls = ADODB_PEAR_Error();
return $cls;
@@ -1567,14 +1567,14 @@
$rs->Close();
return $arr;
}
-
+
function GetRandRow($sql, $arr= false)
{
$rezarr = $this->GetAll($sql, $arr);
$sz = sizeof($rezarr);
return $rezarr[abs(rand()) % $sz];
}
-
+
/**
* Return one row of sql statement. Recordset is disposed for you.
*
@@ -1586,9 +1586,9 @@
global $ADODB_COUNTRECS;
$crecs = $ADODB_COUNTRECS;
$ADODB_COUNTRECS = false;
-
+
$rs = $this->Execute($sql,$inputarr);
-
+
$ADODB_COUNTRECS = $crecs;
if ($rs) {
if (!$rs->EOF) $arr = $rs->fields;
@@ -1596,27 +1596,27 @@
$rs->Close();
return $arr;
}
-
+
$false = false;
return $false;
}
-
+
function CacheGetRow($secs2cache,$sql=false,$inputarr=false)
{
$rs = $this->CacheExecute($secs2cache,$sql,$inputarr);
if ($rs) {
if (!$rs->EOF) $arr = $rs->fields;
else $arr = array();
-
+
$rs->Close();
return $arr;
}
$false = false;
return $false;
}
-
+
/**
- * Insert or replace a single record. Note: this is not the same as MySQL's replace.
+ * Insert or replace a single record. Note: this is not the same as MySQL's replace.
* ADOdb's Replace() uses update-insert semantics, not insert-delete-duplicates of MySQL.
* Also note that no table locking is done currently, so it is possible that the
* record be inserted twice by two programs...
@@ -1632,24 +1632,24 @@
*
* Currently blob replace not supported
*
- * returns 0 = fail, 1 = update, 2 = insert
+ * returns 0 = fail, 1 = update, 2 = insert
*/
-
+
function Replace($table, $fieldArray, $keyCol, $autoQuote=false, $has_autoinc=false)
{
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
-
+
return _adodb_replace($this, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc);
}
-
-
+
+
/**
- * Will select, getting rows from $offset (1-based), for $nrows.
+ * Will select, getting rows from $offset (1-based), for $nrows.
* This simulates the MySQL "select * from table limit $offset,$nrows" , and
* the PostgreSQL "select * from table limit $nrows offset $offset". Note that
* MySQL and PostgreSQL parameter ordering is the opposite of the other.
- * eg.
+ * eg.
* CacheSelectLimit(15,'select * from table',3); will return rows 1 to 3 (1-based)
* CacheSelectLimit(15,'select * from table',3,2); will return rows 3 to 5 (1-based)
*
@@ -1663,7 +1663,7 @@
* @return the recordset ($rs->databaseType == 'array')
*/
function CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false)
- {
+ {
if (!is_numeric($secs2cache)) {
if ($sql === false) $sql = -1;
if ($offset == -1) $offset = false;
@@ -1675,31 +1675,31 @@
}
return $rs;
}
-
-
+
+
/**
- * Flush cached recordsets that match a particular $sql statement.
+ * Flush cached recordsets that match a particular $sql statement.
* If $sql == false, then we purge all files in the cache.
*/
-
+
/**
- * Flush cached recordsets that match a particular $sql statement.
+ * Flush cached recordsets that match a particular $sql statement.
* If $sql == false, then we purge all files in the cache.
*/
function CacheFlush($sql=false,$inputarr=false)
{
global $ADODB_CACHE_DIR, $ADODB_CACHE;
-
+
if (!$sql) {
$ADODB_CACHE->flushall($this->debug);
return;
}
-
+
$f = $this->_gencachename($sql.serialize($inputarr),false);
return $ADODB_CACHE->flushcache($f, $this->debug);
}
-
-
+
+
/**
* Private function to generate filename for caching.
* Filename is generated based on:
@@ -1710,15 +1710,15 @@
* - userid
* - setFetchMode (adodb 4.23)
*
- * When not in safe mode, we create 256 sub-directories in the cache directory ($ADODB_CACHE_DIR).
- * Assuming that we can have 50,000 files per directory with good performance,
+ * When not in safe mode, we create 256 sub-directories in the cache directory ($ADODB_CACHE_DIR).
+ * Assuming that we can have 50,000 files per directory with good performance,
* then we can scale to 12.8 million unique cached recordsets. Wow!
*/
function _gencachename($sql,$createdir)
{
global $ADODB_CACHE, $ADODB_CACHE_DIR;
-
- if ($this->fetchMode === false) {
+
+ if ($this->fetchMode === false) {
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
} else {
@@ -1728,15 +1728,15 @@
if (!$ADODB_CACHE->createdir) return $m;
if (!$createdir) $dir = $ADODB_CACHE->getdirname($m);
else $dir = $ADODB_CACHE->createdir($m, $this->debug);
-
+
return $dir.'/adodb_'.$m.'.cache';
}
-
-
+
+
/**
* Execute SQL, caching recordsets.
*
- * @param [secs2cache] seconds to cache data, set to 0 to force query.
+ * @param [secs2cache] seconds to cache data, set to 0 to force query.
* This is an optional parameter.
* @param sql SQL statement to execute
* @param [inputarr] holds the input data to bind to
@@ -1745,23 +1745,23 @@
function CacheExecute($secs2cache,$sql=false,$inputarr=false)
{
global $ADODB_CACHE;
-
+
if (!is_numeric($secs2cache)) {
$inputarr = $sql;
$sql = $secs2cache;
$secs2cache = $this->cacheSecs;
}
-
+
if (is_array($sql)) {
$sqlparam = $sql;
$sql = $sql[0];
} else
$sqlparam = $sql;
-
-
+
+
$md5file = $this->_gencachename($sql.serialize($inputarr),true);
$err = '';
-
+
if ($secs2cache > 0){
$rs = &$ADODB_CACHE->readcache($md5file,$err,$secs2cache,$this->arrayClass);
$this->numCacheHits += 1;
@@ -1770,7 +1770,7 @@
$rs = false;
$this->numCacheMisses += 1;
}
-
+
if (!$rs) {
// no cached rs found
if ($this->debug) {
@@ -1779,7 +1779,7 @@
}
if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (see sql below)");
}
-
+
$rs = $this->Execute($sqlparam,$inputarr);
if ($rs) {
@@ -1788,13 +1788,13 @@
$rs = $this->_rs2rs($rs); // read entire recordset into memory immediately
$rs->timeCreated = time(); // used by caching
$txt = _rs2serialize($rs,false,$sql); // serialize
-
+
$ok = $ADODB_CACHE->writecache($md5file,$txt,$this->debug, $secs2cache);
if (!$ok) {
if ($ok === false) {
$em = 'Cache write error';
$en = -32000;
-
+
if ($fn = $this->raiseErrorFn) {
$fn($this->databaseType,'CacheExecute', $en, $em, $md5file,$sql,$this);
}
@@ -1803,52 +1803,52 @@
$en = -32001;
// do not call error handling for just a warning
}
-
+
if ($this->debug) ADOConnection::outp( " ".$em);
}
if ($rs->EOF && !$eof) {
$rs->MoveFirst();
- //$rs = csv2rs($md5file,$err);
+ //$rs = csv2rs($md5file,$err);
$rs->connection = $this; // Pablo suggestion
- }
-
+ }
+
} else if (!$this->memCache)
$ADODB_CACHE->flushcache($md5file);
} else {
$this->_errorMsg = '';
$this->_errorCode = 0;
-
+
if ($this->fnCacheExecute) {
$fn = $this->fnCacheExecute;
$fn($this, $secs2cache, $sql, $inputarr);
}
// ok, set cached object found
$rs->connection = $this; // Pablo suggestion
- if ($this->debug){
+ if ($this->debug){
if ($this->debug == 99) adodb_backtrace();
$inBrowser = isset($_SERVER['HTTP_USER_AGENT']);
$ttl = $rs->timeCreated + $secs2cache - time();
$s = is_array($sql) ? $sql[0] : $sql;
if ($inBrowser) $s = '<i>'.htmlspecialchars($s).'</i>';
-
+
ADOConnection::outp( " $md5file reloaded, ttl=$ttl [ $s ]");
}
}
return $rs;
}
-
-
- /*
- Similar to PEAR DB's autoExecute(), except that
+
+
+ /*
+ Similar to PEAR DB's autoExecute(), except that
$mode can be 'INSERT' or 'UPDATE' or DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
If $mode == 'UPDATE', then $where is compulsory as a safety measure.
-
+
$forceUpdate means that even if the data has not changed, perform update.
*/
- function AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false)
+ function AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false)
{
$false = false;
- $sql = 'SELECT * FROM '.$table;
+ $sql = 'SELECT * FROM '.$table;
if ($where!==FALSE) $sql .= ' WHERE '.$where;
else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) {
$this->outp_throw('AutoExecute: Illegal mode=UPDATE with empty WHERE clause','AutoExecute');
@@ -1858,7 +1858,7 @@
$rs = $this->SelectLimit($sql,1);
if (!$rs) return $false; // table does not exist
$rs->tableName = $table;
-
+
switch((string) $mode) {
case 'UPDATE':
case '2':
@@ -1877,15 +1877,15 @@
if ($ret) $ret = true;
return $ret;
}
-
-
+
+
/**
* Generates an Update Query based on an existing recordset.
* $arrFields is an associative array of fields with the value
* that should be assigned.
*
* Note: This function should only be used on a recordset
- * that is run against a single table and sql should only
+ * that is run against a single table and sql should only
* be a simple select stmt with no groupby/orderby/limit
*
* "Jonathan Younger" <jyounger@unilab.com>
@@ -1916,27 +1916,27 @@
* that is run against a single table.
*/
function GetInsertSQL(&$rs, $arrFields,$magicq=false,$force=null)
- {
+ {
global $ADODB_INCLUDED_LIB;
if (!isset($force)) {
global $ADODB_FORCE_TYPE;
$force = $ADODB_FORCE_TYPE;
-
+
}
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force);
}
-
+
/**
* Update a blob column, given a where clause. There are more sophisticated
* blob handling functions that we could have implemented, but all require
* a very complex API. Instead we have chosen something that is extremely
- * simple to understand and use.
+ * simple to understand and use.
*
* Note: $blobtype supports 'BLOB' and 'CLOB', default is BLOB of course.
*
- * Usage to update a $blobvalue which has a primary key blob_id=1 into a
+ * Usage to update a $blobvalue which has a primary key blob_id=1 into a
* field blobtable.blobcolumn:
*
* UpdateBlob('blobtable', 'blobcolumn', $blobvalue, 'blob_id=1');
@@ -1946,7 +1946,7 @@
* $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
* $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
*/
-
+
function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
{
return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;
@@ -1955,7 +1955,7 @@
/**
* Usage:
* UpdateBlob('TABLE', 'COLUMN', '/path/to/file', 'ID=1');
- *
+ *
* $blobtype supports 'BLOB' and 'CLOB'
*
* $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
@@ -1969,45 +1969,45 @@
fclose($fd);
return $this->UpdateBlob($table,$column,$val,$where,$blobtype);
}
-
+
function BlobDecode($blob)
{
return $blob;
}
-
+
function BlobEncode($blob)
{
return $blob;
}
-
+
function SetCharSet($charset)
{
return false;
}
-
- function IfNull( $field, $ifNull )
+
+ function IfNull( $field, $ifNull )
{
return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
}
-
+
function LogSQL($enable=true)
{
include_once(ADODB_DIR.'/adodb-perf.inc.php');
-
+
if ($enable) $this->fnExecute = 'adodb_log_sql';
else $this->fnExecute = false;
-
- $old = $this->_logsql;
+
+ $old = $this->_logsql;
$this->_logsql = $enable;
if ($enable && !$old) $this->_affected = false;
return $old;
}
-
+
function GetCharSet()
{
return false;
}
-
+
/**
* Usage:
* UpdateClob('TABLE', 'COLUMN', $var, 'ID=1', 'CLOB');
@@ -2019,21 +2019,21 @@
{
return $this->UpdateBlob($table,$column,$val,$where,'CLOB');
}
-
+
// not the fastest implementation - quick and dirty - jlim
// for best performance, use the actual $rs->MetaType().
function MetaType($t,$len=-1,$fieldobj=false)
{
-
+
if (empty($this->_metars)) {
$rsclass = $this->rsPrefix.$this->databaseType;
- $this->_metars = new $rsclass(false,$this->fetchMode);
+ $this->_metars = new $rsclass(false,$this->fetchMode);
$this->_metars->connection = $this;
}
return $this->_metars->MetaType($t,$len,$fieldobj);
}
-
-
+
+
/**
* Change the SQL connection locale to a specified locale.
* This is used to get the date formats written depending on the client locale.
@@ -2047,13 +2047,13 @@
$this->fmtDate="'Y-m-d'";
$this->fmtTimeStamp = "'Y-m-d H:i:s'";
break;
-
+
case 'US':
$this->fmtDate = "'m-d-Y'";
$this->fmtTimeStamp = "'m-d-Y H:i:s'";
break;
-
- case 'PT_BR':
+
+ case 'PT_BR':
case 'NL':
case 'FR':
case 'RO':
@@ -2061,12 +2061,12 @@
$this->fmtDate="'d-m-Y'";
$this->fmtTimeStamp = "'d-m-Y H:i:s'";
break;
-
+
case 'GE':
$this->fmtDate="'d.m.Y'";
$this->fmtTimeStamp = "'d.m.Y H:i:s'";
break;
-
+
default:
$this->fmtDate="'Y-m-d'";
$this->fmtTimeStamp = "'Y-m-d H:i:s'";
@@ -2077,29 +2077,29 @@
function GetActiveRecordsClass($class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false)
{
global $_ADODB_ACTIVE_DBS;
-
+
$save = $this->SetFetchMode(ADODB_FETCH_NUM);
if (empty($whereOrderBy)) $whereOrderBy = '1=1';
$rows = $this->GetAll("select * from ".$table.' WHERE '.$whereOrderBy,$bindarr);
$this->SetFetchMode($save);
-
+
$false = false;
-
- if ($rows === false) {
+
+ if ($rows === false) {
return $false;
}
-
-
+
+
if (!isset($_ADODB_ACTIVE_DBS)) {
include(ADODB_DIR.'/adodb-active-record.inc.php');
- }
+ }
if (!class_exists($class)) {
$this->outp_throw("Unknown class $class in GetActiveRecordsClass()",'GetActiveRecordsClass');
return $false;
}
$arr = array();
foreach($rows as $row) {
-
+
$obj = new $class($table,$primkeyArr,$this);
if ($obj->ErrorMsg()){
$this->_errorMsg = $obj->ErrorMsg();
@@ -2110,13 +2110,13 @@
}
return $arr;
}
-
+
function GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false)
{
$arr = $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr);
return $arr;
}
-
+
/**
* Close Connection
*/
@@ -2126,20 +2126,20 @@
$this->_connectionID = false;
return $rez;
}
-
+
/**
* Begin a Transaction. Must be followed by CommitTrans() or RollbackTrans().
*
* @return true if succeeded or false if database does not support transactions
*/
- function BeginTrans()
+ function BeginTrans()
{
if ($this->debug) ADOConnection::outp("BeginTrans: Transactions not supported for this driver");
return false;
}
-
+
/* set transaction mode */
- function SetTransactionMode( $transaction_mode )
+ function SetTransactionMode( $transaction_mode )
{
$transaction_mode = $this->MetaTransaction($transaction_mode, $this->dataProvider);
$this->_transmode = $transaction_mode;
@@ -2154,11 +2154,11 @@
{
$mode = strtoupper($mode);
$mode = str_replace('ISOLATION LEVEL ','',$mode);
-
+
switch($mode) {
case 'READ UNCOMMITTED':
- switch($db) {
+ switch($db) {
case 'oci8':
case 'oracle':
return 'ISOLATION LEVEL READ COMMITTED';
@@ -2166,11 +2166,11 @@
return 'ISOLATION LEVEL READ UNCOMMITTED';
}
break;
-
+
case 'READ COMMITTED':
return 'ISOLATION LEVEL READ COMMITTED';
break;
-
+
case 'REPEATABLE READ':
switch($db) {
case 'oci8':
@@ -2180,16 +2180,16 @@
return 'ISOLATION LEVEL REPEATABLE READ';
}
break;
-
+
case 'SERIALIZABLE':
return 'ISOLATION LEVEL SERIALIZABLE';
break;
-
+
default:
return $mode;
}
}
-
+
/**
* If database does not support transactions, always return true as data always commited
*
@@ -2197,48 +2197,48 @@
*
* @return true/false.
*/
- function CommitTrans($ok=true)
+ function CommitTrans($ok=true)
{ return true;}
-
-
+
+
/**
* If database does not support transactions, rollbacks always fail, so return false
*
* @return true/false.
*/
- function RollbackTrans()
+ function RollbackTrans()
{ return false;}
/**
- * return the databases that the driver can connect to.
+ * return the databases that the driver can connect to.
* Some databases will return an empty array.
*
* @return an array of database names.
*/
- function MetaDatabases()
+ function MetaDatabases()
{
global $ADODB_FETCH_MODE;
-
+
if ($this->metaDatabasesSQL) {
- $save = $ADODB_FETCH_MODE;
- $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-
+ $save = $ADODB_FETCH_MODE;
+ $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
-
+
$arr = $this->GetCol($this->metaDatabasesSQL);
if (isset($savem)) $this->SetFetchMode($savem);
- $ADODB_FETCH_MODE = $save;
-
+ $ADODB_FETCH_MODE = $save;
+
return $arr;
}
-
+
return false;
}
-
-
+
+
/**
- * @param ttype can either be 'VIEW' or 'TABLE' or false.
+ * @param ttype can either be 'VIEW' or 'TABLE' or false.
* If false, both views and tables are returned.
* "VIEW" returns only views
* "TABLE" returns only tables
@@ -2246,34 +2246,34 @@
* @param mask is the input mask - only supported by oci8 and postgresql
*
* @return array of tables for current database.
- */
- function MetaTables($ttype=false,$showSchema=false,$mask=false)
+ */
+ function MetaTables($ttype=false,$showSchema=false,$mask=false)
{
global $ADODB_FETCH_MODE;
-
-
+
+
$false = false;
if ($mask) {
return $false;
}
if ($this->metaTablesSQL) {
- $save = $ADODB_FETCH_MODE;
- $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-
+ $save = $ADODB_FETCH_MODE;
+ $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
-
+
$rs = $this->Execute($this->metaTablesSQL);
if (isset($savem)) $this->SetFetchMode($savem);
- $ADODB_FETCH_MODE = $save;
-
+ $ADODB_FETCH_MODE = $save;
+
if ($rs === false) return $false;
$arr = $rs->GetArray();
$arr2 = array();
-
- if ($hast = ($ttype && isset($arr[0][1]))) {
+
+ if ($hast = ($ttype && isset($arr[0][1]))) {
$showt = strncmp($ttype,'T',1);
}
-
+
for ($i=0; $i < sizeof($arr); $i++) {
if ($hast) {
if ($showt == 0) {
@@ -2289,8 +2289,8 @@
}
return $false;
}
-
-
+
+
function _findschema(&$table,&$schema)
{
if (!$schema && ($at = strpos($table,'.')) !== false) {
@@ -2298,9 +2298,9 @@
$table = substr($table,$at+1);
}
}
-
+
/**
- * List columns in a database as an array of ADOFieldObjects.
+ * List columns in a database as an array of ADOFieldObjects.
* See top of file for definition of object.
*
* @param $table table name to query
@@ -2309,17 +2309,17 @@
*
* @return array of ADOFieldObjects for current table.
*/
- function MetaColumns($table,$normalize=true)
+ function MetaColumns($table,$normalize=true)
{
global $ADODB_FETCH_MODE;
-
+
$false = false;
-
+
if (!empty($this->metaColumnsSQL)) {
-
+
$schema = false;
$this->_findschema($table,$schema);
-
+
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
@@ -2339,24 +2339,24 @@
if ($fld->scale>0) $fld->max_length += 1;
} else
$fld->max_length = $rs->fields[2];
-
- if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
+
+ if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
else $retarr[strtoupper($fld->name)] = $fld;
$rs->MoveNext();
}
$rs->Close();
- return $retarr;
+ return $retarr;
}
return $false;
}
-
+
/**
* List indexes on a table as an array.
* @param table table name to query
* @param primary true to only show primary keys. Not actually used for most databases
*
* @return array of indexes on current table. Each element represents an index, and is itself an associative array.
-
+
Array (
[name_of_index] => Array
(
@@ -2366,7 +2366,7 @@
[0] => firstname
[1] => lastname
)
- )
+ )
*/
function MetaIndexes($table, $primary = false, $owner = false)
{
@@ -2375,12 +2375,12 @@
}
/**
- * List columns names in a table as an array.
+ * List columns names in a table as an array.
* @param table table name to query
*
* @return array of column names for current table.
- */
- function MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */)
+ */
+ function MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */)
{
$objarr = $this->MetaColumns($table);
if (!is_array($objarr)) {
@@ -2391,34 +2391,34 @@
if ($numIndexes) {
$i = 0;
if ($useattnum) {
- foreach($objarr as $v)
+ foreach($objarr as $v)
$arr[$v->attnum] = $v->name;
-
+
} else
foreach($objarr as $v) $arr[$i++] = $v->name;
} else
foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name;
-
+
return $arr;
}
-
+
/**
* Different SQL databases used different methods to combine strings together.
- * This function provides a wrapper.
- *
+ * This function provides a wrapper.
+ *
* param s variable number of string parameters
*
* Usage: $db->Concat($str1,$str2);
- *
+ *
* @return concatenated string
- */
+ */
function Concat()
- {
+ {
$arr = func_get_args();
return implode($this->concat_operator, $arr);
}
-
-
+
+
/**
* Converts a date "d" to a string that the database can understand.
*
@@ -2438,24 +2438,24 @@
return adodb_date($this->fmtDate,$d);
}
-
+
function BindDate($d)
{
$d = $this->DBDate($d);
if (strncmp($d,"'",1)) return $d;
-
+
return substr($d,1,strlen($d)-2);
}
-
+
function BindTimeStamp($d)
{
$d = $this->DBTimeStamp($d);
if (strncmp($d,"'",1)) return $d;
-
+
return substr($d,1,strlen($d)-2);
}
-
-
+
+
/**
* Converts a timestamp "ts" to a string that the database can understand.
*
@@ -2468,16 +2468,16 @@
if (empty($ts) && $ts !== 0) return 'null';
# strlen(14) allows YYYYMMDDHHMMSS format
- if (!is_string($ts) || (is_numeric($ts) && strlen($ts)<14))
+ if (!is_string($ts) || (is_numeric($ts) && strlen($ts)<14))
return adodb_date($this->fmtTimeStamp,$ts);
-
+
if ($ts === 'null') return $ts;
if ($this->isoDates && strlen($ts) !== 14) return "'$ts'";
-
+
$ts = ADOConnection::UnixTimeStamp($ts);
return adodb_date($this->fmtTimeStamp,$ts);
}
-
+
/**
* Also in ADORecordSet.
* @param $v is a date string in YYYY-MM-DD format
@@ -2491,17 +2491,17 @@
//( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )
return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year);
}
-
+
if (is_numeric($v) && strlen($v) !== 8) return $v;
- if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|",
+ if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|",
($v), $rr)) return false;
if ($rr[1] <= TIMESTAMP_FIRST_YEAR) return 0;
// h-m-s-MM-DD-YY
return @adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]);
}
-
+
/**
* Also in ADORecordSet.
* @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format
@@ -2515,18 +2515,18 @@
//( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )
return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year);
}
-
- if (!preg_match(
- "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ ,-]*(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|",
+
+ if (!preg_match(
+ "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ ,-]*(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|",
($v), $rr)) return false;
-
+
if ($rr[1] <= TIMESTAMP_FIRST_YEAR && $rr[2]<= 1) return 0;
-
+
// h-m-s-MM-DD-YY
if (!isset($rr[5])) return adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]);
return @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]);
}
-
+
/**
* Also in ADORecordSet.
*
@@ -2537,7 +2537,7 @@
*
* @return a date formated as user desires
*/
-
+
function UserDate($v,$fmt='Y-m-d',$gmt=false)
{
$tt = $this->UnixDate($v);
@@ -2547,11 +2547,11 @@
else if ($tt == 0) return $this->emptyDate;
else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR
}
-
+
return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);
-
+
}
-
+
/**
*
* @param v is the character timestamp in YYYY-MM-DD hh:mm:ss format
@@ -2570,19 +2570,19 @@
if ($tt == 0) return $this->emptyTimeStamp;
return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);
}
-
+
function escape($s,$magic_quotes=false)
{
return $this->addq($s,$magic_quotes);
}
-
+
/**
- * Quotes a string, without prefixing nor appending quotes.
+ * Quotes a string, without prefixing nor appending quotes.
*/
function addq($s,$magic_quotes=false)
{
if (!$magic_quotes) {
-
+
if ($this->replaceQuote[0] == '\\'){
// only since php 4.0.5
$s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
@@ -2590,10 +2590,10 @@
}
return str_replace("'",$this->replaceQuote,$s);
}
-
+
// undo magic quotes for "
$s = str_replace('\\"','"',$s);
-
+
if ($this->replaceQuote == "\\'") // ' already quoted, no need to change anything
return $s;
else {// change \' to '' for sybase/mssql
@@ -2601,12 +2601,12 @@
return str_replace("\\'",$this->replaceQuote,$s);
}
}
-
+
/**
* Correctly quotes a string so that all strings are escaped. We prefix and append
* to the string single-quotes.
* An example is $db->qstr("Don't bother",magic_quotes_runtime());
- *
+ *
* @param s the string to quote
* @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc().
* This undoes the stupidity of magic quotes for GPC.
@@ -2614,9 +2614,9 @@
* @return quoted string to be sent back to database
*/
function qstr($s,$magic_quotes=false)
- {
+ {
if (!$magic_quotes) {
-
+
if ($this->replaceQuote[0] == '\\'){
// only since php 4.0.5
$s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
@@ -2624,10 +2624,10 @@
}
return "'".str_replace("'",$this->replaceQuote,$s)."'";
}
-
+
// undo magic quotes for "
$s = str_replace('\\"','"',$s);
-
+
if ($this->replaceQuote == "\\'") // ' already quoted, no need to change anything
return "'$s'";
else {// change \' to '' for sybase/mssql
@@ -2635,11 +2635,11 @@
return "'".str_replace("\\'",$this->replaceQuote,$s)."'";
}
}
-
-
+
+
/**
- * Will select the supplied $page number from a recordset, given that it is paginated in pages of
- * $nrows rows per page. It also saves two boolean values saying if the given page is the first
+ * Will select the supplied $page number from a recordset, given that it is paginated in pages of
+ * $nrows rows per page. It also saves two boolean values saying if the given page is the first
* and/or last one of the recordset. Added by Iv疣 Oliva to provide recordset pagination.
*
* See readme.htm#ex8 for an example of usage.
@@ -2654,7 +2654,7 @@
* NOTE: phpLens uses a different algorithm and does not use PageExecute().
*
*/
- function PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0)
+ function PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0)
{
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
@@ -2662,11 +2662,11 @@
else $rs = _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache);
return $rs;
}
-
-
+
+
/**
- * Will select the supplied $page number from a recordset, given that it is paginated in pages of
- * $nrows rows per page. It also saves two boolean values saying if the given page is the first
+ * Will select the supplied $page number from a recordset, given that it is paginated in pages of
+ * $nrows rows per page. It also saves two boolean values saying if the given page is the first
* and/or last one of the recordset. Added by Iv疣 Oliva to provide recordset pagination.
*
* @param secs2cache seconds to cache data, set to 0 to force query
@@ -2676,11 +2676,11 @@
* @param [inputarr] array of bind variables
* @return the recordset ($rs->databaseType == 'array')
*/
- function CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false)
+ function CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false)
{
/*switch($this->dataProvider) {
case 'postgres':
- case 'mysql':
+ case 'mysql':
break;
default: $secs2cache = 0; break;
}*/
@@ -2689,67 +2689,67 @@
}
} // end class ADOConnection
-
-
-
- //==============================================================================================
+
+
+
+ //==============================================================================================
// CLASS ADOFetchObj
- //==============================================================================================
-
+ //==============================================================================================
+
/**
* Internal placeholder for record objects. Used by ADORecordSet->FetchObj().
*/
class ADOFetchObj {
};
-
- //==============================================================================================
+
+ //==============================================================================================
// CLASS ADORecordSet_empty
- //==============================================================================================
-
+ //==============================================================================================
+
class ADODB_Iterator_empty implements Iterator {
-
+
private $rs;
-
- function __construct($rs)
+
+ function __construct($rs)
{
$this->rs = $rs;
}
- function rewind()
+ function rewind()
{
}
-
- function valid()
+
+ function valid()
{
return !$this->rs->EOF;
}
-
- function key()
+
+ function key()
{
return false;
}
-
- function current()
+
+ function current()
{
return false;
}
-
- function next()
+
+ function next()
{
}
-
+
function __call($func, $params)
{
return call_user_func_array(array($this->rs, $func), $params);
}
-
+
function hasMore()
{
return false;
}
-
+
}
-
+
/**
* Lightweight recordset when there are no records to be returned
*/
@@ -2770,60 +2770,60 @@
function Init() {}
function getIterator() {return new ADODB_Iterator_empty($this);}
}
-
- //==============================================================================================
+
+ //==============================================================================================
// DATE AND TIME FUNCTIONS
- //==============================================================================================
+ //==============================================================================================
if (!defined('ADODB_DATE_VERSION')) include(ADODB_DIR.'/adodb-time.inc.php');
-
- //==============================================================================================
+
+ //==============================================================================================
// CLASS ADORecordSet
- //==============================================================================================
+ //==============================================================================================
class ADODB_Iterator implements Iterator {
-
+
private $rs;
-
- function __construct($rs)
+
+ function __construct($rs)
{
$this->rs = $rs;
}
- function rewind()
+ function rewind()
{
$this->rs->MoveFirst();
}
-
- function valid()
+
+ function valid()
{
return !$this->rs->EOF;
}
-
- function key()
+
+ function key()
{
return $this->rs->_currentRow;
}
-
- function current()
+
+ function current()
{
- return $this->rs->fields;
+ return $this->rs->FetchObject(false);// $this->rs->fields;
}
-
- function next()
+
+ function next()
{
$this->rs->MoveNext();
}
-
+
function __call($func, $params)
{
return call_user_func_array(array($this->rs, $func), $params);
}
-
-
+
+
function hasMore()
{
return !$this->rs->EOF;
}
-
+
}
@@ -2836,7 +2836,7 @@
*/
class ADORecordSet implements IteratorAggregate {
/*
- * public variables
+ * public variables
*/
var $dataProvider = "native";
var $fields = false; /// holds the current row data
@@ -2844,8 +2844,8 @@
/// in other words, we use a text area for editing.
var $canSeek = false; /// indicates that seek is supported
var $sql; /// sql text
- var $EOF = false; /// Indicates that the current record position is after the last record in a Recordset object.
-
+ var $EOF = false; /// Indicates that the current record position is after the last record in a Recordset object.
+
var $emptyTimeStamp = '&nbsp;'; /// what to display when $time==0
var $emptyDate = '&nbsp;'; /// what to display when $time==0
var $debug = false;
@@ -2855,7 +2855,7 @@
var $fetchMode; /// default fetch mode
var $connection = false; /// the parent connection
/*
- * private variables
+ * private variables
*/
var $_numOfRows = -1; /** number of rows, or -1 */
var $_numOfFields = -1; /** number of fields in recordset */
@@ -2865,38 +2865,38 @@
var $_inited = false; /** Init() should only be called once */
var $_obj; /** Used by FetchObj */
var $_names; /** Used by FetchObj */
-
+
var $_currentPage = -1; /** Added by Iv疣 Oliva to implement recordset pagination */
var $_atFirstPage = false; /** Added by Iv疣 Oliva to implement recordset pagination */
var $_atLastPage = false; /** Added by Iv疣 Oliva to implement recordset pagination */
- var $_lastPageNo = -1;
+ var $_lastPageNo = -1;
var $_maxRecordCount = 0;
var $datetime = false;
-
+
/**
* Constructor
*
* @param queryID this is the queryID returned by ADOConnection->_query()
*
*/
- function ADORecordSet($queryID)
+ function ADORecordSet($queryID)
{
$this->_queryID = $queryID;
}
-
- function getIterator()
+
+ function getIterator()
{
return new ADODB_Iterator($this);
}
-
+
/* this is experimental - i don't really know what to return... */
function __toString()
{
include_once(ADODB_DIR.'/toexport.inc.php');
return _adodb_export($this,',',',',false,true);
}
-
-
+
+
function Init()
{
if ($this->_inited) return;
@@ -2907,7 +2907,7 @@
$this->_numOfFields = 0;
}
if ($this->_numOfRows != 0 && $this->_numOfFields && $this->_currentRow == -1) {
-
+
$this->_currentRow = 0;
if ($this->EOF = ($this->_fetch() === false)) {
$this->_numOfRows = 0; // _numOfRows could be -1
@@ -2916,11 +2916,11 @@
$this->EOF = true;
}
}
-
-
+
+
/**
* Generate a SELECT tag string from a recordset, and return the string.
- * If the recordset has 2 cols, we treat the 1st col as the containing
+ * If the recordset has 2 cols, we treat the 1st col as the containing
* the text to display to the user, and 2nd col as the return value. Default
* strings are compared with the FIRST column.
*
@@ -2931,7 +2931,7 @@
* @param [size] #rows to show for listbox. not used by popup
* @param [selectAttr] additional attributes to defined for SELECT tag.
* useful for holding javascript onChange='...' handlers.
- & @param [compareFields0] when we have 2 cols in recordset, we compare the defstr with
+ & @param [compareFields0] when we have 2 cols in recordset, we compare the defstr with
* column 0 (1st col) if this is true. This is not documented.
*
* @return HTML
@@ -2946,22 +2946,22 @@
return _adodb_getmenu($this, $name,$defstr,$blank1stItem,$multiple,
$size, $selectAttr,$compareFields0);
}
-
-
+
+
/**
* Generate a SELECT tag string from a recordset, and return the string.
- * If the recordset has 2 cols, we treat the 1st col as the containing
+ * If the recordset has 2 cols, we treat the 1st col as the containing
* the text to display to the user, and 2nd col as the return value. Default
* strings are compared with the SECOND column.
*
*/
- function GetMenu2($name,$defstr='',$blank1stItem=true,$multiple=false,$size=0, $selectAttr='')
+ function GetMenu2($name,$defstr='',$blank1stItem=true,$multiple=false,$size=0, $selectAttr='')
{
return $this->GetMenu($name,$defstr,$blank1stItem,$multiple,
$size, $selectAttr,false);
}
-
+
/*
Grouped Menu
*/
@@ -2981,7 +2981,7 @@
*
* @return an array indexed by the rows (0-based) from the recordset
*/
- function GetArray($nRows = -1)
+ function GetArray($nRows = -1)
{
global $ADODB_EXTENSION; if ($ADODB_EXTENSION) {
$results = adodb_getall($this,$nRows);
@@ -2996,13 +2996,13 @@
}
return $results;
}
-
+
function GetAll($nRows = -1)
{
$arr = $this->GetArray($nRows);
return $arr;
}
-
+
/*
* Some databases allow multiple recordsets to be returned. This function
* will return true if there is a next recordset, or false if no more.
@@ -3011,9 +3011,9 @@
{
return false;
}
-
+
/**
- * return recordset as a 2-dimensional array.
+ * return recordset as a 2-dimensional array.
* Helper function for ADOConnection->SelectLimit()
*
* @param offset is the row to start calculations from (1-based)
@@ -3021,26 +3021,26 @@
*
* @return an array indexed by the rows (0-based) from the recordset
*/
- function GetArrayLimit($nrows,$offset=-1)
- {
+ function GetArrayLimit($nrows,$offset=-1)
+ {
if ($offset <= 0) {
$arr = $this->GetArray($nrows);
return $arr;
- }
-
+ }
+
$this->Move($offset);
-
+
$results = array();
$cnt = 0;
while (!$this->EOF && $nrows != $cnt) {
$results[$cnt++] = $this->fields;
$this->MoveNext();
}
-
+
return $results;
}
-
-
+
+
/**
* Synonym for GetArray() for compatibility with ADO.
*
@@ -3048,15 +3048,15 @@
*
* @return an array indexed by the rows (0-based) from the recordset
*/
- function GetRows($nRows = -1)
+ function GetRows($nRows = -1)
{
$arr = $this->GetArray($nRows);
return $arr;
}
-
+
/**
- * return whole recordset as a 2-dimensional associative array if there are more than 2 columns.
- * The first column is treated as the key and is not included in the array.
+ * return whole recordset as a 2-dimensional associative array if there are more than 2 columns.
+ * The first column is treated as the key and is not included in the array.
* If there is only 2 columns, it will return a 1 dimensional array of key-value pairs unless
* $force_array == true.
*
@@ -3064,16 +3064,16 @@
* array is returned, otherwise a 2 dimensional array is returned. If this sounds confusing,
* read the source.
*
- * @param [first2cols] means if there are more than 2 cols, ignore the remaining cols and
+ * @param [first2cols] means if there are more than 2 cols, ignore the remaining cols and
* instead of returning array[col0] => array(remaining cols), return array[col0] => col1
*
- * @return an associative array indexed by the first column of the array,
+ * @return an associative array indexed by the first column of the array,
* or false if the data has less than 2 cols.
*/
- function GetAssoc($force_array = false, $first2cols = false)
+ function GetAssoc($force_array = false, $first2cols = false)
{
global $ADODB_EXTENSION;
-
+
$cols = $this->_numOfFields;
if ($cols < 2) {
$false = false;
@@ -3081,7 +3081,7 @@
}
$numIndex = isset($this->fields[0]);
$results = array();
-
+
if (!$first2cols && ($cols > 2 || $force_array)) {
if ($ADODB_EXTENSION) {
if ($numIndex) {
@@ -3098,7 +3098,7 @@
foreach($keys as $key) {
$sliced_array[$key] = $this->fields[$key];
}
-
+
$results[trim(reset($this->fields))] = $sliced_array;
adodb_movenext($this);
}
@@ -3118,7 +3118,7 @@
foreach($keys as $key) {
$sliced_array[$key] = $this->fields[$key];
}
-
+
$results[trim(reset($this->fields))] = $sliced_array;
$this->MoveNext();
}
@@ -3137,7 +3137,7 @@
while (!$this->EOF) {
// some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
$v1 = trim(reset($this->fields));
- $v2 = ''.next($this->fields);
+ $v2 = ''.next($this->fields);
$results[$v1] = $v2;
adodb_movenext($this);
}
@@ -3153,19 +3153,19 @@
while (!$this->EOF) {
// some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
$v1 = trim(reset($this->fields));
- $v2 = ''.next($this->fields);
+ $v2 = ''.next($this->fields);
$results[$v1] = $v2;
$this->MoveNext();
}
}
}
}
-
+
$ref = $results; # workaround accelerator incompat with PHP 4.4 :(
- return $ref;
+ return $ref;
}
-
-
+
+
/**
*
* @param v is the character timestamp in YYYY-MM-DD hh:mm:ss format
@@ -3182,8 +3182,8 @@
if ($tt === 0) return $this->emptyTimeStamp;
return adodb_date($fmt,$tt);
}
-
-
+
+
/**
* @param v is the character date in YYYY-MM-DD format, returned by database
* @param fmt is the format to apply to it, using date()
@@ -3200,8 +3200,8 @@
}
return adodb_date($fmt,$tt);
}
-
-
+
+
/**
* @param $v is a date string in YYYY-MM-DD format
*
@@ -3211,8 +3211,8 @@
{
return ADOConnection::UnixDate($v);
}
-
+
/**
* @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format
*
@@ -3222,8 +3222,8 @@
{
return ADOConnection::UnixTimeStamp($v);
}
-
-
+
+
/**
* PEAR DB Compat - do not use internally
*/
@@ -3231,8 +3231,8 @@
{
return $this->Close();
}
-
-
+
+
/**
* PEAR DB compat, number of rows
*/
@@ -3240,8 +3240,8 @@
{
return $this->_numOfRows;
}
-
-
+
+
/**
* PEAR DB compat, number of cols
*/
@@ -3249,9 +3249,9 @@
{
return $this->_numOfFields;
}
-
+
/**
- * Fetch a row, returning false if no more rows.
+ * Fetch a row, returning false if no more rows.
* This is PEAR DB compat mode.
*
* @return false or array containing the current record
@@ -3267,10 +3267,10 @@
if (!$this->_fetch()) $this->EOF = true;
return $arr;
}
-
-
+
+
/**
- * Fetch a row, returning PEAR_Error if no more rows.
+ * Fetch a row, returning PEAR_Error if no more rows.
* This is PEAR DB compat mode.
*
* @return DB_OK or error object
@@ -3282,26 +3282,26 @@
$this->MoveNext();
return 1; // DB_OK
}
-
-
+
+
/**
* Move to the first row in the recordset. Many databases do NOT support this.
*
* @return true or false
*/
- function MoveFirst()
+ function MoveFirst()
{
if ($this->_currentRow == 0) return true;
- return $this->Move(0);
- }
+ return $this->Move(0);
+ }
-
+
/**
- * Move to the last row in the recordset.
+ * Move to the last row in the recordset.
*
* @return true or false
*/
- function MoveLast()
+ function MoveLast()
{
if ($this->_numOfRows >= 0) return $this->Move($this->_numOfRows-1);
if ($this->EOF) return false;
@@ -3313,14 +3313,14 @@
$this->EOF = false;
return true;
}
-
-
+
+
/**
* Move to next record in the recordset.
*
* @return true if there still rows available, or false if there are no more rows (EOF).
*/
- function MoveNext()
+ function MoveNext()
{
if (!$this->EOF) {
$this->_currentRow++;
@@ -3336,8 +3336,8 @@
*/
return false;
}
-
-
+
+
/**
* Random access to a specific row in the recordset. Some databases do not support
* access to previous rows in the databases (no scrolling backwards).
@@ -3346,15 +3346,20 @@
*
* @return true if there still rows available, or false if there are no more rows (EOF).
*/
- function Move($rowNumber = 0)
+ function Move($rowNumber = 0)
{
+ if ($this->_numOfRows == 0) {
+ $this->EOF = true;
+ $this->fields = false;
+ return false;
+ }
$this->EOF = false;
if ($rowNumber == $this->_currentRow) return true;
if ($rowNumber >= $this->_numOfRows)
if ($this->_numOfRows != -1) $rowNumber = $this->_numOfRows-2;
-
- if ($this->canSeek) {
-
+
+ if ($this->canSeek) {
+
if ($this->_seek($rowNumber)) {
$this->_currentRow = $rowNumber;
if ($this->_fetch()) {
@@ -3372,26 +3377,26 @@
adodb_movenext($this);
}
} else {
-
+
while (! $this->EOF && $this->_currentRow < $rowNumber) {
$this->_currentRow++;
-
+
if (!$this->_fetch()) $this->EOF = true;
}
}
return !($this->EOF);
}
-
- $this->fields = false;
+
+ $this->fields = false;
$this->EOF = true;
return false;
}
-
-
+
+
/**
* Get the value of a field in the current row by column name.
* Will not work if ADODB_FETCH_MODE is set to ADODB_FETCH_NUM.
- *
+ *
* @param colname is the field to access
*
* @return the value of $colname column
@@ -3400,7 +3405,7 @@
{
return $this->fields[$colname];
}
-
+
function GetAssocKeys($upper=true)
{
$this->bind = array();
@@ -3410,7 +3415,7 @@
else $this->bind[($upper) ? strtoupper($o->name) : strtolower($o->name)] = $i;
}
}
-
+
/**
* Use associative array to get fields array for databases that do not support
* associative arrays. Submitted by Paolo S. Asioli paolo.asioli#libero.it
@@ -3424,44 +3429,44 @@
{
$record = array();
// if (!$this->fields) return $record;
-
+
if (!$this->bind) {
$this->GetAssocKeys($upper);
}
-
+
foreach($this->bind as $k => $v) {
$record[$k] = $this->fields[$v];
}
return $record;
}
-
-
+
+
/**
* Clean up recordset
*
* @return true or false
*/
- function Close()
+ function Close()
{
// free connection object - this seems to globally free the object
// and not merely the reference, so don't do this...
- // $this->connection = false;
+ // $this->connection = false;
if (!$this->_closed) {
$this->_closed = true;
- return $this->_close();
+ return $this->_close();
} else
return true;
}
-
+
/**
- * synonyms RecordCount and RowCount
+ * synonyms RecordCount and RowCount
*
* @return the number of rows or -1 if this is not supported
*/
function RecordCount() {return $this->_numOfRows;}
-
-
+
+
/*
* If we are using PageExecute(), this will return the maximum possible rows
* that can be returned when paging a recordset.
@@ -3470,15 +3475,15 @@
{
return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount();
}
-
+
/**
- * synonyms RecordCount and RowCount
+ * synonyms RecordCount and RowCount
*
* @return the number of rows or -1 if this is not supported
*/
- function RowCount() {return $this->_numOfRows;}
-
+ function RowCount() {return $this->_numOfRows;}
+
/**
* Portable RecordCount. Pablo Roca <pabloroca@mvps.org>
*
@@ -3486,39 +3491,39 @@
*
* But aware possible problems in multiuser environments. For better speed the table
* must be indexed by the condition. Heavy test this before deploying.
- */
+ */
function PO_RecordCount($table="", $condition="") {
-
+
$lnumrows = $this->_numOfRows;
// the database doesn't support native recordcount, so we do a workaround
if ($lnumrows == -1 && $this->connection) {
IF ($table) {
- if ($condition) $condition = " WHERE " . $condition;
+ if ($condition) $condition = " WHERE " . $condition;
$resultrows = $this->connection->Execute("SELECT COUNT(*) FROM $table $condition");
if ($resultrows) $lnumrows = reset($resultrows->fields);
}
}
return $lnumrows;
}
-
-
+
+
/**
* @return the current row in the recordset. If at EOF, will return the last row. 0-based.
*/
function CurrentRow() {return $this->_currentRow;}
-
+
/**
* synonym for CurrentRow -- for ADO compat
*
* @return the current row in the recordset. If at EOF, will return the last row. 0-based.
*/
function AbsolutePosition() {return $this->_currentRow;}
-
+
/**
* @return the number of columns in the recordset. Some databases will set this to 0
* if no records are returned, others will return the number of columns in the query.
*/
- function FieldCount() {return $this->_numOfFields;}
+ function FieldCount() {return $this->_numOfFields;}
/**
@@ -3528,14 +3533,14 @@
*
* @return the ADOFieldObject for that column, or false.
*/
- function FetchField($fieldoffset = -1)
+ function FetchField($fieldoffset = -1)
{
// must be defined by child class
-
+
$false = false;
return $false;
- }
-
+ }
+
/**
* Get the ADOFieldObjects of all columns in an array.
*
@@ -3543,11 +3548,11 @@
function FieldTypesArray()
{
$arr = array();
- for ($i=0, $max=$this->_numOfFields; $i < $max; $i++)
+ for ($i=0, $max=$this->_numOfFields; $i < $max; $i++)
$arr[] = $this->FetchField($i);
return $arr;
}
-
+
/**
* Return the fields array of the current row as an object for convenience.
* The default case is lowercase field names.
@@ -3559,16 +3564,16 @@
$o = $this->FetchObject(false);
return $o;
}
-
+
/**
* Return the fields array of the current row as an object for convenience.
* The default case is uppercase.
- *
+ *
* @param $isupper to set the object property names to uppercase
*
* @return the object with the properties set to the fields of the current row
*/
- function FetchObject($isupper=true)
+ function FetchObject($isupper=false)
{
if (empty($this->_obj)) {
$this->_obj = new ADOFetchObj();
@@ -3581,21 +3586,22 @@
$i = 0;
if (PHP_VERSION >= 5) $o = clone($this->_obj);
else $o = $this->_obj;
-
+
for ($i=0; $i <$this->_numOfFields; $i++) {
$name = $this->_names[$i];
if ($isupper) $n = strtoupper($name);
- else $n = $name;
-
- $o->$n = $this->Fields($name);
+ else $n = strtolower($name);
+
+ if (strlen($name) != 0)
+ $o->$n = $this->Fields($name);
}
return $o;
}
-
+
/**
* Return the fields array of the current row as an object for convenience.
* The default is lower-case field names.
- *
+ *
* @return the object with the properties set to the fields of the current row,
* or false if EOF
*
@@ -3606,12 +3612,12 @@
$o = $this->FetchNextObject(false);
return $o;
}
-
-
+
+
/**
- * Return the fields array of the current row as an object for convenience.
+ * Return the fields array of the current row as an object for convenience.
* The default is upper case field names.
- *
+ *
* @param $isupper to set the object property names to uppercase
*
* @return the object with the properties set to the fields of the current row,
@@ -3623,14 +3629,14 @@
{
$o = false;
if ($this->_numOfRows != 0 && !$this->EOF) {
- $o = $this->FetchObject($isupper);
+ $o = $this->FetchObject($isupper);
$this->_currentRow++;
if ($this->_fetch()) return $o;
}
$this->EOF = true;
return $o;
}
-
+
/**
* Get the metatype of the column. This is used for formatting. This is because
* many databases use different names for the same type, so we transform the original
@@ -3641,8 +3647,8 @@
* fields bigger than a certain size as a 'B' (blob).
* @param fieldobj is the field object returned by the database driver. Can hold
* additional info (eg. primary_key for mysql).
- *
- * @return the general type of the data:
+ *
+ * @return the general type of the data:
* C for character < 250 chars
* X for teXt (>= 250 chars)
* B for Binary
@@ -3652,8 +3658,8 @@
* L for logical/Boolean
* I for integer
* R for autoincrement counter/integer
- *
*
+ *
*/
function MetaType($t,$len=-1,$fieldobj=false)
{
@@ -3707,7 +3713,7 @@
'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql
##
'BOOL' => 'L',
- 'BOOLEAN' => 'L',
+ 'BOOLEAN' => 'L',
'BIT' => 'L',
'L' => 'L',
##
@@ -3740,21 +3746,21 @@
'NUM' => 'N',
'NUMERIC' => 'N',
'MONEY' => 'N',
-
+
## informix 9.2
- 'SQLINT' => 'I',
- 'SQLSERIAL' => 'I',
- 'SQLSMINT' => 'I',
- 'SQLSMFLOAT' => 'N',
- 'SQLFLOAT' => 'N',
- 'SQLMONEY' => 'N',
- 'SQLDECIMAL' => 'N',
- 'SQLDATE' => 'D',
- 'SQLVCHAR' => 'C',
- 'SQLCHAR' => 'C',
- 'SQLDTIME' => 'T',
- 'SQLINTERVAL' => 'N',
- 'SQLBYTES' => 'B',
+ 'SQLINT' => 'I',
+ 'SQLSERIAL' => 'I',
+ 'SQLSMINT' => 'I',
+ 'SQLSMFLOAT' => 'N',
+ 'SQLFLOAT' => 'N',
+ 'SQLMONEY' => 'N',
+ 'SQLDECIMAL' => 'N',
+ 'SQLDATE' => 'D',
+ 'SQLVCHAR' => 'C',
+ 'SQLCHAR' => 'C',
+ 'SQLDTIME' => 'T',
+ 'SQLINTERVAL' => 'N',
+ 'SQLBYTES' => 'B',
'SQLTEXT' => 'X',
## informix 10
"SQLINT8" => 'I8',
@@ -3764,46 +3770,46 @@
"SQLLVARCHAR" => 'X',
"SQLBOOL" => 'L'
);
-
+
$tmap = false;
$t = strtoupper($t);
$tmap = (isset($typeMap[$t])) ? $typeMap[$t] : 'N';
switch ($tmap) {
case 'C':
-
- // is the char field is too long, return as text field...
+
+ // is the char field is too long, return as text field...
if ($this->blobSize >= 0) {
if ($len > $this->blobSize) return 'X';
} else if ($len > 250) {
return 'X';
}
return 'C';
-
+
case 'I':
if (!empty($fieldobj->primary_key)) return 'R';
return 'I';
-
+
case false:
return 'N';
-
+
case 'B':
- if (isset($fieldobj->binary))
+ if (isset($fieldobj->binary))
return ($fieldobj->binary) ? 'B' : 'X';
return 'B';
-
+
case 'D':
if (!empty($this->connection) && !empty($this->connection->datetime)) return 'T';
return 'D';
-
- default:
+
+ default:
if ($t == 'LONG' && $this->dataProvider == 'oci8') return 'B';
return $tmap;
}
}
-
-
+
+
function _close() {}
-
+
/**
* set/returns the current recordset page when paginating
*/
@@ -3812,7 +3818,7 @@
if ($page != -1) $this->_currentPage = $page;
return $this->_currentPage;
}
-
+
/**
* set/returns the status of the atFirstPage flag when paginating
*/
@@ -3821,13 +3827,13 @@
if ($status != false) $this->_atFirstPage = $status;
return $this->_atFirstPage;
}
-
+
function LastPageNo($page = false)
{
if ($page != false) $this->_lastPageNo = $page;
return $this->_lastPageNo;
}
-
+
/**
* set/returns the status of the atLastPage flag when paginating
*/
@@ -3838,18 +3844,18 @@
}
} // end class ADORecordSet
-
- //==============================================================================================
+
+ //==============================================================================================
// CLASS ADORecordSet_array
- //==============================================================================================
-
+ //==============================================================================================
+
/**
* This class encapsulates the concept of a recordset created in memory
* as an array. This is useful for the creation of cached recordsets.
- *
+ *
* Note that the constructor is different from the standard ADORecordSet
*/
-
+
class ADORecordSet_array extends ADORecordSet
{
var $databaseType = 'array';
@@ -3871,32 +3877,32 @@
function ADORecordSet_array($fakeid=1)
{
global $ADODB_FETCH_MODE,$ADODB_COMPAT_FETCH;
-
+
// fetch() on EOF does not delete $this->fields
$this->compat = !empty($ADODB_COMPAT_FETCH);
- $this->ADORecordSet($fakeid); // fake queryID
+ $this->ADORecordSet($fakeid); // fake queryID
$this->fetchMode = $ADODB_FETCH_MODE;
}
-
+
function _transpose($addfieldnames=true)
{
global $ADODB_INCLUDED_LIB;
-
+
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
$hdr = true;
-
+
$fobjs = $addfieldnames ? $this->_fieldobjects : false;
adodb_transpose($this->_array, $newarr, $hdr, $fobjs);
//adodb_pr($newarr);
-
+
$this->_skiprow1 = false;
$this->_array = $newarr;
$this->_colnames = $hdr;
-
+
adodb_probetypes($newarr,$this->_types);
-
+
$this->_fieldobjects = array();
-
+
foreach($hdr as $k => $name) {
$f = new ADOFieldObject();
$f->name = $name;
@@ -3905,18 +3911,18 @@
$this->_fieldobjects[] = $f;
}
$this->fields = reset($this->_array);
-
+
$this->_initrs();
-
+
}
-
+
/**
* Setup the array.
*
* @param array is a 2-dimensional array holding the data.
- * The first row should hold the column names
+ * The first row should hold the column names
* unless paramter $colnames is used.
- * @param typearr holds an array of types. These are the same types
+ * @param typearr holds an array of types. These are the same types
* used in MetaTypes (C,B,L,I,N).
* @param [colnames] array of column names. If set, then the first row of
* $array should not hold the column names.
@@ -3924,7 +3930,7 @@
function InitArray($array,$typearr,$colnames=false)
{
$this->_array = $array;
- $this->_types = $typearr;
+ $this->_types = $typearr;
if ($colnames) {
$this->_skiprow1 = false;
$this->_colnames = $colnames;
@@ -3938,7 +3944,7 @@
* Setup the Array and datatype file objects
*
* @param array is a 2-dimensional array holding the data.
- * The first row should hold the column names
+ * The first row should hold the column names
* unless paramter $colnames is used.
* @param fieldarr holds an array of ADOFieldObject's.
*/
@@ -3948,10 +3954,10 @@
$this->_skiprow1= false;
if ($fieldarr) {
$this->_fieldobjects = $fieldarr;
- }
+ }
$this->Init();
}
-
+
function GetArray($nRows=-1)
{
if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) {
@@ -3961,21 +3967,21 @@
return $arr;
}
}
-
+
function _initrs()
{
$this->_numOfRows = sizeof($this->_array);
if ($this->_skiprow1) $this->_numOfRows -= 1;
-
+
$this->_numOfFields =(isset($this->_fieldobjects)) ?
sizeof($this->_fieldobjects):sizeof($this->_types);
}
-
+
/* Use associative array to get fields array */
function Fields($colname)
{
$mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode;
-
+
if ($mode & ADODB_FETCH_ASSOC) {
if (!isset($this->fields[$colname]) && !is_null($this->fields[$colname])) $colname = strtolower($colname);
return $this->fields[$colname];
@@ -3989,8 +3995,8 @@
}
return $this->fields[$this->bind[strtoupper($colname)]];
}
-
- function FetchField($fieldOffset = -1)
+
+ function FetchField($fieldOffset = -1)
{
if (isset($this->_fieldobjects)) {
return $this->_fieldobjects[$fieldOffset];
@@ -3999,10 +4005,10 @@
$o->name = $this->_colnames[$fieldOffset];
$o->type = $this->_types[$fieldOffset];
$o->max_length = -1; // length not known
-
+
return $o;
}
-
+
function _seek($row)
{
if (sizeof($this->_array) && 0 <= $row && $row < $this->_numOfRows) {
@@ -4013,31 +4019,31 @@
}
return false;
}
-
- function MoveNext()
+
+ function MoveNext()
{
- if (!$this->EOF) {
+ if (!$this->EOF) {
$this->_currentRow++;
-
+
$pos = $this->_currentRow;
-
+
if ($this->_numOfRows <= $pos) {
if (!$this->compat) $this->fields = false;
} else {
if ($this->_skiprow1) $pos += 1;
$this->fields = $this->_array[$pos];
return true;
- }
+ }
$this->EOF = true;
}
-
+
return false;
- }
-
+ }
+
function _fetch()
{
$pos = $this->_currentRow;
-
+
if ($this->_numOfRows <= $pos) {
if (!$this->compat) $this->fields = false;
return false;
@@ -4046,41 +4052,41 @@
$this->fields = $this->_array[$pos];
return true;
}
-
- function _close()
+
+ function _close()
{
- return true;
+ return true;
}
-
+
} // ADORecordSet_array
- //==============================================================================================
+ //==============================================================================================
// HELPER FUNCTIONS
- //==============================================================================================
-
+ //==============================================================================================
+
/**
* Synonym for ADOLoadCode. Private function. Do not use.
*
* @deprecated
*/
- function ADOLoadDB($dbType)
- {
+ function ADOLoadDB($dbType)
+ {
return ADOLoadCode($dbType);
}
-
+
/**
* Load the code for a specific database driver. Private function. Do not use.
*/
- function ADOLoadCode($dbType)
+ function ADOLoadCode($dbType)
{
global $ADODB_LASTDB;
-
+
if (!$dbType) return false;
$db = strtolower($dbType);
switch ($db) {
- case 'ado':
+ case 'ado':
if (PHP_VERSION >= 5) $db = 'ado5';
- $class = 'ado';
+ $class = 'ado';
break;
case 'ifx':
case 'maxsql': $class = $db = 'mysqlt'; break;
@@ -4090,12 +4096,12 @@
default:
$class = $db; break;
}
-
+
$file = ADODB_DIR."/drivers/adodb-".$db.".inc.php";
@include_once($file);
$ADODB_LASTDB = $class;
if (class_exists("ADODB_" . $class)) return $class;
-
+
//ADOConnection::outp(adodb_pr(get_declared_classes(),true));
if (!file_exists($file)) ADOConnection::outp("Missing file: $file");
else ADOConnection::outp("Syntax error in file: $file");
@@ -4110,7 +4116,7 @@
$tmp = ADONewConnection($db);
return $tmp;
}
-
+
/**
* Instantiate a new Connection class for a specific database driver.
*
@@ -4122,7 +4128,7 @@
function ADONewConnection($db='')
{
GLOBAL $ADODB_NEWCONNECTION, $ADODB_LASTDB;
-
+
if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);
$errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false;
$false = false;
@@ -4141,7 +4147,7 @@
if ($at2 !== FALSE) {
$dsna['host'] = '';
}
-
+
if (strncmp($origdsn,'pdo',3) == 0) {
$sch = explode('_',$dsna['scheme']);
if (sizeof($sch)>1) {
@@ -4150,14 +4156,14 @@
$dsna['scheme'] = 'pdo';
}
}
-
+
$db = @$dsna['scheme'];
if (!$db) return $false;
$dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : '';
$dsna['user'] = isset($dsna['user']) ? rawurldecode($dsna['user']) : '';
$dsna['pass'] = isset($dsna['pass']) ? rawurldecode($dsna['pass']) : '';
$dsna['path'] = isset($dsna['path']) ? rawurldecode(substr($dsna['path'],1)) : ''; # strip off initial /
-
+
if (isset($dsna['query'])) {
$opt1 = explode('&',$dsna['query']);
foreach($opt1 as $k => $v) {
@@ -4179,12 +4185,12 @@
$obj = $ADODB_NEWCONNECTION($db);
} else {
-
+
if (!isset($ADODB_LASTDB)) $ADODB_LASTDB = '';
if (empty($db)) $db = $ADODB_LASTDB;
-
+
if ($db != $ADODB_LASTDB) $db = ADOLoadCode($db);
-
+
if (!$db) {
if (isset($origdsn)) $db = $origdsn;
if ($errorfn) {
@@ -4195,19 +4201,19 @@
$db,false,$ignore);
} else
ADOConnection::outp( "<p>ADONewConnection: Unable to load database driver '$db'</p>",false);
-
+
return $false;
}
-
+
$cls = 'ADODB_'.$db;
if (!class_exists($cls)) {
adodb_backtrace();
return $false;
}
-
+
$obj = new $cls();
}
-
+
# constructor should not fail
if ($obj) {
if ($errorfn) $obj->raiseErrorFn = $errorfn;
@@ -4244,36 +4250,36 @@
$ok = $obj->PConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
else
$ok = $obj->NConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
-
+
if (!$ok) return $false;
}
}
return $obj;
}
-
-
-
+
+
+
// $perf == true means called by NewPerfMonitor(), otherwise for data dictionary
function _adodb_getdriver($provider,$drivername,$perf=false)
{
switch ($provider) {
- case 'odbtp': if (strncmp('odbtp_',$drivername,6)==0) return substr($drivername,6);
- case 'odbc' : if (strncmp('odbc_',$drivername,5)==0) return substr($drivername,5);
+ case 'odbtp': if (strncmp('odbtp_',$drivername,6)==0) return substr($drivername,6);
+ case 'odbc' : if (strncmp('odbc_',$drivername,5)==0) return substr($drivername,5);
case 'ado' : if (strncmp('ado_',$drivername,4)==0) return substr($drivername,4);
case 'native': break;
default:
return $provider;
}
-
+
switch($drivername) {
case 'mysqlt':
- case 'mysqli':
- $drivername='mysql';
+ case 'mysqli':
+ $drivername='mysql';
break;
case 'postgres7':
case 'postgres8':
- $drivername = 'postgres';
- break;
+ $drivername = 'postgres';
+ break;
case 'firebird15': $drivername = 'firebird'; break;
case 'oracle': $drivername = 'oci8'; break;
case 'access': if ($perf) $drivername = ''; break;
@@ -4285,7 +4291,7 @@
}
return $drivername;
}
-
+
function NewPerfMonitor(&$conn)
{
$false = false;
@@ -4296,10 +4302,10 @@
$class = "Perf_$drivername";
if (!class_exists($class)) return $false;
$perf = new $class($conn);
-
+
return $perf;
}
-
+
function NewDataDictionary(&$conn,$drivername=false)
{
$false = false;
@@ -4322,34 +4328,34 @@
$dict->quote = $conn->nameQuote;
if (!empty($conn->_connectionID))
$dict->serverInfo = $conn->ServerInfo();
-
+
return $dict;
}
-
+
/*
Perform a print_r, with pre tags for better formatting.
*/
function adodb_pr($var,$as_string=false)
{
if ($as_string) ob_start();
-
- if (isset($_SERVER['HTTP_USER_AGENT'])) {
+
+ if (isset($_SERVER['HTTP_USER_AGENT'])) {
echo " <pre>\n";print_r($var);echo "</pre>\n";
} else
print_r($var);
-
+
if ($as_string) {
$s = ob_get_contents();
ob_end_clean();
return $s;
}
}
-
+
/*
Perform a stack-crawl and pretty print it.
-
+
@param printOrArr Pass in a boolean to indicate print, or an $exception->trace array (assumes that print is true then).
@param levels Number of levels to display
*/
Index: drivers/adodb-ado5.inc.php
===================================================================
--- drivers/adodb-ado5.inc.php (revision 1)
+++ drivers/adodb-ado5.inc.php (working copy)
@@ -115,6 +115,7 @@
$this->_connectionID = $dbc;
$dbc->CursorLocation = $this->_cursor_location;
+ $dbc->CommandTimeout = 90; // Added 14 OCT 2008 by djb
return $dbc->State > 0;
} catch (exception $e) {
}
@@ -420,8 +421,16 @@
// absoluteposition doesn't work -- my maths is wrong ?
// $rs->AbsolutePosition->$row-2;
// return true;
- if ($this->_currentRow > $row) return false;
- @$rs->Move((integer)$row - $this->_currentRow-1); //adBookmarkFirst
+ //if ($this->_currentRow > $row) return false; // commented out by DJB
+ $fReturn = $rs->Supports( 0x200 /*adMovePrevious*/ );
+ if (! $fReturn )
+ return false;
+ if ( $row == 0 ) {
+ @$rs->MoveFirst();
+ } else {
+ @$rs->Move((integer)$row - $this->_currentRow-1); //adBookmarkFirst
+ }
+ $this->_currentRow = $row;
return true;
}
@@ -643,7 +652,7 @@
@$rs->MoveNext(); // @ needed for some versions of PHP!
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
- $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
+ $this->fields = array_merge($this->fields, $this->GetRowAssoc(ADODB_ASSOC_CASE));
}
return true;
}
Index: drivers/adodb-ado_mssql.inc.php
===================================================================
--- drivers/adodb-ado_mssql.inc.php (revision 1)
+++ drivers/adodb-ado_mssql.inc.php (working copy)
@@ -46,7 +46,7 @@
function _insertid()
{
- return $this->GetOne('select SCOPE_IDENTITY()');
+ return $this->GetOne('select @@IDENTITY');//@@SCOPE_IDENTITY()');
}
function _affectedrows()

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3353
Default Alt Text
adodb505.patch (107 KB)

Event Timeline