[TASK] Update ADOdb to 5.18 53/28253/5
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Tue, 11 Mar 2014 13:33:19 +0000 (14:33 +0100)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Tue, 11 Mar 2014 22:35:44 +0000 (23:35 +0100)
Update ADOdb to current version 5.18 which fixes various bugs
and adds PHP 5.4 compatibility.

Resolves: #56761
Releases: 6.2
Change-Id: I5d46f52f8beb2407a40a3ee5796b00229b79992f
Reviewed-on: https://review.typo3.org/28253
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
134 files changed:
typo3/sysext/adodb/README.txt [new file with mode: 0644]
typo3/sysext/adodb/adodb/adodb-active-record.inc.php
typo3/sysext/adodb/adodb/adodb-active-recordx.inc.php
typo3/sysext/adodb/adodb/adodb-csvlib.inc.php
typo3/sysext/adodb/adodb/adodb-datadict.inc.php
typo3/sysext/adodb/adodb/adodb-error.inc.php
typo3/sysext/adodb/adodb/adodb-errorhandler.inc.php
typo3/sysext/adodb/adodb/adodb-errorpear.inc.php
typo3/sysext/adodb/adodb/adodb-exceptions.inc.php
typo3/sysext/adodb/adodb/adodb-iterator.inc.php
typo3/sysext/adodb/adodb/adodb-lib.inc.php
typo3/sysext/adodb/adodb/adodb-memcache.lib.inc.php
typo3/sysext/adodb/adodb/adodb-pager.inc.php
typo3/sysext/adodb/adodb/adodb-pear.inc.php
typo3/sysext/adodb/adodb/adodb-perf.inc.php
typo3/sysext/adodb/adodb/adodb-php4.inc.php
typo3/sysext/adodb/adodb/adodb-time.inc.php
typo3/sysext/adodb/adodb/adodb.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-access.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-db2.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-firebird.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-generic.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-ibase.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-informix.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-mssql.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-mssqlnative.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-mysql.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-oci8.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-postgres.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-sapdb.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-sqlite.inc.php
typo3/sysext/adodb/adodb/datadict/datadict-sybase.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-access.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-ado.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-ado5.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-ado_access.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-ado_mssql.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-borland_ibase.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-csv.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-db2.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-db2oci.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-db2ora.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-fbsql.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-firebird.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-ibase.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-informix.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-informix72.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-ldap.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-mssql.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-mssql_n.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-mssqlnative.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-mssqlpo.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-mysql.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-mysqli.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-mysqlpo.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-mysqlt.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-netezza.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-oci8.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-oci805.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-oci8po.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-odbc.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-odbc_db2.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-odbc_mssql.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-odbc_oracle.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-odbtp.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-odbtp_unicode.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-oracle.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-pdo.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-pdo_mssql.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-pdo_mysql.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-pdo_oci.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-pdo_pgsql.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-pdo_sqlite.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-postgres.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-postgres64.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-postgres7.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-postgres8.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-postgres9.inc.php [new file with mode: 0644]
typo3/sysext/adodb/adodb/drivers/adodb-proxy.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-sapdb.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-sqlanywhere.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-sqlite.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-sqlite3.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-sqlitepo.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-sybase.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-sybase_ase.inc.php
typo3/sysext/adodb/adodb/drivers/adodb-vfp.inc.php
typo3/sysext/adodb/adodb/lang/adodb-bgutf8.inc.php
typo3/sysext/adodb/adodb/lang/adodb-cn.inc.php
typo3/sysext/adodb/adodb/lang/adodb-cz.inc.php
typo3/sysext/adodb/adodb/lang/adodb-de.inc.php
typo3/sysext/adodb/adodb/lang/adodb-en.inc.php
typo3/sysext/adodb/adodb/lang/adodb-fa.inc.php
typo3/sysext/adodb/adodb/lang/adodb-fr.inc.php
typo3/sysext/adodb/adodb/lang/adodb-ru1251.inc.php
typo3/sysext/adodb/adodb/lang/adodb-sv.inc.php
typo3/sysext/adodb/adodb/license.txt
typo3/sysext/adodb/adodb/pear/Auth/Container/ADOdb.php
typo3/sysext/adodb/adodb/perf/perf-db2.inc.php
typo3/sysext/adodb/adodb/perf/perf-informix.inc.php
typo3/sysext/adodb/adodb/perf/perf-mssql.inc.php
typo3/sysext/adodb/adodb/perf/perf-mssqlnative.inc.php
typo3/sysext/adodb/adodb/perf/perf-mysql.inc.php
typo3/sysext/adodb/adodb/perf/perf-oci8.inc.php
typo3/sysext/adodb/adodb/perf/perf-postgres.inc.php
typo3/sysext/adodb/adodb/pivottable.inc.php
typo3/sysext/adodb/adodb/readme.txt
typo3/sysext/adodb/adodb/rsfilter.inc.php
typo3/sysext/adodb/adodb/server.php
typo3/sysext/adodb/adodb/session/adodb-compress-bzip2.php
typo3/sysext/adodb/adodb/session/adodb-compress-gzip.php
typo3/sysext/adodb/adodb/session/adodb-cryptsession.php
typo3/sysext/adodb/adodb/session/adodb-cryptsession2.php
typo3/sysext/adodb/adodb/session/adodb-encrypt-mcrypt.php
typo3/sysext/adodb/adodb/session/adodb-encrypt-md5.php
typo3/sysext/adodb/adodb/session/adodb-encrypt-secret.php
typo3/sysext/adodb/adodb/session/adodb-encrypt-sha1.php
typo3/sysext/adodb/adodb/session/adodb-sess.txt
typo3/sysext/adodb/adodb/session/adodb-session-clob.php
typo3/sysext/adodb/adodb/session/adodb-session-clob2.php
typo3/sysext/adodb/adodb/session/adodb-session.php
typo3/sysext/adodb/adodb/session/adodb-session2.php
typo3/sysext/adodb/adodb/session/session_schema.xml
typo3/sysext/adodb/adodb/session/session_schema2.xml
typo3/sysext/adodb/adodb/toexport.inc.php
typo3/sysext/adodb/adodb/tohtml.inc.php
typo3/sysext/adodb/adodb/xmlschema.dtd
typo3/sysext/adodb/adodb/xmlschema03.dtd
typo3/sysext/adodb/adodb/xsl/convert-0.1-0.2.xsl
typo3/sysext/adodb/adodb/xsl/convert-0.1-0.3.xsl
typo3/sysext/adodb/adodb/xsl/convert-0.2-0.1.xsl
typo3/sysext/adodb/adodb/xsl/convert-0.2-0.3.xsl
typo3/sysext/adodb/adodb/xsl/remove-0.2.xsl
typo3/sysext/adodb/adodb/xsl/remove-0.3.xsl

diff --git a/typo3/sysext/adodb/README.txt b/typo3/sysext/adodb/README.txt
new file mode 100644 (file)
index 0000000..26a4652
--- /dev/null
@@ -0,0 +1,9 @@
+This folder contains the ADOdb library used by DBAL to connect to the
+various DBMS we are supporting with TYPO3.
+
+Latest version may be downloaded: on http://adodb.sourceforge.net/
+
+BEWARE: At least in version 5.18 and below some methods are not properly
+extending their parent's method signature and cause PHP warnings.
+
+Please apply patch from http://forge.typo3.org/issues/48034 if needed.
index b7553d5..215f769 100644 (file)
@@ -1,18 +1,18 @@
 <?php
 /*
 
 <?php
 /*
 
-@version V5.14 8 Sept 2011   (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
+@version V5.18 3 Sep 2012   (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
   Latest version is available at http://adodb.sourceforge.net
   Latest version is available at http://adodb.sourceforge.net
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
+
+  Released under both BSD license and Lesser GPL library license.
+  Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
   the BSD license will take precedence.
-  
+
   Active Record implementation. Superset of Zend Framework's.
   Active Record implementation. Superset of Zend Framework's.
-  
+
   Version 0.92
   Version 0.92
-  
-  See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord 
+
+  See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord
        for info on Ruby on Rails Active Record implementation
 */
 
        for info on Ruby on Rails Active Record implementation
 */
 
@@ -44,30 +44,30 @@ class ADODB_Active_Table {
 
 // $db = database connection
 // $index = name of index - can be associative, for an example see
 
 // $db = database connection
 // $index = name of index - can be associative, for an example see
-//    http://phplens.com/lens/lensforum/msgs.php?id=17790 
+//    http://phplens.com/lens/lensforum/msgs.php?id=17790
 // returns index into $_ADODB_ACTIVE_DBS
 function ADODB_SetDatabaseAdapter(&$db, $index=false)
 {
        global $_ADODB_ACTIVE_DBS;
 // returns index into $_ADODB_ACTIVE_DBS
 function ADODB_SetDatabaseAdapter(&$db, $index=false)
 {
        global $_ADODB_ACTIVE_DBS;
-       
+
                foreach($_ADODB_ACTIVE_DBS as $k => $d) {
                        if (PHP_VERSION >= 5) {
                                if ($d->db === $db) return $k;
                        } else {
                foreach($_ADODB_ACTIVE_DBS as $k => $d) {
                        if (PHP_VERSION >= 5) {
                                if ($d->db === $db) return $k;
                        } else {
-                               if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) 
+                               if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database)
                                        return $k;
                        }
                }
                                        return $k;
                        }
                }
-               
+
                $obj = new ADODB_Active_DB();
                $obj->db = $db;
                $obj->tables = array();
                $obj = new ADODB_Active_DB();
                $obj->db = $db;
                $obj->tables = array();
-               
+
                if ($index == false) $index = sizeof($_ADODB_ACTIVE_DBS);
 
                if ($index == false) $index = sizeof($_ADODB_ACTIVE_DBS);
 
-               
+
                $_ADODB_ACTIVE_DBS[$index] = $obj;
                $_ADODB_ACTIVE_DBS[$index] = $obj;
-               
+
                return sizeof($_ADODB_ACTIVE_DBS)-1;
 }
 
                return sizeof($_ADODB_ACTIVE_DBS)-1;
 }
 
@@ -75,8 +75,8 @@ function ADODB_SetDatabaseAdapter(&$db, $index=false)
 class ADODB_Active_Record {
        static $_changeNames = true; // dynamically pluralize table names
        static $_quoteNames = false;
 class ADODB_Active_Record {
        static $_changeNames = true; // dynamically pluralize table names
        static $_quoteNames = false;
-       
-       static $_foreignSuffix = '_id'; // 
+
+       static $_foreignSuffix = '_id'; //
        var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat]
        var $_table; // tablename, if set in class definition then use it as table name
        var $_tableat; // associative index pointing to ADODB_Active_Table, eg $ADODB_Active_DBS[_dbat]->tables[$this->_tableat]
        var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat]
        var $_table; // tablename, if set in class definition then use it as table name
        var $_tableat; // associative index pointing to ADODB_Active_Table, eg $ADODB_Active_DBS[_dbat]->tables[$this->_tableat]
@@ -87,6 +87,8 @@ class ADODB_Active_Record {
 
        var $foreignName; // CFR: class name when in a relationship
 
 
        var $foreignName; // CFR: class name when in a relationship
 
+       var $lockMode = ' for update '; // you might want to change to
+
        static function UseDefaultValues($bool=null)
        {
        global $ADODB_ACTIVE_DEFVALS;
        static function UseDefaultValues($bool=null)
        {
        global $ADODB_ACTIVE_DEFVALS;
@@ -95,29 +97,29 @@ class ADODB_Active_Record {
        }
 
        // should be static
        }
 
        // should be static
-       static function SetDatabaseAdapter(&$db, $index=false) 
+       static function SetDatabaseAdapter(&$db, $index=false)
        {
                return ADODB_SetDatabaseAdapter($db, $index);
        }
        {
                return ADODB_SetDatabaseAdapter($db, $index);
        }
-       
-       
+
+
        public function __set($name, $value)
        {
                $name = str_replace(' ', '_', $name);
                $this->$name = $value;
        }
        public function __set($name, $value)
        {
                $name = str_replace(' ', '_', $name);
                $this->$name = $value;
        }
-       
+
        // php5 constructor
        function __construct($table = false, $pkeyarr=false, $db=false)
        {
        global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS;
        // php5 constructor
        function __construct($table = false, $pkeyarr=false, $db=false)
        {
        global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS;
-       
+
                if ($db == false && is_object($pkeyarr)) {
                        $db = $pkeyarr;
                        $pkeyarr = false;
                }
                if ($db == false && is_object($pkeyarr)) {
                        $db = $pkeyarr;
                        $pkeyarr = false;
                }
-               
-               if (!$table) { 
+
+               if (!$table) {
                        if (!empty($this->_table)) $table = $this->_table;
                        else $table = $this->_pluralize(get_class($this));
                }
                        if (!empty($this->_table)) $table = $this->_table;
                        else $table = $this->_pluralize(get_class($this));
                }
@@ -135,13 +137,13 @@ class ADODB_Active_Record {
 
                $this->UpdateActiveTable($pkeyarr);
        }
 
                $this->UpdateActiveTable($pkeyarr);
        }
-       
+
        function __wakeup()
        {
                $class = get_class($this);
                new $class;
        }
        function __wakeup()
        {
                $class = get_class($this);
                new $class;
        }
-       
+
        function _pluralize($table)
        {
                if (!ADODB_Active_Record::$_changeNames) return $table;
        function _pluralize($table)
        {
                if (!ADODB_Active_Record::$_changeNames) return $table;
@@ -152,26 +154,26 @@ class ADODB_Active_Record {
                $lastc2 = substr($ut,$len-2);
                switch ($lastc) {
                case 'S':
                $lastc2 = substr($ut,$len-2);
                switch ($lastc) {
                case 'S':
-                       return $table.'es';     
+                       return $table.'es';
                case 'Y':
                        return substr($table,0,$len-1).'ies';
                case 'Y':
                        return substr($table,0,$len-1).'ies';
-               case 'X':       
+               case 'X':
                        return $table.'es';
                        return $table.'es';
-               case 'H': 
+               case 'H':
                        if ($lastc2 == 'CH' || $lastc2 == 'SH')
                                return $table.'es';
                default:
                        return $table.'s';
                }
        }
                        if ($lastc2 == 'CH' || $lastc2 == 'SH')
                                return $table.'es';
                default:
                        return $table.'s';
                }
        }
-       
+
        // CFR Lamest singular inflector ever - @todo Make it real!
        // Note: There is an assumption here...and it is that the argument's length >= 4
        function _singularize($tables)
        {
        // CFR Lamest singular inflector ever - @todo Make it real!
        // Note: There is an assumption here...and it is that the argument's length >= 4
        function _singularize($tables)
        {
-       
+
                if (!ADODB_Active_Record::$_changeNames) return $table;
                if (!ADODB_Active_Record::$_changeNames) return $table;
-       
+
                $ut = strtoupper($tables);
                $len = strlen($tables);
                if($ut[$len-1] != 'S')
                $ut = strtoupper($tables);
                $len = strlen($tables);
                if($ut[$len-1] != 'S')
@@ -203,14 +205,14 @@ class ADODB_Active_Record {
                $table->_hasMany[$foreignRef] = $ar;
        #       $this->$foreignRef = $this->_hasMany[$foreignRef]; // WATCHME Removed assignment by ref. to please __get()
        }
                $table->_hasMany[$foreignRef] = $ar;
        #       $this->$foreignRef = $this->_hasMany[$foreignRef]; // WATCHME Removed assignment by ref. to please __get()
        }
-       
+
        // use when you don't want ADOdb to auto-pluralize tablename
        static function TableHasMany($table, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
        {
                $ar = new ADODB_Active_Record($table);
                $ar->hasMany($foreignRef, $foreignKey, $foreignClass);
        }
        // use when you don't want ADOdb to auto-pluralize tablename
        static function TableHasMany($table, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
        {
                $ar = new ADODB_Active_Record($table);
                $ar->hasMany($foreignRef, $foreignKey, $foreignClass);
        }
-       
+
        // use when you don't want ADOdb to auto-pluralize tablename
        static function TableKeyHasMany($table, $tablePKey, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
        {
        // use when you don't want ADOdb to auto-pluralize tablename
        static function TableKeyHasMany($table, $tablePKey, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
        {
@@ -218,8 +220,8 @@ class ADODB_Active_Record {
                $ar = new ADODB_Active_Record($table,$tablePKey);
                $ar->hasMany($foreignRef, $foreignKey, $foreignClass);
        }
                $ar = new ADODB_Active_Record($table,$tablePKey);
                $ar->hasMany($foreignRef, $foreignKey, $foreignClass);
        }
-       
-       
+
+
        // use when you want ADOdb to auto-pluralize tablename for you. Note that the class must already be defined.
        // e.g. class Person will generate relationship for table Persons
        static function ClassHasMany($parentclass, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
        // use when you want ADOdb to auto-pluralize tablename for you. Note that the class must already be defined.
        // e.g. class Person will generate relationship for table Persons
        static function ClassHasMany($parentclass, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
@@ -227,7 +229,7 @@ class ADODB_Active_Record {
                $ar = new $parentclass();
                $ar->hasMany($foreignRef, $foreignKey, $foreignClass);
        }
                $ar = new $parentclass();
                $ar->hasMany($foreignRef, $foreignKey, $foreignClass);
        }
-       
+
 
        function belongsTo($foreignRef,$foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
 
        function belongsTo($foreignRef,$foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
@@ -238,24 +240,24 @@ class ADODB_Active_Record {
                $ar->parentKey = $parentKey;
                $ar->UpdateActiveTable();
                $ar->foreignKey = ($foreignKey) ? $foreignKey : $foreignRef.ADODB_Active_Record::$_foreignSuffix;
                $ar->parentKey = $parentKey;
                $ar->UpdateActiveTable();
                $ar->foreignKey = ($foreignKey) ? $foreignKey : $foreignRef.ADODB_Active_Record::$_foreignSuffix;
-               
+
                $table =& $this->TableInfo();
                $table->_belongsTo[$foreignRef] = $ar;
        #       $this->$foreignRef = $this->_belongsTo[$foreignRef];
        }
                $table =& $this->TableInfo();
                $table->_belongsTo[$foreignRef] = $ar;
        #       $this->$foreignRef = $this->_belongsTo[$foreignRef];
        }
-       
+
        static function ClassBelongsTo($class, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
                $ar = new $class();
                $ar->belongsTo($foreignRef, $foreignKey, $parentKey, $parentClass);
        }
        static function ClassBelongsTo($class, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
                $ar = new $class();
                $ar->belongsTo($foreignRef, $foreignKey, $parentKey, $parentClass);
        }
-       
+
        static function TableBelongsTo($table, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
                $ar = new ADOdb_Active_Record($table);
                $ar->belongsTo($foreignRef, $foreignKey, $parentKey, $parentClass);
        }
        static function TableBelongsTo($table, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
                $ar = new ADOdb_Active_Record($table);
                $ar->belongsTo($foreignRef, $foreignKey, $parentKey, $parentClass);
        }
-       
+
        static function TableKeyBelongsTo($table, $tablePKey, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
                if (!is_array($tablePKey)) $tablePKey = array($tablePKey);
        static function TableKeyBelongsTo($table, $tablePKey, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record')
        {
                if (!is_array($tablePKey)) $tablePKey = array($tablePKey);
@@ -266,8 +268,8 @@ class ADODB_Active_Record {
 
        /**
         * __get Access properties - used for lazy loading
 
        /**
         * __get Access properties - used for lazy loading
-        * 
-        * @param mixed $name 
+        *
+        * @param mixed $name
         * @access protected
         * @return mixed
         */
         * @access protected
         * @return mixed
         */
@@ -275,9 +277,9 @@ class ADODB_Active_Record {
        {
                return $this->LoadRelations($name, '', -1, -1);
        }
        {
                return $this->LoadRelations($name, '', -1, -1);
        }
-       
+
        /**
        /**
-        * @param string $name 
+        * @param string $name
         * @param string $whereOrderBy : eg. ' AND field1 = value ORDER BY field2'
         * @param offset
         * @param limit
         * @param string $whereOrderBy : eg. ' AND field1 = value ORDER BY field2'
         * @param offset
         * @param limit
@@ -289,12 +291,12 @@ class ADODB_Active_Record {
                $table = $this->TableInfo();
                if ($limit >= 0) $extras['limit'] = $limit;
                if ($offset >= 0) $extras['offset'] = $offset;
                $table = $this->TableInfo();
                if ($limit >= 0) $extras['limit'] = $limit;
                if ($offset >= 0) $extras['offset'] = $offset;
-               
-               if (strlen($whereOrderBy)) 
+
+               if (strlen($whereOrderBy))
                        if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy))
                                if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy))
                                        $whereOrderBy = 'AND '.$whereOrderBy;
                        if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy))
                                if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy))
                                        $whereOrderBy = 'AND '.$whereOrderBy;
-                               
+
                if(!empty($table->_belongsTo[$name]))
                {
                        $obj = $table->_belongsTo[$name];
                if(!empty($table->_belongsTo[$name]))
                {
                        $obj = $table->_belongsTo[$name];
@@ -305,7 +307,7 @@ class ADODB_Active_Record {
                        {
                                if ($obj->parentKey) $key = $obj->parentKey;
                                else $key = reset($table->keys);
                        {
                                if ($obj->parentKey) $key = $obj->parentKey;
                                else $key = reset($table->keys);
-                               
+
                                $arrayOfOne = $obj->Find($key.'='.$this->$columnName.' '.$whereOrderBy,false,false,$extras);
                                if ($arrayOfOne) {
                                        $this->$name = $arrayOfOne[0];
                                $arrayOfOne = $obj->Find($key.'='.$this->$columnName.' '.$whereOrderBy,false,false,$extras);
                                if ($arrayOfOne) {
                                        $this->$name = $arrayOfOne[0];
@@ -314,7 +316,7 @@ class ADODB_Active_Record {
                        }
                }
                if(!empty($table->_hasMany[$name]))
                        }
                }
                if(!empty($table->_hasMany[$name]))
-               {       
+               {
                        $obj = $table->_hasMany[$name];
                        $key = reset($table->keys);
                        $id = @$this->$key;
                        $obj = $table->_hasMany[$name];
                        $key = reset($table->keys);
                        $id = @$this->$key;
@@ -327,11 +329,11 @@ class ADODB_Active_Record {
                        $this->$name = $objs;
                        return $objs;
                }
                        $this->$name = $objs;
                        return $objs;
                }
-               
+
                return array();
        }
        //////////////////////////////////
                return array();
        }
        //////////////////////////////////
-       
+
        // update metadata
        function UpdateActiveTable($pkeys=false,$forceUpdate=false)
        {
        // update metadata
        function UpdateActiveTable($pkeys=false,$forceUpdate=false)
        {
@@ -347,7 +349,7 @@ class ADODB_Active_Record {
 
                        $acttab = $tables[$tableat];
                        foreach($acttab->flds as $name => $fld) {
 
                        $acttab = $tables[$tableat];
                        foreach($acttab->flds as $name => $fld) {
-                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) 
+                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
                                $this->$name = $fld->default_value;
                        else
                                $this->$name = null;
                                $this->$name = $fld->default_value;
                        else
                                $this->$name = null;
@@ -361,19 +363,19 @@ class ADODB_Active_Record {
                        @flock($fp, LOCK_SH);
                        $acttab = unserialize(fread($fp,100000));
                        fclose($fp);
                        @flock($fp, LOCK_SH);
                        $acttab = unserialize(fread($fp,100000));
                        fclose($fp);
-                       if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) { 
+                       if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) {
                                // abs(rand()) randomizes deletion, reducing contention to delete/refresh file
                                // ideally, you should cache at least 32 secs
                                // abs(rand()) randomizes deletion, reducing contention to delete/refresh file
                                // ideally, you should cache at least 32 secs
-                               
+
                                foreach($acttab->flds as $name => $fld) {
                                foreach($acttab->flds as $name => $fld) {
-                                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) 
+                                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
                                                $this->$name = $fld->default_value;
                                        else
                                                $this->$name = null;
                                }
                                                $this->$name = $fld->default_value;
                                        else
                                                $this->$name = null;
                                }
-       
+
                                $activedb->tables[$table] = $acttab;
                                $activedb->tables[$table] = $acttab;
-                               
+
                                //if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname");
                                return;
                        } else if ($db->debug) {
                                //if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname");
                                return;
                        } else if ($db->debug) {
@@ -382,18 +384,18 @@ class ADODB_Active_Record {
                }
                $activetab = new ADODB_Active_Table();
                $activetab->name = $table;
                }
                $activetab = new ADODB_Active_Table();
                $activetab->name = $table;
-               
+
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
                if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
                if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
-               
+
                $cols = $db->MetaColumns($table);
                $cols = $db->MetaColumns($table);
-               
+
                if (isset($savem)) $db->SetFetchMode($savem);
                $ADODB_FETCH_MODE = $save;
                if (isset($savem)) $db->SetFetchMode($savem);
                $ADODB_FETCH_MODE = $save;
-               
+
                if (!$cols) {
                if (!$cols) {
-                       $this->Error("Invalid table name: $table",'UpdateActiveTable'); 
+                       $this->Error("Invalid table name: $table",'UpdateActiveTable');
                        return false;
                }
                $fld = reset($cols);
                        return false;
                }
                $fld = reset($cols);
@@ -403,17 +405,17 @@ class ADODB_Active_Record {
                                foreach($cols as $name => $fld) {
                                        if (!empty($fld->primary_key)) $pkeys[] = $name;
                                }
                                foreach($cols as $name => $fld) {
                                        if (!empty($fld->primary_key)) $pkeys[] = $name;
                                }
-                       } else  
+                       } else
                                $pkeys = $this->GetPrimaryKeys($db, $table);
                }
                if (empty($pkeys)) {
                        $this->Error("No primary key found for table $table",'UpdateActiveTable');
                        return false;
                }
                                $pkeys = $this->GetPrimaryKeys($db, $table);
                }
                if (empty($pkeys)) {
                        $this->Error("No primary key found for table $table",'UpdateActiveTable');
                        return false;
                }
-               
+
                $attr = array();
                $keys = array();
                $attr = array();
                $keys = array();
-               
+
                switch($ADODB_ASSOC_CASE) {
                case 0:
                        foreach($cols as $name => $fldobj) {
                switch($ADODB_ASSOC_CASE) {
                case 0:
                        foreach($cols as $name => $fldobj) {
@@ -428,18 +430,18 @@ class ADODB_Active_Record {
                                $keys[strtolower($name)] = strtolower($name);
                        }
                        break;
                                $keys[strtolower($name)] = strtolower($name);
                        }
                        break;
-                       
-               case 1: 
+
+               case 1:
                        foreach($cols as $name => $fldobj) {
                                $name = strtoupper($name);
                        foreach($cols as $name => $fldobj) {
                                $name = strtoupper($name);
-               
+
                 if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
                     $this->$name = $fldobj->default_value;
                 else
                                        $this->$name = null;
                                $attr[$name] = $fldobj;
                        }
                 if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
                     $this->$name = $fldobj->default_value;
                 else
                                        $this->$name = null;
                                $attr[$name] = $fldobj;
                        }
-                       
+
                        foreach($pkeys as $k => $name) {
                                $keys[strtoupper($name)] = strtoupper($name);
                        }
                        foreach($pkeys as $k => $name) {
                                $keys[strtoupper($name)] = strtoupper($name);
                        }
@@ -447,7 +449,7 @@ class ADODB_Active_Record {
                default:
                        foreach($cols as $name => $fldobj) {
                                $name = ($fldobj->name);
                default:
                        foreach($cols as $name => $fldobj) {
                                $name = ($fldobj->name);
-                
+
                 if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
                     $this->$name = $fldobj->default_value;
                 else
                 if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
                     $this->$name = $fldobj->default_value;
                 else
@@ -459,7 +461,7 @@ class ADODB_Active_Record {
                        }
                        break;
                }
                        }
                        break;
                }
-               
+
                $activetab->keys = $keys;
                $activetab->flds = $attr;
 
                $activetab->keys = $keys;
                $activetab->flds = $attr;
 
@@ -471,58 +473,58 @@ class ADODB_Active_Record {
                }
                if (isset($activedb->tables[$table])) {
                        $oldtab = $activedb->tables[$table];
                }
                if (isset($activedb->tables[$table])) {
                        $oldtab = $activedb->tables[$table];
-               
+
                        if ($oldtab) $activetab->_belongsTo = $oldtab->_belongsTo;
                        if ($oldtab) $activetab->_hasMany = $oldtab->_hasMany;
                }
                $activedb->tables[$table] = $activetab;
        }
                        if ($oldtab) $activetab->_belongsTo = $oldtab->_belongsTo;
                        if ($oldtab) $activetab->_hasMany = $oldtab->_hasMany;
                }
                $activedb->tables[$table] = $activetab;
        }
-       
+
        function GetPrimaryKeys(&$db, $table)
        {
                return $db->MetaPrimaryKeys($table);
        }
        function GetPrimaryKeys(&$db, $table)
        {
                return $db->MetaPrimaryKeys($table);
        }
-       
-       // error handler for both PHP4+5. 
+
+       // error handler for both PHP4+5.
        function Error($err,$fn)
        {
        global $_ADODB_ACTIVE_DBS;
        function Error($err,$fn)
        {
        global $_ADODB_ACTIVE_DBS;
-       
+
                $fn = get_class($this).'::'.$fn;
                $this->_lasterr = $fn.': '.$err;
                $fn = get_class($this).'::'.$fn;
                $this->_lasterr = $fn.': '.$err;
-               
+
                if ($this->_dbat < 0) $db = false;
                else {
                        $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
                        $db = $activedb->db;
                }
                if ($this->_dbat < 0) $db = false;
                else {
                        $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
                        $db = $activedb->db;
                }
-               
-               if (function_exists('adodb_throw')) {   
+
+               if (function_exists('adodb_throw')) {
                        if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
                        else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
                } else
                        if (!$db || $db->debug) ADOConnection::outp($this->_lasterr);
                        if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
                        else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
                } else
                        if (!$db || $db->debug) ADOConnection::outp($this->_lasterr);
-               
+
        }
        }
-       
+
        // return last error message
        function ErrorMsg()
        {
                if (!function_exists('adodb_throw')) {
                        if ($this->_dbat < 0) $db = false;
                        else $db = $this->DB();
        // return last error message
        function ErrorMsg()
        {
                if (!function_exists('adodb_throw')) {
                        if ($this->_dbat < 0) $db = false;
                        else $db = $this->DB();
-               
+
                        // last error could be database error too
                        if ($db && $db->ErrorMsg()) return $db->ErrorMsg();
                }
                return $this->_lasterr;
        }
                        // last error could be database error too
                        if ($db && $db->ErrorMsg()) return $db->ErrorMsg();
                }
                return $this->_lasterr;
        }
-       
-       function ErrorNo() 
+
+       function ErrorNo()
        {
                if ($this->_dbat < 0) return -9999; // no database connection...
                $db = $this->DB();
        {
                if ($this->_dbat < 0) return -9999; // no database connection...
                $db = $this->DB();
-               
+
                return (int) $db->ErrorNo();
        }
 
                return (int) $db->ErrorNo();
        }
 
@@ -531,7 +533,7 @@ class ADODB_Active_Record {
        function DB()
        {
        global $_ADODB_ACTIVE_DBS;
        function DB()
        {
        global $_ADODB_ACTIVE_DBS;
-       
+
                if ($this->_dbat < 0) {
                        $false = false;
                        $this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB");
                if ($this->_dbat < 0) {
                        $false = false;
                        $this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB");
@@ -541,7 +543,7 @@ class ADODB_Active_Record {
                $db = $activedb->db;
                return $db;
        }
                $db = $activedb->db;
                return $db;
        }
-       
+
        // retrieve ADODB_Active_Table
        function &TableInfo()
        {
        // retrieve ADODB_Active_Table
        function &TableInfo()
        {
@@ -550,8 +552,8 @@ class ADODB_Active_Record {
                $table = $activedb->tables[$this->_tableat];
                return $table;
        }
                $table = $activedb->tables[$this->_tableat];
                return $table;
        }
-       
-       
+
+
        // I have an ON INSERT trigger on a table that sets other columns in the table.
        // So, I find that for myTable, I want to reload an active record after saving it. -- Malcolm Cook
        function Reload()
        // I have an ON INSERT trigger on a table that sets other columns in the table.
        // So, I find that for myTable, I want to reload an active record after saving it. -- Malcolm Cook
        function Reload()
@@ -562,21 +564,21 @@ class ADODB_Active_Record {
                return($this->Load($where));
        }
 
                return($this->Load($where));
        }
 
-       
+
        // set a numeric array (using natural table field ordering) as object properties
        function Set(&$row)
        {
        global $ACTIVE_RECORD_SAFETY;
        // set a numeric array (using natural table field ordering) as object properties
        function Set(&$row)
        {
        global $ACTIVE_RECORD_SAFETY;
-       
+
                $db = $this->DB();
                $db = $this->DB();
-               
+
                if (!$row) {
                if (!$row) {
-                       $this->_saved = false;          
+                       $this->_saved = false;
                        return false;
                }
                        return false;
                }
-               
+
                $this->_saved = true;
                $this->_saved = true;
-               
+
                $table = $this->TableInfo();
                if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) {
             # <AP>
                $table = $this->TableInfo();
                if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) {
             # <AP>
@@ -595,7 +597,7 @@ class ADODB_Active_Record {
                }
         else
                        $keys = array_keys($row);
                }
         else
                        $keys = array_keys($row);
-                       
+
         # <AP>
         reset($keys);
         $this->_original = array();
         # <AP>
         reset($keys);
         $this->_original = array();
@@ -609,7 +611,7 @@ class ADODB_Active_Record {
         # </AP>
                return true;
        }
         # </AP>
                return true;
        }
-       
+
        // get last inserted id for INSERT
        function LastInsertID(&$db,$fieldname)
        {
        // get last inserted id for INSERT
        function LastInsertID(&$db,$fieldname)
        {
@@ -617,32 +619,32 @@ class ADODB_Active_Record {
                        $val = $db->Insert_ID($this->_table,$fieldname);
                else
                        $val = false;
                        $val = $db->Insert_ID($this->_table,$fieldname);
                else
                        $val = false;
-                       
+
                if (is_null($val) || $val === false) {
                        // this might not work reliably in multi-user environment
                        return $db->GetOne("select max(".$fieldname.") from ".$this->_table);
                }
                return $val;
        }
                if (is_null($val) || $val === false) {
                        // this might not work reliably in multi-user environment
                        return $db->GetOne("select max(".$fieldname.") from ".$this->_table);
                }
                return $val;
        }
-       
+
        // quote data in where clause
        function doquote(&$db, $val,$t)
        {
                switch($t) {
                case 'L':
                        if (strpos($db->databaseType,'postgres') !== false) return $db->qstr($val);
        // quote data in where clause
        function doquote(&$db, $val,$t)
        {
                switch($t) {
                case 'L':
                        if (strpos($db->databaseType,'postgres') !== false) return $db->qstr($val);
-               case 'D':       
+               case 'D':
                case 'T':
                        if (empty($val)) return 'null';
                case 'T':
                        if (empty($val)) return 'null';
-               
-               case 'B':       
+
+               case 'B':
                case 'N':
                case 'C':
                case 'X':
                        if (is_null($val)) return 'null';
                case 'N':
                case 'C':
                case 'X':
                        if (is_null($val)) return 'null';
-                       
-                       if (strlen($val)>1 && 
-                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) { 
+
+                       if (strlen($val)>0 &&
+                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) {
                                return $db->qstr($val);
                                break;
                        }
                                return $db->qstr($val);
                                break;
                        }
@@ -651,13 +653,13 @@ class ADODB_Active_Record {
                        break;
                }
        }
                        break;
                }
        }
-       
+
        // generate where clause for an UPDATE/SELECT
        function GenWhere(&$db, &$table)
        {
                $keys = $table->keys;
                $parr = array();
        // generate where clause for an UPDATE/SELECT
        function GenWhere(&$db, &$table)
        {
                $keys = $table->keys;
                $parr = array();
-               
+
                foreach($keys as $k) {
                        $f = $table->flds[$k];
                        if ($f) {
                foreach($keys as $k) {
                        $f = $table->flds[$k];
                        if ($f) {
@@ -666,48 +668,55 @@ class ADODB_Active_Record {
                }
                return implode(' and ', $parr);
        }
                }
                return implode(' and ', $parr);
        }
-       
-       
+
+
        function _QName($n,$db=false)
        {
                if (!ADODB_Active_Record::$_quoteNames) return $n;
                if (!$db) $db = $this->DB(); if (!$db) return false;
                return $db->nameQuote.$n.$db->nameQuote;
        }
        function _QName($n,$db=false)
        {
                if (!ADODB_Active_Record::$_quoteNames) return $n;
                if (!$db) $db = $this->DB(); if (!$db) return false;
                return $db->nameQuote.$n.$db->nameQuote;
        }
-       
+
        //------------------------------------------------------------ Public functions below
        //------------------------------------------------------------ Public functions below
-       
-       function Load($where=null,$bindarr=false)
+
+       function Load($where=null,$bindarr=false, $lock = false)
        {
        global $ADODB_FETCH_MODE;
        {
        global $ADODB_FETCH_MODE;
-       
+
                $db = $this->DB(); if (!$db) return false;
                $this->_where = $where;
                $db = $this->DB(); if (!$db) return false;
                $this->_where = $where;
-               
+
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
                if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
                if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
-               
+
                $qry = "select * from ".$this->_table;
 
                if($where) {
                        $qry .= ' WHERE '.$where;
                }
                $qry = "select * from ".$this->_table;
 
                if($where) {
                        $qry .= ' WHERE '.$where;
                }
+               if ($lock) $qry .= $this->lockMode;
+
                $row = $db->GetRow($qry,$bindarr);
                $row = $db->GetRow($qry,$bindarr);
-               
+
                if (isset($savem)) $db->SetFetchMode($savem);
                $ADODB_FETCH_MODE = $save;
                if (isset($savem)) $db->SetFetchMode($savem);
                $ADODB_FETCH_MODE = $save;
-               
+
                return $this->Set($row);
        }
                return $this->Set($row);
        }
-       
+
+       function LoadLocked($where=null, $bindarr=false)
+       {
+               $this->Load($where,$bindarr,true);
+       }
+
        # useful for multiple record inserts
        # see http://phplens.com/lens/lensforum/msgs.php?id=17795
        function Reset()
        {
         $this->_where=null;
        # useful for multiple record inserts
        # see http://phplens.com/lens/lensforum/msgs.php?id=17795
        function Reset()
        {
         $this->_where=null;
-        $this->_saved = false; 
-        $this->_lasterr = false; 
+        $this->_saved = false;
+        $this->_lasterr = false;
         $this->_original = false;
         $vars=get_object_vars($this);
         foreach($vars as $k=>$v){
         $this->_original = false;
         $vars=get_object_vars($this);
         foreach($vars as $k=>$v){
@@ -718,24 +727,24 @@ class ADODB_Active_Record {
         $this->foreignName=strtolower(get_class($this));
         return true;
     }
         $this->foreignName=strtolower(get_class($this));
         return true;
     }
-       
+
        // false on error
        function Save()
        {
                if ($this->_saved) $ok = $this->Update();
                else $ok = $this->Insert();
        // false on error
        function Save()
        {
                if ($this->_saved) $ok = $this->Update();
                else $ok = $this->Insert();
-               
+
                return $ok;
        }
                return $ok;
        }
-       
-       
+
+
        // false on error
        function Insert()
        {
                $db = $this->DB(); if (!$db) return false;
                $cnt = 0;
                $table = $this->TableInfo();
        // false on error
        function Insert()
        {
                $db = $this->DB(); if (!$db) return false;
                $cnt = 0;
                $table = $this->TableInfo();
-               
+
                $valarr = array();
                $names = array();
                $valstr = array();
                $valarr = array();
                $names = array();
                $valstr = array();
@@ -749,7 +758,7 @@ class ADODB_Active_Record {
                                $cnt += 1;
                        }
                }
                                $cnt += 1;
                        }
                }
-               
+
                if (empty($names)){
                        foreach($table->flds as $name=>$fld) {
                                $valarr[] = null;
                if (empty($names)){
                        foreach($table->flds as $name=>$fld) {
                                $valarr[] = null;
@@ -760,7 +769,7 @@ class ADODB_Active_Record {
                }
                $sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')';
                $ok = $db->Execute($sql,$valarr);
                }
                $sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')';
                $ok = $db->Execute($sql,$valarr);
-               
+
                if ($ok) {
                        $this->_saved = true;
                        $autoinc = false;
                if ($ok) {
                        $this->_saved = true;
                        $autoinc = false;
@@ -775,23 +784,23 @@ class ADODB_Active_Record {
                                $this->$k = $this->LastInsertID($db,$k);
                        }
                }
                                $this->$k = $this->LastInsertID($db,$k);
                        }
                }
-               
+
                $this->_original = $valarr;
                return !empty($ok);
        }
                $this->_original = $valarr;
                return !empty($ok);
        }
-       
+
        function Delete()
        {
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
        function Delete()
        {
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
-               
+
                $where = $this->GenWhere($db,$table);
                $sql = 'DELETE FROM '.$this->_table.' WHERE '.$where;
                $ok = $db->Execute($sql);
                $where = $this->GenWhere($db,$table);
                $sql = 'DELETE FROM '.$this->_table.' WHERE '.$where;
                $ok = $db->Execute($sql);
-               
+
                return $ok ? true : false;
        }
                return $ok ? true : false;
        }
-       
+
        // returns an array of active record objects
        function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array())
        {
        // returns an array of active record objects
        function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array())
        {
@@ -799,17 +808,17 @@ class ADODB_Active_Record {
                $arr = $db->GetActiveRecordsClass(get_class($this),$this->_table, $whereOrderBy,$bindarr,$pkeysArr,$extra);
                return $arr;
        }
                $arr = $db->GetActiveRecordsClass(get_class($this),$this->_table, $whereOrderBy,$bindarr,$pkeysArr,$extra);
                return $arr;
        }
-       
+
        // returns 0 on error, 1 on update, 2 on insert
        function Replace()
        {
        global $ADODB_ASSOC_CASE;
        // returns 0 on error, 1 on update, 2 on insert
        function Replace()
        {
        global $ADODB_ASSOC_CASE;
-               
+
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
-               
+
                $pkey = $table->keys;
                $pkey = $table->keys;
-               
+
                foreach($table->flds as $name=>$fld) {
                        $val = $this->$name;
                        /*
                foreach($table->flds as $name=>$fld) {
                        $val = $this->$name;
                        /*
@@ -825,24 +834,24 @@ class ADODB_Active_Record {
                        if (is_null($val) && !empty($fld->auto_increment)) {
                continue;
             }
                        if (is_null($val) && !empty($fld->auto_increment)) {
                continue;
             }
-                       
+
                        if (is_array($val)) continue;
                        if (is_array($val)) continue;
-                       
+
                        $t = $db->MetaType($fld->type);
                        $arr[$name] = $this->doquote($db,$val,$t);
                        $valarr[] = $val;
                }
                        $t = $db->MetaType($fld->type);
                        $arr[$name] = $this->doquote($db,$val,$t);
                        $valarr[] = $val;
                }
-               
+
                if (!is_array($pkey)) $pkey = array($pkey);
                if (!is_array($pkey)) $pkey = array($pkey);
-               
-               
-               if ($ADODB_ASSOC_CASE == 0) 
+
+
+               if ($ADODB_ASSOC_CASE == 0)
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtolower($v);
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtolower($v);
-               elseif ($ADODB_ASSOC_CASE == 1) 
+               elseif ($ADODB_ASSOC_CASE == 1)
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtoupper($v);
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtoupper($v);
-                               
+
                $ok = $db->Replace($this->_table,$arr,$pkey);
                if ($ok) {
                        $this->_saved = true; // 1= update 2=insert
                $ok = $db->Replace($this->_table,$arr,$pkey);
                if ($ok) {
                        $this->_saved = true; // 1= update 2=insert
@@ -859,9 +868,9 @@ class ADODB_Active_Record {
                                        $this->$k = $this->LastInsertID($db,$k);
                                }
                        }
                                        $this->$k = $this->LastInsertID($db,$k);
                                }
                        }
-                       
+
                        $this->_original = $valarr;
                        $this->_original = $valarr;
-               } 
+               }
                return $ok;
        }
 
                return $ok;
        }
 
@@ -870,14 +879,14 @@ class ADODB_Active_Record {
        {
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
        {
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
-               
+
                $where = $this->GenWhere($db, $table);
                $where = $this->GenWhere($db, $table);
-               
+
                if (!$where) {
                        $this->error("Where missing for table $table", "Update");
                        return false;
                }
                if (!$where) {
                        $this->error("Where missing for table $table", "Update");
                        return false;
                }
-               $valarr = array(); 
+               $valarr = array();
                $neworig = array();
                $pairs = array();
                $i = -1;
                $neworig = array();
                $pairs = array();
                $i = -1;
@@ -886,10 +895,10 @@ class ADODB_Active_Record {
                        $i += 1;
                        $val = $this->$name;
                        $neworig[] = $val;
                        $i += 1;
                        $val = $this->$name;
                        $neworig[] = $val;
-                       
-                       if (isset($table->keys[$name]) || is_array($val)) 
+
+                       if (isset($table->keys[$name]) || is_array($val))
                                continue;
                                continue;
-                       
+
                        if (is_null($val)) {
                                if (isset($fld->not_null) && $fld->not_null) {
                                        if (isset($fld->default_value) && strlen($fld->default_value)) continue;
                        if (is_null($val)) {
                                if (isset($fld->not_null) && $fld->not_null) {
                                        if (isset($fld->default_value) && strlen($fld->default_value)) continue;
@@ -900,15 +909,16 @@ class ADODB_Active_Record {
                                }
                        }
 
                                }
                        }
 
-                       if (isset($this->_original[$i]) && strcmp($val,$this->_original[$i]) == 0) {
-                               continue;
-                       }
+                       if (isset($this->_original[$i]) && strcmp($val,$this->_original[$i]) == 0) continue;
+
+                       if (is_null($this->_original[$i]) && is_null($val)) continue;
+
                        $valarr[] = $val;
                        $pairs[] = $this->_QName($name,$db).'='.$db->Param($cnt);
                        $cnt += 1;
                }
                        $valarr[] = $val;
                        $pairs[] = $this->_QName($name,$db).'='.$db->Param($cnt);
                        $cnt += 1;
                }
-               
-               
+
+
                if (!$cnt) return -1;
                $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where;
                $ok = $db->Execute($sql,$valarr);
                if (!$cnt) return -1;
                $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where;
                $ok = $db->Execute($sql,$valarr);
@@ -918,14 +928,14 @@ class ADODB_Active_Record {
                }
                return 0;
        }
                }
                return 0;
        }
-       
+
        function GetAttributeNames()
        {
                $table = $this->TableInfo();
                if (!$table) return false;
                return array_keys($table->flds);
        }
        function GetAttributeNames()
        {
                $table = $this->TableInfo();
                if (!$table) return false;
                return array_keys($table->flds);
        }
-       
+
 };
 
 function adodb_GetActiveRecordsClass(&$db, $class, $table,$whereOrderBy,$bindarr, $primkeyArr,
 };
 
 function adodb_GetActiveRecordsClass(&$db, $class, $table,$whereOrderBy,$bindarr, $primkeyArr,
@@ -933,10 +943,10 @@ function adodb_GetActiveRecordsClass(&$db, $class, $table,$whereOrderBy,$bindarr
 {
 global $_ADODB_ACTIVE_DBS;
 
 {
 global $_ADODB_ACTIVE_DBS;
 
-       
+
        $save = $db->SetFetchMode(ADODB_FETCH_NUM);
        $qry = "select * from ".$table;
        $save = $db->SetFetchMode(ADODB_FETCH_NUM);
        $qry = "select * from ".$table;
-       
+
        if (!empty($whereOrderBy))
                $qry .= ' WHERE '.$whereOrderBy;
        if(isset($extra['limit']))
        if (!empty($whereOrderBy))
                $qry .= ' WHERE '.$whereOrderBy;
        if(isset($extra['limit']))
@@ -957,13 +967,13 @@ global $_ADODB_ACTIVE_DBS;
                $rows = $db->GetAll($qry,$bindarr);
 
        $db->SetFetchMode($save);
                $rows = $db->GetAll($qry,$bindarr);
 
        $db->SetFetchMode($save);
-       
+
        $false = false;
        $false = false;
-       
-       if ($rows === false) {  
+
+       if ($rows === false) {
                return $false;
        }
                return $false;
        }
-       
+
 
        if (!class_exists($class)) {
                $db->outp_throw("Unknown class $class in GetActiveRecordsClass()",'GetActiveRecordsClass');
 
        if (!class_exists($class)) {
                $db->outp_throw("Unknown class $class in GetActiveRecordsClass()",'GetActiveRecordsClass');
@@ -977,7 +987,7 @@ global $_ADODB_ACTIVE_DBS;
        $arrRef = array();
        $bTos = array(); // Will store belongTo's indices if any
        foreach($rows as $row) {
        $arrRef = array();
        $bTos = array(); // Will store belongTo's indices if any
        foreach($rows as $row) {
-       
+
                $obj = new $class($table,$primkeyArr,$db);
                if ($obj->ErrorNo()){
                        $db->_errorMsg = $obj->ErrorMsg();
                $obj = new $class($table,$primkeyArr,$db);
                if ($obj->ErrorNo()){
                        $db->_errorMsg = $obj->ErrorMsg();
@@ -985,7 +995,7 @@ global $_ADODB_ACTIVE_DBS;
                }
                $obj->Set($row);
                $arr[] = $obj;
                }
                $obj->Set($row);
                $arr[] = $obj;
-       } // foreach($rows as $row) 
+       } // foreach($rows as $row)
 
        return $arr;
 }
 
        return $arr;
 }
index 994b86b..03f4593 100644 (file)
@@ -1,20 +1,20 @@
 <?php
 /*
 
 <?php
 /*
 
-@version V5.06 29 Sept 2008   (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
+@version V5.06 29 Sept 2008   (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
   Latest version is available at http://adodb.sourceforge.net
   Latest version is available at http://adodb.sourceforge.net
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
+
+  Released under both BSD license and Lesser GPL library license.
+  Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
   the BSD license will take precedence.
-  
+
   Active Record implementation. Superset of Zend Framework's.
   Active Record implementation. Superset of Zend Framework's.
-  
-  This is "Active Record eXtended" to support JOIN, WORK and LAZY mode by Chris Ravenscroft  chris#voilaweb.com 
-  
+
+  This is "Active Record eXtended" to support JOIN, WORK and LAZY mode by Chris Ravenscroft  chris#voilaweb.com
+
   Version 0.9
   Version 0.9
-  
-  See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord 
+
+  See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord
        for info on Ruby on Rails Active Record implementation
 */
 
        for info on Ruby on Rails Active Record implementation
 */
 
@@ -63,29 +63,29 @@ class ADODB_Active_Table {
 function ADODB_SetDatabaseAdapter(&$db)
 {
        global $_ADODB_ACTIVE_DBS;
 function ADODB_SetDatabaseAdapter(&$db)
 {
        global $_ADODB_ACTIVE_DBS;
-       
+
                foreach($_ADODB_ACTIVE_DBS as $k => $d) {
                        if (PHP_VERSION >= 5) {
                                if ($d->db === $db) return $k;
                        } else {
                foreach($_ADODB_ACTIVE_DBS as $k => $d) {
                        if (PHP_VERSION >= 5) {
                                if ($d->db === $db) return $k;
                        } else {
-                               if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) 
+                               if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database)
                                        return $k;
                        }
                }
                                        return $k;
                        }
                }
-               
+
                $obj = new ADODB_Active_DB();
                $obj->db = $db;
                $obj->tables = array();
                $obj = new ADODB_Active_DB();
                $obj->db = $db;
                $obj->tables = array();
-               
+
                $_ADODB_ACTIVE_DBS[] = $obj;
                $_ADODB_ACTIVE_DBS[] = $obj;
-               
+
                return sizeof($_ADODB_ACTIVE_DBS)-1;
 }
 
 
 class ADODB_Active_Record {
        static $_changeNames = true; // dynamically pluralize table names
                return sizeof($_ADODB_ACTIVE_DBS)-1;
 }
 
 
 class ADODB_Active_Record {
        static $_changeNames = true; // dynamically pluralize table names
-       static $_foreignSuffix = '_id'; // 
+       static $_foreignSuffix = '_id'; //
        var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat]
        var $_table; // tablename, if set in class definition then use it as table name
        var $_sTable; // singularized table name
        var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat]
        var $_table; // tablename, if set in class definition then use it as table name
        var $_sTable; // singularized table name
@@ -106,18 +106,18 @@ class ADODB_Active_Record {
        }
 
        // should be static
        }
 
        // should be static
-       static function SetDatabaseAdapter(&$db) 
+       static function SetDatabaseAdapter(&$db)
        {
                return ADODB_SetDatabaseAdapter($db);
        }
        {
                return ADODB_SetDatabaseAdapter($db);
        }
-       
-       
+
+
        public function __set($name, $value)
        {
                $name = str_replace(' ', '_', $name);
                $this->$name = $value;
        }
        public function __set($name, $value)
        {
                $name = str_replace(' ', '_', $name);
                $this->$name = $value;
        }
-       
+
        // php5 constructor
        // Note: if $table is defined, then we will use it as our table name
        // Otherwise we will use our classname...
        // php5 constructor
        // Note: if $table is defined, then we will use it as our table name
        // Otherwise we will use our classname...
@@ -131,12 +131,12 @@ class ADODB_Active_Record {
        function __construct($table = false, $pkeyarr=false, $db=false, $options=array())
        {
        global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS;
        function __construct($table = false, $pkeyarr=false, $db=false, $options=array())
        {
        global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS;
-       
+
                if ($db == false && is_object($pkeyarr)) {
                        $db = $pkeyarr;
                        $pkeyarr = false;
                }
                if ($db == false && is_object($pkeyarr)) {
                        $db = $pkeyarr;
                        $pkeyarr = false;
                }
-               
+
                if($table)
                {
                        // table argument exists. It is expected to be
                if($table)
                {
                        // table argument exists. It is expected to be
@@ -159,10 +159,10 @@ class ADODB_Active_Record {
                        $this->_dbat = ADODB_Active_Record::SetDatabaseAdapter($db);
                } else
                        $this->_dbat = sizeof($_ADODB_ACTIVE_DBS)-1;
                        $this->_dbat = ADODB_Active_Record::SetDatabaseAdapter($db);
                } else
                        $this->_dbat = sizeof($_ADODB_ACTIVE_DBS)-1;
-               
-               
+
+
                if ($this->_dbat < 0) $this->Error("No database connection set; use ADOdb_Active_Record::SetDatabaseAdapter(\$db)",'ADODB_Active_Record::__constructor');
                if ($this->_dbat < 0) $this->Error("No database connection set; use ADOdb_Active_Record::SetDatabaseAdapter(\$db)",'ADODB_Active_Record::__constructor');
-               
+
                $this->_tableat = $this->_table; # reserved for setting the assoc value to a non-table name, eg. the sql string in future
 
                // CFR: Just added this option because UpdateActiveTable() can refresh its information
                $this->_tableat = $this->_table; # reserved for setting the assoc value to a non-table name, eg. the sql string in future
 
                // CFR: Just added this option because UpdateActiveTable() can refresh its information
@@ -178,13 +178,13 @@ class ADODB_Active_Record {
                        $table->_belongsTo = array();
                }
        }
                        $table->_belongsTo = array();
                }
        }
-       
+
        function __wakeup()
        {
                $class = get_class($this);
                new $class;
        }
        function __wakeup()
        {
                $class = get_class($this);
                new $class;
        }
-       
+
        // CFR: Constants found in Rails
        static $IrregularP = array(
                'PERSON'    => 'people',
        // CFR: Constants found in Rails
        static $IrregularP = array(
                'PERSON'    => 'people',
@@ -231,26 +231,26 @@ class ADODB_Active_Record {
                $lastc2 = substr($ut,$len-2);
                switch ($lastc) {
                case 'S':
                $lastc2 = substr($ut,$len-2);
                switch ($lastc) {
                case 'S':
-                       return $table.'es';     
+                       return $table.'es';
                case 'Y':
                        return substr($table,0,$len-1).'ies';
                case 'Y':
                        return substr($table,0,$len-1).'ies';
-               case 'X':       
+               case 'X':
                        return $table.'es';
                        return $table.'es';
-               case 'H': 
+               case 'H':
                        if ($lastc2 == 'CH' || $lastc2 == 'SH')
                                return $table.'es';
                default:
                        return $table.'s';
                }
        }
                        if ($lastc2 == 'CH' || $lastc2 == 'SH')
                                return $table.'es';
                default:
                        return $table.'s';
                }
        }
-       
+
        // CFR Lamest singular inflector ever - @todo Make it real!
        // Note: There is an assumption here...and it is that the argument's length >= 4
        function _singularize($table)
        {
        // CFR Lamest singular inflector ever - @todo Make it real!
        // Note: There is an assumption here...and it is that the argument's length >= 4
        function _singularize($table)
        {
-       
+
                if (!ADODB_Active_Record::$_changeNames) return $table;
                if (!ADODB_Active_Record::$_changeNames) return $table;
-       
+
                $ut = strtoupper($table);
                if(isset(self::$WeIsI[$ut]))
                {
                $ut = strtoupper($table);
                if(isset(self::$WeIsI[$ut]))
                {
@@ -320,7 +320,7 @@ class ADODB_Active_Record {
                $ar->foreignName = $foreignRef;
                $ar->UpdateActiveTable();
                $ar->foreignKey = ($foreignKey) ? $foreignKey : $ar->foreignName . self::$_foreignSuffix;
                $ar->foreignName = $foreignRef;
                $ar->UpdateActiveTable();
                $ar->foreignKey = ($foreignKey) ? $foreignKey : $ar->foreignName . self::$_foreignSuffix;
-               
+
                $table =& $this->TableInfo();
                if(!isset($table->_belongsTo[$foreignRef]))
                {
                $table =& $this->TableInfo();
                if(!isset($table->_belongsTo[$foreignRef]))
                {
@@ -332,8 +332,8 @@ class ADODB_Active_Record {
 
        /**
         * __get Access properties - used for lazy loading
 
        /**
         * __get Access properties - used for lazy loading
-        * 
-        * @param mixed $name 
+        *
+        * @param mixed $name
         * @access protected
         * @return void
         */
         * @access protected
         * @return void
         */
@@ -348,12 +348,12 @@ class ADODB_Active_Record {
                if($offset >= 0) $extras['offset'] = $offset;
                if($limit >= 0) $extras['limit'] = $limit;
                $table =& $this->TableInfo();
                if($offset >= 0) $extras['offset'] = $offset;
                if($limit >= 0) $extras['limit'] = $limit;
                $table =& $this->TableInfo();
-               
-               if (strlen($whereOrderBy)) 
+
+               if (strlen($whereOrderBy))
                        if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy))
                                if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy))
                                        $whereOrderBy = 'AND '.$whereOrderBy;
                        if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy))
                                if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy))
                                        $whereOrderBy = 'AND '.$whereOrderBy;
-                                       
+
                if(!empty($table->_belongsTo[$name]))
                {
                        $obj = $table->_belongsTo[$name];
                if(!empty($table->_belongsTo[$name]))
                {
                        $obj = $table->_belongsTo[$name];
@@ -366,7 +366,7 @@ class ADODB_Active_Record {
                                        $belongsToId = $k;
                                else
                                        $belongsToId = 'id';
                                        $belongsToId = $k;
                                else
                                        $belongsToId = 'id';
-                               
+
                                $arrayOfOne =
                                        $obj->Find(
                                                $belongsToId.'='.$this->$columnName.' '.$whereOrderBy, false, false, $extras);
                                $arrayOfOne =
                                        $obj->Find(
                                                $belongsToId.'='.$this->$columnName.' '.$whereOrderBy, false, false, $extras);
@@ -380,7 +380,7 @@ class ADODB_Active_Record {
                        if(($k = reset($table->keys)))
                                $hasManyId   = $k;
                        else
                        if(($k = reset($table->keys)))
                                $hasManyId   = $k;
                        else
-                               $hasManyId   = 'id';                    
+                               $hasManyId   = 'id';
 
                        $this->$name =
                                $obj->Find(
 
                        $this->$name =
                                $obj->Find(
@@ -389,7 +389,7 @@ class ADODB_Active_Record {
                }
        }
        //////////////////////////////////
                }
        }
        //////////////////////////////////
-       
+
        // update metadata
        function UpdateActiveTable($pkeys=false,$forceUpdate=false)
        {
        // update metadata
        function UpdateActiveTable($pkeys=false,$forceUpdate=false)
        {
@@ -405,14 +405,14 @@ class ADODB_Active_Record {
 
                        $tobj = $tables[$tableat];
                        foreach($tobj->flds as $name => $fld) {
 
                        $tobj = $tables[$tableat];
                        foreach($tobj->flds as $name => $fld) {
-                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) 
+                       if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
                                $this->$name = $fld->default_value;
                        else
                                $this->$name = null;
                        }
                        return;
                }
                                $this->$name = $fld->default_value;
                        else
                                $this->$name = null;
                        }
                        return;
                }
-               
+
                $db = $activedb->db;
                $fname = $ADODB_CACHE_DIR . '/adodb_' . $db->databaseType . '_active_'. $table . '.cache';
                if (!$forceUpdate && $ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR && file_exists($fname)) {
                $db = $activedb->db;
                $fname = $ADODB_CACHE_DIR . '/adodb_' . $db->databaseType . '_active_'. $table . '.cache';
                if (!$forceUpdate && $ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR && file_exists($fname)) {
@@ -420,11 +420,11 @@ class ADODB_Active_Record {
                        @flock($fp, LOCK_SH);
                        $acttab = unserialize(fread($fp,100000));
                        fclose($fp);
                        @flock($fp, LOCK_SH);
                        $acttab = unserialize(fread($fp,100000));
                        fclose($fp);
-                       if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) { 
+                       if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) {
                                // abs(rand()) randomizes deletion, reducing contention to delete/refresh file
                                // ideally, you should cache at least 32 secs
                                $activedb->tables[$table] = $acttab;
                                // abs(rand()) randomizes deletion, reducing contention to delete/refresh file
                                // ideally, you should cache at least 32 secs
                                $activedb->tables[$table] = $acttab;
-                               
+
                                //if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname");
                                return;
                        } else if ($db->debug) {
                                //if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname");
                                return;
                        } else if ($db->debug) {
@@ -433,18 +433,18 @@ class ADODB_Active_Record {
                }
                $activetab = new ADODB_Active_Table();
                $activetab->name = $table;
                }
                $activetab = new ADODB_Active_Table();
                $activetab->name = $table;
-               
+
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
                if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
                if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false);
-               
+
                $cols = $db->MetaColumns($table);
                $cols = $db->MetaColumns($table);
-               
+
                if (isset($savem)) $db->SetFetchMode($savem);
                $ADODB_FETCH_MODE = $save;
                if (isset($savem)) $db->SetFetchMode($savem);
                $ADODB_FETCH_MODE = $save;
-               
+
                if (!$cols) {
                if (!$cols) {
-                       $this->Error("Invalid table name: $table",'UpdateActiveTable'); 
+                       $this->Error("Invalid table name: $table",'UpdateActiveTable');
                        return false;
                }
                $fld = reset($cols);
                        return false;
                }
                $fld = reset($cols);
@@ -454,17 +454,17 @@ class ADODB_Active_Record {
                                foreach($cols as $name => $fld) {
                                        if (!empty($fld->primary_key)) $pkeys[] = $name;
                                }
                                foreach($cols as $name => $fld) {
                                        if (!empty($fld->primary_key)) $pkeys[] = $name;
                                }
-                       } else  
+                       } else
                                $pkeys = $this->GetPrimaryKeys($db, $table);
                }
                if (empty($pkeys)) {
                        $this->Error("No primary key found for table $table",'UpdateActiveTable');
                        return false;
                }
                                $pkeys = $this->GetPrimaryKeys($db, $table);
                }
                if (empty($pkeys)) {
                        $this->Error("No primary key found for table $table",'UpdateActiveTable');
                        return false;
                }
-               
+
                $attr = array();
                $keys = array();
                $attr = array();
                $keys = array();
-               
+
                switch($ADODB_ASSOC_CASE) {
                case 0:
                        foreach($cols as $name => $fldobj) {
                switch($ADODB_ASSOC_CASE) {
                case 0:
                        foreach($cols as $name => $fldobj) {
@@ -479,18 +479,18 @@ class ADODB_Active_Record {
                                $keys[strtolower($name)] = strtolower($name);
                        }
                        break;
                                $keys[strtolower($name)] = strtolower($name);
                        }
                        break;
-                       
-               case 1: 
+
+               case 1:
                        foreach($cols as $name => $fldobj) {
                                $name = strtoupper($name);
                        foreach($cols as $name => $fldobj) {
                                $name = strtoupper($name);
-               
+
                 if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
                     $this->$name = $fldobj->default_value;
                 else
                                        $this->$name = null;
                                $attr[$name] = $fldobj;
                        }
                 if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
                     $this->$name = $fldobj->default_value;
                 else
                                        $this->$name = null;
                                $attr[$name] = $fldobj;
                        }
-                       
+
                        foreach($pkeys as $k => $name) {
                                $keys[strtoupper($name)] = strtoupper($name);
                        }
                        foreach($pkeys as $k => $name) {
                                $keys[strtoupper($name)] = strtoupper($name);
                        }
@@ -498,7 +498,7 @@ class ADODB_Active_Record {
                default:
                        foreach($cols as $name => $fldobj) {
                                $name = ($fldobj->name);
                default:
                        foreach($cols as $name => $fldobj) {
                                $name = ($fldobj->name);
-                
+
                 if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
                     $this->$name = $fldobj->default_value;
                 else
                 if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
                     $this->$name = $fldobj->default_value;
                 else
@@ -510,7 +510,7 @@ class ADODB_Active_Record {
                        }
                        break;
                }
                        }
                        break;
                }
-               
+
                $activetab->keys = $keys;
                $activetab->flds = $attr;
                $activetab->updateColsCount();
                $activetab->keys = $keys;
                $activetab->flds = $attr;
                $activetab->updateColsCount();
@@ -523,58 +523,58 @@ class ADODB_Active_Record {
                }
                if (isset($activedb->tables[$table])) {
                        $oldtab = $activedb->tables[$table];
                }
                if (isset($activedb->tables[$table])) {
                        $oldtab = $activedb->tables[$table];
-               
+
                        if ($oldtab) $activetab->_belongsTo = $oldtab->_belongsTo;
                        if ($oldtab) $activetab->_hasMany = $oldtab->_hasMany;
                }
                $activedb->tables[$table] = $activetab;
        }
                        if ($oldtab) $activetab->_belongsTo = $oldtab->_belongsTo;
                        if ($oldtab) $activetab->_hasMany = $oldtab->_hasMany;
                }
                $activedb->tables[$table] = $activetab;
        }
-       
+
        function GetPrimaryKeys(&$db, $table)
        {
                return $db->MetaPrimaryKeys($table);
        }
        function GetPrimaryKeys(&$db, $table)
        {
                return $db->MetaPrimaryKeys($table);
        }
-       
-       // error handler for both PHP4+5. 
+
+       // error handler for both PHP4+5.
        function Error($err,$fn)
        {
        global $_ADODB_ACTIVE_DBS;
        function Error($err,$fn)
        {
        global $_ADODB_ACTIVE_DBS;
-       
+
                $fn = get_class($this).'::'.$fn;
                $this->_lasterr = $fn.': '.$err;
                $fn = get_class($this).'::'.$fn;
                $this->_lasterr = $fn.': '.$err;
-               
+
                if ($this->_dbat < 0) $db = false;
                else {
                        $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
                        $db = $activedb->db;
                }
                if ($this->_dbat < 0) $db = false;
                else {
                        $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
                        $db = $activedb->db;
                }
-               
-               if (function_exists('adodb_throw')) {   
+
+               if (function_exists('adodb_throw')) {
                        if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
                        else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
                } else
                        if (!$db || $db->debug) ADOConnection::outp($this->_lasterr);
                        if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
                        else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
                } else
                        if (!$db || $db->debug) ADOConnection::outp($this->_lasterr);
-               
+
        }
        }
-       
+
        // return last error message
        function ErrorMsg()
        {
                if (!function_exists('adodb_throw')) {
                        if ($this->_dbat < 0) $db = false;
                        else $db = $this->DB();
        // return last error message
        function ErrorMsg()
        {
                if (!function_exists('adodb_throw')) {
                        if ($this->_dbat < 0) $db = false;
                        else $db = $this->DB();
-               
+
                        // last error could be database error too
                        if ($db && $db->ErrorMsg()) return $db->ErrorMsg();
                }
                return $this->_lasterr;
        }
                        // last error could be database error too
                        if ($db && $db->ErrorMsg()) return $db->ErrorMsg();
                }
                return $this->_lasterr;
        }
-       
-       function ErrorNo() 
+
+       function ErrorNo()
        {
                if ($this->_dbat < 0) return -9999; // no database connection...
                $db = $this->DB();
        {
                if ($this->_dbat < 0) return -9999; // no database connection...
                $db = $this->DB();
-               
+
                return (int) $db->ErrorNo();
        }
 
                return (int) $db->ErrorNo();
        }
 
@@ -583,7 +583,7 @@ class ADODB_Active_Record {
        function DB()
        {
        global $_ADODB_ACTIVE_DBS;
        function DB()
        {
        global $_ADODB_ACTIVE_DBS;
-       
+
                if ($this->_dbat < 0) {
                        $false = false;
                        $this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB");
                if ($this->_dbat < 0) {
                        $false = false;
                        $this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB");
@@ -593,18 +593,18 @@ class ADODB_Active_Record {
                $db = $activedb->db;
                return $db;
        }
                $db = $activedb->db;
                return $db;
        }
-       
+
        // retrieve ADODB_Active_Table
        function &TableInfo()
        {
        global $_ADODB_ACTIVE_DBS;
        // retrieve ADODB_Active_Table
        function &TableInfo()
        {
        global $_ADODB_ACTIVE_DBS;
-       
+
                $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
                $table = $activedb->tables[$this->_tableat];
                return $table;
        }
                $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
                $table = $activedb->tables[$this->_tableat];
                return $table;
        }
-       
-       
+
+
        // I have an ON INSERT trigger on a table that sets other columns in the table.
        // So, I find that for myTable, I want to reload an active record after saving it. -- Malcolm Cook
        function Reload()
        // I have an ON INSERT trigger on a table that sets other columns in the table.
        // So, I find that for myTable, I want to reload an active record after saving it. -- Malcolm Cook
        function Reload()
@@ -615,21 +615,21 @@ class ADODB_Active_Record {
                return($this->Load($where));
        }
 
                return($this->Load($where));
        }
 
-       
+
        // set a numeric array (using natural table field ordering) as object properties
        function Set(&$row)
        {
        global $ACTIVE_RECORD_SAFETY;
        // set a numeric array (using natural table field ordering) as object properties
        function Set(&$row)
        {
        global $ACTIVE_RECORD_SAFETY;
-       
+
                $db = $this->DB();
                $db = $this->DB();
-               
+
                if (!$row) {
                if (!$row) {
-                       $this->_saved = false;          
+                       $this->_saved = false;
                        return false;
                }
                        return false;
                }
-               
+
                $this->_saved = true;
                $this->_saved = true;
-               
+
                $table = $this->TableInfo();
                $sizeofFlds = sizeof($table->flds);
                $sizeofRow  = sizeof($row);
                $table = $this->TableInfo();
                $sizeofFlds = sizeof($table->flds);
                $sizeofRow  = sizeof($row);
@@ -687,7 +687,7 @@ class ADODB_Active_Record {
         # </AP>
                return true;
        }
         # </AP>
                return true;
        }
-       
+
        // get last inserted id for INSERT
        function LastInsertID(&$db,$fieldname)
        {
        // get last inserted id for INSERT
        function LastInsertID(&$db,$fieldname)
        {
@@ -695,14 +695,14 @@ class ADODB_Active_Record {
                        $val = $db->Insert_ID($this->_table,$fieldname);
                else
                        $val = false;
                        $val = $db->Insert_ID($this->_table,$fieldname);
                else
                        $val = false;
-                       
+
                if (is_null($val) || $val === false) {
                        // this might not work reliably in multi-user environment
                        return $db->GetOne("select max(".$fieldname.") from ".$this->_table);
                }
                return $val;
        }
                if (is_null($val) || $val === false) {
                        // this might not work reliably in multi-user environment
                        return $db->GetOne("select max(".$fieldname.") from ".$this->_table);
                }
                return $val;
        }
-       
+
        // quote data in where clause
        function doquote(&$db, $val,$t)
        {
        // quote data in where clause
        function doquote(&$db, $val,$t)
        {
@@ -710,13 +710,13 @@ class ADODB_Active_Record {
                case 'D':
                case 'T':
                        if (empty($val)) return 'null';
                case 'D':
                case 'T':
                        if (empty($val)) return 'null';
-                       
+
                case 'C':
                case 'X':
                        if (is_null($val)) return 'null';
                case 'C':
                case 'X':
                        if (is_null($val)) return 'null';
-                       
-                       if (strlen($val)>1 && 
-                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) { 
+
+                       if (strlen($val)>0 &&
+                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) {
                                return $db->qstr($val);
                                break;
                        }
                                return $db->qstr($val);
                                break;
                        }
@@ -725,13 +725,13 @@ class ADODB_Active_Record {
                        break;
                }
        }
                        break;
                }
        }
-       
+
        // generate where clause for an UPDATE/SELECT
        function GenWhere(&$db, &$table)
        {
                $keys = $table->keys;
                $parr = array();
        // generate where clause for an UPDATE/SELECT
        function GenWhere(&$db, &$table)
        {
                $keys = $table->keys;
                $parr = array();
-               
+
                foreach($keys as $k) {
                        $f = $table->flds[$k];
                        if ($f) {
                foreach($keys as $k) {
                        $f = $table->flds[$k];
                        if ($f) {
@@ -740,15 +740,15 @@ class ADODB_Active_Record {
                }
                return implode(' and ', $parr);
        }
                }
                return implode(' and ', $parr);
        }
-       
-       
+
+
        //------------------------------------------------------------ Public functions below
        //------------------------------------------------------------ Public functions below
-       
+
        function Load($where=null,$bindarr=false)
        {
                $db = $this->DB(); if (!$db) return false;
                $this->_where = $where;
        function Load($where=null,$bindarr=false)
        {
                $db = $this->DB(); if (!$db) return false;
                $this->_where = $where;
-               
+
                $save = $db->SetFetchMode(ADODB_FETCH_NUM);
                $qry = "select * from ".$this->_table;
                $table =& $this->TableInfo();
                $save = $db->SetFetchMode(ADODB_FETCH_NUM);
                $qry = "select * from ".$this->_table;
                $table =& $this->TableInfo();
@@ -757,7 +757,7 @@ class ADODB_Active_Record {
                        $hasManyId   = $k;
                else
                        $hasManyId   = 'id';
                        $hasManyId   = $k;
                else
                        $hasManyId   = 'id';
-               
+
                foreach($table->_belongsTo as $foreignTable)
                {
                        if(($k = reset($foreignTable->TableInfo()->keys)))
                foreach($table->_belongsTo as $foreignTable)
                {
                        if(($k = reset($foreignTable->TableInfo()->keys)))
@@ -780,7 +780,7 @@ class ADODB_Active_Record {
                }
                if($where)
                        $qry .= ' WHERE '.$where;
                }
                if($where)
                        $qry .= ' WHERE '.$where;
-               
+
                // Simple case: no relations. Load row and return.
                if((count($table->_hasMany) + count($table->_belongsTo)) < 1)
                {
                // Simple case: no relations. Load row and return.
                if((count($table->_hasMany) + count($table->_belongsTo)) < 1)
                {
@@ -790,7 +790,7 @@ class ADODB_Active_Record {
                        $db->SetFetchMode($save);
                        return $this->Set($row);
                }
                        $db->SetFetchMode($save);
                        return $this->Set($row);
                }
-               
+
                // More complex case when relations have to be collated
                $rows = $db->GetAll($qry,$bindarr);
                if(!$rows)
                // More complex case when relations have to be collated
                $rows = $db->GetAll($qry,$bindarr);
                if(!$rows)
@@ -800,7 +800,7 @@ class ADODB_Active_Record {
                        return false;
                $class = get_class($this);
                $isFirstRow = true;
                        return false;
                $class = get_class($this);
                $isFirstRow = true;
-               
+
                if(($k = reset($this->TableInfo()->keys)))
                        $myId   = $k;
                else
                if(($k = reset($this->TableInfo()->keys)))
                        $myId   = $k;
                else
@@ -819,7 +819,7 @@ class ADODB_Active_Record {
                }
                if(!$found)
                        $this->outp_throw("Unable to locate key $myId for $class in Load()",'Load');
                }
                if(!$found)
                        $this->outp_throw("Unable to locate key $myId for $class in Load()",'Load');
-               
+
                foreach($rows as $row)
                {
                        $rowId = intval($row[$index]);
                foreach($rows as $row)
                {
                        $rowId = intval($row[$index]);
@@ -873,21 +873,21 @@ class ADODB_Active_Record {
                                                        }
                                                }
                                        }
                                                        }
                                                }
                                        }
-                               }                               
+                               }
                        }
                }
                return true;
        }
                        }
                }
                return true;
        }
-       
+
        // false on error
        function Save()
        {
                if ($this->_saved) $ok = $this->Update();
                else $ok = $this->Insert();
        // false on error
        function Save()
        {
                if ($this->_saved) $ok = $this->Update();
                else $ok = $this->Insert();
-               
+
                return $ok;
        }
                return $ok;
        }
-       
+
        // CFR: Sometimes we may wish to consider that an object is not to be replaced but inserted.
        // Sample use case: an 'undo' command object (after a delete())
        function Dirty()
        // CFR: Sometimes we may wish to consider that an object is not to be replaced but inserted.
        // Sample use case: an 'undo' command object (after a delete())
        function Dirty()
@@ -901,7 +901,7 @@ class ADODB_Active_Record {
                $db = $this->DB(); if (!$db) return false;
                $cnt = 0;
                $table = $this->TableInfo();
                $db = $this->DB(); if (!$db) return false;
                $cnt = 0;
                $table = $this->TableInfo();
-               
+
                $valarr = array();
                $names = array();
                $valstr = array();
                $valarr = array();
                $names = array();
                $valstr = array();
@@ -915,7 +915,7 @@ class ADODB_Active_Record {
                                $cnt += 1;
                        }
                }
                                $cnt += 1;
                        }
                }
-               
+
                if (empty($names)){
                        foreach($table->flds as $name=>$fld) {
                                $valarr[] = null;
                if (empty($names)){
                        foreach($table->flds as $name=>$fld) {
                                $valarr[] = null;
@@ -926,7 +926,7 @@ class ADODB_Active_Record {
                }
                $sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')';
                $ok = $db->Execute($sql,$valarr);
                }
                $sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')';
                $ok = $db->Execute($sql,$valarr);
-               
+
                if ($ok) {
                        $this->_saved = true;
                        $autoinc = false;
                if ($ok) {
                        $this->_saved = true;
                        $autoinc = false;
@@ -941,23 +941,23 @@ class ADODB_Active_Record {
                                $this->$k = $this->LastInsertID($db,$k);
                        }
                }
                                $this->$k = $this->LastInsertID($db,$k);
                        }
                }
-               
+
                $this->_original = $valarr;
                return !empty($ok);
        }
                $this->_original = $valarr;
                return !empty($ok);
        }
-       
+
        function Delete()
        {
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
        function Delete()
        {
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
-               
+
                $where = $this->GenWhere($db,$table);
                $sql = 'DELETE FROM '.$this->_table.' WHERE '.$where;
                $ok = $db->Execute($sql);
                $where = $this->GenWhere($db,$table);
                $sql = 'DELETE FROM '.$this->_table.' WHERE '.$where;
                $ok = $db->Execute($sql);
-               
+
                return $ok ? true : false;
        }
                return $ok ? true : false;
        }
-       
+
        // returns an array of active record objects
        function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array())
        {
        // returns an array of active record objects
        function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array())
        {
@@ -967,7 +967,7 @@ class ADODB_Active_Record {
                        array('foreignName'=>$this->foreignName, 'belongsTo'=>$table->_belongsTo, 'hasMany'=>$table->_hasMany));
                return $arr;
        }
                        array('foreignName'=>$this->foreignName, 'belongsTo'=>$table->_belongsTo, 'hasMany'=>$table->_hasMany));
                return $arr;
        }
-       
+
        // CFR: In introduced this method to ensure that inner workings are not disturbed by
        // subclasses...for instance when GetActiveRecordsClass invokes Find()
        // Why am I not invoking parent::Find?
        // CFR: In introduced this method to ensure that inner workings are not disturbed by
        // subclasses...for instance when GetActiveRecordsClass invokes Find()
        // Why am I not invoking parent::Find?
@@ -985,12 +985,12 @@ class ADODB_Active_Record {
        function Replace()
        {
        global $ADODB_ASSOC_CASE;
        function Replace()
        {
        global $ADODB_ASSOC_CASE;
-               
+
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
-               
+
                $pkey = $table->keys;
                $pkey = $table->keys;
-               
+
                foreach($table->flds as $name=>$fld) {
                        $val = $this->$name;
                        /*
                foreach($table->flds as $name=>$fld) {
                        $val = $this->$name;
                        /*
@@ -1010,17 +1010,17 @@ class ADODB_Active_Record {
                        $arr[$name] = $this->doquote($db,$val,$t);
                        $valarr[] = $val;
                }
                        $arr[$name] = $this->doquote($db,$val,$t);
                        $valarr[] = $val;
                }
-               
+
                if (!is_array($pkey)) $pkey = array($pkey);
                if (!is_array($pkey)) $pkey = array($pkey);
-               
-               
-               if ($ADODB_ASSOC_CASE == 0) 
+
+
+               if ($ADODB_ASSOC_CASE == 0)
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtolower($v);
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtolower($v);
-               elseif ($ADODB_ASSOC_CASE == 1) 
+               elseif ($ADODB_ASSOC_CASE == 1)
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtoupper($v);
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtoupper($v);
-                               
+
                $ok = $db->Replace($this->_table,$arr,$pkey);
                if ($ok) {
                        $this->_saved = true; // 1= update 2=insert
                $ok = $db->Replace($this->_table,$arr,$pkey);
                if ($ok) {
                        $this->_saved = true; // 1= update 2=insert
@@ -1037,9 +1037,9 @@ class ADODB_Active_Record {
                                        $this->$k = $this->LastInsertID($db,$k);
                                }
                        }
                                        $this->$k = $this->LastInsertID($db,$k);
                                }
                        }
-                       
+
                        $this->_original = $valarr;
                        $this->_original = $valarr;
-               } 
+               }
                return $ok;
        }
 
                return $ok;
        }
 
@@ -1048,14 +1048,14 @@ class ADODB_Active_Record {
        {
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
        {
                $db = $this->DB(); if (!$db) return false;
                $table = $this->TableInfo();
-               
+
                $where = $this->GenWhere($db, $table);
                $where = $this->GenWhere($db, $table);
-               
+
                if (!$where) {
                        $this->error("Where missing for table $table", "Update");
                        return false;
                }
                if (!$where) {
                        $this->error("Where missing for table $table", "Update");
                        return false;
                }
-               $valarr = array(); 
+               $valarr = array();
                $neworig = array();
                $pairs = array();
                $i = -1;
                $neworig = array();
                $pairs = array();
                $i = -1;
@@ -1064,11 +1064,11 @@ class ADODB_Active_Record {
                        $i += 1;
                        $val = $this->$name;
                        $neworig[] = $val;
                        $i += 1;
                        $val = $this->$name;
                        $neworig[] = $val;
-                       
+
                        if (isset($table->keys[$name])) {
                                continue;
                        }
                        if (isset($table->keys[$name])) {
                                continue;
                        }
-                       
+
                        if (is_null($val)) {
                                if (isset($fld->not_null) && $fld->not_null) {
                                        if (isset($fld->default_value) && strlen($fld->default_value)) continue;
                        if (is_null($val)) {
                                if (isset($fld->not_null) && $fld->not_null) {
                                        if (isset($fld->default_value) && strlen($fld->default_value)) continue;
@@ -1078,16 +1078,16 @@ class ADODB_Active_Record {
                                        }
                                }
                        }
                                        }
                                }
                        }
-                       
+
                        if (isset($this->_original[$i]) && $val == $this->_original[$i]) {
                                continue;
                        if (isset($this->_original[$i]) && $val == $this->_original[$i]) {
                                continue;
-                       }                       
+                       }
                        $valarr[] = $val;
                        $pairs[] = $name.'='.$db->Param($cnt);
                        $cnt += 1;
                }
                        $valarr[] = $val;
                        $pairs[] = $name.'='.$db->Param($cnt);
                        $cnt += 1;
                }
-               
-               
+
+
                if (!$cnt) return -1;
                $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where;
                $ok = $db->Execute($sql,$valarr);
                if (!$cnt) return -1;
                $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where;
                $ok = $db->Execute($sql,$valarr);
@@ -1097,23 +1097,23 @@ class ADODB_Active_Record {
                }
                return 0;
        }
                }
                return 0;
        }
-       
+
        function GetAttributeNames()
        {
                $table = $this->TableInfo();
                if (!$table) return false;
                return array_keys($table->flds);
        }
        function GetAttributeNames()
        {
                $table = $this->TableInfo();
                if (!$table) return false;
                return array_keys($table->flds);
        }
-       
+
 };
 
 function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bindarr, $primkeyArr,
                        $extra, $relations)
 {
        global $_ADODB_ACTIVE_DBS;
 };
 
 function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bindarr, $primkeyArr,
                        $extra, $relations)
 {
        global $_ADODB_ACTIVE_DBS;
-       
+
                if (empty($extra['loading'])) $extra['loading'] = ADODB_LAZY_AR;
                if (empty($extra['loading'])) $extra['loading'] = ADODB_LAZY_AR;
-               
+
                $save = $db->SetFetchMode(ADODB_FETCH_NUM);
                $table = &$tableObj->_table;
                $tableInfo =& $tableObj->TableInfo();
                $save = $db->SetFetchMode(ADODB_FETCH_NUM);
                $table = &$tableObj->_table;
                $tableInfo =& $tableObj->TableInfo();
@@ -1135,7 +1135,7 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                }
                if(!$found)
                        $db->outp_throw("Unable to locate key $myId for $class in GetActiveRecordsClass()",'GetActiveRecordsClass');
                }
                if(!$found)
                        $db->outp_throw("Unable to locate key $myId for $class in GetActiveRecordsClass()",'GetActiveRecordsClass');
-               
+
                $qry = "select * from ".$table;
                if(ADODB_JOIN_AR == $extra['loading'])
                {
                $qry = "select * from ".$table;
                if(ADODB_JOIN_AR == $extra['loading'])
                {
@@ -1192,19 +1192,19 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                        }
                } else
                        $rows = $db->GetAll($qry,$bindarr);
                        }
                } else
                        $rows = $db->GetAll($qry,$bindarr);
-                       
+
                $db->SetFetchMode($save);
                $db->SetFetchMode($save);
-               
+
                $false = false;
                $false = false;
-               
-               if ($rows === false) {  
+
+               if ($rows === false) {
                        return $false;
                }
                        return $false;
                }
-               
-               
+
+
                if (!isset($_ADODB_ACTIVE_DBS)) {
                        include(ADODB_DIR.'/adodb-active-record.inc.php');
                if (!isset($_ADODB_ACTIVE_DBS)) {
                        include(ADODB_DIR.'/adodb-active-record.inc.php');
-               }       
+               }
                if (!class_exists($class)) {
                        $db->outp_throw("Unknown class $class in GetActiveRecordsClass()",'GetActiveRecordsClass');
                        return $false;
                if (!class_exists($class)) {
                        $db->outp_throw("Unknown class $class in GetActiveRecordsClass()",'GetActiveRecordsClass');
                        return $false;
@@ -1218,7 +1218,7 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                $arrRef = array();
                $bTos = array(); // Will store belongTo's indices if any
                foreach($rows as $row) {
                $arrRef = array();
                $bTos = array(); // Will store belongTo's indices if any
                foreach($rows as $row) {
-               
+
                        $obj = new $class($table,$primkeyArr,$db);
                        if ($obj->ErrorNo()){
                                $db->_errorMsg = $obj->ErrorMsg();
                        $obj = new $class($table,$primkeyArr,$db);
                        if ($obj->ErrorNo()){
                                $db->_errorMsg = $obj->ErrorMsg();
@@ -1268,7 +1268,7 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                        {
                                if(ADODB_JOIN_AR == $extra['loading'])
                                {
                        {
                                if(ADODB_JOIN_AR == $extra['loading'])
                                {
-                                       $isNewObj = !isset($uniqArr['_'.$row[0]]); 
+                                       $isNewObj = !isset($uniqArr['_'.$row[0]]);
                                        if($isNewObj)
                                                $uniqArr['_'.$row[0]] = $obj;
 
                                        if($isNewObj)
                                                $uniqArr['_'.$row[0]] = $obj;
 
@@ -1322,7 +1322,7 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                                                }
                                        }
                                        if(!$isNewObj)
                                                }
                                        }
                                        if(!$isNewObj)
-                                               unset($obj); // We do not need this object itself anymore and do not want it re-added to the main array                                 
+                                               unset($obj); // We do not need this object itself anymore and do not want it re-added to the main array
                                }
                                else if(ADODB_LAZY_AR == $extra['loading'])
                                {
                                }
                                else if(ADODB_LAZY_AR == $extra['loading'])
                                {
@@ -1382,7 +1382,7 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                                                array_push($arrRef[$obj->$dbClassRef]->$foreignName, $obj);
                                        }
                                }
                                                array_push($arrRef[$obj->$dbClassRef]->$foreignName, $obj);
                                        }
                                }
-                               
+
                        }
                        if(!empty($relations['belongsTo']))
                        {
                        }
                        if(!empty($relations['belongsTo']))
                        {
@@ -1398,7 +1398,7 @@ function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bind
                                        else
                                        {
                                                $belongsToId = 'id';
                                        else
                                        {
                                                $belongsToId = 'id';
-                                       }                                               
+                                       }
                                        $origObjsArr = $bTos[$foreignTableRef];
                                        $bTosString = implode(',', array_keys($bTos[$foreignTableRef]));
                                        $foreignName = $foreignTable->foreignName;
                                        $origObjsArr = $bTos[$foreignTableRef];
                                        $bTosString = implode(',', array_keys($bTos[$foreignTableRef]));
                                        $foreignName = $foreignTable->foreignName;
index 2d2449d..03a56f0 100644 (file)
@@ -6,19 +6,19 @@ if (!defined('ADODB_DIR')) die();
 global $ADODB_INCLUDED_CSV;
 $ADODB_INCLUDED_CSV = 1;
 
 global $ADODB_INCLUDED_CSV;
 $ADODB_INCLUDED_CSV = 1;
 
-/* 
+/*
 
 
-  V5.14 8 Sept 2011   (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
-  the BSD license will take precedence. See License.txt. 
+  V5.18 3 Sep 2012   (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
+  Released under both BSD license and Lesser GPL library license.
+  Whenever there is any discrepancy between the two licenses,
+  the BSD license will take precedence. See License.txt.
   Set tabs to 4 for best viewing.
   Set tabs to 4 for best viewing.
-  
+
   Latest version is available at http://adodb.sourceforge.net
   Latest version is available at http://adodb.sourceforge.net
-  
-  Library for CSV serialization. This is used by the csv/proxy driver and is the 
-  CacheExecute() serialization format. 
-  
+
+  Library for CSV serialization. This is used by the csv/proxy driver and is the
+  CacheExecute() serialization format.
+
   ==== NOTE ====
   Format documented at http://php.weblogs.com/ADODB_CSV
   ==============
   ==== NOTE ====
   Format documented at http://php.weblogs.com/ADODB_CSV
   ==============
@@ -34,61 +34,61 @@ $ADODB_INCLUDED_CSV = 1;
        function _rs2serialize(&$rs,$conn=false,$sql='')
        {
                $max = ($rs) ? $rs->FieldCount() : 0;
        function _rs2serialize(&$rs,$conn=false,$sql='')
        {
                $max = ($rs) ? $rs->FieldCount() : 0;
-               
+
                if ($sql) $sql = urlencode($sql);
                // metadata setup
                if ($sql) $sql = urlencode($sql);
                // metadata setup
-               
+
                if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete
                        if (is_object($conn)) {
                                $sql .= ','.$conn->Affected_Rows();
                                $sql .= ','.$conn->Insert_ID();
                        } else
                                $sql .= ',,';
                if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete
                        if (is_object($conn)) {
                                $sql .= ','.$conn->Affected_Rows();
                                $sql .= ','.$conn->Insert_ID();
                        } else
                                $sql .= ',,';
-                       
+
                        $text = "====-1,0,$sql\n";
                        return $text;
                }
                $tt = ($rs->timeCreated) ? $rs->timeCreated : time();
                        $text = "====-1,0,$sql\n";
                        return $text;
                }
                $tt = ($rs->timeCreated) ? $rs->timeCreated : time();
-               
+
                ## changed format from ====0 to ====1
                $line = "====1,$tt,$sql\n";
                ## changed format from ====0 to ====1
                $line = "====1,$tt,$sql\n";
-               
+
                if ($rs->databaseType == 'array') {
                        $rows = $rs->_array;
                } else {
                        $rows = array();
                if ($rs->databaseType == 'array') {
                        $rows = $rs->_array;
                } else {
                        $rows = array();
-                       while (!$rs->EOF) {     
+                       while (!$rs->EOF) {
                                $rows[] = $rs->fields;
                                $rs->MoveNext();
                                $rows[] = $rs->fields;
                                $rs->MoveNext();
-                       } 
+                       }
                }
                }
-               
+
                for($i=0; $i < $max; $i++) {
                        $o = $rs->FetchField($i);
                        $flds[] = $o;
                }
                for($i=0; $i < $max; $i++) {
                        $o = $rs->FetchField($i);
                        $flds[] = $o;
                }
-       
+
                $savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
                $class = $rs->connection->arrayClass;
                $rs2 = new $class();
                $rs2->timeCreated = $rs->timeCreated; # memcache fix
                $rs2->sql = $rs->sql;
                $savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
                $class = $rs->connection->arrayClass;
                $rs2 = new $class();
                $rs2->timeCreated = $rs->timeCreated; # memcache fix
                $rs2->sql = $rs->sql;
-               $rs2->oldProvider = $rs->dataProvider; 
+               $rs2->oldProvider = $rs->dataProvider;
                $rs2->InitArrayFields($rows,$flds);
                $rs2->fetchMode = $savefetch;
                return $line.serialize($rs2);
        }
 
                $rs2->InitArrayFields($rows,$flds);
                $rs2->fetchMode = $savefetch;
                return $line.serialize($rs2);
        }
 
-       
+
 /**
 /**
-* Open CSV file and convert it into Data. 
+* Open CSV file and convert it into Data.
 *
 * @param url           file/ftp/http url
 * @param err           returns the error message
 * @param timeout       dispose if recordset has been alive for $timeout secs
 *
 * @return              recordset, or false if error occured. If no
 *
 * @param url           file/ftp/http url
 * @param err           returns the error message
 * @param timeout       dispose if recordset has been alive for $timeout secs
 *
 * @return              recordset, or false if error occured. If no
-*                      error occurred in sql INSERT/UPDATE/DELETE, 
+*                      error occurred in sql INSERT/UPDATE/DELETE,
 *                      empty recordset is returned
 */
        function csv2rs($url,&$err,$timeout=0, $rsclass='ADORecordSet_array')
 *                      empty recordset is returned
 */
        function csv2rs($url,&$err,$timeout=0, $rsclass='ADORecordSet_array')
@@ -103,7 +103,7 @@ $ADODB_INCLUDED_CSV = 1;
                @flock($fp, LOCK_SH);
                $arr = array();
                $ttl = 0;
                @flock($fp, LOCK_SH);
                $arr = array();
                $ttl = 0;
-               
+
                if ($meta = fgetcsv($fp, 32000, ",")) {
                        // check if error message
                        if (strncmp($meta[0],'****',4) === 0) {
                if ($meta = fgetcsv($fp, 32000, ",")) {
                        // check if error message
                        if (strncmp($meta[0],'****',4) === 0) {
@@ -113,10 +113,10 @@ $ADODB_INCLUDED_CSV = 1;
                        }
                        // check for meta data
                        // $meta[0] is -1 means return an empty recordset
                        }
                        // check for meta data
                        // $meta[0] is -1 means return an empty recordset
-                       // $meta[1] contains a time 
-       
+                       // $meta[1] contains a time
+
                        if (strncmp($meta[0], '====',4) === 0) {
                        if (strncmp($meta[0], '====',4) === 0) {
-                       
+
                                if ($meta[0] == "====-1") {
                                        if (sizeof($meta) < 5) {
                                                $err = "Corrupt first line for format -1";
                                if ($meta[0] == "====-1") {
                                        if (sizeof($meta) < 5) {
                                                $err = "Corrupt first line for format -1";
@@ -124,12 +124,12 @@ $ADODB_INCLUDED_CSV = 1;
                                                return $false;
                                        }
                                        fclose($fp);
                                                return $false;
                                        }
                                        fclose($fp);
-                                       
+
                                        if ($timeout > 0) {
                                                $err = " Illegal Timeout $timeout ";
                                                return $false;
                                        }
                                        if ($timeout > 0) {
                                                $err = " Illegal Timeout $timeout ";
                                                return $false;
                                        }
-                                       
+
                                        $rs = new $rsclass($val=true);
                                        $rs->fields = array();
                                        $rs->timeCreated = $meta[1];
                                        $rs = new $rsclass($val=true);
                                        $rs->fields = array();
                                        $rs->timeCreated = $meta[1];
@@ -137,9 +137,9 @@ $ADODB_INCLUDED_CSV = 1;
                                        $rs->_numOfFields = 0;
                                        $rs->sql = urldecode($meta[2]);
                                        $rs->affectedrows = (integer)$meta[3];
                                        $rs->_numOfFields = 0;
                                        $rs->sql = urldecode($meta[2]);
                                        $rs->affectedrows = (integer)$meta[3];
-                                       $rs->insertid = $meta[4];       
+                                       $rs->insertid = $meta[4];
                                        return $rs;
                                        return $rs;
-                               } 
+                               }
                        # Under high volume loads, we want only 1 thread/process to _write_file
                        # so that we don't have 50 processes queueing to write the same data.
                        # We use probabilistic timeout, ahead of time.
                        # Under high volume loads, we want only 1 thread/process to _write_file
                        # so that we don't have 50 processes queueing to write the same data.
                        # We use probabilistic timeout, ahead of time.
@@ -149,7 +149,7 @@ $ADODB_INCLUDED_CSV = 1;
                        # -1 sec after timeout give processes 1/4 chance of timing out
                        # +0 sec after timeout, give processes 100% chance of timing out
                                if (sizeof($meta) > 1) {
                        # -1 sec after timeout give processes 1/4 chance of timing out
                        # +0 sec after timeout, give processes 100% chance of timing out
                                if (sizeof($meta) > 1) {
-                                       if($timeout >0){ 
+                                       if($timeout >0){
                                                $tdiff = (integer)( $meta[1]+$timeout - time());
                                                if ($tdiff <= 2) {
                                                        switch($tdiff) {
                                                $tdiff = (integer)( $meta[1]+$timeout - time());
                                                if ($tdiff <= 2) {
                                                        switch($tdiff) {
@@ -161,7 +161,7 @@ $ADODB_INCLUDED_CSV = 1;
                                                                        return $false;
                                                                }
                                                                break;
                                                                        return $false;
                                                                }
                                                                break;
-                                                       case 2: 
+                                                       case 2:
                                                                if ((rand() & 15) == 0) {
                                                                        fclose($fp);
                                                                        $err = "Timeout 2";
                                                                if ((rand() & 15) == 0) {
                                                                        fclose($fp);
                                                                        $err = "Timeout 2";
@@ -175,12 +175,12 @@ $ADODB_INCLUDED_CSV = 1;
                                                                        return $false;
                                                                }
                                                                break;
                                                                        return $false;
                                                                }
                                                                break;
-                                                       default: 
+                                                       default:
                                                                fclose($fp);
                                                                $err = "Timeout 0";
                                                                return $false;
                                                        } // switch
                                                                fclose($fp);
                                                                $err = "Timeout 0";
                                                                return $false;
                                                        } // switch
-                                                       
+
                                                } // if check flush cache
                                        }// (timeout>0)
                                        $ttl = $meta[1];
                                                } // if check flush cache
                                        }// (timeout>0)
                                        $ttl = $meta[1];
@@ -190,7 +190,7 @@ $ADODB_INCLUDED_CSV = 1;
                                if ($meta[0] === '====1') {
                                        // slurp in the data
                                        $MAXSIZE = 128000;
                                if ($meta[0] === '====1') {
                                        // slurp in the data
                                        $MAXSIZE = 128000;
-                                       
+
                                        $text = fread($fp,$MAXSIZE);
                                        if (strlen($text)) {
                                                while ($txt = fread($fp,$MAXSIZE)) {
                                        $text = fread($fp,$MAXSIZE);
                                        if (strlen($text)) {
                                                while ($txt = fread($fp,$MAXSIZE)) {
@@ -206,7 +206,7 @@ $ADODB_INCLUDED_CSV = 1;
                                        }
                                        return $rs;
                                }
                                        }
                                        return $rs;
                                }
-                               
+
                                $meta = false;
                                $meta = fgetcsv($fp, 32000, ",");
                                if (!$meta) {
                                $meta = false;
                                $meta = fgetcsv($fp, 32000, ",");
                                if (!$meta) {
@@ -236,15 +236,15 @@ $ADODB_INCLUDED_CSV = 1;
                        $err = "Recordset had unexpected EOF 2";
                        return $false;
                }
                        $err = "Recordset had unexpected EOF 2";
                        return $false;
                }
-               
+
                // slurp in the data
                $MAXSIZE = 128000;
                // slurp in the data
                $MAXSIZE = 128000;
-               
+
                $text = '';
                while ($txt = fread($fp,$MAXSIZE)) {
                        $text .= $txt;
                }
                $text = '';
                while ($txt = fread($fp,$MAXSIZE)) {
                        $text .= $txt;
                }
-                       
+
                fclose($fp);
                @$arr = unserialize($text);
                //var_dump($arr);
                fclose($fp);
                @$arr = unserialize($text);
                //var_dump($arr);
@@ -258,18 +258,18 @@ $ADODB_INCLUDED_CSV = 1;
                $rs->InitArrayFields($arr,$flds);
                return $rs;
        }
                $rs->InitArrayFields($arr,$flds);
                return $rs;
        }
-       
+
 
        /**
        * Save a file $filename and its $contents (normally for caching) with file locking
        * Returns true if ok, false if fopen/fwrite error, 0 if rename error (eg. file is locked)
        */
        function adodb_write_file($filename, $contents,$debug=false)
 
        /**
        * Save a file $filename and its $contents (normally for caching) with file locking
        * Returns true if ok, false if fopen/fwrite error, 0 if rename error (eg. file is locked)
        */
        function adodb_write_file($filename, $contents,$debug=false)
-       { 
+       {
        # http://www.php.net/bugs.php?id=9203 Bug that flock fails on Windows
        # So to simulate locking, we assume that rename is an atomic operation.
        # http://www.php.net/bugs.php?id=9203 Bug that flock fails on Windows
        # So to simulate locking, we assume that rename is an atomic operation.
-       # First we delete $filename, then we create a $tempfile write to it and 
-       # rename to the desired $filename. If the rename works, then we successfully 
+       # First we delete $filename, then we create a $tempfile write to it and
+       # rename to the desired $filename. If the rename works, then we successfully
        # modified the file exclusively.
        # What a stupid need - having to simulate locking.
        # Risks:
        # modified the file exclusively.
        # What a stupid need - having to simulate locking.
        # Risks:
@@ -279,14 +279,14 @@ $ADODB_INCLUDED_CSV = 1;
        # 4. another process creates $filename between unlink() and rename() -- ok, rename() fails and  cache updated
                if (strncmp(PHP_OS,'WIN',3) === 0) {
                        // skip the decimal place
        # 4. another process creates $filename between unlink() and rename() -- ok, rename() fails and  cache updated
                if (strncmp(PHP_OS,'WIN',3) === 0) {
                        // skip the decimal place
-                       $mtime = substr(str_replace(' ','_',microtime()),2); 
+                       $mtime = substr(str_replace(' ','_',microtime()),2);
                        // getmypid() actually returns 0 on Win98 - never mind!
                        $tmpname = $filename.uniqid($mtime).getmypid();
                        if (!($fd = @fopen($tmpname,'w'))) return false;
                        if (fwrite($fd,$contents)) $ok = true;
                        else $ok = false;
                        fclose($fd);
                        // getmypid() actually returns 0 on Win98 - never mind!
                        $tmpname = $filename.uniqid($mtime).getmypid();
                        if (!($fd = @fopen($tmpname,'w'))) return false;
                        if (fwrite($fd,$contents)) $ok = true;
                        else $ok = false;
                        fclose($fd);
-                       
+
                        if ($ok) {
                                @chmod($tmpname,0644);
                                // the tricky moment
                        if ($ok) {
                                @chmod($tmpname,0644);
                                // the tricky moment
@@ -312,7 +312,7 @@ $ADODB_INCLUDED_CSV = 1;
                        if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
                        $ok = false;
                }
                        if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
                        $ok = false;
                }
-       
+
                return $ok;
        }
 ?>
\ No newline at end of file
                return $ok;
        }
 ?>
\ No newline at end of file
index 31acb2d..6a9fa6b 100644 (file)
@@ -1,15 +1,15 @@
 <?php
 
 /**
 <?php
 
 /**
-  V5.14 8 Sept 2011   (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
+  V5.18 3 Sep 2012   (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
+  Released under both BSD license and Lesser GPL library license.
+  Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
   the BSD license will take precedence.
-       
+
   Set tabs to 4 for best viewing.
   Set tabs to 4 for best viewing.
+
        DOCUMENTATION:
        DOCUMENTATION:
-       
+
                See adodb/tests/test-datadict.php for docs and examples.
 */
 
                See adodb/tests/test-datadict.php for docs and examples.
 */
 
@@ -42,13 +42,13 @@ if (!function_exists('ctype_alnum')) {
 /**
        Parse arguments, treat "text" (text) and 'text' as quotation marks.
        To escape, use "" or '' or ))
 /**
        Parse arguments, treat "text" (text) and 'text' as quotation marks.
        To escape, use "" or '' or ))
-       
+
        Will read in "abc def" sans quotes, as: abc def
        Same with 'abc def'.
        However if `abc def`, then will read in as `abc def`
        Will read in "abc def" sans quotes, as: abc def
        Same with 'abc def'.
        However if `abc def`, then will read in as `abc def`
-       
+
        @param endstmtchar    Character that indicates end of statement
        @param endstmtchar    Character that indicates end of statement
-       @param tokenchars     Include the following characters in tokens apart from A-Z and 0-9 
+       @param tokenchars     Include the following characters in tokens apart from A-Z and 0-9
        @returns 2 dimensional array containing parsed tokens.
 */
 function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
        @returns 2 dimensional array containing parsed tokens.
 */
 function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
@@ -62,7 +62,7 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
        $max = strlen($args);
        $quoted = false;
        $tokarr = array();
        $max = strlen($args);
        $quoted = false;
        $tokarr = array();
-       
+
        while ($pos < $max) {
                $ch = substr($args,$pos,1);
                switch($ch) {
        while ($pos < $max) {
                $ch = substr($args,$pos,1);
                switch($ch) {
@@ -77,17 +77,17 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
                                }
                                break;
                        }
                                }
                                break;
                        }
-                       
+
                        $tokarr[] = $ch;
                        break;
                        $tokarr[] = $ch;
                        break;
-               
+
                case '`':
                        if ($intoken) $tokarr[] = $ch;
                case '(':
                case '`':
                        if ($intoken) $tokarr[] = $ch;
                case '(':
-               case ')':       
+               case ')':
                case '"':
                case "'":
                case '"':
                case "'":
-                       
+
                        if ($intoken) {
                                if (empty($endquote)) {
                                        $tokens[$stmtno][] = implode('',$tokarr);
                        if ($intoken) {
                                if (empty($endquote)) {
                                        $tokens[$stmtno][] = implode('',$tokarr);
@@ -109,9 +109,9 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
                                        }
                                } else
                                        $tokarr[] = $ch;
                                        }
                                } else
                                        $tokarr[] = $ch;
-                                       
+
                        }else {
                        }else {
-                       
+
                                if ($ch == '(') $endquote = ')';
                                else $endquote = $ch;
                                $quoted = true;
                                if ($ch == '(') $endquote = ')';
                                else $endquote = $ch;
                                $quoted = true;
@@ -120,27 +120,27 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
                                if ($ch == '`') $tokarr[] = '`';
                        }
                        break;
                                if ($ch == '`') $tokarr[] = '`';
                        }
                        break;
-                       
+
                default:
                default:
-                       
+
                        if (!$intoken) {
                                if ($ch == $endstmtchar) {
                                        $stmtno += 1;
                                        $tokens[$stmtno] = array();
                                        break;
                                }
                        if (!$intoken) {
                                if ($ch == $endstmtchar) {
                                        $stmtno += 1;
                                        $tokens[$stmtno] = array();
                                        break;
                                }
-                       
+
                                $intoken = true;
                                $quoted = false;
                                $endquote = false;
                                $tokarr = array();
                                $intoken = true;
                                $quoted = false;
                                $endquote = false;
                                $tokarr = array();
-       
+
                        }
                        }
-                       
+
                        if ($quoted) $tokarr[] = $ch;
                        else if (ctype_alnum($ch) || strpos($tokenchars,$ch) !== false) $tokarr[] = $ch;
                        else {
                        if ($quoted) $tokarr[] = $ch;
                        else if (ctype_alnum($ch) || strpos($tokenchars,$ch) !== false) $tokarr[] = $ch;
                        else {
-                               if ($ch == $endstmtchar) {                      
+                               if ($ch == $endstmtchar) {
                                        $tokens[$stmtno][] = implode('',$tokarr);
                                        $stmtno += 1;
                                        $tokens[$stmtno] = array();
                                        $tokens[$stmtno][] = implode('',$tokarr);
                                        $stmtno += 1;
                                        $tokens[$stmtno] = array();
@@ -156,7 +156,7 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
                $pos += 1;
        }
        if ($intoken) $tokens[$stmtno][] = implode('',$tokarr);
                $pos += 1;
        }
        if ($intoken) $tokens[$stmtno][] = implode('',$tokarr);
-       
+
        return $tokens;
 }
 
        return $tokens;
 }
 
@@ -165,7 +165,7 @@ class ADODB_DataDict {
        var $connection;
        var $debug = false;
        var $dropTable = 'DROP TABLE %s';
        var $connection;
        var $debug = false;
        var $dropTable = 'DROP TABLE %s';
-       var $renameTable = 'RENAME TABLE %s TO %s'; 
+       var $renameTable = 'RENAME TABLE %s TO %s';
        var $dropIndex = 'DROP INDEX %s';
        var $addCol = ' ADD';
        var $alterCol = ' ALTER COLUMN';
        var $dropIndex = 'DROP INDEX %s';
        var $addCol = ' ADD';
        var $alterCol = ' ALTER COLUMN';
@@ -180,43 +180,43 @@ class ADODB_DataDict {
        var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql
        var $blobSize = 100;    /// any varchar/char field this size or greater is treated as a blob
                                                        /// in other words, we use a text area for editting.
        var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql
        var $blobSize = 100;    /// any varchar/char field this size or greater is treated as a blob
                                                        /// in other words, we use a text area for editting.
-       
+
        function GetCommentSQL($table,$col)
        {
                return false;
        }
        function GetCommentSQL($table,$col)
        {
                return false;
        }
-       
+
        function SetCommentSQL($table,$col,$cmt)
        {
                return false;
        }
        function SetCommentSQL($table,$col,$cmt)
        {
                return false;
        }
-       
+
        function MetaTables()
        {
                if (!$this->connection->IsConnected()) return array();
                return $this->connection->MetaTables();
        }
        function MetaTables()
        {
                if (!$this->connection->IsConnected()) return array();
                return $this->connection->MetaTables();
        }
-       
+
        function MetaColumns($tab, $upper=true, $schema=false)
        {
                if (!$this->connection->IsConnected()) return array();
                return $this->connection->MetaColumns($this->TableName($tab), $upper, $schema);
        }
        function MetaColumns($tab, $upper=true, $schema=false)
        {
                if (!$this->connection->IsConnected()) return array();
                return $this->connection->MetaColumns($this->TableName($tab), $upper, $schema);
        }
-       
+
        function MetaPrimaryKeys($tab,$owner=false,$intkey=false)
        {
                if (!$this->connection->IsConnected()) return array();
                return $this->connection->MetaPrimaryKeys($this->TableName($tab), $owner, $intkey);
        }
        function MetaPrimaryKeys($tab,$owner=false,$intkey=false)
        {
                if (!$this->connection->IsConnected()) return array();
                return $this->connection->MetaPrimaryKeys($this->TableName($tab), $owner, $intkey);
        }
-       
+
        function MetaIndexes($table, $primary = false, $owner = false)
        {
                if (!$this->connection->IsConnected()) return array();
                return $this->connection->MetaIndexes($this->TableName($table), $primary, $owner);
        }
        function MetaIndexes($table, $primary = false, $owner = false)
        {
                if (!$this->connection->IsConnected()) return array();
                return $this->connection->MetaIndexes($this->TableName($table), $primary, $owner);
        }
-       
+
        function MetaType($t,$len=-1,$fieldobj=false)
        function MetaType($t,$len=-1,$fieldobj=false)
-       {               
+       {
                static $typeMap = array(
                'VARCHAR' => 'C',
                'VARCHAR2' => 'C',
                static $typeMap = array(
                'VARCHAR' => 'C',
                'VARCHAR2' => 'C',
@@ -263,7 +263,7 @@ class ADODB_DataDict {
                'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql
                ##
                'BOOL' => 'L',
                'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql
                ##
                'BOOL' => 'L',
-               'BOOLEAN' => 'L', 
+               'BOOLEAN' => 'L',
                'BIT' => 'L',
                'L' => 'L',
                ##
                'BIT' => 'L',
                'L' => 'L',
                ##
@@ -296,21 +296,21 @@ class ADODB_DataDict {
                'NUM' => 'N',
                'NUMERIC' => 'N',
                'MONEY' => 'N',
                'NUM' => 'N',
                'NUMERIC' => 'N',
                'MONEY' => 'N',
-               
+
                ## informix 9.2
                ## 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',
                'SQLTEXT' => 'X',
                 ## informix 10
                "SQLINT8" => 'I8',
@@ -320,7 +320,7 @@ class ADODB_DataDict {
                "SQLLVARCHAR" => 'X',
                "SQLBOOL" => 'L'
                );
                "SQLLVARCHAR" => 'X',
                "SQLBOOL" => 'L'
                );
-               
+
                if (!$this->connection->IsConnected()) {
                        $t = strtoupper($t);
                        if (isset($typeMap[$t])) return $typeMap[$t];
                if (!$this->connection->IsConnected()) {
                        $t = strtoupper($t);
                        if (isset($typeMap[$t])) return $typeMap[$t];
@@ -328,36 +328,36 @@ class ADODB_DataDict {
                }
                return $this->connection->MetaType($t,$len,$fieldobj);
        }
                }
                return $this->connection->MetaType($t,$len,$fieldobj);
        }
-       
+
        function NameQuote($name = NULL,$allowBrackets=false)
        {
                if (!is_string($name)) {
                        return FALSE;
                }
        function NameQuote($name = NULL,$allowBrackets=false)
        {
                if (!is_string($name)) {
                        return FALSE;
                }
-               
+
                $name = trim($name);
                $name = trim($name);
-               
+
                if ( !is_object($this->connection) ) {
                        return $name;
                }
                if ( !is_object($this->connection) ) {
                        return $name;
                }
-               
+
                $quote = $this->connection->nameQuote;
                $quote = $this->connection->nameQuote;
-               
+
                // if name is of the form `name`, quote it
                if ( preg_match('/^`(.+)`$/', $name, $matches) ) {
                        return $quote . $matches[1] . $quote;
                }
                // if name is of the form `name`, quote it
                if ( preg_match('/^`(.+)`$/', $name, $matches) ) {
                        return $quote . $matches[1] . $quote;
                }
-               
+
                // if name contains special characters, quote it
                $regex = ($allowBrackets) ? $this->nameRegexBrackets : $this->nameRegex;
                // if name contains special characters, quote it
                $regex = ($allowBrackets) ? $this->nameRegexBrackets : $this->nameRegex;
-               
+
                if ( !preg_match('/^[' . $regex . ']+$/', $name) ) {
                        return $quote . $name . $quote;
                }
                if ( !preg_match('/^[' . $regex . ']+$/', $name) ) {
                        return $quote . $name . $quote;
                }
-               
+
                return $name;
        }
                return $name;
        }
-       
+
        function TableName($name)
        {
                if ( $this->schema ) {
        function TableName($name)
        {
                if ( $this->schema ) {
@@ -365,7 +365,7 @@ class ADODB_DataDict {
                }
                return $this->NameQuote($name);
        }
                }
                return $this->NameQuote($name);
        }
-       
+
        // Executes the sql array returned by GetTableSQL and GetIndexSQL
        function ExecuteSQLArray($sql, $continueOnError = true)
        {
        // Executes the sql array returned by GetTableSQL and GetIndexSQL
        function ExecuteSQLArray($sql, $continueOnError = true)
        {
@@ -373,7 +373,7 @@ class ADODB_DataDict {
                $conn = $this->connection;
                $saved = $conn->debug;
                foreach($sql as $line) {
                $conn = $this->connection;
                $saved = $conn->debug;
                foreach($sql as $line) {
-                       
+
                        if ($this->debug) $conn->debug = true;
                        $ok = $conn->Execute($line);
                        $conn->debug = $saved;
                        if ($this->debug) $conn->debug = true;
                        $ok = $conn->Execute($line);
                        $conn->debug = $saved;
@@ -385,43 +385,43 @@ class ADODB_DataDict {
                }
                return $rez;
        }
                }
                return $rez;
        }
-       
+
        /**
                Returns the actual type given a character code.
        /**
                Returns the actual type given a character code.
-               
+
                C:  varchar
                X:  CLOB (character large object) or largest varchar size if CLOB is not supported
                C2: Multibyte varchar
                X2: Multibyte CLOB
                C:  varchar
                X:  CLOB (character large object) or largest varchar size if CLOB is not supported
                C2: Multibyte varchar
                X2: Multibyte CLOB
-               
+
                B:  BLOB (binary large object)
                B:  BLOB (binary large object)
-               
+
                D:  Date
                D:  Date
-               T:  Date-time 
+               T:  Date-time
                L:  Integer field suitable for storing booleans (0 or 1)
                I:  Integer
                F:  Floating point number
                N:  Numeric or decimal number
        */
                L:  Integer field suitable for storing booleans (0 or 1)
                I:  Integer
                F:  Floating point number
                N:  Numeric or decimal number
        */
-       
+
        function ActualType($meta)
        {
                return $meta;
        }
        function ActualType($meta)
        {
                return $meta;
        }
-       
+
        function CreateDatabase($dbname,$options=false)
        {
                $options = $this->_Options($options);
                $sql = array();
        function CreateDatabase($dbname,$options=false)
        {
                $options = $this->_Options($options);
                $sql = array();
-               
+
                $s = 'CREATE DATABASE ' . $this->NameQuote($dbname);
                if (isset($options[$this->upperName]))
                        $s .= ' '.$options[$this->upperName];
                $s = 'CREATE DATABASE ' . $this->NameQuote($dbname);
                if (isset($options[$this->upperName]))
                        $s .= ' '.$options[$this->upperName];
-               
+
                $sql[] = $s;
                return $sql;
        }
                $sql[] = $s;
                return $sql;
        }
-       
+
        /*
         Generates the SQL to create index. Returns an array of sql strings.
        */
        /*
         Generates the SQL to create index. Returns an array of sql strings.
        */
@@ -430,25 +430,25 @@ class ADODB_DataDict {
                if (!is_array($flds)) {
                        $flds = explode(',',$flds);
                }
                if (!is_array($flds)) {
                        $flds = explode(',',$flds);
                }
-               
+
                foreach($flds as $key => $fld) {
                        # some indexes can use partial fields, eg. index first 32 chars of "name" with NAME(32)
                        $flds[$key] = $this->NameQuote($fld,$allowBrackets=true);
                }
                foreach($flds as $key => $fld) {
                        # some indexes can use partial fields, eg. index first 32 chars of "name" with NAME(32)
                        $flds[$key] = $this->NameQuote($fld,$allowBrackets=true);
                }
-               
+
                return $this->_IndexSQL($this->NameQuote($idxname), $this->TableName($tabname), $flds, $this->_Options($idxoptions));
        }
                return $this->_IndexSQL($this->NameQuote($idxname), $this->TableName($tabname), $flds, $this->_Options($idxoptions));
        }
-       
+
        function DropIndexSQL ($idxname, $tabname = NULL)
        {
                return array(sprintf($this->dropIndex, $this->NameQuote($idxname), $this->TableName($tabname)));
        }
        function DropIndexSQL ($idxname, $tabname = NULL)
        {
                return array(sprintf($this->dropIndex, $this->NameQuote($idxname), $this->TableName($tabname)));
        }
-       
+
        function SetSchema($schema)
        {
                $this->schema = $schema;
        }
        function SetSchema($schema)
        {
                $this->schema = $schema;
        }
-       
+
        function AddColumnSQL($tabname, $flds)
        {
                $tabname = $this->TableName ($tabname);
        function AddColumnSQL($tabname, $flds)
        {
                $tabname = $this->TableName ($tabname);
@@ -468,7 +468,7 @@ class ADODB_DataDict {
                }
                return $sql;
        }
                }
                return $sql;
        }
-       
+
        /**
         * Change the definition of one column
         *
        /**
         * Change the definition of one column
         *
@@ -500,7 +500,7 @@ class ADODB_DataDict {
                }
                return $sql;
        }
                }
                return $sql;
        }
-       
+
        /**
         * Rename one column
         *
        /**
         * Rename one column
         *
@@ -523,7 +523,7 @@ class ADODB_DataDict {
                }
                return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def));
        }
                }
                return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def));
        }
-               
+
        /**
         * Drop one column
         *
        /**
         * Drop one column
         *
@@ -546,17 +546,17 @@ class ADODB_DataDict {
                }
                return $sql;
        }
                }
                return $sql;
        }
-       
+
        function DropTableSQL($tabname)
        {
                return array (sprintf($this->dropTable, $this->TableName($tabname)));
        }
        function DropTableSQL($tabname)
        {
                return array (sprintf($this->dropTable, $this->TableName($tabname)));
        }
-       
+
        function RenameTableSQL($tabname,$newname)
        {
                return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname)));
        function RenameTableSQL($tabname,$newname)
        {
                return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname)));
-       }       
-       
+       }
+
        /**
         Generate the SQL to create table. Returns an array of sql strings.
        */
        /**
         Generate the SQL to create table. Returns an array of sql strings.
        */
@@ -565,11 +565,11 @@ class ADODB_DataDict {
                list($lines,$pkey,$idxs) = $this->_GenFields($flds, true);
                // genfields can return FALSE at times
                if ($lines == null) $lines = array();
                list($lines,$pkey,$idxs) = $this->_GenFields($flds, true);
                // genfields can return FALSE at times
                if ($lines == null) $lines = array();
-               
+
                $taboptions = $this->_Options($tableoptions);
                $tabname = $this->TableName ($tabname);
                $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
                $taboptions = $this->_Options($tableoptions);
                $tabname = $this->TableName ($tabname);
                $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
-               
+
                // ggiunta - 2006/10/12 - KLUDGE:
         // if we are on autoincrement, and table options includes REPLACE, the
         // autoincrement sequence has already been dropped on table creation sql, so
                // ggiunta - 2006/10/12 - KLUDGE:
         // if we are on autoincrement, and table options includes REPLACE, the
         // autoincrement sequence has already been dropped on table creation sql, so
@@ -579,7 +579,7 @@ class ADODB_DataDict {
                unset($taboptions['REPLACE']);
                $tsql = $this->_Triggers($tabname,$taboptions);
                foreach($tsql as $s) $sql[] = $s;
                unset($taboptions['REPLACE']);
                $tsql = $this->_Triggers($tabname,$taboptions);
                foreach($tsql as $s) $sql[] = $s;
-               
+
                if (is_array($idxs)) {
                        foreach($idxs as $idx => $idxdef) {
                                $sql_idxs = $this->CreateIndexSql($idx, $tabname,  $idxdef['cols'], $idxdef['opts']);
                if (is_array($idxs)) {
                        foreach($idxs as $idx => $idxdef) {
                                $sql_idxs = $this->CreateIndexSql($idx, $tabname,  $idxdef['cols'], $idxdef['opts']);
@@ -589,9 +589,9 @@ class ADODB_DataDict {
 
                return $sql;
        }
 
                return $sql;
        }
-               
-       
-       
+
+
+
        function _GenFields($flds,$widespacing=false)
        {
                if (is_string($flds)) {
        function _GenFields($flds,$widespacing=false)
        {
                if (is_string($flds)) {
@@ -608,7 +608,7 @@ class ADODB_DataDict {
                                                $f1['INDEX'] = '';
                                                // fall through intentionally
                                        case 'CONSTRAINT':
                                                $f1['INDEX'] = '';
                                                // fall through intentionally
                                        case 'CONSTRAINT':
-                                       case 'DEFAULT': 
+                                       case 'DEFAULT':
                                                $hasparam = $token;
                                                break;
                                        default:
                                                $hasparam = $token;
                                                break;
                                        default:
@@ -633,7 +633,7 @@ class ADODB_DataDict {
                                $hasparam = false;
 
                                $flds[] = $f1;
                                $hasparam = false;
 
                                $flds[] = $f1;
-                               
+
                        }
                }
                $this->autoIncrement = false;
                        }
                }
                $this->autoIncrement = false;
@@ -642,7 +642,7 @@ class ADODB_DataDict {
                $idxs = array();
                foreach($flds as $fld) {
                        $fld = _array_change_key_case($fld);
                $idxs = array();
                foreach($flds as $fld) {
                        $fld = _array_change_key_case($fld);
-                       
+
                        $fname = false;
                        $fdefault = false;
                        $fautoinc = false;
                        $fname = false;
                        $fdefault = false;
                        $fautoinc = false;
@@ -658,20 +658,20 @@ class ADODB_DataDict {
                        $funsigned = false;
                        $findex = '';
                        $funiqueindex = false;
                        $funsigned = false;
                        $findex = '';
                        $funiqueindex = false;
-                       
+
                        //-----------------
                        // Parse attributes
                        foreach($fld as $attr => $v) {
                                if ($attr == 2 && is_numeric($v)) $attr = 'SIZE';
                                else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v);
                        //-----------------
                        // Parse attributes
                        foreach($fld as $attr => $v) {
                                if ($attr == 2 && is_numeric($v)) $attr = 'SIZE';
                                else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v);
-                               
+
                                switch($attr) {
                                case '0':
                                case 'NAME':    $fname = $v; break;
                                case '1':
                                case 'TYPE':    $ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;
                                switch($attr) {
                                case '0':
                                case 'NAME':    $fname = $v; break;
                                case '1':
                                case 'TYPE':    $ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;
-                               
-                               case 'SIZE':    
+
+                               case 'SIZE':
                                                                $dotat = strpos($v,'.'); if ($dotat === false) $dotat = strpos($v,',');
                                                                if ($dotat === false) $fsize = $v;
                                                                else {
                                                                $dotat = strpos($v,'.'); if ($dotat === false) $dotat = strpos($v,',');
                                                                if ($dotat === false) $fsize = $v;
                                                                else {
@@ -697,33 +697,33 @@ class ADODB_DataDict {
                                case 'UNIQUE': $funiqueindex = true; break;
                                } //switch
                        } // foreach $fld
                                case 'UNIQUE': $funiqueindex = true; break;
                                } //switch
                        } // foreach $fld
-                       
+
                        //--------------------
                        // VALIDATE FIELD INFO
                        if (!strlen($fname)) {
                                if ($this->debug) ADOConnection::outp("Undefined NAME");
                                return false;
                        }
                        //--------------------
                        // VALIDATE FIELD INFO
                        if (!strlen($fname)) {
                                if ($this->debug) ADOConnection::outp("Undefined NAME");
                                return false;
                        }
-                       
+
                        $fid = strtoupper(preg_replace('/^`(.+)`$/', '$1', $fname));
                        $fname = $this->NameQuote($fname);
                        $fid = strtoupper(preg_replace('/^`(.+)`$/', '$1', $fname));
                        $fname = $this->NameQuote($fname);
-                       
+
                        if (!strlen($ftype)) {
                                if ($this->debug) ADOConnection::outp("Undefined TYPE for field '$fname'");
                                return false;
                        } else {
                                $ftype = strtoupper($ftype);
                        }
                        if (!strlen($ftype)) {
                                if ($this->debug) ADOConnection::outp("Undefined TYPE for field '$fname'");
                                return false;
                        } else {
                                $ftype = strtoupper($ftype);
                        }
-                       
+
                        $ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);
                        $ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);
-                       
+
                        if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls
                        if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls
-                       
+
                        if ($fprimary) $pkey[] = $fname;
                        if ($fprimary) $pkey[] = $fname;
-                       
+
                        // some databases do not allow blobs to have defaults
                        if ($ty == 'X') $fdefault = false;
                        // some databases do not allow blobs to have defaults
                        if ($ty == 'X') $fdefault = false;
-                       
+
                        // build list of indexes
                        if ($findex != '') {
                                if (array_key_exists($findex, $idxs)) {
                        // build list of indexes
                        if ($findex != '') {
                                if (array_key_exists($findex, $idxs)) {
@@ -760,7 +760,7 @@ class ADODB_DataDict {
                                        $fdefault = $this->connection->sysDate;
                                }
                        } else if ($fdefault !== false && !$fnoquote) {
                                        $fdefault = $this->connection->sysDate;
                                }
                        } else if ($fdefault !== false && !$fnoquote) {
-                               if ($ty == 'C' or $ty == 'X' or 
+                               if ($ty == 'C' or $ty == 'X' or
                                        ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault))) {
 
                                        if (($ty == 'D' || $ty == 'T') && strtolower($fdefault) != 'null') {
                                        ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault))) {
 
                                        if (($ty == 'D' || $ty == 'T') && strtolower($fdefault) != 'null') {
@@ -775,27 +775,27 @@ class ADODB_DataDict {
                                                }
                                        }
                                        else
                                                }
                                        }
                                        else
-                                       if (strlen($fdefault) != 1 && substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ') 
+                                       if (strlen($fdefault) != 1 && substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ')
                                                $fdefault = trim($fdefault);
                                        else if (strtolower($fdefault) != 'null')
                                                $fdefault = $this->connection->qstr($fdefault);
                                }
                        }
                        $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned);
                                                $fdefault = trim($fdefault);
                                        else if (strtolower($fdefault) != 'null')
                                                $fdefault = $this->connection->qstr($fdefault);
                                }
                        }
                        $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned);
-                       
+
                        // add index creation
                        if ($widespacing) $fname = str_pad($fname,24);
                        // add index creation
                        if ($widespacing) $fname = str_pad($fname,24);
-                       
+
                         // check for field names appearing twice
             if (array_key_exists($fid, $lines)) {
                 ADOConnection::outp("Field '$fname' defined twice");
             }
                         // check for field names appearing twice
             if (array_key_exists($fid, $lines)) {
                 ADOConnection::outp("Field '$fname' defined twice");
             }
-                       
+
                        $lines[$fid] = $fname.' '.$ftype.$suffix;
                        $lines[$fid] = $fname.' '.$ftype.$suffix;
-                       
+
                        if ($fautoinc) $this->autoIncrement = true;
                } // foreach $flds
                        if ($fautoinc) $this->autoIncrement = true;
                } // foreach $flds
-               
+
                return array($lines,$pkey,$idxs);
        }
 
                return array($lines,$pkey,$idxs);
        }
 
@@ -813,56 +813,56 @@ class ADODB_DataDict {
                }
                return $ftype;
        }
                }
                return $ftype;
        }
-       
-       
+
+
        // return string must begin with space
        function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
        // return string must begin with space
        function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
-       {       
+       {
                $suffix = '';
                if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
                if ($fnotnull) $suffix .= ' NOT NULL';
                if ($fconstraint) $suffix .= ' '.$fconstraint;
                return $suffix;
        }
                $suffix = '';
                if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
                if ($fnotnull) $suffix .= ' NOT NULL';
                if ($fconstraint) $suffix .= ' '.$fconstraint;
                return $suffix;
        }
-       
+
        function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
        {
                $sql = array();
        function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
        {
                $sql = array();
-               
+
                if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
                        $sql[] = sprintf ($this->dropIndex, $idxname);
                        if ( isset($idxoptions['DROP']) )
                                return $sql;
                }
                if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
                        $sql[] = sprintf ($this->dropIndex, $idxname);
                        if ( isset($idxoptions['DROP']) )
                                return $sql;
                }
-               
+
                if ( empty ($flds) ) {
                        return $sql;
                }
                if ( empty ($flds) ) {
                        return $sql;
                }
-               
+
                $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
                $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
-       
+
                $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' ';
                $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' ';
-               
+
                if ( isset($idxoptions[$this->upperName]) )
                        $s .= $idxoptions[$this->upperName];
                if ( isset($idxoptions[$this->upperName]) )
                        $s .= $idxoptions[$this->upperName];
-               
+
                if ( is_array($flds) )
                        $flds = implode(', ',$flds);
                $s .= '(' . $flds . ')';
                $sql[] = $s;
                if ( is_array($flds) )
                        $flds = implode(', ',$flds);
                $s .= '(' . $flds . ')';
                $sql[] = $s;
-               
+
                return $sql;
        }
                return $sql;
        }
-       
+
        function _DropAutoIncrement($tabname)
        {
                return false;
        }
        function _DropAutoIncrement($tabname)
        {
                return false;
        }
-       
+
        function _TableSQL($tabname,$lines,$pkey,$tableoptions)
        {
                $sql = array();
        function _TableSQL($tabname,$lines,$pkey,$tableoptions)
        {
                $sql = array();
-               
+
                if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) {
                        $sql[] = sprintf($this->dropTable,$tabname);
                        if ($this->autoIncrement) {
                if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) {
                        $sql[] = sprintf($this->dropTable,$tabname);
                        if ($this->autoIncrement) {
@@ -879,19 +879,19 @@ class ADODB_DataDict {
                        $s .= ",\n                 PRIMARY KEY (";
                        $s .= implode(", ",$pkey).")";
                }
                        $s .= ",\n                 PRIMARY KEY (";
                        $s .= implode(", ",$pkey).")";
                }
-               if (isset($tableoptions['CONSTRAINTS'])) 
+               if (isset($tableoptions['CONSTRAINTS']))
                        $s .= "\n".$tableoptions['CONSTRAINTS'];
                        $s .= "\n".$tableoptions['CONSTRAINTS'];
-               
-               if (isset($tableoptions[$this->upperName.'_CONSTRAINTS'])) 
+
+               if (isset($tableoptions[$this->upperName.'_CONSTRAINTS']))
                        $s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];
                        $s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];
-               
+
                $s .= "\n)";
                if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];
                $sql[] = $s;
                $s .= "\n)";
                if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];
                $sql[] = $s;
-               
+
                return $sql;
        }
                return $sql;
        }
-       
+
        /**
                GENERATE TRIGGERS IF NEEDED
                used when table has auto-incrementing field that is emulated using triggers
        /**
                GENERATE TRIGGERS IF NEEDED
                used when table has auto-incrementing field that is emulated using triggers
@@ -900,7 +900,7 @@ class ADODB_DataDict {
        {
                return array();
        }
        {
                return array();
        }
-       
+
        /**
                Sanitize options, so that array elements with no keys are promoted to keys
        */
        /**
                Sanitize options, so that array elements with no keys are promoted to keys
        */
@@ -914,8 +914,8 @@ class ADODB_DataDict {
                }
                return $newopts;
        }
                }
                return $newopts;
        }
-       
-       
+
+
        function _getSizePrec($size)
        {
                $fsize = false;
        function _getSizePrec($size)
        {
                $fsize = false;
@@ -929,34 +929,34 @@ class ADODB_DataDict {
                }
                return array($fsize, $fprec);
        }
                }
                return array($fsize, $fprec);
        }
-       
+
        /**
        "Florian Buzin [ easywe ]" <florian.buzin#easywe.de>
        /**
        "Florian Buzin [ easywe ]" <florian.buzin#easywe.de>
-       
+
        This function changes/adds new fields to your table. You don't
        have to know if the col is new or not. It will check on its own.
        */
        function ChangeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false)
        {
        global $ADODB_FETCH_MODE;
        This function changes/adds new fields to your table. You don't
        have to know if the col is new or not. It will check on its own.
        */
        function ChangeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false)
        {
        global $ADODB_FETCH_MODE;
-       
+
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
                if ($this->connection->fetchMode !== false) $savem = $this->connection->SetFetchMode(false);
                $save = $ADODB_FETCH_MODE;
                $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
                if ($this->connection->fetchMode !== false) $savem = $this->connection->SetFetchMode(false);
-               
+
                // check table exists
                $save_handler = $this->connection->raiseErrorFn;
                $this->connection->raiseErrorFn = '';
                $cols = $this->MetaColumns($tablename);
                $this->connection->raiseErrorFn = $save_handler;
                // check table exists
                $save_handler = $this->connection->raiseErrorFn;
                $this->connection->raiseErrorFn = '';
                $cols = $this->MetaColumns($tablename);
                $this->connection->raiseErrorFn = $save_handler;
-               
+
                if (isset($savem)) $this->connection->SetFetchMode($savem);
                $ADODB_FETCH_MODE = $save;
                if (isset($savem)) $this->connection->SetFetchMode($savem);
                $ADODB_FETCH_MODE = $save;
-               
-               if ( empty($cols)) { 
+
+               if ( empty($cols)) {
                        return $this->CreateTableSQL($tablename, $flds, $tableoptions);
                }
                        return $this->CreateTableSQL($tablename, $flds, $tableoptions);
                }
-               
+
                if (is_array($flds)) {
                // Cycle through the update fields, comparing
                // existing fields to fields to update.
                if (is_array($flds)) {
                // Cycle through the update fields, comparing
                // existing fields to fields to update.
@@ -969,16 +969,16 @@ class ADODB_DataDict {
                                        $obj = $cols[$k];
                                        if (isset($obj->not_null) && $obj->not_null)
                                                $v = str_replace('NOT NULL','',$v);
                                        $obj = $cols[$k];
                                        if (isset($obj->not_null) && $obj->not_null)
                                                $v = str_replace('NOT NULL','',$v);
-                                       if (isset($obj->auto_increment) && $obj->auto_increment && empty($v['AUTOINCREMENT'])) 
+                                       if (isset($obj->auto_increment) && $obj->auto_increment && empty($v['AUTOINCREMENT']))
                                            $v = str_replace('AUTOINCREMENT','',$v);
                                            $v = str_replace('AUTOINCREMENT','',$v);
-                                       
+
                                        $c = $cols[$k];
                                        $ml = $c->max_length;
                                        $mt = $this->MetaType($c->type,$ml);
                                        $c = $cols[$k];
                                        $ml = $c->max_length;
                                        $mt = $this->MetaType($c->type,$ml);
-                                       
+
                                        if (isset($c->scale)) $sc = $c->scale;
                                        else $sc = 99; // always force change if scale not known.
                                        if (isset($c->scale)) $sc = $c->scale;
                                        else $sc = 99; // always force change if scale not known.
-                                       
+
                                        if ($sc == -1) $sc = false;
                                        list($fsize, $fprec) = $this->_getSizePrec($v['SIZE']);
 
                                        if ($sc == -1) $sc = false;
                                        list($fsize, $fprec) = $this->_getSizePrec($v['SIZE']);
 
@@ -989,11 +989,11 @@ class ADODB_DataDict {
                                        }
                                } else {
                                        $holdflds[$k] = $v;
                                        }
                                } else {
                                        $holdflds[$k] = $v;
-                               }               
+                               }
                        }
                        $flds = $holdflds;
                }
                        }
                        $flds = $holdflds;
                }
-       
+
 
                // already exists, alter table instead
                list($lines,$pkey,$idxs) = $this->_GenFields($flds);
 
                // already exists, alter table instead
                list($lines,$pkey,$idxs) = $this->_GenFields($flds);
@@ -1004,26 +1004,26 @@ class ADODB_DataDict {
 
                foreach ( $lines as $id => $v ) {
                        if ( isset($cols[$id]) && is_object($cols[$id]) ) {
 
                foreach ( $lines as $id => $v ) {
                        if ( isset($cols[$id]) && is_object($cols[$id]) ) {
-                       
+
                                $flds = Lens_ParseArgs($v,',');
                                $flds = Lens_ParseArgs($v,',');
-                               
+
                                //  We are trying to change the size of the field, if not allowed, simply ignore the request.
                                // $flds[1] holds the type, $flds[2] holds the size -postnuke addition
                                if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)
                                 && (isset($flds[0][2]) && is_numeric($flds[0][2]))) {
                                        if ($this->debug) ADOConnection::outp(sprintf("<h3>%s cannot be changed to %s currently</h3>", $flds[0][0], $flds[0][1]));
                                        #echo "<h3>$this->alterCol cannot be changed to $flds currently</h3>";
                                //  We are trying to change the size of the field, if not allowed, simply ignore the request.
                                // $flds[1] holds the type, $flds[2] holds the size -postnuke addition
                                if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)
                                 && (isset($flds[0][2]) && is_numeric($flds[0][2]))) {
                                        if ($this->debug) ADOConnection::outp(sprintf("<h3>%s cannot be changed to %s currently</h3>", $flds[0][0], $flds[0][1]));
                                        #echo "<h3>$this->alterCol cannot be changed to $flds currently</h3>";
-                                       continue;        
+                                       continue;
                                }
                                $sql[] = $alter . $this->alterCol . ' ' . $v;
                        } else {
                                $sql[] = $alter . $this->addCol . ' ' . $v;
                        }
                }
                                }
                                $sql[] = $alter . $this->alterCol . ' ' . $v;
                        } else {
                                $sql[] = $alter . $this->addCol . ' ' . $v;
                        }
                }
-               
+
                if ($dropOldFlds) {
                        foreach ( $cols as $id => $v )
                if ($dropOldFlds) {
                        foreach ( $cols as $id => $v )
-                           if ( !isset($lines[$id]) ) 
+                           if ( !isset($lines[$id]) )
                                        $sql[] = $alter . $this->dropCol . ' ' . $v->name;
                }
                return $sql;
                                        $sql[] = $alter . $this->dropCol . ' ' . $v->name;
                }
                return $sql;
index e140a67..559545f 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 <?php
-/** 
- * @version V5.14 8 Sept 2011  (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
- * Released under both BSD license and Lesser GPL library license. 
- * Whenever there is any discrepancy between the two licenses, 
- * the BSD license will take precedence. 
+/**
+ * @version V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
+ * Released under both BSD license and Lesser GPL library license.
+ * Whenever there is any discrepancy between the two licenses,
+ * the BSD license will take precedence.
  *
  * Set tabs to 4 for best viewing.
  *
  * Set tabs to 4 for best viewing.
- * 
+ *
  * The following code is adapted from the PEAR DB error handling code.
  * Portions (c)1997-2002 The PHP Group.
  */
  * The following code is adapted from the PEAR DB error handling code.
  * Portions (c)1997-2002 The PHP Group.
  */
@@ -41,6 +41,9 @@ if (!defined("DB_ERROR_SYNTAX")) {
        define("DB_ERROR_EXTENSION_NOT_FOUND",-25);
        define("DB_ERROR_NOSUCHDB",           -25);
        define("DB_ERROR_ACCESS_VIOLATION",   -26);
        define("DB_ERROR_EXTENSION_NOT_FOUND",-25);
        define("DB_ERROR_NOSUCHDB",           -25);
        define("DB_ERROR_ACCESS_VIOLATION",   -26);
+       define("DB_ERROR_DEADLOCK",           -27);
+       define("DB_ERROR_STATEMENT_TIMEOUT",  -28);
+       define("DB_ERROR_SERIALIZATION_FAILURE", -29);
 }
 
 function adodb_errormsg($value)
 }
 
 function adodb_errormsg($value)
@@ -59,27 +62,27 @@ function adodb_error($provider,$dbType,$errno)
 {
        //var_dump($errno);
        if (is_numeric($errno) && $errno == 0) return 0;
 {
        //var_dump($errno);
        if (is_numeric($errno) && $errno == 0) return 0;
-       switch($provider) { 
+       switch($provider) {
        case 'mysql': $map = adodb_error_mysql(); break;
        case 'mysql': $map = adodb_error_mysql(); break;
-       
+
        case 'oracle':
        case 'oci8': $map = adodb_error_oci8(); break;
        case 'oracle':
        case 'oci8': $map = adodb_error_oci8(); break;
-       
+
        case 'ibase': $map = adodb_error_ibase(); break;
        case 'ibase': $map = adodb_error_ibase(); break;
-       
+
        case 'odbc': $map = adodb_error_odbc(); break;
        case 'odbc': $map = adodb_error_odbc(); break;
-       
+
        case 'mssql':
        case 'sybase': $map = adodb_error_mssql(); break;
        case 'mssql':
        case 'sybase': $map = adodb_error_mssql(); break;
-       
+
        case 'informix': $map = adodb_error_ifx(); break;
        case 'informix': $map = adodb_error_ifx(); break;
-       
+
        case 'postgres': return adodb_error_pg($errno); break;
        case 'postgres': return adodb_error_pg($errno); break;
-       
+
        case 'sqlite': return $map = adodb_error_sqlite(); break;
        default:
                return DB_ERROR;
        case 'sqlite': return $map = adodb_error_sqlite(); break;
        default:
                return DB_ERROR;
-       }       
+       }
        //print_r($map);
        //var_dump($errno);
        if (isset($map[$errno])) return $map[$errno];
        //print_r($map);
        //var_dump($errno);
        if (isset($map[$errno])) return $map[$errno];
@@ -91,16 +94,19 @@ function adodb_error($provider,$dbType,$errno)
 function adodb_error_pg($errormsg)
 {
        if (is_numeric($errormsg)) return (integer) $errormsg;
 function adodb_error_pg($errormsg)
 {
        if (is_numeric($errormsg)) return (integer) $errormsg;
+       // Postgres has no lock-wait timeout.  The best we could do would be to set a statement timeout.
     static $error_regexps = array(
             '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/i' => DB_ERROR_NOSUCHTABLE,
     static $error_regexps = array(
             '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/i' => DB_ERROR_NOSUCHTABLE,
-            '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/i'      => DB_ERROR_ALREADY_EXISTS,
-            '/divide by zero$/i'                     => DB_ERROR_DIVZERO,
+            '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key.*violates unique constraint/i'     => DB_ERROR_ALREADY_EXISTS,
+            '/database ".+" does not exist$/i'       => DB_ERROR_NOSUCHDB,
+            '/(divide|division) by zero$/i'          => DB_ERROR_DIVZERO,
             '/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER,
             '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/i' => DB_ERROR_NOSUCHFIELD,
             '/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER,
             '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/i' => DB_ERROR_NOSUCHFIELD,
-            '/parser: parse error at or near \"/i'   => DB_ERROR_SYNTAX,
+            '/(parser: parse|syntax) error at or near \"/i'   => DB_ERROR_SYNTAX,
             '/referential integrity violation/i'     => DB_ERROR_CONSTRAINT,
             '/referential integrity violation/i'     => DB_ERROR_CONSTRAINT,
-                       '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key.*violates unique constraint/i'     
-                                => DB_ERROR_ALREADY_EXISTS
+            '/deadlock detected$/i'                  => DB_ERROR_DEADLOCK,
+            '/canceling statement due to statement timeout$/i' => DB_ERROR_STATEMENT_TIMEOUT,
+            '/could not serialize access due to/i'   => DB_ERROR_SERIALIZATION_FAILURE
         );
        reset($error_regexps);
     while (list($regexp,$code) = each($error_regexps)) {
         );
        reset($error_regexps);
     while (list($regexp,$code) = each($error_regexps)) {
@@ -111,7 +117,7 @@ function adodb_error_pg($errormsg)
     // Fall back to DB_ERROR if there was no mapping.
     return DB_ERROR;
 }
     // Fall back to DB_ERROR if there was no mapping.
     return DB_ERROR;
 }
-       
+
 function adodb_error_odbc()
 {
 static $MAP = array(
 function adodb_error_odbc()
 {
 static $MAP = array(
@@ -169,7 +175,7 @@ static $MAP = array(
             -923 => DB_ERROR_CONNECT_FAILED,
             -924 => DB_ERROR_CONNECT_FAILED
         );
             -923 => DB_ERROR_CONNECT_FAILED,
             -924 => DB_ERROR_CONNECT_FAILED
         );
-               
+
                return $MAP;
 }
 
                return $MAP;
 }
 
@@ -187,7 +193,7 @@ static $MAP = array(
             '-1210'   => DB_ERROR_INVALID_DATE,
             '-1212'   => DB_ERROR_INVALID_DATE
        );
             '-1210'   => DB_ERROR_INVALID_DATE,
             '-1212'   => DB_ERROR_INVALID_DATE
        );
-          
+
           return $MAP;
 }
 
           return $MAP;
 }
 
@@ -206,7 +212,7 @@ static $MAP = array(
             2291 => DB_ERROR_CONSTRAINT,
             2449 => DB_ERROR_CONSTRAINT
         );
             2291 => DB_ERROR_CONSTRAINT,
             2449 => DB_ERROR_CONSTRAINT
         );
-          
+
        return $MAP;
 }
 
        return $MAP;
 }
 
@@ -216,7 +222,7 @@ static $MAP = array(
                  208 => DB_ERROR_NOSUCHTABLE,
           2601 => DB_ERROR_ALREADY_EXISTS
        );
                  208 => DB_ERROR_NOSUCHTABLE,
           2601 => DB_ERROR_ALREADY_EXISTS
        );
-          
+
        return $MAP;
 }
 
        return $MAP;
 }
 
@@ -225,7 +231,7 @@ function adodb_error_sqlite()
 static $MAP = array(
                  1 => DB_ERROR_SYNTAX
        );
 static $MAP = array(
                  1 => DB_ERROR_SYNTAX
        );
-          
+
        return $MAP;
 }
 
        return $MAP;
 }
 
@@ -252,7 +258,7 @@ static $MAP = array(
                    2002 => DB_ERROR_CONNECT_FAILED,
                        2005 => DB_ERROR_CONNECT_FAILED
        );
                    2002 => DB_ERROR_CONNECT_FAILED,
                        2005 => DB_ERROR_CONNECT_FAILED
        );
-          
+
        return $MAP;
 }
 ?>
\ No newline at end of file
        return $MAP;
 }
 ?>
\ No newline at end of file