]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8429 Upgrade ADOdb to 4.9.4
authorskodak <skodak>
Sat, 7 Apr 2007 08:30:19 +0000 (08:30 +0000)
committerskodak <skodak>
Sat, 7 Apr 2007 08:30:19 +0000 (08:30 +0000)
102 files changed:
lib/adodb/adodb-active-record.inc.php
lib/adodb/adodb-csvlib.inc.php
lib/adodb/adodb-datadict.inc.php
lib/adodb/adodb-error.inc.php
lib/adodb/adodb-errorhandler.inc.php
lib/adodb/adodb-errorpear.inc.php
lib/adodb/adodb-exceptions.inc.php
lib/adodb/adodb-iterator.inc.php
lib/adodb/adodb-lib.inc.php
lib/adodb/adodb-memcache.lib.inc.php
lib/adodb/adodb-pager.inc.php
lib/adodb/adodb-pear.inc.php
lib/adodb/adodb-perf.inc.php
lib/adodb/adodb-php4.inc.php
lib/adodb/adodb-xmlschema.inc.php
lib/adodb/adodb-xmlschema03.inc.php
lib/adodb/adodb.inc.php
lib/adodb/datadict/datadict-access.inc.php
lib/adodb/datadict/datadict-db2.inc.php
lib/adodb/datadict/datadict-firebird.inc.php
lib/adodb/datadict/datadict-generic.inc.php
lib/adodb/datadict/datadict-ibase.inc.php
lib/adodb/datadict/datadict-informix.inc.php
lib/adodb/datadict/datadict-mssql.inc.php
lib/adodb/datadict/datadict-mysql.inc.php
lib/adodb/datadict/datadict-oci8.inc.php
lib/adodb/datadict/datadict-postgres.inc.php
lib/adodb/datadict/datadict-sapdb.inc.php
lib/adodb/datadict/datadict-sybase.inc.php
lib/adodb/drivers/adodb-access.inc.php
lib/adodb/drivers/adodb-ado.inc.php
lib/adodb/drivers/adodb-ado5.inc.php
lib/adodb/drivers/adodb-ado_access.inc.php
lib/adodb/drivers/adodb-ado_mssql.inc.php
lib/adodb/drivers/adodb-borland_ibase.inc.php
lib/adodb/drivers/adodb-csv.inc.php
lib/adodb/drivers/adodb-db2.inc.php
lib/adodb/drivers/adodb-fbsql.inc.php
lib/adodb/drivers/adodb-firebird.inc.php
lib/adodb/drivers/adodb-ibase.inc.php
lib/adodb/drivers/adodb-informix.inc.php
lib/adodb/drivers/adodb-informix72.inc.php
lib/adodb/drivers/adodb-ldap.inc.php
lib/adodb/drivers/adodb-mssql.inc.php
lib/adodb/drivers/adodb-mssql_n.inc.php
lib/adodb/drivers/adodb-mssqlpo.inc.php
lib/adodb/drivers/adodb-mysql.inc.php
lib/adodb/drivers/adodb-mysqli.inc.php
lib/adodb/drivers/adodb-mysqlt.inc.php
lib/adodb/drivers/adodb-netezza.inc.php
lib/adodb/drivers/adodb-oci8.inc.php
lib/adodb/drivers/adodb-oci805.inc.php
lib/adodb/drivers/adodb-oci8po.inc.php
lib/adodb/drivers/adodb-odbc.inc.php
lib/adodb/drivers/adodb-odbc_db2.inc.php
lib/adodb/drivers/adodb-odbc_mssql.inc.php
lib/adodb/drivers/adodb-odbc_oracle.inc.php
lib/adodb/drivers/adodb-odbtp.inc.php
lib/adodb/drivers/adodb-odbtp_unicode.inc.php
lib/adodb/drivers/adodb-oracle.inc.php
lib/adodb/drivers/adodb-pdo.inc.php
lib/adodb/drivers/adodb-pdo_mssql.inc.php
lib/adodb/drivers/adodb-pdo_mysql.inc.php
lib/adodb/drivers/adodb-pdo_oci.inc.php
lib/adodb/drivers/adodb-pdo_pgsql.inc.php
lib/adodb/drivers/adodb-postgres.inc.php
lib/adodb/drivers/adodb-postgres64.inc.php
lib/adodb/drivers/adodb-postgres7.inc.php
lib/adodb/drivers/adodb-postgres8.inc.php
lib/adodb/drivers/adodb-proxy.inc.php
lib/adodb/drivers/adodb-sapdb.inc.php
lib/adodb/drivers/adodb-sqlanywhere.inc.php
lib/adodb/drivers/adodb-sqlite.inc.php
lib/adodb/drivers/adodb-sqlitepo.inc.php
lib/adodb/drivers/adodb-sybase.inc.php
lib/adodb/drivers/adodb-sybase_ase.inc.php
lib/adodb/drivers/adodb-vfp.inc.php
lib/adodb/perf/perf-db2.inc.php
lib/adodb/perf/perf-informix.inc.php
lib/adodb/perf/perf-mssql.inc.php
lib/adodb/perf/perf-mysql.inc.php
lib/adodb/perf/perf-oci8.inc.php
lib/adodb/perf/perf-postgres.inc.php
lib/adodb/pivottable.inc.php
lib/adodb/readme_moodle.txt
lib/adodb/rsfilter.inc.php
lib/adodb/session/adodb-compress-bzip2.php
lib/adodb/session/adodb-compress-gzip.php
lib/adodb/session/adodb-cryptsession.php
lib/adodb/session/adodb-cryptsession2.php
lib/adodb/session/adodb-encrypt-mcrypt.php
lib/adodb/session/adodb-encrypt-md5.php
lib/adodb/session/adodb-encrypt-secret.php
lib/adodb/session/adodb-session-clob.php
lib/adodb/session/adodb-session-clob2.php
lib/adodb/session/adodb-session.php
lib/adodb/session/adodb-session2.php
lib/adodb/session/old/adodb-cryptsession.php
lib/adodb/session/old/adodb-session-clob.php
lib/adodb/session/old/adodb-session.php
lib/adodb/toexport.inc.php
lib/adodb/tohtml.inc.php

index fb2395154f3e751a40083c4867eb2b11f8a8b1ea..35bf968edde3315c9b1ab02320460f3e97e647e5 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
 
-@version V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+@version V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Latest version is available at http://adodb.sourceforge.net
  
   Released under both BSD license and Lesser GPL library license. 
@@ -10,7 +10,7 @@
   
   Active Record implementation. Superset of Zend Framework's.
   
-  Version 0.04
+  Version 0.07
   
   See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord 
        for info on Ruby on Rails Active Record implementation
@@ -42,9 +42,9 @@ function ADODB_SetDatabaseAdapter(&$db)
        
                foreach($_ADODB_ACTIVE_DBS as $k => $d) {
                        if (PHP_VERSION >= 5) {
-                               if ($d->db == $db) return $k;
+                               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;
                        }
                }
@@ -223,7 +223,7 @@ class ADODB_Active_Record {
                        break;
                default:
                        foreach($cols as $name => $fldobj) {
-                               $name = ($fldobj->$name);
+                               $name = ($fldobj->name);
                                $this->$name = null;
                                $attr[$name] = $fldobj;
                        }
@@ -285,6 +285,15 @@ class ADODB_Active_Record {
                return $this->_lasterr;
        }
        
+       function ErrorNo() 
+       {
+               if ($this->_dbat < 0) return -9999; // no database connection...
+               $db = $this->DB();
+               
+               return (int) $db->ErrorNo();
+       }
+
+
        // retrieve ADOConnection from _ADODB_Active_DBs
        function &DB()
        {
index a031d985cc7ca0b905c70a3bc3e0f92e6d91f70b..1e34d39eef0d83991f002c68dc9fa65af235fa2f 100644 (file)
@@ -8,7 +8,7 @@ $ADODB_INCLUDED_CSV = 1;
 
 /* 
 
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index edfa5a65c8f203848e5ea0237455a1c408783435..c31edd82237ada2f960b169822df3ef2f0d9a912 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -277,7 +277,7 @@ class ADODB_DataDict {
                return $rez;
        }
        
-       /*
+       /**
                Returns the actual type given a character code.
                
                C:  varchar
@@ -344,11 +344,19 @@ class ADODB_DataDict {
        {
                $tabname = $this->TableName ($tabname);
                $sql = array();
-               list($lines,$pkey) = $this->_GenFields($flds);
+               list($lines,$pkey,$idxs) = $this->_GenFields($flds);
+               // genfields can return FALSE at times
+               if ($lines  == null) $lines = array();
                $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' ';
                foreach($lines as $v) {
                        $sql[] = $alter . $v;
                }
+               if (is_array($idxs)) {
+                       foreach($idxs as $idx => $idxdef) {
+                               $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']);
+                               $sql = array_merge($sql, $sql_idxs);
+                       }
+               }
                return $sql;
        }
        
@@ -367,11 +375,20 @@ class ADODB_DataDict {
        {
                $tabname = $this->TableName ($tabname);
                $sql = array();
-               list($lines,$pkey) = $this->_GenFields($flds);
+               list($lines,$pkey,$idxs) = $this->_GenFields($flds);
+               // genfields can return FALSE at times
+               if ($lines == null) $lines = array();
                $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' ';
                foreach($lines as $v) {
                        $sql[] = $alter . $v;
                }
+               if (is_array($idxs)) {
+                       foreach($idxs as $idx => $idxdef) {
+                               $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']);
+                               $sql = array_merge($sql, $sql_idxs);
+                       }
+
+               }
                return $sql;
        }
        
@@ -389,7 +406,9 @@ class ADODB_DataDict {
        {
                $tabname = $this->TableName ($tabname);
                if ($flds) {
-                       list($lines,$pkey) = $this->_GenFields($flds);
+                       list($lines,$pkey,$idxs) = $this->_GenFields($flds);
+                       // genfields can return FALSE at times
+                       if ($lines == null) $lines = array();
                        list(,$first) = each($lines);
                        list(,$column_def) = split("[\t ]+",$first,2);
                }
@@ -429,22 +448,36 @@ class ADODB_DataDict {
                return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname)));
        }       
        
-       /*
+       /**
         Generate the SQL to create table. Returns an array of sql strings.
        */
-       function CreateTableSQL($tabname, $flds, $tableoptions=false)
+       function CreateTableSQL($tabname, $flds, $tableoptions=array())
        {
-               if (!$tableoptions) $tableoptions = array();
-               
-               list($lines,$pkey) = $this->_GenFields($flds, true);
+               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);
                
+               // 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
+        // we avoid passing REPLACE to trigger creation code. This prevents
+        // creating sql that double-drops the sequence
+        if ($this->autoIncrement && isset($taboptions['REPLACE']))
+               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']);
+                               $sql = array_merge($sql, $sql_idxs);
+                       }
+               }
+
                return $sql;
        }
        
@@ -460,6 +493,9 @@ class ADODB_DataDict {
                                $f1 = array();
                                foreach($f0 as $token) {
                                        switch (strtoupper($token)) {
+                                       case 'INDEX':
+                                               $f1['INDEX'] = '';
+                                               // fall through intentionally
                                        case 'CONSTRAINT':
                                        case 'DEFAULT': 
                                                $hasparam = $token;
@@ -471,6 +507,20 @@ class ADODB_DataDict {
                                                break;
                                        }
                                }
+                               // 'index' token without a name means single column index: name it after column
+                               if (array_key_exists('INDEX', $f1) && $f1['INDEX'] == '') {
+                                       $f1['INDEX'] = isset($f0['NAME']) ? $f0['NAME'] : $f0[0];
+                                       // check if column name used to create an index name was quoted
+                                       if (($f1['INDEX'][0] == '"' || $f1['INDEX'][0] == "'" || $f1['INDEX'][0] == "`") &&
+                                               ($f1['INDEX'][0] == substr($f1['INDEX'], -1))) {
+                                               $f1['INDEX'] = $f1['INDEX'][0].'idx_'.substr($f1['INDEX'], 1, -1).$f1['INDEX'][0];
+                                       }
+                                       else
+                                               $f1['INDEX'] = 'idx_'.$f1['INDEX'];
+                               }
+                               // reset it, so we don't get next field 1st token as INDEX...
+                               $hasparam = false;
+
                                $flds[] = $f1;
                                
                        }
@@ -478,9 +528,10 @@ class ADODB_DataDict {
                $this->autoIncrement = false;
                $lines = array();
                $pkey = array();
+               $idxs = array();
                foreach($flds as $fld) {
                        $fld = _array_change_key_case($fld);
-               
+                       
                        $fname = false;
                        $fdefault = false;
                        $fautoinc = false;
@@ -494,6 +545,8 @@ class ADODB_DataDict {
                        $fconstraint = false;
                        $fnotnull = false;
                        $funsigned = false;
+                       $findex = '';
+                       $funiqueindex = false;
                        
                        //-----------------
                        // Parse attributes
@@ -519,7 +572,8 @@ class ADODB_DataDict {
                                case 'AUTOINCREMENT':
                                case 'AUTO':    $fautoinc = true; $fnotnull = true; break;
                                case 'KEY':
-                               case 'PRIMARY': $fprimary = $v; $fnotnull = true; break;
+                // a primary key col can be non unique in itself (if key spans many cols...)
+                               case 'PRIMARY': $fprimary = $v; $fnotnull = true; /*$funiqueindex = true;*/ break;
                                case 'DEF':
                                case 'DEFAULT': $fdefault = $v; break;
                                case 'NOTNULL': $fnotnull = $v; break;
@@ -527,6 +581,9 @@ class ADODB_DataDict {
                                case 'DEFDATE': $fdefdate = $v; break;
                                case 'DEFTIMESTAMP': $fdefts = $v; break;
                                case 'CONSTRAINT': $fconstraint = $v; break;
+                               // let INDEX keyword create a 'very standard' index on column
+                               case 'INDEX': $findex = $v; break;
+                               case 'UNIQUE': $funiqueindex = true; break;
                                } //switch
                        } // foreach $fld
                        
@@ -556,6 +613,27 @@ class ADODB_DataDict {
                        // 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)) {
+                                       $idxs[$findex]['cols'][] = ($fname);
+                                       if (in_array('UNIQUE', $idxs[$findex]['opts']) != $funiqueindex) {
+                                               if ($this->debug) ADOConnection::outp("Index $findex defined once UNIQUE and once not");
+                                       }
+                                       if ($funiqueindex && !in_array('UNIQUE', $idxs[$findex]['opts']))
+                                               $idxs[$findex]['opts'][] = 'UNIQUE';
+                               }
+                               else
+                               {
+                                       $idxs[$findex] = array();
+                                       $idxs[$findex]['cols'] = array($fname);
+                                       if ($funiqueindex)
+                                               $idxs[$findex]['opts'] = array('UNIQUE');
+                                       else
+                                               $idxs[$findex]['opts'] = array();
+                               }
+                       }
+
                        //--------------------
                        // CONSTRUCT FIELD SQL
                        if ($fdefts) {
@@ -570,24 +648,47 @@ class ADODB_DataDict {
                                } else {
                                        $fdefault = $this->connection->sysDate;
                                }
-                       } else if ($fdefault !== false && !$fnoquote)
+                       } else if ($fdefault !== false && !$fnoquote) {
                                if ($ty == 'C' or $ty == 'X' or 
-                                       ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault)))
+                                       ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault))) {
+
+                                       if (($ty == 'D' || $ty == 'T') && strtolower($fdefault) != 'null') {
+                                               // convert default date into database-aware code
+                                               if ($ty == 'T')
+                                               {
+                                                       $fdefault = $this->connection->DBTimeStamp($fdefault);
+                                               }
+                                               else
+                                               {
+                                                       $fdefault = $this->connection->DBDate($fdefault);
+                                               }
+                                       }
+                                       else
                                        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);
                        
+                       // 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");
+            }
+                       
                        $lines[$fid] = $fname.' '.$ftype.$suffix;
                        
                        if ($fautoinc) $this->autoIncrement = true;
                } // foreach $flds
                
-               return array($lines,$pkey);
+               return array($lines,$pkey,$idxs);
        }
-       /*
+
+       /**
                 GENERATE THE SIZE PART OF THE DATATYPE
                        $ftype is the actual type
                        $ty is the type defined originally in the DDL
@@ -680,7 +781,7 @@ class ADODB_DataDict {
                return $sql;
        }
        
-       /*
+       /**
                GENERATE TRIGGERS IF NEEDED
                used when table has auto-incrementing field that is emulated using triggers
        */
@@ -689,7 +790,7 @@ class ADODB_DataDict {
                return array();
        }
        
-       /*
+       /**
                Sanitize options, so that array elements with no keys are promoted to keys
        */
        function _Options($opts)
@@ -703,7 +804,7 @@ class ADODB_DataDict {
                return $newopts;
        }
        
-       /*
+       /**
        "Florian Buzin [ easywe ]" <florian.buzin#easywe.de>
        
        This function changes/adds new fields to your table. You don't
@@ -760,7 +861,9 @@ class ADODB_DataDict {
        
 
                // already exists, alter table instead
-               list($lines,$pkey) = $this->_GenFields($flds);
+               list($lines,$pkey,$idxs) = $this->_GenFields($flds);
+               // genfields can return FALSE at times
+               if ($lines == null) $lines = array();
                $alter = 'ALTER TABLE ' . $this->TableName($tablename);
                $sql = array();
 
@@ -770,8 +873,10 @@ class ADODB_DataDict {
                                $flds = Lens_ParseArgs($v,',');
                                
                                //  We are trying to change the size of the field, if not allowed, simply ignore the request.
-                               if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) continue;         
-                       
+                               if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) {
+                                       echo "<h3>$this->alterCol cannot be changed to $flds currently</h3>";
+                                       continue;        
+                               }
                                $sql[] = $alter . $this->alterCol . ' ' . $v;
                        } else {
                                $sql[] = $alter . $this->addCol . ' ' . $v;
index 8c959dc82c5f633aab786d97b6a3e9bd2692aeea..e60976b0d8e59421e8e446521bbc168541bab251 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /** 
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license. 
  * Whenever there is any discrepancy between the two licenses, 
  * the BSD license will take precedence. 
index 6b852118da9761a26ad87c93513283ca635db064..87a9267c5ea82a10d47db74d97af9f874a061f86 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @version V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license.
  * Whenever there is any discrepancy between the two licenses,
  * the BSD license will take precedence.
index 37d7bf13192c87b5acd9d3a4f9798d78a5c29844..31cbe6141b4562c3c69866397e24ab8ff671a0cd 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /** 
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 1f11e5481f64a8617f2a7fe28a8d879107893ea4..3eebc4e065219febec2df613ffa1e909ad70e3c4 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * @version V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license.
  * Whenever there is any discrepancy between the two licenses,
  * the BSD license will take precedence.
index 031c963d50242e8da18d8da8e0f707496c0b622e..d291e78a13638308acccae4560ecc1551fd06dd1 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index b3e9246c59d0d04cb3dd576933c0db6e432a11d5..2cae67c1003ce029ee70060a06437db6735dfe7c 100644 (file)
@@ -7,7 +7,7 @@ global $ADODB_INCLUDED_LIB;
 $ADODB_INCLUDED_LIB = 1;
 
 /* 
- @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim\@natsoft.com.my). All rights reserved.
+ @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim\@natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
@@ -56,16 +56,17 @@ function adodb_probetypes(&$array,&$types,$probe=8)
                        
                }
        }
+       
 }
 
-function  &adodb_transpose(&$arr, &$newarr, &$hdr)
+function  adodb_transpose(&$arr, &$newarr, &$hdr, &$fobjs)
 {
        $oldX = sizeof(reset($arr));
        $oldY = sizeof($arr);   
        
        if ($hdr) {
                $startx = 1;
-               $hdr = array();
+               $hdr = array('Fields');
                for ($y = 0; $y < $oldY; $y++) {
                        $hdr[] = $arr[$y][0];
                }
@@ -73,7 +74,12 @@ function  &adodb_transpose(&$arr, &$newarr, &$hdr)
                $startx = 0;
 
        for ($x = $startx; $x < $oldX; $x++) {
-               $newarr[] = array();
+               if ($fobjs) {
+                       $o = $fobjs[$x];
+                       $newarr[] = array($o->name);
+               } else
+                       $newarr[] = array();
+                       
                for ($y = 0; $y < $oldY; $y++) {
                        $newarr[$x-$startx][] = $arr[$y][$x];
                }
@@ -560,6 +566,8 @@ function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputar
 
 function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=2)
 {
+       global $ADODB_QUOTE_FIELDNAMES;
+
                if (!$rs) {
                        printf(ADODB_BAD_RS,'GetUpdateSQL');
                        return false;
@@ -606,7 +614,7 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
                                                $type = 'C';
                                        }
                                        
-                                       if (strpos($upperfname,' ') !== false)
+                                       if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
                                                $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
                                        else
                                                $fnameq = $upperfname;
@@ -720,6 +728,7 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false,$force=2)
 static $cacheRS = false;
 static $cacheSig = 0;
 static $cacheCols;
+       global $ADODB_QUOTE_FIELDNAMES;
 
        $tableName = '';
        $values = '';
@@ -769,7 +778,7 @@ static $cacheCols;
                $upperfname = strtoupper($field->name);
                if (adodb_key_exists($upperfname,$arrFields,$force)) {
                        $bad = false;
-                       if (strpos($upperfname,' ') !== false)
+                       if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
                                $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
                        else
                                $fnameq = $upperfname;
index fc4748a36cb5327cce931bebbada4d2c59df4299..bc6b420bc6452e2fb256005065b0fb5022f2f9b8 100644 (file)
-<?php
-
-// security - hide paths
-if (!defined('ADODB_DIR')) die();
-
-global $ADODB_INCLUDED_MEMCACHE;
-$ADODB_INCLUDED_MEMCACHE = 1;
-
-/* 
-
-  V4.90 8 June 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
-  the BSD license will take precedence. See License.txt. 
-  Set tabs to 4 for best viewing.
-  
-  Latest version is available at http://adodb.sourceforge.net
-  
-*/
-
-       function &getmemcache($key,&$err, $timeout=0, $host, $port)
-       {
-               $false = false;
-               $err = false;
-
-               if (!function_exists('memcache_pconnect')) {
-                       $err = 'Memcache module PECL extension not found!';
-                       return $false;
-               }
-
-               $memcache = new Memcache;
-               if (!@$memcache->pconnect($host, $port)) {
-                       $err = 'Can\'t connect to memcache server on: '.$host.':'.$port;
-                       return $false;
-               }
-
-               $rs = $memcache->get($key);
-               if (!$rs) {
-                       $err = 'Item with such key doesn\'t exists on the memcached server.';
-                       return $false;
-               }
-
-               $tdiff = intval($rs->timeCreated+$timeout - time());
-               if ($tdiff <= 2) {
-                       switch($tdiff) {
-                               case 2: 
-                                       if ((rand() & 15) == 0) {
-                                               $err = "Timeout 2";
-                                               return $false;
-                                       }
-                                       break;
-                               case 1:
-                                       if ((rand() & 3) == 0) {
-                                               $err = "Timeout 1";
-                                               return $false;
-                                       }
-                                       break;
-                               default: 
-                                       $err = "Timeout 0";
-                                       return $false;
-                       }
-               }
-               return $rs;
-       }
-
-       function putmemcache($key, $rs, $host, $port, $compress, $debug=false)
-       {
-               $false = false;
-               $true = true;
-
-               if (!function_exists('memcache_pconnect')) {
-                       if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
-                       return $false;
-               }
-
-               $memcache = new Memcache;
-               if (!@$memcache->pconnect($host, $port)) {
-                       if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
-                       return $false;
-               }
-
-               $rs->timeCreated = time();
-               if (!$memcache->set($key, $rs, $compress, 0)) {
-                       if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n");
-                       return $false;
-               }
-               return $true;
-       }
-
-       function flushmemcache($key=false, $host, $port, $debug=false)
-       {
-               if (!function_exists('memcache_pconnect')) {
-                       if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
-                       return;
-               }
-
-               $memcache = new Memcache;
-               if (!@$memcache->pconnect($host, $port)) {
-                       if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
-                       return;
-               }
-
-               if ($key) {
-                       if (!$memcache->delete($key)) {
-                               if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n");
-                       } else {
-                               if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n");
-                       }
-               } else {
-                       if (!$memcache->flush()) {
-                               if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");
-                       } else {
-                               if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");
-                       }
-               }
-               return;
-       }
-?>
+<?php\r
+\r
+// security - hide paths\r
+if (!defined('ADODB_DIR')) die();\r
+\r
+global $ADODB_INCLUDED_MEMCACHE;\r
+$ADODB_INCLUDED_MEMCACHE = 1;\r
+\r
+/* \r
+\r
+  V4.90 8 June 2006  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence. See License.txt. \r
+  Set tabs to 4 for best viewing.\r
+  \r
+  Latest version is available at http://adodb.sourceforge.net\r
+  \r
+*/\r
+\r
+       function &getmemcache($key,&$err, $timeout=0, $host, $port)\r
+       {\r
+               $false = false;\r
+               $err = false;\r
+\r
+               if (!function_exists('memcache_pconnect')) {\r
+                       $err = 'Memcache module PECL extension not found!';\r
+                       return $false;\r
+               }\r
+\r
+               $memcache = new Memcache;\r
+               if (!@$memcache->pconnect($host, $port)) {\r
+                       $err = 'Can\'t connect to memcache server on: '.$host.':'.$port;\r
+                       return $false;\r
+               }\r
+\r
+               $rs = $memcache->get($key);\r
+               if (!$rs) {\r
+                       $err = 'Item with such key doesn\'t exists on the memcached server.';\r
+                       return $false;\r
+               }\r
+\r
+               $tdiff = intval($rs->timeCreated+$timeout - time());\r
+               if ($tdiff <= 2) {\r
+                       switch($tdiff) {\r
+                               case 2: \r
+                                       if ((rand() & 15) == 0) {\r
+                                               $err = "Timeout 2";\r
+                                               return $false;\r
+                                       }\r
+                                       break;\r
+                               case 1:\r
+                                       if ((rand() & 3) == 0) {\r
+                                               $err = "Timeout 1";\r
+                                               return $false;\r
+                                       }\r
+                                       break;\r
+                               default: \r
+                                       $err = "Timeout 0";\r
+                                       return $false;\r
+                       }\r
+               }\r
+               return $rs;\r
+       }\r
+\r
+       function putmemcache($key, $rs, $host, $port, $compress, $debug=false)\r
+       {\r
+               $false = false;\r
+               $true = true;\r
+\r
+               if (!function_exists('memcache_pconnect')) {\r
+                       if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");\r
+                       return $false;\r
+               }\r
+\r
+               $memcache = new Memcache;\r
+               if (!@$memcache->pconnect($host, $port)) {\r
+                       if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");\r
+                       return $false;\r
+               }\r
+\r
+               $rs->timeCreated = time();\r
+               if (!$memcache->set($key, $rs, $compress, 0)) {\r
+                       if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n");\r
+                       return $false;\r
+               }\r
+               return $true;\r
+       }\r
+\r
+       function flushmemcache($key=false, $host, $port, $debug=false)\r
+       {\r
+               if (!function_exists('memcache_pconnect')) {\r
+                       if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");\r
+                       return;\r
+               }\r
+\r
+               $memcache = new Memcache;\r
+               if (!@$memcache->pconnect($host, $port)) {\r
+                       if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");\r
+                       return;\r
+               }\r
+\r
+               if ($key) {\r
+                       if (!$memcache->delete($key)) {\r
+                               if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n");\r
+                       } else {\r
+                               if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n");\r
+                       }\r
+               } else {\r
+                       if (!$memcache->flush()) {\r
+                               if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");\r
+                       } else {\r
+                               if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");\r
+                       }\r
+               }\r
+               return;\r
+       }\r
+?>\r
index 0aa3e6a69b2220d52a98aa9ac80c041496ac8665..22321b2eb0ba2f4f77a0e35117c2f267e4bcee46 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-       V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+       V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Released under both BSD license and Lesser GPL library license. 
          Whenever there is any discrepancy between the two licenses, 
          the BSD license will take precedence. 
index e1d17b88b5bfcb5e987b4b1687afa8ba66bc896d..ecaf75310c95b4c49d1d7a3fbdc6f5597cac0d3b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /** 
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license. 
  * Whenever there is any discrepancy between the two licenses, 
  * the BSD license will take precedence. 
index a9093c48d2e041a41901751b089eab728834edf5..e00359fcc1ae377df88b3e8672a09fd10544ff4f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index a23dc17038c1c205f5a86a026b7a00b4be279ca9..99fda1769996f2a96cc134de9b1a1668c343552a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 19612a6ac30c4449a96b0c8d3041a8f994b59e65..c925f0b53d7463fa82f04bd3737e977a69d412a9 100644 (file)
@@ -10,9 +10,9 @@
  * build a database on any ADOdb-supported platform using a simple
  * XML schema.
  *
- * Last Editor: $Author: skodak $
+ * Last Editor: $Author$
  * @author Richard Tango-Lowy & Dan Cech
- * @version $Revision: 1.14 $
+ * @version $Revision$
  *
  * @package axmls
  * @tutorial getting_started.pkg
@@ -1209,7 +1209,7 @@ class dbQuerySet extends dbObject {
 * @tutorial getting_started.pkg
 *
 * @author Richard Tango-Lowy & Dan Cech
-* @version $Revision: 1.14 $
+* @version $Revision$
 *
 * @package axmls
 */
index 40ae3a57fbda69131a0e9494da41f3d02bc8d935..cc98bec6bb2c6fd5ce8517fb383e8632fe4c53b0 100644 (file)
@@ -10,9 +10,9 @@
  * build a database on any ADOdb-supported platform using a simple
  * XML schema.
  *
- * Last Editor: $Author: skodak $
+ * Last Editor: $Author$
  * @author Richard Tango-Lowy & Dan Cech
- * @version $Revision: 1.4 $
+ * @version $Revision$
  *
  * @package axmls
  * @tutorial getting_started.pkg
@@ -1309,7 +1309,7 @@ class dbQuerySet extends dbObject {
 * @tutorial getting_started.pkg
 *
 * @author Richard Tango-Lowy & Dan Cech
-* @version $Revision: 1.4 $
+* @version $Revision$
 *
 * @package axmls
 */
index d8c1b59082988a7337dfaa588f9eba33549078fe..351d505e330d66ac165caba99ee86baf0abd134b 100644 (file)
@@ -14,7 +14,7 @@
 /**
        \mainpage       
        
-        @version V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+        @version V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
 
        Released under both BSD license and Lesser GPL library license. You can choose which license
        you prefer.
@@ -56,7 +56,8 @@
                $ADODB_CACHE_DIR,       // directory to cache recordsets
                $ADODB_EXTENSION,   // ADODB extension installed
                $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF
-               $ADODB_FETCH_MODE;      // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
+               $ADODB_FETCH_MODE,      // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
+               $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql.    
        
        //==============================================================================================        
        // GLOBAL SETUP
                $ADODB_COUNTRECS,       // count number of records returned - slows down query
                $ADODB_CACHE_DIR,       // directory to cache recordsets
                $ADODB_FETCH_MODE,
-               $ADODB_FORCE_TYPE;
+               $ADODB_FORCE_TYPE,
+               $ADODB_QUOTE_FIELDNAMES;
                
                $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;
                $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE;
                /**
                 * ADODB version as a string.
                 */
-               $ADODB_vers = 'V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
+               $ADODB_vers = 'V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
        
                /**
                 * Determines whether recordset->RecordCount() is used. 
                } 
                
                if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead
-                       $rs =& new ADORecordSet_empty();
+                       $rs = new ADORecordSet_empty();
                        return $rs;
                }
                
                return $rv;
        }
        
-       function &Transpose(&$rs)
+       function &Transpose(&$rs,$addfieldnames=true)
        {
                $rs2 =& $this->_rs2rs($rs);
                $false = false;
                if (!$rs2) return $false;
                
-               $rs2->_transpose();
+               $rs2->_transpose($addfieldnames);
                return $rs2;
        }
  
                
                if (empty($this->_metars)) {
                        $rsclass = $this->rsPrefix.$this->databaseType;
-                       $this->_metars =& new $rsclass(false,$this->fetchMode); 
+                       $this->_metars = new $rsclass(false,$this->fetchMode); 
                        $this->_metars->connection =& $this;
                }
                return $this->_metars->MetaType($t,$len,$fieldobj);
                                $this->fmtTimeStamp = "'m-d-Y H:i:s'";
                                break;
                                
+                       case 'PT_BR':   
                        case 'NL':
                        case 'FR':
                        case 'RO':
                $arr = array();
                foreach($rows as $row) {
                
-                       $obj =& new $class($table,$primkeyArr,$this);
+                       $obj = new $class($table,$primkeyArr,$this);
                        if ($obj->ErrorMsg()){
                                $this->_errorMsg = $obj->ErrorMsg();
                                return $false;
                        }
                        $obj->Set($row);
-                       $arr[] =& $obj;
+                       $arr[] = $obj;
                }
                return $arr;
        }
         *
         * @return true if succeeded or false if database does not support transactions
         */
-       function BeginTrans() {return false;}
+       function BeginTrans() 
+       {
+               if ($this->debug) ADOConnection::outp("BeginTrans: Transactions not supported for this driver");
+               return false;
+       }
        
        /* set transaction mode */
        function SetTransactionMode( $transaction_mode ) 
@@ -3387,9 +3394,12 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
         *
         * @return the ADOFieldObject for that column, or false.
         */
-       function &FetchField($fieldoffset) 
+       function &FetchField($fieldoffset = -1
        {
                // must be defined by child class
+               
+               $false = false;
+               return $false;
        }       
        
        /**
@@ -3734,14 +3744,15 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
                        $this->fetchMode = $ADODB_FETCH_MODE;
                }
                
-               function _transpose()
+               function _transpose($addfieldnames=true)
                {
                global $ADODB_INCLUDED_LIB;
                        
                        if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
                        $hdr = true;
                        
-                       adodb_transpose($this->_array, $newarr, $hdr);
+                       $fobjs = $addfieldnames ? $this->_fieldobjects : false;
+                       adodb_transpose($this->_array, $newarr, $hdr, $fobjs);
                        //adodb_pr($newarr);
                        
                        $this->_skiprow1 = false;
@@ -3758,7 +3769,6 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
                                $f->type = $this->_types[$k];
                                $f->max_length = -1;
                                $this->_fieldobjects[] = $f;
-                               
                        }
                        $this->fields = reset($this->_array);
                        
index b6b5379e39e9623681572a2e945f2a899eb33882..4b62eb848155e47ccae2e11315cbd88c0675185a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 2ae7d930c7d03c180d31f6c224a87dc1c81a8786..21191b35b527b9684681970c9536ebf2370ad1d8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 483ff42ea67dc43d6f02ab398a04174a2f387e6a..6598d95aeb17c7008e3251c9ea9adc1115150372 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index c9bf0e0dac86afe5d1098dab1f02462b0d823d8d..fc5ba76849c0fc5664174385067ae354d9250915 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index be2061348d2bed8421787a7a4759ce7a7b74736c..163ba81d7000cc751686a31ead5f05a23c47f005 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 40818e57fffaa3c9ec32d98dd5540b9f6c861fc9..879813bed264ed58f4fce401742b19a2511c33e9 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index d5d094220a7541ea288710934c9f92a868306d2e..5737c27ad1ef3621f4635971cd16b1fe912e304e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 338e2864c25ff3438674d6adf023f60de19ba7b7..a4af25ff006db2f9bca78f83ef4f4f9a505607e4 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index c40f2d245fc95c6a86758411b04172bdec9659ca..238fab47c69f4ccd9ffdb7a5fc29b90e22fd8f03 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -196,6 +196,14 @@ end;
                        $seqname = $this->seqPrefix.$tabname;
                        $trigname = $this->trigPrefix.$seqname;
                }
+               
+               if (strlen($seqname) > 30) {
+                       $seqname = $this->seqPrefix.uniqid('');
+               } // end if
+               if (strlen($trigname) > 30) {
+                       $trigname = $this->trigPrefix.uniqid('');
+               } // end if
+
                if (isset($tableoptions['REPLACE'])) $sql[] = "DROP SEQUENCE $seqname";
                $seqCache = '';
                if (isset($tableoptions['SEQUENCE_CACHE'])){$seqCache = $tableoptions['SEQUENCE_CACHE'];}
index 36c8b853d4f50a72083f26f26ae4589bcd3e3654..c56d3b6e7f5b00d777b18216fa4c2992d1fd512e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 144d81c068b3465cab1e4d9c637dac6052df0b66..37de29ed614eec24c801e00150e01016f83dcdd0 100644 (file)
-<?php
-
-/**
-  V4.50 6 July 2004  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
-  the BSD license will take precedence.
-       
-  Set tabs to 4 for best viewing.
-  
-  Modified from datadict-generic.inc.php for sapdb by RalfBecker-AT-outdoor-training.de
-*/
-
-// security - hide paths
-if (!defined('ADODB_DIR')) die();
-
-class ADODB2_sapdb extends ADODB_DataDict {
-       
-       var $databaseType = 'sapdb';
-       var $seqField = false;  
-       var $renameColumn = 'RENAME COLUMN %s.%s TO %s';
-       
-       function ActualType($meta)
-       {
-               switch($meta) {
-               case 'C': return 'VARCHAR';
-               case 'XL':
-               case 'X': return 'LONG';
-               
-               case 'C2': return 'VARCHAR UNICODE';
-               case 'X2': return 'LONG UNICODE';
-               
-               case 'B': return 'LONG';
-                       
-               case 'D': return 'DATE';
-               case 'T': return 'TIMESTAMP';
-               
-               case 'L': return 'BOOLEAN';
-               case 'I': return 'INTEGER';
-               case 'I1': return 'FIXED(3)';
-               case 'I2': return 'SMALLINT';
-               case 'I4': return 'INTEGER';
-               case 'I8': return 'FIXED(20)';
-               
-               case 'F': return 'FLOAT(38)';
-               case 'N': return 'FIXED';
-               default:
-                       return $meta;
-               }
-       }
-       
-       function MetaType($t,$len=-1,$fieldobj=false)
-       {
-               if (is_object($t)) {
-                       $fieldobj = $t;
-                       $t = $fieldobj->type;
-                       $len = $fieldobj->max_length;
-               }
-               static $maxdb_type2adodb = array(
-                       'VARCHAR'       => 'C',
-                       'CHARACTER'     => 'C',
-                       'LONG'          => 'X',         // no way to differ between 'X' and 'B' :-(
-                       'DATE'          => 'D',
-                       'TIMESTAMP'     => 'T',
-                       'BOOLEAN'       => 'L',
-                       'INTEGER'       => 'I4',
-                       'SMALLINT'      => 'I2',
-                       'FLOAT'         => 'F',
-                       'FIXED'         => 'N',
-               );
-               $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C';
-
-               // convert integer-types simulated with fixed back to integer
-               if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {
-                       $type = $len == 20 ? 'I8' : 'I1';
-               }
-               if ($fieldobj->auto_increment) $type = 'R';
-
-               return $type;
-       }
-       
-       // return string must begin with space
-       function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
-       {       
-               $suffix = '';
-               if ($funsigned) $suffix .= ' UNSIGNED';
-               if ($fnotnull) $suffix .= ' NOT NULL';
-               if ($fautoinc) $suffix .= ' DEFAULT SERIAL';
-               elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
-               if ($fconstraint) $suffix .= ' '.$fconstraint;
-               return $suffix;
-       }
-
-       function AddColumnSQL($tabname, $flds)
-       {
-               $tabname = $this->TableName ($tabname);
-               $sql = array();
-               list($lines,$pkey) = $this->_GenFields($flds);
-               return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' );
-       }
-       
-       function AlterColumnSQL($tabname, $flds)
-       {
-               $tabname = $this->TableName ($tabname);
-               $sql = array();
-               list($lines,$pkey) = $this->_GenFields($flds);
-               return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' );
-       }
-
-       function DropColumnSQL($tabname, $flds)
-       {
-               $tabname = $this->TableName ($tabname);
-               if (!is_array($flds)) $flds = explode(',',$flds);
-               foreach($flds as $k => $v) {
-                       $flds[$k] = $this->NameQuote($v);
-               }
-               return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' );
-       }       
-}
-
+<?php\r
+\r
+/**\r
+  V4.50 6 July 2004  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+       \r
+  Set tabs to 4 for best viewing.\r
+  \r
+  Modified from datadict-generic.inc.php for sapdb by RalfBecker-AT-outdoor-training.de\r
+*/\r
+\r
+// security - hide paths\r
+if (!defined('ADODB_DIR')) die();\r
+\r
+class ADODB2_sapdb extends ADODB_DataDict {\r
+       \r
+       var $databaseType = 'sapdb';\r
+       var $seqField = false;  \r
+       var $renameColumn = 'RENAME COLUMN %s.%s TO %s';\r
+       \r
+       function ActualType($meta)\r
+       {\r
+               switch($meta) {\r
+               case 'C': return 'VARCHAR';\r
+               case 'XL':\r
+               case 'X': return 'LONG';\r
+               \r
+               case 'C2': return 'VARCHAR UNICODE';\r
+               case 'X2': return 'LONG UNICODE';\r
+               \r
+               case 'B': return 'LONG';\r
+                       \r
+               case 'D': return 'DATE';\r
+               case 'T': return 'TIMESTAMP';\r
+               \r
+               case 'L': return 'BOOLEAN';\r
+               case 'I': return 'INTEGER';\r
+               case 'I1': return 'FIXED(3)';\r
+               case 'I2': return 'SMALLINT';\r
+               case 'I4': return 'INTEGER';\r
+               case 'I8': return 'FIXED(20)';\r
+               \r
+               case 'F': return 'FLOAT(38)';\r
+               case 'N': return 'FIXED';\r
+               default:\r
+                       return $meta;\r
+               }\r
+       }\r
+       \r
+       function MetaType($t,$len=-1,$fieldobj=false)\r
+       {\r
+               if (is_object($t)) {\r
+                       $fieldobj = $t;\r
+                       $t = $fieldobj->type;\r
+                       $len = $fieldobj->max_length;\r
+               }\r
+               static $maxdb_type2adodb = array(\r
+                       'VARCHAR'       => 'C',\r
+                       'CHARACTER'     => 'C',\r
+                       'LONG'          => 'X',         // no way to differ between 'X' and 'B' :-(\r
+                       'DATE'          => 'D',\r
+                       'TIMESTAMP'     => 'T',\r
+                       'BOOLEAN'       => 'L',\r
+                       'INTEGER'       => 'I4',\r
+                       'SMALLINT'      => 'I2',\r
+                       'FLOAT'         => 'F',\r
+                       'FIXED'         => 'N',\r
+               );\r
+               $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C';\r
+\r
+               // convert integer-types simulated with fixed back to integer\r
+               if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {\r
+                       $type = $len == 20 ? 'I8' : 'I1';\r
+               }\r
+               if ($fieldobj->auto_increment) $type = 'R';\r
+\r
+               return $type;\r
+       }\r
+       \r
+       // return string must begin with space\r
+       function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)\r
+       {       \r
+               $suffix = '';\r
+               if ($funsigned) $suffix .= ' UNSIGNED';\r
+               if ($fnotnull) $suffix .= ' NOT NULL';\r
+               if ($fautoinc) $suffix .= ' DEFAULT SERIAL';\r
+               elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";\r
+               if ($fconstraint) $suffix .= ' '.$fconstraint;\r
+               return $suffix;\r
+       }\r
+\r
+       function AddColumnSQL($tabname, $flds)\r
+       {\r
+               $tabname = $this->TableName ($tabname);\r
+               $sql = array();\r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+               return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' );\r
+       }\r
+       \r
+       function AlterColumnSQL($tabname, $flds)\r
+       {\r
+               $tabname = $this->TableName ($tabname);\r
+               $sql = array();\r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+               return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' );\r
+       }\r
+\r
+       function DropColumnSQL($tabname, $flds)\r
+       {\r
+               $tabname = $this->TableName ($tabname);\r
+               if (!is_array($flds)) $flds = explode(',',$flds);\r
+               foreach($flds as $k => $v) {\r
+                       $flds[$k] = $this->NameQuote($v);\r
+               }\r
+               return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' );\r
+       }       \r
+}\r
+\r
 ?>
\ No newline at end of file
index e9fd86f4e334927e24ec783822a87ab7974893a7..4d2150212a5becf3e3ddc2d1da5f02552dd0783d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index a37ba512749f01a722462ecca43a0d6c83dec4ec..0b2cb2b23970572d9f1159d0cde4caf478b7bf38 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
@@ -27,6 +27,7 @@ class  ADODB_access extends ADODB_odbc {
        var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
        var $sysTimeStamp = 'NOW';
        var $hasTransactions = false;
+       var $upperCase = 'ucase';
        
        function ADODB_access()
        {
index 027fa3294e489bbcdb39a334d159dcd11ebdd897..4d730f273735031b3b04b9f63da807079e0292fe 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 8131619cc729710aa437c2b6b06636121c88d052..a0e2e3ee3653d3c92408296181c03b665283fb8b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 44dc982c4aa12840be9e95828b86166e7be8cf00..ab83e26df4c131f81954dff0459a7a6b0f992c09 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
 Released under both BSD license and Lesser GPL library license. 
 Whenever there is any discrepancy between the two licenses, 
 the BSD license will take precedence. See License.txt. 
@@ -27,6 +27,7 @@ class  ADODB_ado_access extends ADODB_ado {
        var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
        var $sysTimeStamp = 'NOW';
        var $hasTransactions = false;
+       var $upperCase = 'ucase';
        
        function ADODB_ado_access()
        {
index 6926706b42ae2e03125551ce6b6a7447e565011b..576223d5c2372486dabe32492824ce099d97abac 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
@@ -65,6 +65,12 @@ class  ADODB_ado_mssql extends ADODB_ado {
                $this->Execute("SET TRANSACTION ".$transaction_mode);
        }
        
+       function qstr($s,$magic_quotes=false)
+       {
+               $s = ADOConnection::qstr($s, $magic_quotes);
+               return str_replace("\0", "\\\\000", $s);
+       }
+       
        function MetaColumns($table)
        {
         $table = strtoupper($table);
index a5e748b1770efa81ac23d3f2b4e2325bea7dc8c2..ab15feff39e48e3e254c9bbfcd816e7081d8ff8b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index bbd4e61369f1a27ec6929a895bb3724d25800ce1..a977416f5cd5bc1709e0b8898ed7231ce944588f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 964a2665bc2552dcc05ee2c989d1667271204490..9c1882d2f6df115f40da630c08f2ea779de145bd 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-  V4.93 10 Oct 2006  (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved.
 
   This is a version of the ADODB driver for DB2.  It uses the 'ibm_db2' PECL extension
   for PHP (http://pecl.php.net/package/ibm_db2), which in turn requires DB2 V8.2.2 or
index 0f0522641eb8a4542733a3fad7073c9edce0fcb7..6a19bc202289bb2addf5ec7f804d2ddd5652e2bd 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
  Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index f3d7a134735cb432407a5c4efa58a1d8ad47073a..9b7b59ee10d359edf6c091851d4640088ca9754d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index efd8a0caeba8da2c57a2538ddb6934da28c2cbae..335493d90d8ef1dd5691fc41061fdcd765fc1641 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.  
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.  
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 52b2cf645ebace30d85922dc4ab43f1e3391f49b..eed00b056f1ad8a37f9d8eeef97bb764cdb0c093 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
-* @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+* @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
 * Released under both BSD license and Lesser GPL library license.
 * Whenever there is any discrepancy between the two licenses,
 * the BSD license will take precedence.
index c02a47162251252756408a635e498931a5321e10..3bf65ef9b4d526fc33bc58d55ff5de871a6bae11 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim. All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim. 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.
index c4137cd9d777f4d3be75836da4adf7b22ea97c17..bbf0cbf02f6b4d4526fde477cce5552ac8a4b9b2 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
    Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 53e6d9536c73a6fdf0f3369d7b56498e150cbeef..8eebd914b168ca9056172fbbc09608bfbab4472c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index bbadc5a0a95fbe410bebfe1b956112de0f5d5e06..d112f89ab653dc6900ed40d0f766cff7982c60e0 100644 (file)
-<?php  /// $Id $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// ADOdb  - Database Abstraction Library for PHP                         //
-//          http://adodb.sourceforge.net/                                //
-//                                                                       //
-// Copyright (C) 2000-2006 John Lim (jlim\@natsoft.com.my)               //
-//          All rights reserved.                                         //
-//          Released under both BSD license and LGPL library license.    //
-//          Whenever there is any discrepancy between the two licenses,  //
-//          the BSD license will take precedence                         //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 2001-3001 Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/**
-*  MSSQL Driver with auto-prepended "N" for correct unicode storage
-*  of SQL literal strings. Intended to be used with MSSQL drivers that
-*  are sending UCS-2 data to MSSQL (FreeTDS and ODBTP) in order to get
-*  true cross-db compatibility from the application point of view.
-*/
-
-// security - hide paths
-if (!defined('ADODB_DIR')) die();
-
-// one useful constant
-if (!defined('SINGLEQUOTE')) define('SINGLEQUOTE', "'");
-
-include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php');
-
-class ADODB_mssql_n extends ADODB_mssql {
-       var $databaseType = "mssql_n";
-       
-       function ADODB_mssqlpo()
-       {
-               ADODB_mssql::ADODB_mssql();
-       }
-
-       function _query($sql,$inputarr)
-       {
-        $sql = $this->_appendN($sql);
-               return ADODB_mssql::_query($sql,$inputarr);
-       }
-
-    /**
-     * This function will intercept all the literals used in the SQL, prepending the "N" char to them
-     * in order to allow mssql to store properly data sent in the correct UCS-2 encoding (by freeTDS
-     * and ODBTP) keeping SQL compatibility at ADOdb level (instead of hacking every project to add
-     * the "N" notation when working against MSSQL.
-     *
-     * Note that this hack only must be used if ALL the char-based columns in your DB are of type nchar,
-     * nvarchar and ntext 
-     */
-    function _appendN($sql) {
-
-        $result = $sql;
-
-    /// Check we have some single quote in the query. Exit ok.
-        if (strpos($sql, SINGLEQUOTE) === false) {
-            return $sql;
-        }
-
-    /// Check we haven't an odd number of single quotes (this can cause problems below
-    /// and should be considered one wrong SQL). Exit with debug info.
-        if ((substr_count($sql, SINGLEQUOTE) & 1)) {
-            if ($this->debug) {
-                ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Wrong number of quotes (odd)");
-            }
-            return $sql;
-        }
-
-    /// Check we haven't any backslash + single quote combination. It should mean wrong
-    /// backslashes use (bad magic_quotes_sybase?). Exit with debug info.
-        $regexp = '/(\\\\' . SINGLEQUOTE . '[^' . SINGLEQUOTE . '])/';
-        if (preg_match($regexp, $sql)) {
-            if ($this->debug) {
-                ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Found bad use of backslash + single quote");
-            }
-            return $sql;
-        }
-
-    /// Remove pairs of single-quotes
-        $pairs = array();
-        $regexp = '/(' . SINGLEQUOTE . SINGLEQUOTE . ')/';
-        preg_match_all($regexp, $result, $list_of_pairs);
-        if ($list_of_pairs) {
-            foreach (array_unique($list_of_pairs[0]) as $key=>$value) {
-                $pairs['<@#@#@PAIR-'.$key.'@#@#@>'] = $value;
-            }
-            if (!empty($pairs)) {
-                $result = str_replace($pairs, array_keys($pairs), $result);
-            }
-        }
-
-    /// Remove the rest of literals present in the query
-        $literals = array();
-        $regexp = '/(N?' . SINGLEQUOTE . '.*?' . SINGLEQUOTE . ')/is';
-        preg_match_all($regexp, $result, $list_of_literals);
-        if ($list_of_literals) {
-            foreach (array_unique($list_of_literals[0]) as $key=>$value) {
-                $literals['<#@#@#LITERAL-'.$key.'#@#@#>'] = $value;
-            }
-            if (!empty($literals)) {
-                $result = str_replace($literals, array_keys($literals), $result);
-            }
-        }
-
-    /// Analyse literals to prepend the N char to them if their contents aren't numeric
-        if (!empty($literals)) {
-            foreach ($literals as $key=>$value) {
-                if (!is_numeric(trim($value, SINGLEQUOTE))) {
-                /// Non numeric string, prepend our dear N
-                    $literals[$key] = 'N' . trim($value, 'N'); //Trimming potentially existing previous "N"
-                }
-            }
-        }
-
-    /// Re-apply literals to the text
-        if (!empty($literals)) {
-            $result = str_replace(array_keys($literals), $literals, $result);
-        }
-
-    /// Re-apply pairs of single-quotes to the text
-        if (!empty($pairs)) {
-            $result = str_replace(array_keys($pairs), $pairs, $result);
-        }
-
-    /// Print transformation if debug = on
-        if ($result != $sql && $this->debug) {
-            ADOConnection::outp("{$this->databaseType} internal transformation:<br>{$sql}<br>to<br>{$result}");
-        }
-
-        return $result;
-    }
-}
-
-class ADORecordset_mssql_n extends ADORecordset_mssql {
-       var $databaseType = "mssql_n";
-       function ADORecordset_mssql_n($id,$mode=false)
-       {
-               $this->ADORecordset_mssql($id,$mode);
-       }
-}
-?>
+<?php  \r
+\r
+/// $Id $\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//                                                                       //\r
+// NOTICE OF COPYRIGHT                                                   //\r
+//                                                                       //\r
+// ADOdb  - Database Abstraction Library for PHP                         //\r
+//          http://adodb.sourceforge.net/                                //\r
+//                                                                       //\r
+// Copyright (C) 2000-2007 John Lim (jlim\@natsoft.com.my)               //\r
+//          All rights reserved.                                         //\r
+//          Released under both BSD license and LGPL library license.    //\r
+//          Whenever there is any discrepancy between the two licenses,  //\r
+//          the BSD license will take precedence                         //\r
+//                                                                       //\r
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //\r
+//          http://moodle.com                                            //\r
+//                                                                       //\r
+// Copyright (C) 2001-3001 Martin Dougiamas        http://dougiamas.com  //\r
+//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //\r
+//                                                                       //\r
+// This program is free software; you can redistribute it and/or modify  //\r
+// it under the terms of the GNU General Public License as published by  //\r
+// the Free Software Foundation; either version 2 of the License, or     //\r
+// (at your option) any later version.                                   //\r
+//                                                                       //\r
+// This program is distributed in the hope that it will be useful,       //\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //\r
+// GNU General Public License for more details:                          //\r
+//                                                                       //\r
+//          http://www.gnu.org/copyleft/gpl.html                         //\r
+//                                                                       //\r
+///////////////////////////////////////////////////////////////////////////\r
+\r
+/**\r
+*  MSSQL Driver with auto-prepended "N" for correct unicode storage\r
+*  of SQL literal strings. Intended to be used with MSSQL drivers that\r
+*  are sending UCS-2 data to MSSQL (FreeTDS and ODBTP) in order to get\r
+*  true cross-db compatibility from the application point of view.\r
+*/\r
+\r
+// security - hide paths\r
+if (!defined('ADODB_DIR')) die();\r
+\r
+// one useful constant\r
+if (!defined('SINGLEQUOTE')) define('SINGLEQUOTE', "'");\r
+\r
+include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php');\r
+\r
+class ADODB_mssql_n extends ADODB_mssql {\r
+       var $databaseType = "mssql_n";\r
+       \r
+       function ADODB_mssqlpo()\r
+       {\r
+               ADODB_mssql::ADODB_mssql();\r
+       }\r
+\r
+       function _query($sql,$inputarr)\r
+       {\r
+        $sql = $this->_appendN($sql);\r
+               return ADODB_mssql::_query($sql,$inputarr);\r
+       }\r
+\r
+    /**\r
+     * This function will intercept all the literals used in the SQL, prepending the "N" char to them\r
+     * in order to allow mssql to store properly data sent in the correct UCS-2 encoding (by freeTDS\r
+     * and ODBTP) keeping SQL compatibility at ADOdb level (instead of hacking every project to add\r
+     * the "N" notation when working against MSSQL.\r
+     *\r
+     * Note that this hack only must be used if ALL the char-based columns in your DB are of type nchar,\r
+     * nvarchar and ntext \r
+     */\r
+    function _appendN($sql) {\r
+\r
+        $result = $sql;\r
+\r
+    /// Check we have some single quote in the query. Exit ok.\r
+        if (strpos($sql, SINGLEQUOTE) === false) {\r
+            return $sql;\r
+        }\r
+\r
+    /// Check we haven't an odd number of single quotes (this can cause problems below\r
+    /// and should be considered one wrong SQL). Exit with debug info.\r
+        if ((substr_count($sql, SINGLEQUOTE) & 1)) {\r
+            if ($this->debug) {\r
+                ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Wrong number of quotes (odd)");\r
+            }\r
+            return $sql;\r
+        }\r
+\r
+    /// Check we haven't any backslash + single quote combination. It should mean wrong\r
+    /// backslashes use (bad magic_quotes_sybase?). Exit with debug info.\r
+        $regexp = '/(\\\\' . SINGLEQUOTE . '[^' . SINGLEQUOTE . '])/';\r
+        if (preg_match($regexp, $sql)) {\r
+            if ($this->debug) {\r
+                ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Found bad use of backslash + single quote");\r
+            }\r
+            return $sql;\r
+        }\r
+\r
+    /// Remove pairs of single-quotes\r
+        $pairs = array();\r
+        $regexp = '/(' . SINGLEQUOTE . SINGLEQUOTE . ')/';\r
+        preg_match_all($regexp, $result, $list_of_pairs);\r
+        if ($list_of_pairs) {\r
+            foreach (array_unique($list_of_pairs[0]) as $key=>$value) {\r
+                $pairs['<@#@#@PAIR-'.$key.'@#@#@>'] = $value;\r
+            }\r
+            if (!empty($pairs)) {\r
+                $result = str_replace($pairs, array_keys($pairs), $result);\r
+            }\r
+        }\r
+\r
+    /// Remove the rest of literals present in the query\r
+        $literals = array();\r
+        $regexp = '/(N?' . SINGLEQUOTE . '.*?' . SINGLEQUOTE . ')/is';\r
+        preg_match_all($regexp, $result, $list_of_literals);\r
+        if ($list_of_literals) {\r
+            foreach (array_unique($list_of_literals[0]) as $key=>$value) {\r
+                $literals['<#@#@#LITERAL-'.$key.'#@#@#>'] = $value;\r
+            }\r
+            if (!empty($literals)) {\r
+                $result = str_replace($literals, array_keys($literals), $result);\r
+            }\r
+        }\r
+\r
+    /// Analyse literals to prepend the N char to them if their contents aren't numeric\r
+        if (!empty($literals)) {\r
+            foreach ($literals as $key=>$value) {\r
+                if (!is_numeric(trim($value, SINGLEQUOTE))) {\r
+                /// Non numeric string, prepend our dear N\r
+                    $literals[$key] = 'N' . trim($value, 'N'); //Trimming potentially existing previous "N"\r
+                }\r
+            }\r
+        }\r
+\r
+    /// Re-apply literals to the text\r
+        if (!empty($literals)) {\r
+            $result = str_replace(array_keys($literals), $literals, $result);\r
+        }\r
+\r
+    /// Re-apply pairs of single-quotes to the text\r
+        if (!empty($pairs)) {\r
+            $result = str_replace(array_keys($pairs), $pairs, $result);\r
+        }\r
+\r
+    /// Print transformation if debug = on\r
+        if ($result != $sql && $this->debug) {\r
+            ADOConnection::outp("{$this->databaseType} internal transformation:<br>{$sql}<br>to<br>{$result}");\r
+        }\r
+\r
+        return $result;\r
+    }\r
+}\r
+\r
+class ADORecordset_mssql_n extends ADORecordset_mssql {\r
+       var $databaseType = "mssql_n";\r
+       function ADORecordset_mssql_n($id,$mode=false)\r
+       {\r
+               $this->ADORecordset_mssql($id,$mode);\r
+       }\r
+}\r
+?>
\ No newline at end of file
index 5e7ae1f40473eb31a63e330ef7b115c1a2e7fa50..df482860b5bb6c90e526bd21bf530cd56dcc838a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
-* @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+* @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
 * Released under both BSD license and Lesser GPL library license.
 * Whenever there is any discrepancy between the two licenses,
 * the BSD license will take precedence.
index 8e79d4a75276035d4bd1a1223f7bc048dae28b0b..14d288e7e683ffa827c3458d3d692afc7fdb10b4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -628,13 +628,13 @@ class ADORecordSet_mysql extends ADORecordSet{
                if ($fieldOffset != -1) {
                        $o = @mysql_fetch_field($this->_queryID, $fieldOffset);
                        $f = @mysql_field_flags($this->_queryID,$fieldOffset);
-                       $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)
+                       $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich#att.com)
                        //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
                        $o->binary = (strpos($f,'binary')!== false);
                }
                else if ($fieldOffset == -1) {  /*      The $fieldOffset argument is not provided thus its -1   */
                        $o = @mysql_fetch_field($this->_queryID);
-               $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)
+               $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich#att.com)
                //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
                }
                        
index 415ae2bd2ce6956d30ade6560162de2874d5b299..00b53ccf83df770472e27629b26179dba90dce62 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -138,6 +138,18 @@ class ADODB_mysqli extends ADOConnection {
                return " IFNULL($field, $ifNull) "; // if MySQL
        }
        
+       // do not use $ADODB_COUNTRECS
+       function GetOne($sql,$inputarr=false)
+       {
+               $ret = false;
+               $rs = &$this->Execute($sql,$inputarr);
+               if ($rs) {      
+                       if (!$rs->EOF) $ret = reset($rs->fields);
+                       $rs->Close();
+               }
+               return $ret;
+       }
+       
        function ServerInfo()
        {
                $arr['description'] = $this->GetOne("select version()");
@@ -150,7 +162,9 @@ class ADODB_mysqli extends ADOConnection {
        {         
                if ($this->transOff) return true;
                $this->transCnt += 1;
-               $this->Execute('SET AUTOCOMMIT=0');
+               
+               //$this->Execute('SET AUTOCOMMIT=0');
+               mysqli_autocommit($this->_connectionID, false);
                $this->Execute('BEGIN');
                return true;
        }
@@ -162,7 +176,9 @@ class ADODB_mysqli extends ADOConnection {
                
                if ($this->transCnt) $this->transCnt -= 1;
                $this->Execute('COMMIT');
-               $this->Execute('SET AUTOCOMMIT=1');
+               
+               //$this->Execute('SET AUTOCOMMIT=1');
+               mysqli_autocommit($this->_connectionID, true);
                return true;
        }
        
@@ -171,7 +187,8 @@ class ADODB_mysqli extends ADOConnection {
                if ($this->transOff) return true;
                if ($this->transCnt) $this->transCnt -= 1;
                $this->Execute('ROLLBACK');
-               $this->Execute('SET AUTOCOMMIT=1');
+               //$this->Execute('SET AUTOCOMMIT=1');
+               mysqli_autocommit($this->_connectionID, true);
                return true;
        }
        
index 715d6934a1632747d8029123a65ceef7d9b0d001..9f1b53a799a1dd894900889f9ce71b4f335d57d7 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index d03fab9f24bb58bc59a958886fde6ff083bec156..eedf51dfe8e6552c2f5ec6a460d52a3bc987874b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
  
   First cut at the Netezza Driver by Josh Eldridge joshuae74#hotmail.com
  Based on the previous postgres drivers.
index 6dae98cc80b77e2449a5fdc74ee208a5a5959f81..3681876f2e48deb30324614aceef610fda40ea2a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
 
-  version V4.93 10 Oct 2006 (c) 2000-2006 John Lim. All rights reserved.
+  version V4.94 23 Jan 2007 (c) 2000-2007 John Lim. All rights reserved.
 
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
@@ -211,22 +211,22 @@ NATSOFT.DOMAIN =
                //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
                if ($mode==1) {
                        $this->_connectionID = ($this->charSet) ? 
-                               OCIPLogon($argUsername,$argPassword, $argDatabasename)
+                               OCIPLogon($argUsername,$argPassword, $argDatabasename,$this->charSet)
                                :
-                               OCIPLogon($argUsername,$argPassword, $argDatabasename, $this->charSet)
+                               OCIPLogon($argUsername,$argPassword, $argDatabasename)
                                ;
                        if ($this->_connectionID && $this->autoRollback)  OCIrollback($this->_connectionID);
                } else if ($mode==2) {
                        $this->_connectionID = ($this->charSet) ? 
-                               OCINLogon($argUsername,$argPassword, $argDatabasename)
+                               OCINLogon($argUsername,$argPassword, $argDatabasename,$this->charSet)
                                :
-                               OCINLogon($argUsername,$argPassword, $argDatabasename, $this->charSet);
+                               OCINLogon($argUsername,$argPassword, $argDatabasename);
                                
                } else {
                        $this->_connectionID = ($this->charSet) ? 
-                               OCILogon($argUsername,$argPassword, $argDatabasename)
+                               OCILogon($argUsername,$argPassword, $argDatabasename,$this->charSet)
                                :
-                               OCILogon($argUsername,$argPassword, $argDatabasename,$this->charSet);
+                               OCILogon($argUsername,$argPassword, $argDatabasename);
                }
                if (!$this->_connectionID) return false;
                if ($this->_initdate) {
@@ -434,10 +434,10 @@ NATSOFT.DOMAIN =
        {
                if ($this->_errorMsg !== false) return $this->_errorMsg;
 
-               if (is_resource($this->_stmt)) $arr = @OCIerror($this->_stmt);
+               if (is_resource($this->_stmt)) $arr = @OCIError($this->_stmt);
                if (empty($arr)) {
-                       $arr = @OCIerror($this->_connectionID);
-                       if ($arr === false) $arr = @OCIError();
+                       if (is_resource($this->_connectionID)) $arr = @OCIError($this->_connectionID);
+                       else $arr = @OCIError();
                        if ($arr === false) return '';
                }
                $this->_errorMsg = $arr['message'];
@@ -783,8 +783,17 @@ NATSOFT.DOMAIN =
        
                $stmt = OCIParse($this->_connectionID,$sql);
 
-               if (!$stmt) return false;
-
+               if (!$stmt) {
+                       $this->_errorMsg = false;
+                       $this->_errorCode = false;
+                       $arr = @OCIError($this->_connectionID);
+                       if ($arr === false) return false;
+               
+                       $this->_errorMsg = $arr['message'];
+                       $this->_errorCode = $arr['code'];
+                       return false;
+               }
+               
                $BINDNUM += 1;
                
                $sttype = @OCIStatementType($stmt);
@@ -1374,10 +1383,11 @@ class ADORecordset_oci8 extends ADORecordSet {
                        $arr =& $this->GetArray($nrows);
                        return $arr;
                }
+               $arr = array();
                for ($i=1; $i < $offset; $i++) 
-                       if (!@OCIFetch($this->_queryID)) return array();
+                       if (!@OCIFetch($this->_queryID)) return $arr;
                        
-               if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array();
+               if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return $arr;;
                $results = array();
                $cnt = 0;
                while (!$this->EOF && $nrows != $cnt) {
index 4073b604c443aba8d450f7de6b0b8d607b145b19..8da0ba19800acfa9d43fa78c668a8c6eb37a876a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /** 
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license. 
  * Whenever there is any discrepancy between the two licenses, 
  * the BSD license will take precedence. 
index dc75c79456d52418dff4ab0851d4ec7d452ed37c..2432f395a1a9fd9485b2ef6f1eaa29dbddf2baef 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim. All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim. 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.
index adfbabad5fd007d94d45c24a6c3170b438e63380..d8b8f18599193e183c6033f21a7e2fbe9e90b43e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 7a728cab31567159d41f4b1599f65b2d45557d8f..3ae91d7a325f1ede5572b22926c315e5d22c52a1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 54f1dfb0cfa8c6d512cab5f81253bea59d0190ee..ce36d2e394db7554fbd3390f705e774e5569a526 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 9b3e540f59e109433bcd571f270b77e9844e6b21..cb29f0b20fadc8247ead34ede1adbccc1ddd9e3c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 402b22600fe7a4ffeeec236e44d044094a2dbbc0..6f52ae772ed726909ad06ff4a921c63e6661155f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence. See License.txt.
@@ -149,13 +149,14 @@ class ADODB_odbtp extends ADOConnection{
        //if uid & pwd can be separate
     function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
        {
-               $this->_connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase);
-               odbtp_convert_datetime($this->_connectionID,true);
-               
+               $this->_connectionID = odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase);
                if ($this->_connectionID === false) {
                        $this->_errorMsg = $this->ErrorMsg() ;
                        return false;
                }
+               
+               odbtp_convert_datetime($this->_connectionID,true);
+               
                if ($this->_dontPoolDBC) {
                        if (function_exists('odbtp_dont_pool_dbc'))
                                @odbtp_dont_pool_dbc($this->_connectionID);
@@ -217,6 +218,7 @@ class ADODB_odbtp extends ADOConnection{
                                $this->replaceQuote = "'+chr(39)+'";
                                $this->true = '.T.';
                                $this->false = '.F.';
+
                                break;
                        case 'oracle':
                                $this->databaseType = 'odbtp_oci8';
@@ -288,7 +290,7 @@ class ADODB_odbtp extends ADOConnection{
                for ($i=0; $i < sizeof($arr); $i++) {
                        if ($arr[$i][3] == 'SYSTEM TABLE' )     continue;
                        if ($arr[$i][2])
-                               $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2];
+                               $arr2[] = $showSchema && $arr[$i][1]? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2];
                }
                return $arr2;
        }
@@ -324,10 +326,11 @@ class ADODB_odbtp extends ADOConnection{
                                $fld->max_length = $rs->fields[6];
                        $fld->not_null = !empty($rs->fields[9]);
                                $fld->scale = $rs->fields[7];
-                               if (!is_null($rs->fields[12])) {
-                                       $fld->has_default = true;
-                                       $fld->default_value = $rs->fields[12];
-                               }
+                               if (isset($rs->fields[12])) // vfp does not have field 12
+                                       if (!is_null($rs->fields[12])) {
+                                               $fld->has_default = true;
+                                               $fld->default_value = $rs->fields[12];
+                                       }
                                $retarr[strtoupper($fld->name)] = $fld;
                        } else if (!empty($retarr))
                                break;
@@ -547,7 +550,7 @@ class ADODB_odbtp extends ADOConnection{
                                return false;
                        }
                } else {
-                       $stmtid = @odbtp_query($sql,$this->_connectionID);
+                       $stmtid = odbtp_query($sql,$this->_connectionID);
                }
                $this->_lastAffectedRows = 0;
                if ($stmtid) {
@@ -642,6 +645,12 @@ class ADORecordSet_odbtp extends ADORecordSet {
             default:
                                $this->fields = @odbtp_fetch_array($this->_queryID, $type);
                }
+               if ($this->databaseType = 'odbtp_vfp') {
+                       if ($this->fields)
+                       foreach($this->fields as $k => $v) {
+                               if (strncmp($v,'1899-12-30',10) == 0) $this->fields[$k] = '';
+                       }
+               }
                return is_array($this->fields);
        }
 
index 2a8b44db86a6c2c6671314e6235c08756cdd6c3f..ff793733859b844e1bdc88182f0d8e4748ef99be 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-       V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+       V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence. See License.txt.
index 5329770b7b3ac8371de271f0c67eeaa0890b986b..3c6dbd3014ea7cd16cbd4c3409827aad04c51a39 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 346034969a1fe81ae1849e347e08dbdbee294cb8..e3f77f1f8ed3cfb3d56ec6203b033bca7f6de1cf 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
@@ -133,7 +133,12 @@ class ADODB_pdo extends ADOConnection {
                $this->random = $d->random;
                $this->concat_operator = $d->concat_operator;
                $this->nameQuote = $d->nameQuote;
-               
+                               
+               $this->hasGenID = $d->hasGenID;
+               $this->_genIDSQL = $d->_genIDSQL;
+               $this->_genSeqSQL = $d->_genSeqSQL;
+               $this->_dropSeqSQL = $d->_dropSeqSQL;
+
                $d->_init($this);
        }
        
index cdfcaae1ee70611776deaf8bfc8ea435650c24d3..9470dd8f07abc3f7d100e4f68fae814275749013 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index fc803b76692d1b2f3b61536c1777d2f935100e7b..b80241df04d9ebf358d53af8cec7fcda2314064c 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index ebfd4a3986147fed1d35b28300f16fad3c2fc841..9d40f14ab4e40ed6da60debd890527df64dbfd97 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 5c0c531a0712d116fac78a78b071ee169e1c557d..e802d799e2cec30f470758da83a7e1aea1fed92e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 4dd3f82c1a6d5d229c7b21b5bfd47132ce3dfa7a..5e8ce48e05b40f1c4b686e8fafabb997ff83cf00 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 270ccd70df218971831632e9b3a48bed93429b99..69d44fc7d71ef8616c02bd1fb3aa5af7a292f160 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -770,11 +770,11 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
                                }
                                $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2);               
                                //adodb_pr($s);
-                               pg_exec($this->_connectionID,$s);
+                               $rez = pg_exec($this->_connectionID,$s);
                                //echo $this->ErrorMsg();
                        }
-                       
-                       $rez = pg_exec($this->_connectionID,$exsql);
+                       if ($rez)
+                               $rez = pg_exec($this->_connectionID,$exsql);
                } else {
                        //adodb_backtrace();
                        $rez = pg_exec($this->_connectionID,$sql);
index 83b225cff06e58db90262b1a013e0438cb553a39..5c3d7bb63ba7457b7a1dab70bc3452da0336305a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index ab364a71d93d3c9f8ba96216ee592db55489ce6c..f3712a3947a45954bd4e2befd8663c71cdfb5eee 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 82af4496bb3676457a3326cdfd6dc725891f1eb4..022a64ee388cb34a66fc2e6ff4ade9d61dba528e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 53c74b412f2ffd6eb0850704bc79c76c568109f0..493893e4ad96cf0e2efd9cff3292279a635ee0ad 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 206e1e16dc6630007c9325cfb48023683e275a8a..88af3ae689683f972b3930f1c768ff893ea826bf 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-version V4.93 10 Oct 2006 (c) 2000-2006  John Lim (jlim#natsoft.com.my).  All rights
+version V4.94 23 Jan 2007 (c) 2000-2007  John Lim (jlim#natsoft.com.my).  All rights
 reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
index 8f93fda90eea9e91fbe274db685baa8fa78c21b7..665cc543828d9906477a60fc710fb4bfd1411479 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index b46fc9e7a79737ae86b0815ef800c2cfbff28e42..dbd0271b0ffadb9616fe318670d0f6fda4ab1909 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
index 023534eeafbcd54f1aea86e2a92bf659afd5e7f1..ba6b91922446f88a400e790a39b293e5cc80ec88 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim. All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim. 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. 
index 02e4757e7606e5b420e3eb0dd7f21ce84b064da9..9b5334d30a9660212863446dd565e24ead3a2bec 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 4f15f42fc68461c09cf1d3e656a7b2a33996a244..034eee2f09b1cb0213ba70d0dd9c93d4cf2bcedb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 5b5ef115f5f2ba0e95872dc078d09e0fb195ded3..9c8e77265a0259e5e522228b8e5c3af319a136d7 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index dd82708286debddf3954e4e0f42d0df81fbf2eae..d5e47578921dd55418df292de5c4438d30edee1d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index f652c761393f4a5e639f9f17ecaaaa8d72702663..f2dfa7ba63dd0b5ec1f7c912a95662f1ac100594 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index 062e2a2fc17ea91a6685bfa65e0c65fb1b93be3b..50639d957203a72459c6287a2cb4710b3a86c948 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index 48fbcd841fd7b5ff1afe8e20d8f7753acd181188..a4bcda67fdfef3a5b5633040665aac07de08d870 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index 37656a60f46286365bdcb765c46f19bba4262ccc..da41ebe4bfdb84abdff54b7f63e5d9730ca73743 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /* 
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index 3c22f380185130f6531f222e9564e050f360b2f9..0e0e7b1f985684cb96268a73074887a1ed1a8d33 100644 (file)
-<?php
-/** 
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
- * Released under both BSD license and Lesser GPL library license. 
- * Whenever there is any discrepancy between the two licenses, 
- * the BSD license will take precedence. 
- *
- * Set tabs to 4 for best viewing.
- * 
-*/
-
-/*
- * Concept from daniel.lucazeau@ajornet.com. 
- *
- * @param db           Adodb database connection
- * @param tables       List of tables to join
- * @rowfields          List of fields to display on each row
- * @colfield           Pivot field to slice and display in columns, if we want to calculate
- *                                             ranges, we pass in an array (see example2)
- * @where                      Where clause. Optional.
- * @aggfield           This is the field to sum. Optional. 
- *                                             Since 2.3.1, if you can use your own aggregate function 
- *                                             instead of SUM, eg. $aggfield = 'fieldname'; $aggfn = 'AVG';
- * @sumlabel           Prefix to display in sum columns. Optional.
- * @aggfn                      Aggregate function to use (could be AVG, SUM, COUNT)
- * @showcount          Show count of records
- *
- * @returns                    Sql generated
- */
- function PivotTableSQL(&$db,$tables,$rowfields,$colfield, $where=false,
-       $aggfield = false,$sumlabel='Sum ',$aggfn ='SUM', $showcount = true)
- {
-       if ($aggfield) $hidecnt = true;
-       else $hidecnt = false;
-       
-       $iif = strpos($db->databaseType,'access') !== false; 
-               // note - vfp 6 still doesn' work even with IIF enabled || $db->databaseType == 'vfp';
-       
-       //$hidecnt = false;
-       
-       if ($where) $where = "\nWHERE $where";
-       if (!is_array($colfield)) $colarr = $db->GetCol("select distinct $colfield from $tables $where order by 1");
-       if (!$aggfield) $hidecnt = false;
-       
-       $sel = "$rowfields, ";
-       if (is_array($colfield)) {
-               foreach ($colfield as $k => $v) {
-                       $k = trim($k);
-                       if (!$hidecnt) {
-                               $sel .= $iif ? 
-                                       "\n\t$aggfn(IIF($v,1,0)) AS \"$k\", "
-                                       :
-                                       "\n\t$aggfn(CASE WHEN $v THEN 1 ELSE 0 END) AS \"$k\", ";
-                       }
-                       if ($aggfield) {
-                               $sel .= $iif ?
-                                       "\n\t$aggfn(IIF($v,$aggfield,0)) AS \"$sumlabel$k\", "
-                                       :
-                                       "\n\t$aggfn(CASE WHEN $v THEN $aggfield ELSE 0 END) AS \"$sumlabel$k\", ";
-                       }
-               } 
-       } else {
-               foreach ($colarr as $v) {
-                       if (!is_numeric($v)) $vq = $db->qstr($v);
-                       else $vq = $v;
-                       $v = trim($v);
-                       if (strlen($v) == 0     ) $v = 'null';
-                       if (!$hidecnt) {
-                               $sel .= $iif ?
-                                       "\n\t$aggfn(IIF($colfield=$vq,1,0)) AS \"$v\", "
-                                       :
-                                       "\n\t$aggfn(CASE WHEN $colfield=$vq THEN 1 ELSE 0 END) AS \"$v\", ";
-                       }
-                       if ($aggfield) {
-                               if ($hidecnt) $label = $v;
-                               else $label = "{$v}_$aggfield";
-                               $sel .= $iif ?
-                                       "\n\t$aggfn(IIF($colfield=$vq,$aggfield,0)) AS \"$label\", "
-                                       :
-                                       "\n\t$aggfn(CASE WHEN $colfield=$vq THEN $aggfield ELSE 0 END) AS \"$label\", ";
-                       }
-               }
-       }
-       if ($aggfield && $aggfield != '1'){
-               $agg = "$aggfn($aggfield)";
-               $sel .= "\n\t$agg as \"$sumlabel$aggfield\", ";         
-       }
-       
-       if ($showcount)
-               $sel .= "\n\tSUM(1) as Total";
-       else
-               $sel = substr($sel,0,strlen($sel)-2);
-       
-       
-       // Strip aliases
-       $rowfields = preg_replace('/ AS (\w+)/i', '', $rowfields);
-       
-       $sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields";
-       
-       return $sql;
- }
-
-/* EXAMPLES USING MS NORTHWIND DATABASE */
-if (0) {
-
-# example1
-#
-# Query the main "product" table
-# Set the rows to CompanyName and QuantityPerUnit
-# and the columns to the Categories
-# and define the joins to link to lookup tables 
-# "categories" and "suppliers"
-#
-
- $sql = PivotTableSQL(
-       $gDB,                                                                                   # adodb connection
-       'products p ,categories c ,suppliers s',                # tables
-       'CompanyName,QuantityPerUnit',                                  # row fields
-       'CategoryName',                                                                 # column fields 
-       'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where
-);
- print "<pre>$sql";
- $rs = $gDB->Execute($sql);
- rs2html($rs);
-/*
-Generated SQL:
-
-SELECT CompanyName,QuantityPerUnit, 
-       SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS "Beverages", 
-       SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS "Condiments", 
-       SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS "Confections", 
-       SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS "Dairy Products", 
-       SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS "Grains/Cereals", 
-       SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS "Meat/Poultry", 
-       SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS "Produce", 
-       SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS "Seafood", 
-       SUM(1) as Total 
-FROM products p ,categories c ,suppliers s  WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
-GROUP BY CompanyName,QuantityPerUnit
-*/
-//=====================================================================
-
-# example2
-#
-# Query the main "product" table
-# Set the rows to CompanyName and QuantityPerUnit
-# and the columns to the UnitsInStock for diiferent ranges
-# and define the joins to link to lookup tables 
-# "categories" and "suppliers"
-#
- $sql = PivotTableSQL(
-       $gDB,                                                                           # adodb connection
-       'products p ,categories c ,suppliers s',        # tables
-       'CompanyName,QuantityPerUnit',                          # row fields
-                                                                                               # column ranges
-array(                                                                         
-' 0 ' => 'UnitsInStock <= 0',
-"1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5',
-"6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10',
-"11 to 15"  => '10 < UnitsInStock and UnitsInStock <= 15',
-"16+" =>'15 < UnitsInStock'
-),
-       ' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where
-       'UnitsInStock',                                                         # sum this field
-       'Sum'                                                                           # sum label prefix
-);
- print "<pre>$sql";
- $rs = $gDB->Execute($sql);
- rs2html($rs);
- /*
- Generated SQL:
-SELECT CompanyName,QuantityPerUnit, 
-       SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum  0 ", 
-       SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock ELSE 0 END) AS "Sum 1 to 5", 
-       SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock ELSE 0 END) AS "Sum 6 to 10", 
-       SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock ELSE 0 END) AS "Sum 11 to 15", 
-       SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 16+",
-       SUM(UnitsInStock) AS "Sum UnitsInStock", 
-       SUM(1) as Total 
-FROM products p ,categories c ,suppliers s  WHERE  p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
-GROUP BY CompanyName,QuantityPerUnit
- */
-}
+<?php\r
+/** \r
+ * @version V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Set tabs to 4 for best viewing.\r
+ * \r
+*/\r
+\r
+/*\r
+ * Concept from daniel.lucazeau@ajornet.com. \r
+ *\r
+ * @param db           Adodb database connection\r
+ * @param tables       List of tables to join\r
+ * @rowfields          List of fields to display on each row\r
+ * @colfield           Pivot field to slice and display in columns, if we want to calculate\r
+ *                                             ranges, we pass in an array (see example2)\r
+ * @where                      Where clause. Optional.\r
+ * @aggfield           This is the field to sum. Optional. \r
+ *                                             Since 2.3.1, if you can use your own aggregate function \r
+ *                                             instead of SUM, eg. $aggfield = 'fieldname'; $aggfn = 'AVG';\r
+ * @sumlabel           Prefix to display in sum columns. Optional.\r
+ * @aggfn                      Aggregate function to use (could be AVG, SUM, COUNT)\r
+ * @showcount          Show count of records\r
+ *\r
+ * @returns                    Sql generated\r
+ */\r
\r
+ function PivotTableSQL(&$db,$tables,$rowfields,$colfield, $where=false,\r
+       $aggfield = false,$sumlabel='Sum ',$aggfn ='SUM', $showcount = true)\r
+ {\r
+       if ($aggfield) $hidecnt = true;\r
+       else $hidecnt = false;\r
+       \r
+       $iif = strpos($db->databaseType,'access') !== false; \r
+               // note - vfp 6 still doesn' work even with IIF enabled || $db->databaseType == 'vfp';\r
+       \r
+       //$hidecnt = false;\r
+       \r
+       if ($where) $where = "\nWHERE $where";\r
+       if (!is_array($colfield)) $colarr = $db->GetCol("select distinct $colfield from $tables $where order by 1");\r
+       if (!$aggfield) $hidecnt = false;\r
+       \r
+       $sel = "$rowfields, ";\r
+       if (is_array($colfield)) {\r
+               foreach ($colfield as $k => $v) {\r
+                       $k = trim($k);\r
+                       if (!$hidecnt) {\r
+                               $sel .= $iif ? \r
+                                       "\n\t$aggfn(IIF($v,1,0)) AS \"$k\", "\r
+                                       :\r
+                                       "\n\t$aggfn(CASE WHEN $v THEN 1 ELSE 0 END) AS \"$k\", ";\r
+                       }\r
+                       if ($aggfield) {\r
+                               $sel .= $iif ?\r
+                                       "\n\t$aggfn(IIF($v,$aggfield,0)) AS \"$sumlabel$k\", "\r
+                                       :\r
+                                       "\n\t$aggfn(CASE WHEN $v THEN $aggfield ELSE 0 END) AS \"$sumlabel$k\", ";\r
+                       }\r
+               } \r
+       } else {\r
+               foreach ($colarr as $v) {\r
+                       if (!is_numeric($v)) $vq = $db->qstr($v);\r
+                       else $vq = $v;\r
+                       $v = trim($v);\r
+                       if (strlen($v) == 0     ) $v = 'null';\r
+                       if (!$hidecnt) {\r
+                               $sel .= $iif ?\r
+                                       "\n\t$aggfn(IIF($colfield=$vq,1,0)) AS \"$v\", "\r
+                                       :\r
+                                       "\n\t$aggfn(CASE WHEN $colfield=$vq THEN 1 ELSE 0 END) AS \"$v\", ";\r
+                       }\r
+                       if ($aggfield) {\r
+                               if ($hidecnt) $label = $v;\r
+                               else $label = "{$v}_$aggfield";\r
+                               $sel .= $iif ?\r
+                                       "\n\t$aggfn(IIF($colfield=$vq,$aggfield,0)) AS \"$label\", "\r
+                                       :\r
+                                       "\n\t$aggfn(CASE WHEN $colfield=$vq THEN $aggfield ELSE 0 END) AS \"$label\", ";\r
+                       }\r
+               }\r
+       }\r
+       if ($aggfield && $aggfield != '1'){\r
+               $agg = "$aggfn($aggfield)";\r
+               $sel .= "\n\t$agg as \"$sumlabel$aggfield\", ";         \r
+       }\r
+       \r
+       if ($showcount)\r
+               $sel .= "\n\tSUM(1) as Total";\r
+       else\r
+               $sel = substr($sel,0,strlen($sel)-2);\r
+       \r
+       \r
+       // Strip aliases\r
+       $rowfields = preg_replace('/ AS (\w+)/i', '', $rowfields);\r
+       \r
+       $sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields";\r
+       \r
+       return $sql;\r
+ }\r
+\r
+/* EXAMPLES USING MS NORTHWIND DATABASE */\r
+if (0) {\r
+\r
+# example1\r
+#\r
+# Query the main "product" table\r
+# Set the rows to CompanyName and QuantityPerUnit\r
+# and the columns to the Categories\r
+# and define the joins to link to lookup tables \r
+# "categories" and "suppliers"\r
+#\r
+\r
+ $sql = PivotTableSQL(\r
+       $gDB,                                                                                   # adodb connection\r
+       'products p ,categories c ,suppliers s',                # tables\r
+       'CompanyName,QuantityPerUnit',                                  # row fields\r
+       'CategoryName',                                                                 # column fields \r
+       'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where\r
+);\r
+ print "<pre>$sql";\r
+ $rs = $gDB->Execute($sql);\r
+ rs2html($rs);\r
\r
+/*\r
+Generated SQL:\r
+\r
+SELECT CompanyName,QuantityPerUnit, \r
+       SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS "Beverages", \r
+       SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS "Condiments", \r
+       SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS "Confections", \r
+       SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS "Dairy Products", \r
+       SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS "Grains/Cereals", \r
+       SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS "Meat/Poultry", \r
+       SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS "Produce", \r
+       SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS "Seafood", \r
+       SUM(1) as Total \r
+FROM products p ,categories c ,suppliers s  WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID \r
+GROUP BY CompanyName,QuantityPerUnit\r
+*/\r
+//=====================================================================\r
+\r
+# example2\r
+#\r
+# Query the main "product" table\r
+# Set the rows to CompanyName and QuantityPerUnit\r
+# and the columns to the UnitsInStock for diiferent ranges\r
+# and define the joins to link to lookup tables \r
+# "categories" and "suppliers"\r
+#\r
+ $sql = PivotTableSQL(\r
+       $gDB,                                                                           # adodb connection\r
+       'products p ,categories c ,suppliers s',        # tables\r
+       'CompanyName,QuantityPerUnit',                          # row fields\r
+                                                                                               # column ranges\r
+array(                                                                         \r
+' 0 ' => 'UnitsInStock <= 0',\r
+"1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5',\r
+"6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10',\r
+"11 to 15"  => '10 < UnitsInStock and UnitsInStock <= 15',\r
+"16+" =>'15 < UnitsInStock'\r
+),\r
+       ' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where\r
+       'UnitsInStock',                                                         # sum this field\r
+       'Sum'                                                                           # sum label prefix\r
+);\r
+ print "<pre>$sql";\r
+ $rs = $gDB->Execute($sql);\r
+ rs2html($rs);\r
+ /*\r
+ Generated SQL:\r
\r
+SELECT CompanyName,QuantityPerUnit, \r
+       SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum  0 ", \r
+       SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock ELSE 0 END) AS "Sum 1 to 5", \r
+       SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock ELSE 0 END) AS "Sum 6 to 10", \r
+       SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock ELSE 0 END) AS "Sum 11 to 15", \r
+       SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 16+",\r
+       SUM(UnitsInStock) AS "Sum UnitsInStock", \r
+       SUM(1) as Total \r
+FROM products p ,categories c ,suppliers s  WHERE  p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID \r
+GROUP BY CompanyName,QuantityPerUnit\r
+ */\r
+}\r
 ?>
\ No newline at end of file
index d9adc86e094087c102facd6516010e4b87b01209..f4db42b3a8d1bee618d7881c6038214485539e22 100644 (file)
@@ -1,4 +1,4 @@
-Description of ADODB v4.93 library import into Moodle
+Description of ADODB v4.94 library import into Moodle
 
 Removed:
  * contrib/
@@ -19,7 +19,7 @@ Our changes:
        working properly. Simplified logic (now that we are FETCH_ASSOC). Work in progress
        for the annoying http://tracker.moodle.org/browse/MDL-6877.
        Once fixed by adodb guys, we'll return to their official distro.
- * removed bogus "_connec" from first line of adodb-postgres64.inc.php
 
 skodak
-11 October 2006
+
+$Id$
index b1106c0d367fc794ed6cb0b393c9f43f05fb9c23..29662a215eb7809a5a5f3d3bd5b5cea8c75213db 100644 (file)
@@ -1,61 +1,61 @@
-<?php
-/** 
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
- * Released under both BSD license and Lesser GPL library license. 
- * Whenever there is any discrepancy between the two licenses, 
- * the BSD license will take precedence. 
- *
- * Set tabs to 4 for best viewing.
- * 
- * Latest version is available at http://php.weblogs.com
- *
- * Requires PHP4.01pl2 or later because it uses include_once
-*/
-
-/*
-       Filter all fields and all rows in a recordset and returns the 
-       processed recordset. We scroll to the beginning of the new recordset
-       after processing.
-       
-       We pass a recordset and function name to RSFilter($rs,'rowfunc');
-       and the function will be called multiple times, once
-       for each row in the recordset. The function will be passed
-       an array containing one row repeatedly.
-       
-       Example: 
-       
-       // ucwords() every element in the recordset
-       function do_ucwords(&$arr,$rs)
-       {
-               foreach($arr as $k => $v) {
-                       $arr[$k] = ucwords($v);
-               }
-       }
-       $rs = RSFilter($rs,'do_ucwords');
- */
-function &RSFilter($rs,$fn)
-{
-       if ($rs->databaseType != 'array') {
-               if (!$rs->connection) return false;
-               
-               $rs = &$rs->connection->_rs2rs($rs);
-       }
-       $rows = $rs->RecordCount();
-       for ($i=0; $i < $rows; $i++) {
-               if (is_array ($fn)) {
-               $obj = $fn[0];
-               $method = $fn[1];
-               $obj->$method ($rs->_array[$i],$rs);
-      } else {
-                       $fn($rs->_array[$i],$rs);
-      }
-         
-       }
-       if (!$rs->EOF) {
-               $rs->_currentRow = 0;
-               $rs->fields = $rs->_array[0];
-       }
-       
-       return $rs;
-}
+<?php\r
+/** \r
+ * @version V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Set tabs to 4 for best viewing.\r
+ * \r
+ * Latest version is available at http://php.weblogs.com\r
+ *\r
+ * Requires PHP4.01pl2 or later because it uses include_once\r
+*/\r
+\r
+/*\r
+       Filter all fields and all rows in a recordset and returns the \r
+       processed recordset. We scroll to the beginning of the new recordset\r
+       after processing.\r
+       \r
+       We pass a recordset and function name to RSFilter($rs,'rowfunc');\r
+       and the function will be called multiple times, once\r
+       for each row in the recordset. The function will be passed\r
+       an array containing one row repeatedly.\r
+       \r
+       Example: \r
+       \r
+       // ucwords() every element in the recordset\r
+       function do_ucwords(&$arr,$rs)\r
+       {\r
+               foreach($arr as $k => $v) {\r
+                       $arr[$k] = ucwords($v);\r
+               }\r
+       }\r
+       $rs = RSFilter($rs,'do_ucwords');\r
+ */\r
+function &RSFilter($rs,$fn)\r
+{\r
+       if ($rs->databaseType != 'array') {\r
+               if (!$rs->connection) return false;\r
+               \r
+               $rs = &$rs->connection->_rs2rs($rs);\r
+       }\r
+       $rows = $rs->RecordCount();\r
+       for ($i=0; $i < $rows; $i++) {\r
+               if (is_array ($fn)) {\r
+               $obj = $fn[0];\r
+               $method = $fn[1];\r
+               $obj->$method ($rs->_array[$i],$rs);\r
+      } else {\r
+                       $fn($rs->_array[$i],$rs);\r
+      }\r
+         \r
+       }\r
+       if (!$rs->EOF) {\r
+               $rs->_currentRow = 0;\r
+               $rs->fields = $rs->_array[0];\r
+       }\r
+       \r
+       return $rs;\r
+}\r
 ?>
\ No newline at end of file
index 2ecc46dd52aef28141f49f22a29755ad4186faf2..79c3823f7f3b2e48798cc6412e6ebe54918bdd69 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index ead02c079162c85f3299526d79a7a938dd7e7036..da8d3d4e535dceac793d6f1bd61af4f51c4b9ec7 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index eb709273bc0d6f7beb1a8391154e54691b1d4f59..ddf619dd885171efc85924f63336ed872a6d0d73 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index 06d2ecfa94a5ecbb474fde895aa591b27b788ed1..6334eaf8a57788f38d679bd3edd29e7438dd6891 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index b6cdd4148e21923dbcffc920c46dd83ba7433d1f..a047579f073a52e07c4e3a09a00e7510ba893ee7 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index 4ee5120a776334b6468739b2f9387f8f7ce5efed..24caa6620b6b2bcd6faaf5e253d4d84072f6b637 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index 07e10c2a92cce6ef1dccbd10e9aef78676efa6b8..cc7e2fb257b5c48a311497e722229868f4c27868 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index 0a193662af6134fa707fedd412ff7704ee26f7ce..a2cd480025252e6e40064e71cdee9f8527e669e7 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index b684533bfd8ab426a83cb27a28bfb57e755fdae4..54b80439eaf9727cc470ad3058179d8527633e70 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index 474548a2b17b24917d29f7cb619dd854583ac8e2..f0054ef878f4eb8c85d792ffbca535d759adbb3c 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
index a773aa043ed7f41a535f7581a0e858cc6d7ef82f..c5932b64aebf46125daae3494a24de5b00085548 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
          Contributed by Ross Smith (adodb@netebb.com). 
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
@@ -769,7 +769,7 @@ class ADODB_Session {
                        
                        $qkey = $conn->qstr($key);
                        $rs2 =& $conn->UpdateBlob($table, 'sessdata', $val, " sesskey=$qkey", strtoupper($clob));
-                       $rs = $conn->CompleteTrans();
+                       $rs = @$conn->CompleteTrans();
                        
                        
                }
index d17f32cec2b337f526d89b1cd04cfa98b2a38675..40ce283be3e4d7edad69c3eecf36fef225bba75e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 370a137897029fe8e78c6b6740adfbfc0e194efa..788e184a94e2cf0add10bf1dcb24892cc04c5022 100644 (file)
-<?php
-/*
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
-  the BSD license will take precedence.
-         Set tabs to 4 for best viewing.
-  
-  Latest version of ADODB is available at http://php.weblogs.com/adodb
-  ======================================================================
-  
- This file provides PHP4 session management using the ADODB database
- wrapper library, using Oracle CLOB's to store data. Contributed by achim.gosse@ddd.de.
-
- Example
- =======
-       include('adodb.inc.php');
-       include('adodb-session.php');
-       session_start();
-       session_register('AVAR');
-       $_SESSION['AVAR'] += 1;
-       print "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";
-       
-To force non-persistent connections, call adodb_session_open first before session_start():
-
-       include('adodb.inc.php');
-       include('adodb-session.php');
-       adodb_session_open(false,false,false);
-       session_start();
-       session_register('AVAR');
-       $_SESSION['AVAR'] += 1;
-       print "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";
-
- Installation
- ============
- 1. Create this table in your database (syntax might vary depending on your db):
-  create table sessions (
-          SESSKEY char(32) not null,
-          EXPIRY int(11) unsigned not null,
-          EXPIREREF varchar(64),
-          DATA CLOB,
-         primary key (sesskey)
-  );
-
-
-  2. Then define the following parameters in this file:
-       $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';
-       $ADODB_SESSION_CONNECT='server to connect to';
-       $ADODB_SESSION_USER ='user';
-       $ADODB_SESSION_PWD ='password';
-       $ADODB_SESSION_DB ='database';
-       $ADODB_SESSION_TBL = 'sessions'
-       $ADODB_SESSION_USE_LOBS = false; (or, if you wanna use CLOBS (= 'CLOB') or ( = 'BLOB')
-       
-  3. Recommended is PHP 4.1.0 or later. There are documented
-        session bugs in earlier versions of PHP.
-
-  4. If you want to receive notifications when a session expires, then
-        you can tag a session with an EXPIREREF, and before the session
-        record is deleted, we can call a function that will pass the EXPIREREF
-        as the first parameter, and the session key as the second parameter.
-        
-        To do this, define a notification function, say NotifyFn:
-        
-               function NotifyFn($expireref, $sesskey)
-               {
-               }
-        
-        Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY.
-        This is an array with 2 elements, the first being the name of the variable
-        you would like to store in the EXPIREREF field, and the 2nd is the 
-        notification function's name.
-        
-        In this example, we want to be notified when a user's session 
-        has expired, so we store the user id in the global variable $USERID, 
-        store this value in the EXPIREREF field:
-        
-               $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn');
-               
-       Then when the NotifyFn is called, we are passed the $USERID as the first
-       parameter, eg. NotifyFn($userid, $sesskey).
-*/
-
-if (!defined('_ADODB_LAYER')) {
-       include (dirname(__FILE__).'/adodb.inc.php');
-}
-
-if (!defined('ADODB_SESSION')) {
-
- define('ADODB_SESSION',1);
- /* if database time and system time is difference is greater than this, then give warning */
- define('ADODB_SESSION_SYNCH_SECS',60); 
-
-/****************************************************************************************\
-       Global definitions
-\****************************************************************************************/
-GLOBAL         $ADODB_SESSION_CONNECT, 
-       $ADODB_SESSION_DRIVER,
-       $ADODB_SESSION_USER,
-       $ADODB_SESSION_PWD,
-       $ADODB_SESSION_DB,
-       $ADODB_SESS_CONN,
-       $ADODB_SESS_LIFE,
-       $ADODB_SESS_DEBUG,
-       $ADODB_SESSION_EXPIRE_NOTIFY,
-       $ADODB_SESSION_CRC,
-       $ADODB_SESSION_USE_LOBS,
-       $ADODB_SESSION_TBL;
-       
-       if (!isset($ADODB_SESSION_USE_LOBS)) $ADODB_SESSION_USE_LOBS = 'CLOB';
-       
-       $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime');
-       if ($ADODB_SESS_LIFE <= 1) {
-        // bug in PHP 4.0.3 pl 1  -- how about other versions?
-        //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";
-               $ADODB_SESS_LIFE=1440;
-       }
-       $ADODB_SESSION_CRC = false;
-       //$ADODB_SESS_DEBUG = true;
-       
-       //////////////////////////////////
-       /* SET THE FOLLOWING PARAMETERS */
-       //////////////////////////////////
-       
-       if (empty($ADODB_SESSION_DRIVER)) {
-               $ADODB_SESSION_DRIVER='mysql';
-               $ADODB_SESSION_CONNECT='localhost';
-               $ADODB_SESSION_USER ='root';
-               $ADODB_SESSION_PWD ='';
-               $ADODB_SESSION_DB ='xphplens_2';
-       }
-       
-       if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {
-               $ADODB_SESSION_EXPIRE_NOTIFY = false;
-       }
-       //  Made table name configurable - by David Johnson djohnson@inpro.net
-       if (empty($ADODB_SESSION_TBL)){
-               $ADODB_SESSION_TBL = 'sessions';
-       }
-       
-
-       // defaulting $ADODB_SESSION_USE_LOBS
-       if (!isset($ADODB_SESSION_USE_LOBS) || empty($ADODB_SESSION_USE_LOBS)) {
-               $ADODB_SESSION_USE_LOBS = false;
-       }
-
-       /*
-       $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER;
-       $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT;
-       $ADODB_SESS['user'] = $ADODB_SESSION_USER;
-       $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD;
-       $ADODB_SESS['db'] = $ADODB_SESSION_DB;
-       $ADODB_SESS['life'] = $ADODB_SESS_LIFE;
-       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;
-       
-       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;
-       $ADODB_SESS['table'] = $ADODB_SESS_TBL;
-       */
-       
-/****************************************************************************************\
-       Create the connection to the database. 
-       
-       If $ADODB_SESS_CONN already exists, reuse that connection
-\****************************************************************************************/
-function adodb_sess_open($save_path, $session_name,$persist=true) 
-{
-GLOBAL $ADODB_SESS_CONN;
-       if (isset($ADODB_SESS_CONN)) return true;
-       
-GLOBAL         $ADODB_SESSION_CONNECT, 
-       $ADODB_SESSION_DRIVER,
-       $ADODB_SESSION_USER,
-       $ADODB_SESSION_PWD,
-       $ADODB_SESSION_DB,
-       $ADODB_SESS_DEBUG;
-       
-       // cannot use & below - do not know why...
-       $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);
-       if (!empty($ADODB_SESS_DEBUG)) {
-               $ADODB_SESS_CONN->debug = true;
-               ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ");
-       }
-       if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,
-                       $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
-       else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,
-                       $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
-       
-       if (!$ok) ADOConnection::outp( "
--- Session: connection failed</p>",false);
-}
-
-/****************************************************************************************\
-       Close the connection
-\****************************************************************************************/
-function adodb_sess_close() 
-{
-global $ADODB_SESS_CONN;
-
-       if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();
-       return true;
-}
-
-/****************************************************************************************\
-       Slurp in the session variables and return the serialized string
-\****************************************************************************************/
-function adodb_sess_read($key) 
-{
-global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;
-
-       $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());
-       if ($rs) {
-               if ($rs->EOF) {
-                       $v = '';
-               } else 
-                       $v = rawurldecode(reset($rs->fields));
-                       
-               $rs->Close();
-               
-               // new optimization adodb 2.1
-               $ADODB_SESSION_CRC = strlen($v).crc32($v);
-               
-               return $v;
-       }
-       
-       return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com
-}
-
-/****************************************************************************************\
-       Write the serialized data to a database.
-       
-       If the data has not been modified since adodb_sess_read(), we do not write.
-\****************************************************************************************/
-function adodb_sess_write($key, $val) 
-{
-       global
-               $ADODB_SESS_CONN, 
-               $ADODB_SESS_LIFE, 
-               $ADODB_SESSION_TBL,
-               $ADODB_SESS_DEBUG, 
-               $ADODB_SESSION_CRC,
-               $ADODB_SESSION_EXPIRE_NOTIFY,
-               $ADODB_SESSION_DRIVER,                  // added
-               $ADODB_SESSION_USE_LOBS;                // added
-
-       $expiry = time() + $ADODB_SESS_LIFE;
-       
-       // crc32 optimization since adodb 2.1
-       // now we only update expiry date, thx to sebastian thom in adodb 2.32
-       if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) {
-               if ($ADODB_SESS_DEBUG) echo "
--- Session: Only updating date - crc32 not changed</p>";
-               $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time();
-               $rs = $ADODB_SESS_CONN->Execute($qry);  
-               return true;
-       }
-       $val = rawurlencode($val);
-       
-       $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val);
-       if ($ADODB_SESSION_EXPIRE_NOTIFY) {
-               $var = reset($ADODB_SESSION_EXPIRE_NOTIFY);
-               global $$var;
-               $arr['expireref'] = $$var;
-       }
-
-       
-       if ($ADODB_SESSION_USE_LOBS === false) {        // no lobs, simply use replace()
-               $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, 'sesskey',$autoQuote = true);
-               if (!$rs) {
-                       $err = $ADODB_SESS_CONN->ErrorMsg();
-               }
-       } else {
-               // what value shall we insert/update for lob row?
-               switch ($ADODB_SESSION_DRIVER) {
-                       // empty_clob or empty_lob for oracle dbs
-                       case "oracle":
-                       case "oci8":
-                       case "oci8po":
-                       case "oci805":
-                               $lob_value = sprintf("empty_%s()", strtolower($ADODB_SESSION_USE_LOBS));
-                               break;
-
-                       // null for all other
-                       default:
-                               $lob_value = "null";
-                               break;
-               }
-
-               // do we insert or update? => as for sesskey
-               $res = $ADODB_SESS_CONN->Execute("select count(*) as cnt from $ADODB_SESSION_TBL where sesskey = '$key'");
-               if ($res && reset($res->fields) > 0) {
-                       $qry = sprintf("update %s set expiry = %d, data = %s where sesskey = '%s'", $ADODB_SESSION_TBL, $expiry, $lob_value, $key);
-               } else {
-                       // insert
-                       $qry = sprintf("insert into %s (sesskey, expiry, data) values ('%s', %d, %s)", $ADODB_SESSION_TBL, $key, $expiry, $lob_value);
-               }
-
-               $err = "";
-               $rs1 = $ADODB_SESS_CONN->Execute($qry);
-               if (!$rs1) {
-                       $err .= $ADODB_SESS_CONN->ErrorMsg()."\n";
-               }
-               $rs2 = $ADODB_SESS_CONN->UpdateBlob($ADODB_SESSION_TBL, 'data', $val, "sesskey='$key'", strtoupper($ADODB_SESSION_USE_LOBS));
-               if (!$rs2) {
-                       $err .= $ADODB_SESS_CONN->ErrorMsg()."\n";
-               }
-               $rs = ($rs1 && $rs2) ? true : false;
-       }
-
-       if (!$rs) {
-               ADOConnection::outp( '
--- Session Replace: '.nl2br($err).'</p>',false);
-       }  else {
-               // bug in access driver (could be odbc?) means that info is not commited
-               // properly unless select statement executed in Win2000
-               if ($ADODB_SESS_CONN->databaseType == 'access') 
-                       $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");
-       }
-       return !empty($rs);
-}
-
-function adodb_sess_destroy($key) 
-{
-       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;
-       
-       if ($ADODB_SESSION_EXPIRE_NOTIFY) {
-               reset($ADODB_SESSION_EXPIRE_NOTIFY);
-               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);
-               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);
-               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");
-               $ADODB_SESS_CONN->SetFetchMode($savem);
-               if ($rs) {
-                       $ADODB_SESS_CONN->BeginTrans();
-                       while (!$rs->EOF) {
-                               $ref = $rs->fields[0];
-                               $key = $rs->fields[1];
-                               $fn($ref,$key);
-                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");
-                               $rs->MoveNext();
-                       }
-                       $ADODB_SESS_CONN->CommitTrans();
-               }
-       } else {
-               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";
-               $rs = $ADODB_SESS_CONN->Execute($qry);
-       }
-       return $rs ? true : false;
-}
-
-function adodb_sess_gc($maxlifetime) 
-{
-       global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;
-       
-       if ($ADODB_SESSION_EXPIRE_NOTIFY) {
-               reset($ADODB_SESSION_EXPIRE_NOTIFY);
-               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);
-               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);
-               $t = time();
-               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t");
-               $ADODB_SESS_CONN->SetFetchMode($savem);
-               if ($rs) {
-                       $ADODB_SESS_CONN->BeginTrans();
-                       while (!$rs->EOF) {
-                               $ref = $rs->fields[0];
-                               $key = $rs->fields[1];
-                               $fn($ref,$key);
-                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");
-                               $rs->MoveNext();
-                       }
-                       $rs->Close();
-                       
-                       //$ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < $t");
-                       $ADODB_SESS_CONN->CommitTrans();
-                       
-               }
-       } else {
-               $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time());
-       
-               if ($ADODB_SESS_DEBUG) ADOConnection::outp("
--- <b>Garbage Collection</b>: $qry</p>");
-       }
-       // suggested by Cameron, "GaM3R" <gamr@outworld.cx>
-       if (defined('ADODB_SESSION_OPTIMIZE')) {
-       global $ADODB_SESSION_DRIVER;
-       
-               switch( $ADODB_SESSION_DRIVER ) {
-                       case 'mysql':
-                       case 'mysqlt':
-                               $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL;
-                               break;
-                       case 'postgresql':
-                       case 'postgresql7':
-                               $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL;        
-                               break;
-               }
-               if (!empty($opt_qry)) {
-                       $ADODB_SESS_CONN->Execute($opt_qry);
-               }
-       }
-       if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select  TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL;
-       else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL;
-       
-       $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1);
-       if ($rs && !$rs->EOF) {
-       
-               $dbts = reset($rs->fields);
-               $rs->Close();
-               $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts);
-               $t = time();
-               if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) {
-                       $msg = 
-                       __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)";
-                       error_log($msg);
-                       if ($ADODB_SESS_DEBUG) ADOConnection::outp("
--- $msg</p>");
-               }
-       }
-       
-       return true;
-}
-
-session_module_name('user'); 
-session_set_save_handler(
-       "adodb_sess_open",
-       "adodb_sess_close",
-       "adodb_sess_read",
-       "adodb_sess_write",
-       "adodb_sess_destroy",
-       "adodb_sess_gc");
-}
-
-/*  TEST SCRIPT -- UNCOMMENT */
-
-if (0) {
-
-       session_start();
-       session_register('AVAR');
-       $_SESSION['AVAR'] += 1;
-       ADOConnection::outp( "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>",false);
-}
-
-?>
+<?php\r
+/*\r
+  V4.93 10 Oct 2006  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+         Set tabs to 4 for best viewing.\r
+  \r
+  Latest version of ADODB is available at http://php.weblogs.com/adodb\r
+  ======================================================================\r
+  \r
+ This file provides PHP4 session management using the ADODB database\r
+ wrapper library, using Oracle CLOB's to store data. Contributed by achim.gosse@ddd.de.\r
+\r
+ Example\r
+ =======\r
\r
+       include('adodb.inc.php');\r
+       include('adodb-session.php');\r
+       session_start();\r
+       session_register('AVAR');\r
+       $_SESSION['AVAR'] += 1;\r
+       print "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";\r
+       \r
+To force non-persistent connections, call adodb_session_open first before session_start():\r
+\r
+       include('adodb.inc.php');\r
+       include('adodb-session.php');\r
+       adodb_session_open(false,false,false);\r
+       session_start();\r
+       session_register('AVAR');\r
+       $_SESSION['AVAR'] += 1;\r
+       print "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";\r
+\r
\r
+ Installation\r
+ ============\r
+ 1. Create this table in your database (syntax might vary depending on your db):\r
\r
+  create table sessions (\r
+          SESSKEY char(32) not null,\r
+          EXPIRY int(11) unsigned not null,\r
+          EXPIREREF varchar(64),\r
+          DATA CLOB,\r
+         primary key (sesskey)\r
+  );\r
+\r
+\r
+  2. Then define the following parameters in this file:\r
+       $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';\r
+       $ADODB_SESSION_CONNECT='server to connect to';\r
+       $ADODB_SESSION_USER ='user';\r
+       $ADODB_SESSION_PWD ='password';\r
+       $ADODB_SESSION_DB ='database';\r
+       $ADODB_SESSION_TBL = 'sessions'\r
+       $ADODB_SESSION_USE_LOBS = false; (or, if you wanna use CLOBS (= 'CLOB') or ( = 'BLOB')\r
+       \r
+  3. Recommended is PHP 4.1.0 or later. There are documented\r
+        session bugs in earlier versions of PHP.\r
+\r
+  4. If you want to receive notifications when a session expires, then\r
+        you can tag a session with an EXPIREREF, and before the session\r
+        record is deleted, we can call a function that will pass the EXPIREREF\r
+        as the first parameter, and the session key as the second parameter.\r
+        \r
+        To do this, define a notification function, say NotifyFn:\r
+        \r
+               function NotifyFn($expireref, $sesskey)\r
+               {\r
+               }\r
+        \r
+        Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY.\r
+        This is an array with 2 elements, the first being the name of the variable\r
+        you would like to store in the EXPIREREF field, and the 2nd is the \r
+        notification function's name.\r
+        \r
+        In this example, we want to be notified when a user's session \r
+        has expired, so we store the user id in the global variable $USERID, \r
+        store this value in the EXPIREREF field:\r
+        \r
+               $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn');\r
+               \r
+       Then when the NotifyFn is called, we are passed the $USERID as the first\r
+       parameter, eg. NotifyFn($userid, $sesskey).\r
+*/\r
+\r
+if (!defined('_ADODB_LAYER')) {\r
+       include (dirname(__FILE__).'/adodb.inc.php');\r
+}\r
+\r
+if (!defined('ADODB_SESSION')) {\r
+\r
+ define('ADODB_SESSION',1);\r
\r
+ /* if database time and system time is difference is greater than this, then give warning */\r
+ define('ADODB_SESSION_SYNCH_SECS',60); \r
+\r
+/****************************************************************************************\\r
+       Global definitions\r
+\****************************************************************************************/\r
+GLOBAL         $ADODB_SESSION_CONNECT, \r
+       $ADODB_SESSION_DRIVER,\r
+       $ADODB_SESSION_USER,\r
+       $ADODB_SESSION_PWD,\r
+       $ADODB_SESSION_DB,\r
+       $ADODB_SESS_CONN,\r
+       $ADODB_SESS_LIFE,\r
+       $ADODB_SESS_DEBUG,\r
+       $ADODB_SESSION_EXPIRE_NOTIFY,\r
+       $ADODB_SESSION_CRC,\r
+       $ADODB_SESSION_USE_LOBS,\r
+       $ADODB_SESSION_TBL;\r
+       \r
+       if (!isset($ADODB_SESSION_USE_LOBS)) $ADODB_SESSION_USE_LOBS = 'CLOB';\r
+       \r
+       $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime');\r
+       if ($ADODB_SESS_LIFE <= 1) {\r
+        // bug in PHP 4.0.3 pl 1  -- how about other versions?\r
+        //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";\r
+               $ADODB_SESS_LIFE=1440;\r
+       }\r
+       $ADODB_SESSION_CRC = false;\r
+       //$ADODB_SESS_DEBUG = true;\r
+       \r
+       //////////////////////////////////\r
+       /* SET THE FOLLOWING PARAMETERS */\r
+       //////////////////////////////////\r
+       \r
+       if (empty($ADODB_SESSION_DRIVER)) {\r
+               $ADODB_SESSION_DRIVER='mysql';\r
+               $ADODB_SESSION_CONNECT='localhost';\r
+               $ADODB_SESSION_USER ='root';\r
+               $ADODB_SESSION_PWD ='';\r
+               $ADODB_SESSION_DB ='xphplens_2';\r
+       }\r
+       \r
+       if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {\r
+               $ADODB_SESSION_EXPIRE_NOTIFY = false;\r
+       }\r
+       //  Made table name configurable - by David Johnson djohnson@inpro.net\r
+       if (empty($ADODB_SESSION_TBL)){\r
+               $ADODB_SESSION_TBL = 'sessions';\r
+       }\r
+       \r
+\r
+       // defaulting $ADODB_SESSION_USE_LOBS\r
+       if (!isset($ADODB_SESSION_USE_LOBS) || empty($ADODB_SESSION_USE_LOBS)) {\r
+               $ADODB_SESSION_USE_LOBS = false;\r
+       }\r
+\r
+       /*\r
+       $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER;\r
+       $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT;\r
+       $ADODB_SESS['user'] = $ADODB_SESSION_USER;\r
+       $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD;\r
+       $ADODB_SESS['db'] = $ADODB_SESSION_DB;\r
+       $ADODB_SESS['life'] = $ADODB_SESS_LIFE;\r
+       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+       \r
+       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+       $ADODB_SESS['table'] = $ADODB_SESS_TBL;\r
+       */\r
+       \r
+/****************************************************************************************\\r
+       Create the connection to the database. \r
+       \r
+       If $ADODB_SESS_CONN already exists, reuse that connection\r
+\****************************************************************************************/\r
+function adodb_sess_open($save_path, $session_name,$persist=true) \r
+{\r
+GLOBAL $ADODB_SESS_CONN;\r
+       if (isset($ADODB_SESS_CONN)) return true;\r
+       \r
+GLOBAL         $ADODB_SESSION_CONNECT, \r
+       $ADODB_SESSION_DRIVER,\r
+       $ADODB_SESSION_USER,\r
+       $ADODB_SESSION_PWD,\r
+       $ADODB_SESSION_DB,\r
+       $ADODB_SESS_DEBUG;\r
+       \r
+       // cannot use & below - do not know why...\r
+       $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);\r
+       if (!empty($ADODB_SESS_DEBUG)) {\r
+               $ADODB_SESS_CONN->debug = true;\r
+               ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ");\r
+       }\r
+       if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,\r
+                       $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
+       else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,\r
+                       $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
+       \r
+       if (!$ok) ADOConnection::outp( "\r
+-- Session: connection failed</p>",false);\r
+}\r
+\r
+/****************************************************************************************\\r
+       Close the connection\r
+\****************************************************************************************/\r
+function adodb_sess_close() \r
+{\r
+global $ADODB_SESS_CONN;\r
+\r
+       if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();\r
+       return true;\r
+}\r
+\r
+/****************************************************************************************\\r
+       Slurp in the session variables and return the serialized string\r
+\****************************************************************************************/\r
+function adodb_sess_read($key) \r
+{\r
+global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;\r
+\r
+       $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());\r
+       if ($rs) {\r
+               if ($rs->EOF) {\r
+                       $v = '';\r
+               } else \r
+                       $v = rawurldecode(reset($rs->fields));\r
+                       \r
+               $rs->Close();\r
+               \r
+               // new optimization adodb 2.1\r
+               $ADODB_SESSION_CRC = strlen($v).crc32($v);\r
+               \r
+               return $v;\r
+       }\r
+       \r
+       return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com\r
+}\r
+\r
+/****************************************************************************************\\r
+       Write the serialized data to a database.\r
+       \r
+       If the data has not been modified since adodb_sess_read(), we do not write.\r
+\****************************************************************************************/\r
+function adodb_sess_write($key, $val) \r
+{\r
+       global\r
+               $ADODB_SESS_CONN, \r
+               $ADODB_SESS_LIFE, \r
+               $ADODB_SESSION_TBL,\r
+               $ADODB_SESS_DEBUG, \r
+               $ADODB_SESSION_CRC,\r
+               $ADODB_SESSION_EXPIRE_NOTIFY,\r
+               $ADODB_SESSION_DRIVER,                  // added\r
+               $ADODB_SESSION_USE_LOBS;                // added\r
+\r
+       $expiry = time() + $ADODB_SESS_LIFE;\r
+       \r
+       // crc32 optimization since adodb 2.1\r
+       // now we only update expiry date, thx to sebastian thom in adodb 2.32\r
+       if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) {\r
+               if ($ADODB_SESS_DEBUG) echo "\r
+-- Session: Only updating date - crc32 not changed</p>";\r
+               $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time();\r
+               $rs = $ADODB_SESS_CONN->Execute($qry);  \r
+               return true;\r
+       }\r
+       $val = rawurlencode($val);\r
+       \r
+       $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val);\r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               $var = reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               global $$var;\r
+               $arr['expireref'] = $$var;\r
+       }\r
+\r
+       \r
+       if ($ADODB_SESSION_USE_LOBS === false) {        // no lobs, simply use replace()\r
+               $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, 'sesskey',$autoQuote = true);\r
+               if (!$rs) {\r
+                       $err = $ADODB_SESS_CONN->ErrorMsg();\r
+               }\r
+       } else {\r
+               // what value shall we insert/update for lob row?\r
+               switch ($ADODB_SESSION_DRIVER) {\r
+                       // empty_clob or empty_lob for oracle dbs\r
+                       case "oracle":\r
+                       case "oci8":\r
+                       case "oci8po":\r
+                       case "oci805":\r
+                               $lob_value = sprintf("empty_%s()", strtolower($ADODB_SESSION_USE_LOBS));\r
+                               break;\r
+\r
+                       // null for all other\r
+                       default:\r
+                               $lob_value = "null";\r
+                               break;\r
+               }\r
+\r
+               // do we insert or update? => as for sesskey\r
+               $res = $ADODB_SESS_CONN->Execute("select count(*) as cnt from $ADODB_SESSION_TBL where sesskey = '$key'");\r
+               if ($res && reset($res->fields) > 0) {\r
+                       $qry = sprintf("update %s set expiry = %d, data = %s where sesskey = '%s'", $ADODB_SESSION_TBL, $expiry, $lob_value, $key);\r
+               } else {\r
+                       // insert\r
+                       $qry = sprintf("insert into %s (sesskey, expiry, data) values ('%s', %d, %s)", $ADODB_SESSION_TBL, $key, $expiry, $lob_value);\r
+               }\r
+\r
+               $err = "";\r
+               $rs1 = $ADODB_SESS_CONN->Execute($qry);\r
+               if (!$rs1) {\r
+                       $err .= $ADODB_SESS_CONN->ErrorMsg()."\n";\r
+               }\r
+               $rs2 = $ADODB_SESS_CONN->UpdateBlob($ADODB_SESSION_TBL, 'data', $val, "sesskey='$key'", strtoupper($ADODB_SESSION_USE_LOBS));\r
+               if (!$rs2) {\r
+                       $err .= $ADODB_SESS_CONN->ErrorMsg()."\n";\r
+               }\r
+               $rs = ($rs1 && $rs2) ? true : false;\r
+       }\r
+\r
+       if (!$rs) {\r
+               ADOConnection::outp( '\r
+-- Session Replace: '.nl2br($err).'</p>',false);\r
+       }  else {\r
+               // bug in access driver (could be odbc?) means that info is not commited\r
+               // properly unless select statement executed in Win2000\r
+               if ($ADODB_SESS_CONN->databaseType == 'access') \r
+                       $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+       }\r
+       return !empty($rs);\r
+}\r
+\r
+function adodb_sess_destroy($key) \r
+{\r
+       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+       \r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+               $ADODB_SESS_CONN->SetFetchMode($savem);\r
+               if ($rs) {\r
+                       $ADODB_SESS_CONN->BeginTrans();\r
+                       while (!$rs->EOF) {\r
+                               $ref = $rs->fields[0];\r
+                               $key = $rs->fields[1];\r
+                               $fn($ref,$key);\r
+                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+                               $rs->MoveNext();\r
+                       }\r
+                       $ADODB_SESS_CONN->CommitTrans();\r
+               }\r
+       } else {\r
+               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";\r
+               $rs = $ADODB_SESS_CONN->Execute($qry);\r
+       }\r
+       return $rs ? true : false;\r
+}\r
+\r
+function adodb_sess_gc($maxlifetime) \r
+{\r
+       global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+       \r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+               $t = time();\r
+               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t");\r
+               $ADODB_SESS_CONN->SetFetchMode($savem);\r
+               if ($rs) {\r
+                       $ADODB_SESS_CONN->BeginTrans();\r
+                       while (!$rs->EOF) {\r
+                               $ref = $rs->fields[0];\r
+                               $key = $rs->fields[1];\r
+                               $fn($ref,$key);\r
+                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+                               $rs->MoveNext();\r
+                       }\r
+                       $rs->Close();\r
+                       \r
+                       //$ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < $t");\r
+                       $ADODB_SESS_CONN->CommitTrans();\r
+                       \r
+               }\r
+       } else {\r
+               $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time());\r
+       \r
+               if ($ADODB_SESS_DEBUG) ADOConnection::outp("\r
+-- <b>Garbage Collection</b>: $qry</p>");\r
+       }\r
+       // suggested by Cameron, "GaM3R" <gamr@outworld.cx>\r
+       if (defined('ADODB_SESSION_OPTIMIZE')) {\r
+       global $ADODB_SESSION_DRIVER;\r
+       \r
+               switch( $ADODB_SESSION_DRIVER ) {\r
+                       case 'mysql':\r
+                       case 'mysqlt':\r
+                               $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL;\r
+                               break;\r
+                       case 'postgresql':\r
+                       case 'postgresql7':\r
+                               $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL;        \r
+                               break;\r
+               }\r
+               if (!empty($opt_qry)) {\r
+                       $ADODB_SESS_CONN->Execute($opt_qry);\r
+               }\r
+       }\r
+       if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select  TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL;\r
+       else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL;\r
+       \r
+       $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1);\r
+       if ($rs && !$rs->EOF) {\r
+       \r
+               $dbts = reset($rs->fields);\r
+               $rs->Close();\r
+               $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts);\r
+               $t = time();\r
+               if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) {\r
+                       $msg = \r
+                       __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)";\r
+                       error_log($msg);\r
+                       if ($ADODB_SESS_DEBUG) ADOConnection::outp("\r
+-- $msg</p>");\r
+               }\r
+       }\r
+       \r
+       return true;\r
+}\r
+\r
+session_module_name('user'); \r
+session_set_save_handler(\r
+       "adodb_sess_open",\r
+       "adodb_sess_close",\r
+       "adodb_sess_read",\r
+       "adodb_sess_write",\r
+       "adodb_sess_destroy",\r
+       "adodb_sess_gc");\r
+}\r
+\r
+/*  TEST SCRIPT -- UNCOMMENT */\r
+\r
+if (0) {\r
+\r
+       session_start();\r
+       session_register('AVAR');\r
+       $_SESSION['AVAR'] += 1;\r
+       ADOConnection::outp( "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>",false);\r
+}\r
+\r
+?>\r
index c4183dee94b5139431f81f50fdbe7639e7347f6d..6fc9b2fe05e3e0b237716287ab059a4198377640 100644 (file)
-<?php
-/*
-V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
-  the BSD license will take precedence.
-         Set tabs to 4 for best viewing.
-  
-  Latest version of ADODB is available at http://php.weblogs.com/adodb
-  ======================================================================
-  
- This file provides PHP4 session management using the ADODB database
-wrapper library.
- Example
- =======
-       include('adodb.inc.php');
-       include('adodb-session.php');
-       session_start();
-       session_register('AVAR');
-       $_SESSION['AVAR'] += 1;
-       print "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";
-       
-To force non-persistent connections, call adodb_session_open first before session_start():
-
-       include('adodb.inc.php');
-       include('adodb-session.php');
-       adodb_sess_open(false,false,false);
-       session_start();
-       session_register('AVAR');
-       $_SESSION['AVAR'] += 1;
-       print "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";
-
- Installation
- ============
- 1. Create this table in your database (syntax might vary depending on your db):
-  create table sessions (
-          SESSKEY char(32) not null,
-          EXPIRY int(11) unsigned not null,
-          EXPIREREF varchar(64),
-          DATA text not null,
-         primary key (sesskey)
-  );
-  
-  For oracle:
-    create table sessions (
-          SESSKEY char(32) not null,
-          EXPIRY DECIMAL(16)  not null,
-          EXPIREREF varchar(64),
-          DATA varchar(4000) not null,
-         primary key (sesskey)
-  );
-
-
-  2. Then define the following parameters. You can either modify
-     this file, or define them before this file is included:
-        
-       $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';
-       $ADODB_SESSION_CONNECT='server to connect to';
-       $ADODB_SESSION_USER ='user';
-       $ADODB_SESSION_PWD ='password';
-       $ADODB_SESSION_DB ='database';
-       $ADODB_SESSION_TBL = 'sessions'
-       
-  3. Recommended is PHP 4.1.0 or later. There are documented
-        session bugs in earlier versions of PHP.
-
-  4. If you want to receive notifications when a session expires, then
-        you can tag a session with an EXPIREREF, and before the session
-        record is deleted, we can call a function that will pass the EXPIREREF
-        as the first parameter, and the session key as the second parameter.
-        
-        To do this, define a notification function, say NotifyFn:
-        
-               function NotifyFn($expireref, $sesskey)
-               {
-               }
-        
-        Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY.
-        This is an array with 2 elements, the first being the name of the variable
-        you would like to store in the EXPIREREF field, and the 2nd is the 
-        notification function's name.
-        
-        In this example, we want to be notified when a user's session 
-        has expired, so we store the user id in the global variable $USERID, 
-        store this value in the EXPIREREF field:
-        
-               $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn');
-               
-       Then when the NotifyFn is called, we are passed the $USERID as the first
-       parameter, eg. NotifyFn($userid, $sesskey).
-*/
-
-if (!defined('_ADODB_LAYER')) {
-       include (dirname(__FILE__).'/adodb.inc.php');
-}
-
-if (!defined('ADODB_SESSION')) {
-
- define('ADODB_SESSION',1);
- /* if database time and system time is difference is greater than this, then give warning */
- define('ADODB_SESSION_SYNCH_SECS',60); 
-
- /*
-       Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1
-*/
-function adodb_session_regenerate_id() 
-{
-       $conn =& ADODB_Session::_conn();
-       if (!$conn) return false;
-
-       $old_id = session_id();
-       if (function_exists('session_regenerate_id')) {
-               session_regenerate_id();
-       } else {
-               session_id(md5(uniqid(rand(), true)));
-               $ck = session_get_cookie_params();
-               setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);
-               //@session_start();
-       }
-       $new_id = session_id();
-       $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id));
-       
-       /* it is possible that the update statement fails due to a collision */
-       if (!$ok) {
-               session_id($old_id);
-               if (empty($ck)) $ck = session_get_cookie_params();
-               setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);
-               return false;
-       }
-       
-       return true;
-}
-
-/****************************************************************************************\
-       Global definitions
-\****************************************************************************************/
-GLOBAL         $ADODB_SESSION_CONNECT, 
-       $ADODB_SESSION_DRIVER,
-       $ADODB_SESSION_USER,
-       $ADODB_SESSION_PWD,
-       $ADODB_SESSION_DB,
-       $ADODB_SESS_CONN,
-       $ADODB_SESS_LIFE,
-       $ADODB_SESS_DEBUG,
-       $ADODB_SESSION_EXPIRE_NOTIFY,
-       $ADODB_SESSION_CRC,
-       $ADODB_SESSION_TBL;
-       
-       
-       $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime');
-       if ($ADODB_SESS_LIFE <= 1) {
-        // bug in PHP 4.0.3 pl 1  -- how about other versions?
-        //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";
-               $ADODB_SESS_LIFE=1440;
-       }
-       $ADODB_SESSION_CRC = false;
-       //$ADODB_SESS_DEBUG = true;
-       
-       //////////////////////////////////
-       /* SET THE FOLLOWING PARAMETERS */
-       //////////////////////////////////
-       
-       if (empty($ADODB_SESSION_DRIVER)) {
-               $ADODB_SESSION_DRIVER='mysql';
-               $ADODB_SESSION_CONNECT='localhost';
-               $ADODB_SESSION_USER ='root';
-               $ADODB_SESSION_PWD ='';
-               $ADODB_SESSION_DB ='xphplens_2';
-       }
-       
-       if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {
-               $ADODB_SESSION_EXPIRE_NOTIFY = false;
-       }
-       //  Made table name configurable - by David Johnson djohnson@inpro.net
-       if (empty($ADODB_SESSION_TBL)){
-               $ADODB_SESSION_TBL = 'sessions';
-       }
-       
-       /*
-       $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER;
-       $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT;
-       $ADODB_SESS['user'] = $ADODB_SESSION_USER;
-       $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD;
-       $ADODB_SESS['db'] = $ADODB_SESSION_DB;
-       $ADODB_SESS['life'] = $ADODB_SESS_LIFE;
-       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;
-       
-       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;
-       $ADODB_SESS['table'] = $ADODB_SESS_TBL;
-       */
-       
-/****************************************************************************************\
-       Create the connection to the database. 
-       
-       If $ADODB_SESS_CONN already exists, reuse that connection
-\****************************************************************************************/
-function adodb_sess_open($save_path, $session_name,$persist=true) 
-{
-GLOBAL $ADODB_SESS_CONN;
-       if (isset($ADODB_SESS_CONN)) return true;
-       
-GLOBAL         $ADODB_SESSION_CONNECT, 
-       $ADODB_SESSION_DRIVER,
-       $ADODB_SESSION_USER,
-       $ADODB_SESSION_PWD,
-       $ADODB_SESSION_DB,
-       $ADODB_SESS_DEBUG;
-       
-       // cannot use & below - do not know why...
-       $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);
-       if (!empty($ADODB_SESS_DEBUG)) {
-               $ADODB_SESS_CONN->debug = true;
-               ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ");
-       }
-       if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,
-                       $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
-       else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,
-                       $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
-       
-       if (!$ok) ADOConnection::outp( "
--- Session: connection failed</p>",false);
-}
-
-/****************************************************************************************\
-       Close the connection
-\****************************************************************************************/
-function adodb_sess_close() 
-{
-global $ADODB_SESS_CONN;
-
-       if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();
-       return true;
-}
-
-/****************************************************************************************\
-       Slurp in the session variables and return the serialized string
-\****************************************************************************************/
-function adodb_sess_read($key) 
-{
-global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;
-
-       $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());
-       if ($rs) {
-               if ($rs->EOF) {
-                       $v = '';
-               } else 
-                       $v = rawurldecode(reset($rs->fields));
-                       
-               $rs->Close();
-               
-               // new optimization adodb 2.1
-               $ADODB_SESSION_CRC = strlen($v).crc32($v);
-               
-               return $v;
-       }
-       
-       return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com
-}
-
-/****************************************************************************************\
-       Write the serialized data to a database.
-       
-       If the data has not been modified since adodb_sess_read(), we do not write.
-\****************************************************************************************/
-function adodb_sess_write($key, $val) 
-{
-       global
-               $ADODB_SESS_CONN, 
-               $ADODB_SESS_LIFE, 
-               $ADODB_SESSION_TBL,
-               $ADODB_SESS_DEBUG, 
-               $ADODB_SESSION_CRC,
-               $ADODB_SESSION_EXPIRE_NOTIFY;
-
-       $expiry = time() + $ADODB_SESS_LIFE;
-       
-       // crc32 optimization since adodb 2.1
-       // now we only update expiry date, thx to sebastian thom in adodb 2.32
-       if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) {
-               if ($ADODB_SESS_DEBUG) echo "
--- Session: Only updating date - crc32 not changed</p>";
-               $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time();
-               $rs = $ADODB_SESS_CONN->Execute($qry);  
-               return true;
-       }
-       $val = rawurlencode($val);
-       
-       $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val);
-       if ($ADODB_SESSION_EXPIRE_NOTIFY) {
-               $var = reset($ADODB_SESSION_EXPIRE_NOTIFY);
-               global $$var;
-               $arr['expireref'] = $$var;
-       }
-       $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr,
-       'sesskey',$autoQuote = true);
-       
-       if (!$rs) {
-               ADOConnection::outp( '
--- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'</p>',false);
-       }  else {
-               // bug in access driver (could be odbc?) means that info is not commited
-               // properly unless select statement executed in Win2000
-               if ($ADODB_SESS_CONN->databaseType == 'access') 
-                       $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");
-       }
-       return !empty($rs);
-}
-
-function adodb_sess_destroy($key) 
-{
-       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;
-       
-       if ($ADODB_SESSION_EXPIRE_NOTIFY) {
-               reset($ADODB_SESSION_EXPIRE_NOTIFY);
-               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);
-               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);
-               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");
-               $ADODB_SESS_CONN->SetFetchMode($savem);
-               if ($rs) {
-                       $ADODB_SESS_CONN->BeginTrans();
-                       while (!$rs->EOF) {
-                               $ref = $rs->fields[0];
-                               $key = $rs->fields[1];
-                               $fn($ref,$key);
-                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");
-                               $rs->MoveNext();
-                       }
-                       $ADODB_SESS_CONN->CommitTrans();
-               }
-       } else {
-               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";
-               $rs = $ADODB_SESS_CONN->Execute($qry);
-       }
-       return $rs ? true : false;
-}
-
-function adodb_sess_gc($maxlifetime) 
-{
-       global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;
-       
-       if ($ADODB_SESSION_EXPIRE_NOTIFY) {
-               reset($ADODB_SESSION_EXPIRE_NOTIFY);
-               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);
-               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);
-               $t = time();
-               $rs =& $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t");
-               $ADODB_SESS_CONN->SetFetchMode($savem);
-               if ($rs) {
-                       $ADODB_SESS_CONN->BeginTrans();
-                       while (!$rs->EOF) {
-                               $ref = $rs->fields[0];
-                               $key = $rs->fields[1];
-                               $fn($ref,$key);
-                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");
-                               $rs->MoveNext();
-                       }
-                       $rs->Close();
-                       
-                       $ADODB_SESS_CONN->CommitTrans();
-                       
-               }
-       } else {
-               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();
-               $ADODB_SESS_CONN->Execute($qry);
-       
-               if ($ADODB_SESS_DEBUG) ADOConnection::outp("
--- <b>Garbage Collection</b>: $qry</p>");
-       }
-       // suggested by Cameron, "GaM3R" <gamr@outworld.cx>
-       if (defined('ADODB_SESSION_OPTIMIZE')) {
-       global $ADODB_SESSION_DRIVER;
-       
-               switch( $ADODB_SESSION_DRIVER ) {
-                       case 'mysql':
-                       case 'mysqlt':
-                               $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL;
-                               break;
-                       case 'postgresql':
-                       case 'postgresql7':
-                               $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL;        
-                               break;
-               }
-               if (!empty($opt_qry)) {
-                       $ADODB_SESS_CONN->Execute($opt_qry);
-               }
-       }
-       if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select  TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL;
-       else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL;
-       
-       $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1);
-       if ($rs && !$rs->EOF) {
-       
-               $dbts = reset($rs->fields);
-               $rs->Close();
-               $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts);
-               $t = time();
-       
-               if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) {
-               
-                       $msg = 
-                       __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)";
-                       error_log($msg);
-                       if ($ADODB_SESS_DEBUG) ADOConnection::outp("
--- $msg</p>");
-               }
-       }
-       
-       return true;
-}
-
-session_module_name('user'); 
-session_set_save_handler(
-       "adodb_sess_open",
-       "adodb_sess_close",
-       "adodb_sess_read",
-       "adodb_sess_write",
-       "adodb_sess_destroy",
-       "adodb_sess_gc");
-}
-
-/*  TEST SCRIPT -- UNCOMMENT */
-
-if (0) {
-
-       session_start();
-       session_register('AVAR');
-       $_SESSION['AVAR'] += 1;
-       ADOConnection::outp( "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>",false);
-}
-
+<?php\r
+/*\r
+V4.93 10 Oct 2006  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+         Set tabs to 4 for best viewing.\r
+  \r
+  Latest version of ADODB is available at http://php.weblogs.com/adodb\r
+  ======================================================================\r
+  \r
+ This file provides PHP4 session management using the ADODB database\r
+wrapper library.\r
\r
+ Example\r
+ =======\r
\r
+       include('adodb.inc.php');\r
+       include('adodb-session.php');\r
+       session_start();\r
+       session_register('AVAR');\r
+       $_SESSION['AVAR'] += 1;\r
+       print "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";\r
+       \r
+To force non-persistent connections, call adodb_session_open first before session_start():\r
+\r
+       include('adodb.inc.php');\r
+       include('adodb-session.php');\r
+       adodb_sess_open(false,false,false);\r
+       session_start();\r
+       session_register('AVAR');\r
+       $_SESSION['AVAR'] += 1;\r
+       print "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";\r
+\r
\r
+ Installation\r
+ ============\r
+ 1. Create this table in your database (syntax might vary depending on your db):\r
\r
+  create table sessions (\r
+          SESSKEY char(32) not null,\r
+          EXPIRY int(11) unsigned not null,\r
+          EXPIREREF varchar(64),\r
+          DATA text not null,\r
+         primary key (sesskey)\r
+  );\r
+  \r
+  For oracle:\r
+    create table sessions (\r
+          SESSKEY char(32) not null,\r
+          EXPIRY DECIMAL(16)  not null,\r
+          EXPIREREF varchar(64),\r
+          DATA varchar(4000) not null,\r
+         primary key (sesskey)\r
+  );\r
+\r
+\r
+  2. Then define the following parameters. You can either modify\r
+     this file, or define them before this file is included:\r
+        \r
+       $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';\r
+       $ADODB_SESSION_CONNECT='server to connect to';\r
+       $ADODB_SESSION_USER ='user';\r
+       $ADODB_SESSION_PWD ='password';\r
+       $ADODB_SESSION_DB ='database';\r
+       $ADODB_SESSION_TBL = 'sessions'\r
+       \r
+  3. Recommended is PHP 4.1.0 or later. There are documented\r
+        session bugs in earlier versions of PHP.\r
+\r
+  4. If you want to receive notifications when a session expires, then\r
+        you can tag a session with an EXPIREREF, and before the session\r
+        record is deleted, we can call a function that will pass the EXPIREREF\r
+        as the first parameter, and the session key as the second parameter.\r
+        \r
+        To do this, define a notification function, say NotifyFn:\r
+        \r
+               function NotifyFn($expireref, $sesskey)\r
+               {\r
+               }\r
+        \r
+        Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY.\r
+        This is an array with 2 elements, the first being the name of the variable\r
+        you would like to store in the EXPIREREF field, and the 2nd is the \r
+        notification function's name.\r
+        \r
+        In this example, we want to be notified when a user's session \r
+        has expired, so we store the user id in the global variable $USERID, \r
+        store this value in the EXPIREREF field:\r
+        \r
+               $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn');\r
+               \r
+       Then when the NotifyFn is called, we are passed the $USERID as the first\r
+       parameter, eg. NotifyFn($userid, $sesskey).\r
+*/\r
+\r
+if (!defined('_ADODB_LAYER')) {\r
+       include (dirname(__FILE__).'/adodb.inc.php');\r
+}\r
+\r
+if (!defined('ADODB_SESSION')) {\r
+\r
+ define('ADODB_SESSION',1);\r
\r
+ /* if database time and system time is difference is greater than this, then give warning */\r
+ define('ADODB_SESSION_SYNCH_SECS',60); \r
+\r
+ /*\r
+       Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1\r
+*/\r
+function adodb_session_regenerate_id() \r
+{\r
+       $conn =& ADODB_Session::_conn();\r
+       if (!$conn) return false;\r
+\r
+       $old_id = session_id();\r
+       if (function_exists('session_regenerate_id')) {\r
+               session_regenerate_id();\r
+       } else {\r
+               session_id(md5(uniqid(rand(), true)));\r
+               $ck = session_get_cookie_params();\r
+               setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);\r
+               //@session_start();\r
+       }\r
+       $new_id = session_id();\r
+       $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id));\r
+       \r
+       /* it is possible that the update statement fails due to a collision */\r
+       if (!$ok) {\r
+               session_id($old_id);\r
+               if (empty($ck)) $ck = session_get_cookie_params();\r
+               setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);\r
+               return false;\r
+       }\r
+       \r
+       return true;\r
+}\r
+\r
+/****************************************************************************************\\r
+       Global definitions\r
+\****************************************************************************************/\r
+GLOBAL         $ADODB_SESSION_CONNECT, \r
+       $ADODB_SESSION_DRIVER,\r
+       $ADODB_SESSION_USER,\r
+       $ADODB_SESSION_PWD,\r
+       $ADODB_SESSION_DB,\r
+       $ADODB_SESS_CONN,\r
+       $ADODB_SESS_LIFE,\r
+       $ADODB_SESS_DEBUG,\r
+       $ADODB_SESSION_EXPIRE_NOTIFY,\r
+       $ADODB_SESSION_CRC,\r
+       $ADODB_SESSION_TBL;\r
+       \r
+       \r
+       $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime');\r
+       if ($ADODB_SESS_LIFE <= 1) {\r
+        // bug in PHP 4.0.3 pl 1  -- how about other versions?\r
+        //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";\r
+               $ADODB_SESS_LIFE=1440;\r
+       }\r
+       $ADODB_SESSION_CRC = false;\r
+       //$ADODB_SESS_DEBUG = true;\r
+       \r
+       //////////////////////////////////\r
+       /* SET THE FOLLOWING PARAMETERS */\r
+       //////////////////////////////////\r
+       \r
+       if (empty($ADODB_SESSION_DRIVER)) {\r
+               $ADODB_SESSION_DRIVER='mysql';\r
+               $ADODB_SESSION_CONNECT='localhost';\r
+               $ADODB_SESSION_USER ='root';\r
+               $ADODB_SESSION_PWD ='';\r
+               $ADODB_SESSION_DB ='xphplens_2';\r
+       }\r
+       \r
+       if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {\r
+               $ADODB_SESSION_EXPIRE_NOTIFY = false;\r
+       }\r
+       //  Made table name configurable - by David Johnson djohnson@inpro.net\r
+       if (empty($ADODB_SESSION_TBL)){\r
+               $ADODB_SESSION_TBL = 'sessions';\r
+       }\r
+       \r
+       /*\r
+       $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER;\r
+       $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT;\r
+       $ADODB_SESS['user'] = $ADODB_SESSION_USER;\r
+       $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD;\r
+       $ADODB_SESS['db'] = $ADODB_SESSION_DB;\r
+       $ADODB_SESS['life'] = $ADODB_SESS_LIFE;\r
+       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+       \r
+       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+       $ADODB_SESS['table'] = $ADODB_SESS_TBL;\r
+       */\r
+       \r
+/****************************************************************************************\\r
+       Create the connection to the database. \r
+       \r
+       If $ADODB_SESS_CONN already exists, reuse that connection\r
+\****************************************************************************************/\r
+function adodb_sess_open($save_path, $session_name,$persist=true) \r
+{\r
+GLOBAL $ADODB_SESS_CONN;\r
+       if (isset($ADODB_SESS_CONN)) return true;\r
+       \r
+GLOBAL         $ADODB_SESSION_CONNECT, \r
+       $ADODB_SESSION_DRIVER,\r
+       $ADODB_SESSION_USER,\r
+       $ADODB_SESSION_PWD,\r
+       $ADODB_SESSION_DB,\r
+       $ADODB_SESS_DEBUG;\r
+       \r
+       // cannot use & below - do not know why...\r
+       $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);\r
+       if (!empty($ADODB_SESS_DEBUG)) {\r
+               $ADODB_SESS_CONN->debug = true;\r
+               ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ");\r
+       }\r
+       if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,\r
+                       $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
+       else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,\r
+                       $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
+       \r
+       if (!$ok) ADOConnection::outp( "\r
+-- Session: connection failed</p>",false);\r
+}\r
+\r
+/****************************************************************************************\\r
+       Close the connection\r
+\****************************************************************************************/\r
+function adodb_sess_close() \r
+{\r
+global $ADODB_SESS_CONN;\r
+\r
+       if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();\r
+       return true;\r
+}\r
+\r
+/****************************************************************************************\\r
+       Slurp in the session variables and return the serialized string\r
+\****************************************************************************************/\r
+function adodb_sess_read($key) \r
+{\r
+global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;\r
+\r
+       $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());\r
+       if ($rs) {\r
+               if ($rs->EOF) {\r
+                       $v = '';\r
+               } else \r
+                       $v = rawurldecode(reset($rs->fields));\r
+                       \r
+               $rs->Close();\r
+               \r
+               // new optimization adodb 2.1\r
+               $ADODB_SESSION_CRC = strlen($v).crc32($v);\r
+               \r
+               return $v;\r
+       }\r
+       \r
+       return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com\r
+}\r
+\r
+/****************************************************************************************\\r
+       Write the serialized data to a database.\r
+       \r
+       If the data has not been modified since adodb_sess_read(), we do not write.\r
+\****************************************************************************************/\r
+function adodb_sess_write($key, $val) \r
+{\r
+       global\r
+               $ADODB_SESS_CONN, \r
+               $ADODB_SESS_LIFE, \r
+               $ADODB_SESSION_TBL,\r
+               $ADODB_SESS_DEBUG, \r
+               $ADODB_SESSION_CRC,\r
+               $ADODB_SESSION_EXPIRE_NOTIFY;\r
+\r
+       $expiry = time() + $ADODB_SESS_LIFE;\r
+       \r
+       // crc32 optimization since adodb 2.1\r
+       // now we only update expiry date, thx to sebastian thom in adodb 2.32\r
+       if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) {\r
+               if ($ADODB_SESS_DEBUG) echo "\r
+-- Session: Only updating date - crc32 not changed</p>";\r
+               $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time();\r
+               $rs = $ADODB_SESS_CONN->Execute($qry);  \r
+               return true;\r
+       }\r
+       $val = rawurlencode($val);\r
+       \r
+       $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val);\r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               $var = reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               global $$var;\r
+               $arr['expireref'] = $$var;\r
+       }\r
+       $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr,\r
+       'sesskey',$autoQuote = true);\r
+       \r
+       if (!$rs) {\r
+               ADOConnection::outp( '\r
+-- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'</p>',false);\r
+       }  else {\r
+               // bug in access driver (could be odbc?) means that info is not commited\r
+               // properly unless select statement executed in Win2000\r
+               if ($ADODB_SESS_CONN->databaseType == 'access') \r
+                       $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+       }\r
+       return !empty($rs);\r
+}\r
+\r
+function adodb_sess_destroy($key) \r
+{\r
+       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+       \r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+               $ADODB_SESS_CONN->SetFetchMode($savem);\r
+               if ($rs) {\r
+                       $ADODB_SESS_CONN->BeginTrans();\r
+                       while (!$rs->EOF) {\r
+                               $ref = $rs->fields[0];\r
+                               $key = $rs->fields[1];\r
+                               $fn($ref,$key);\r
+                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+                               $rs->MoveNext();\r
+                       }\r
+                       $ADODB_SESS_CONN->CommitTrans();\r
+               }\r
+       } else {\r
+               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";\r
+               $rs = $ADODB_SESS_CONN->Execute($qry);\r
+       }\r
+       return $rs ? true : false;\r
+}\r
+\r
+function adodb_sess_gc($maxlifetime) \r
+{\r
+       global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+       \r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+               $t = time();\r
+               $rs =& $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t");\r
+               $ADODB_SESS_CONN->SetFetchMode($savem);\r
+               if ($rs) {\r
+                       $ADODB_SESS_CONN->BeginTrans();\r
+                       while (!$rs->EOF) {\r
+                               $ref = $rs->fields[0];\r
+                               $key = $rs->fields[1];\r
+                               $fn($ref,$key);\r
+                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+                               $rs->MoveNext();\r
+                       }\r
+                       $rs->Close();\r
+                       \r
+                       $ADODB_SESS_CONN->CommitTrans();\r
+                       \r
+               }\r
+       } else {\r
+               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();\r
+               $ADODB_SESS_CONN->Execute($qry);\r
+       \r
+               if ($ADODB_SESS_DEBUG) ADOConnection::outp("\r
+-- <b>Garbage Collection</b>: $qry</p>");\r
+       }\r
+       // suggested by Cameron, "GaM3R" <gamr@outworld.cx>\r
+       if (defined('ADODB_SESSION_OPTIMIZE')) {\r
+       global $ADODB_SESSION_DRIVER;\r
+       \r
+               switch( $ADODB_SESSION_DRIVER ) {\r
+                       case 'mysql':\r
+                       case 'mysqlt':\r
+                               $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL;\r
+                               break;\r
+                       case 'postgresql':\r
+                       case 'postgresql7':\r
+                               $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL;        \r
+                               break;\r
+               }\r
+               if (!empty($opt_qry)) {\r
+                       $ADODB_SESS_CONN->Execute($opt_qry);\r
+               }\r
+       }\r
+       if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select  TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL;\r
+       else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL;\r
+       \r
+       $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1);\r
+       if ($rs && !$rs->EOF) {\r
+       \r
+               $dbts = reset($rs->fields);\r
+               $rs->Close();\r
+               $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts);\r
+               $t = time();\r
+       \r
+               if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) {\r
+               \r
+                       $msg = \r
+                       __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)";\r
+                       error_log($msg);\r
+                       if ($ADODB_SESS_DEBUG) ADOConnection::outp("\r
+-- $msg</p>");\r
+               }\r
+       }\r
+       \r
+       return true;\r
+}\r
+\r
+session_module_name('user'); \r
+session_set_save_handler(\r
+       "adodb_sess_open",\r
+       "adodb_sess_close",\r
+       "adodb_sess_read",\r
+       "adodb_sess_write",\r
+       "adodb_sess_destroy",\r
+       "adodb_sess_gc");\r
+}\r
+\r
+/*  TEST SCRIPT -- UNCOMMENT */\r
+\r
+if (0) {\r
+\r
+       session_start();\r
+       session_register('AVAR');\r
+       $_SESSION['AVAR'] += 1;\r
+       ADOConnection::outp( "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>",false);\r
+}\r
+\r
 ?>
\ No newline at end of file
index 6e0f777d53176cbe299354cdae0c00af3984f176..ba3f37a21cbe85d3a6d98f88831f40e139f6a4b3 100644 (file)
-<?php
-
-/** 
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
- * Released under both BSD license and Lesser GPL library license. 
- * Whenever there is any discrepancy between the two licenses, 
- * the BSD license will take precedence. 
- *
- * Code to export recordsets in several formats:
- *
- * AS VARIABLE
- * $s = rs2csv($rs); # comma-separated values
- * $s = rs2tab($rs); # tab delimited
- * 
- * TO A FILE
- * $f = fopen($path,'w');
- * rs2csvfile($rs,$f);
- * fclose($f);
- *
- * TO STDOUT
- * rs2csvout($rs);
- */
-// returns a recordset as a csv string
-function rs2csv(&$rs,$addtitles=true)
-{
-       return _adodb_export($rs,',',',',false,$addtitles);
-}
-
-// writes recordset to csv file 
-function rs2csvfile(&$rs,$fp,$addtitles=true)
-{
-       _adodb_export($rs,',',',',$fp,$addtitles);
-}
-
-// write recordset as csv string to stdout
-function rs2csvout(&$rs,$addtitles=true)
-{
-       $fp = fopen('php://stdout','wb');
-       _adodb_export($rs,',',',',true,$addtitles);
-       fclose($fp);
-}
-
-function rs2tab(&$rs,$addtitles=true)
-{
-       return _adodb_export($rs,"\t",',',false,$addtitles);
-}
-
-// to file pointer
-function rs2tabfile(&$rs,$fp,$addtitles=true)
-{
-       _adodb_export($rs,"\t",',',$fp,$addtitles);
-}
-
-// to stdout
-function rs2tabout(&$rs,$addtitles=true)
-{
-       $fp = fopen('php://stdout','wb');
-       _adodb_export($rs,"\t",' ',true,$addtitles);
-       if ($fp) fclose($fp);
-}
-
-function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ')
-{
-       if (!$rs) return '';
-       //----------
-       // CONSTANTS
-       $NEWLINE = "\r\n";
-       $BUFLINES = 100;
-       $escquotequote = $escquote.$quote;
-       $s = '';
-       
-       if ($addtitles) {
-               $fieldTypes = $rs->FieldTypesArray();
-               reset($fieldTypes);
-               while(list(,$o) = each($fieldTypes)) {
-                       
-                       $v = $o->name;
-                       if ($escquote) $v = str_replace($quote,$escquotequote,$v);
-                       $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));
-                       $elements[] = $v;
-                       
-               }
-               $s .= implode($sep, $elements).$NEWLINE;
-       }
-       $hasNumIndex = isset($rs->fields[0]);
-       
-       $line = 0;
-       $max = $rs->FieldCount();
-       
-       while (!$rs->EOF) {
-               $elements = array();
-               $i = 0;
-               
-               if ($hasNumIndex) {
-                       for ($j=0; $j < $max; $j++) {
-                               $v = $rs->fields[$j];
-                               if (!is_object($v)) $v = trim($v);
-                               else $v = 'Object';
-                               if ($escquote) $v = str_replace($quote,$escquotequote,$v);
-                               $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));
-                               
-                               if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote";
-                               else $elements[] = $v;
-                       }
-               } else { // ASSOCIATIVE ARRAY
-                       foreach($rs->fields as $v) {
-                               if ($escquote) $v = str_replace($quote,$escquotequote,trim($v));
-                               $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));
-                               
-                               if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote";
-                               else $elements[] = $v;
-                       }
-               }
-               $s .= implode($sep, $elements).$NEWLINE;
-               $rs->MoveNext();
-               $line += 1;
-               if ($fp && ($line % $BUFLINES) == 0) {
-                       if ($fp === true) echo $s;
-                       else fwrite($fp,$s);
-                       $s = '';
-               }
-       }
-       
-       if ($fp) {
-               if ($fp === true) echo $s;
-               else fwrite($fp,$s);
-               $s = '';
-       }
-       
-       return $s;
-}
+<?php\r
+\r
+/** \r
+ * @version V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Code to export recordsets in several formats:\r
+ *\r
+ * AS VARIABLE\r
+ * $s = rs2csv($rs); # comma-separated values\r
+ * $s = rs2tab($rs); # tab delimited\r
+ * \r
+ * TO A FILE\r
+ * $f = fopen($path,'w');\r
+ * rs2csvfile($rs,$f);\r
+ * fclose($f);\r
+ *\r
+ * TO STDOUT\r
+ * rs2csvout($rs);\r
+ */\r
\r
+// returns a recordset as a csv string\r
+function rs2csv(&$rs,$addtitles=true)\r
+{\r
+       return _adodb_export($rs,',',',',false,$addtitles);\r
+}\r
+\r
+// writes recordset to csv file \r
+function rs2csvfile(&$rs,$fp,$addtitles=true)\r
+{\r
+       _adodb_export($rs,',',',',$fp,$addtitles);\r
+}\r
+\r
+// write recordset as csv string to stdout\r
+function rs2csvout(&$rs,$addtitles=true)\r
+{\r
+       $fp = fopen('php://stdout','wb');\r
+       _adodb_export($rs,',',',',true,$addtitles);\r
+       fclose($fp);\r
+}\r
+\r
+function rs2tab(&$rs,$addtitles=true)\r
+{\r
+       return _adodb_export($rs,"\t",',',false,$addtitles);\r
+}\r
+\r
+// to file pointer\r
+function rs2tabfile(&$rs,$fp,$addtitles=true)\r
+{\r
+       _adodb_export($rs,"\t",',',$fp,$addtitles);\r
+}\r
+\r
+// to stdout\r
+function rs2tabout(&$rs,$addtitles=true)\r
+{\r
+       $fp = fopen('php://stdout','wb');\r
+       _adodb_export($rs,"\t",' ',true,$addtitles);\r
+       if ($fp) fclose($fp);\r
+}\r
+\r
+function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ')\r
+{\r
+       if (!$rs) return '';\r
+       //----------\r
+       // CONSTANTS\r
+       $NEWLINE = "\r\n";\r
+       $BUFLINES = 100;\r
+       $escquotequote = $escquote.$quote;\r
+       $s = '';\r
+       \r
+       if ($addtitles) {\r
+               $fieldTypes = $rs->FieldTypesArray();\r
+               reset($fieldTypes);\r
+               while(list(,$o) = each($fieldTypes)) {\r
+                       \r
+                       $v = $o->name;\r
+                       if ($escquote) $v = str_replace($quote,$escquotequote,$v);\r
+                       $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));\r
+                       $elements[] = $v;\r
+                       \r
+               }\r
+               $s .= implode($sep, $elements).$NEWLINE;\r
+       }\r
+       $hasNumIndex = isset($rs->fields[0]);\r
+       \r
+       $line = 0;\r
+       $max = $rs->FieldCount();\r
+       \r
+       while (!$rs->EOF) {\r
+               $elements = array();\r
+               $i = 0;\r
+               \r
+               if ($hasNumIndex) {\r
+                       for ($j=0; $j < $max; $j++) {\r
+                               $v = $rs->fields[$j];\r
+                               if (!is_object($v)) $v = trim($v);\r
+                               else $v = 'Object';\r
+                               if ($escquote) $v = str_replace($quote,$escquotequote,$v);\r
+                               $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));\r
+                               \r
+                               if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote";\r
+                               else $elements[] = $v;\r
+                       }\r
+               } else { // ASSOCIATIVE ARRAY\r
+                       foreach($rs->fields as $v) {\r
+                               if ($escquote) $v = str_replace($quote,$escquotequote,trim($v));\r
+                               $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));\r
+                               \r
+                               if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote";\r
+                               else $elements[] = $v;\r
+                       }\r
+               }\r
+               $s .= implode($sep, $elements).$NEWLINE;\r
+               $rs->MoveNext();\r
+               $line += 1;\r
+               if ($fp && ($line % $BUFLINES) == 0) {\r
+                       if ($fp === true) echo $s;\r
+                       else fwrite($fp,$s);\r
+                       $s = '';\r
+               }\r
+       }\r
+       \r
+       if ($fp) {\r
+               if ($fp === true) echo $s;\r
+               else fwrite($fp,$s);\r
+               $s = '';\r
+       }\r
+       \r
+       return $s;\r
+}\r
 ?>
\ No newline at end of file
index 5f1071cc7d34c2b4c15aaff4c4e99a1644990dc2..b9bef03f57a3ed46957f0735905b6a74b90c6df7 100644 (file)
-<?php 
-/*
-  V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
-  Released under both BSD license and Lesser GPL library license. 
-  Whenever there is any discrepancy between the two licenses, 
-  the BSD license will take precedence.
-  
-  Some pretty-printing by Chris Oxenreider <oxenreid@state.net>
-*/ 
-  
-// specific code for tohtml
-GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND;
-
-$ADODB_ROUND=4; // rounding
-$gSQLMaxRows = 1000; // max no of rows to download
-$gSQLBlockRows=20; // max no of rows per table block
-
-// RecordSet to HTML Table
-//------------------------------------------------------------
-// Convert a recordset to a html table. Multiple tables are generated
-// if the number of rows is > $gSQLBlockRows. This is because
-// web browsers normally require the whole table to be downloaded
-// before it can be rendered, so we break the output into several
-// smaller faster rendering tables.
-//
-// $rs: the recordset
-// $ztabhtml: the table tag attributes (optional)
-// $zheaderarray: contains the replacement strings for the headers (optional)
-//
-//  USAGE:
-//     include('adodb.inc.php');
-//     $db = ADONewConnection('mysql');
-//     $db->Connect('mysql','userid','password','database');
-//     $rs = $db->Execute('select col1,col2,col3 from table');
-//     rs2html($rs, 'BORDER=2', array('Title1', 'Title2', 'Title3'));
-//     $rs->Close();
-//
-// RETURNS: number of rows displayed
-
-
-function rs2html(&$rs,$ztabhtml=false,$zheaderarray=false,$htmlspecialchars=true,$echo = true)
-{
-$s ='';$rows=0;$docnt = false;
-GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND;
-
-       if (!$rs) {
-               printf(ADODB_BAD_RS,'rs2html');
-               return false;
-       }
-       
-       if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'";
-       //else $docnt = true;
-       $typearr = array();
-       $ncols = $rs->FieldCount();
-       $hdr = "<TABLE COLS=$ncols $ztabhtml><tr>\n\n";
-       for ($i=0; $i < $ncols; $i++) { 
-               $field = $rs->FetchField($i);
-               if ($field) {
-                       if ($zheaderarray) $fname = $zheaderarray[$i];
-                       else $fname = htmlspecialchars($field->name);   
-                       $typearr[$i] = $rs->MetaType($field->type,$field->max_length);
-                       //print " $field->name $field->type $typearr[$i] ";
-               } else {
-                       $fname = 'Field '.($i+1);
-                       $typearr[$i] = 'C';
-               }
-               if (strlen($fname)==0) $fname = '&nbsp;';
-               $hdr .= "<TH>$fname</TH>";
-       }
-       $hdr .= "\n</tr>";
-       if ($echo) print $hdr."\n\n";
-       else $html = $hdr;
-       
-       // smart algorithm - handles ADODB_FETCH_MODE's correctly by probing...
-       $numoffset = isset($rs->fields[0]) ||isset($rs->fields[1]) || isset($rs->fields[2]);
-       while (!$rs->EOF) {
-               
-               $s .= "<TR valign=top>\n";
-               
-               for ($i=0; $i < $ncols; $i++) {
-                       if ($i===0) $v=($numoffset) ? $rs->fields[0] : reset($rs->fields);
-                       else $v = ($numoffset) ? $rs->fields[$i] : next($rs->fields);
-                       
-                       $type = $typearr[$i];
-                       switch($type) {
-                       case 'D':
-                               if (empty($v)) $s .= "<TD> &nbsp; </TD>\n";
-                               else if (!strpos($v,':')) {
-                                       $s .= " <TD>".$rs->UserDate($v,"D d, M Y") ."&nbsp;</TD>\n";
-                               }
-                               break;
-                       case 'T':
-                               if (empty($v)) $s .= "<TD> &nbsp; </TD>\n";
-                               else $s .= "    <TD>".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ."&nbsp;</TD>\n";
-                       break;
-                       
-                       case 'N':
-                               if (abs(abs($v) - round($v,0)) < 0.00000001)
-                                       $v = round($v);
-                               else
-                                       $v = round($v,$ADODB_ROUND);
-                       case 'I':
-                               $s .= " <TD align=right>".stripslashes((trim($v))) ."&nbsp;</TD>\n";
-                               
-                       break;
-                       /*
-                       case 'B':
-                               if (substr($v,8,2)=="BM" ) $v = substr($v,8);
-                               $mtime = substr(str_replace(' ','_',microtime()),2);
-                               $tmpname = "tmp/".uniqid($mtime).getmypid();
-                               $fd = @fopen($tmpname,'a');
-                               @ftruncate($fd,0);
-                               @fwrite($fd,$v);
-                               @fclose($fd);
-                               if (!function_exists ("mime_content_type")) {
-                                 function mime_content_type ($file) {
-                                   return exec("file -bi ".escapeshellarg($file));
-                                 }
-                               }
-                               $t = mime_content_type($tmpname);
-                               $s .= (substr($t,0,5)=="image") ? " <td><img src='$tmpname' alt='$t'></td>\\n" : " <td><a
-                               href='$tmpname'>$t</a></td>\\n";
-                               break;
-                       */
-
-                       default:
-                               if ($htmlspecialchars) $v = htmlspecialchars(trim($v));
-                               $v = trim($v);
-                               if (strlen($v) == 0) $v = '&nbsp;';
-                               $s .= " <TD>". str_replace("\n",'<br>',stripslashes($v)) ."</TD>\n";
-                         
-                       }
-               } // for
-               $s .= "</TR>\n\n";
-                         
-               $rows += 1;
-               if ($rows >= $gSQLMaxRows) {
-                       $rows = "<p>Truncated at $gSQLMaxRows</p>";
-                       break;
-               } // switch
-
-               $rs->MoveNext();
-       
-       // additional EOF check to prevent a widow header
-               if (!$rs->EOF && $rows % $gSQLBlockRows == 0) {
-       
-               //if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP
-                       if ($echo) print $s . "</TABLE>\n\n";
-                       else $html .= $s ."</TABLE>\n\n";
-                       $s = $hdr;
-               }
-       } // while
-
-       if ($echo) print $s."</TABLE>\n\n";
-       else $html .= $s."</TABLE>\n\n";
-       
-       if ($docnt) if ($echo) print "<H2>".$rows." Rows</H2>";
-       
-       return ($echo) ? $rows : $html;
- }
-// pass in 2 dimensional array
-function arr2html(&$arr,$ztabhtml='',$zheaderarray='')
-{
-       if (!$ztabhtml) $ztabhtml = 'BORDER=1';
-       
-       $s = "<TABLE $ztabhtml>";//';print_r($arr);
-
-       if ($zheaderarray) {
-               $s .= '<TR>';
-               for ($i=0; $i<sizeof($zheaderarray); $i++) {
-                       $s .= " <TH>{$zheaderarray[$i]}</TH>\n";
-               }
-               $s .= "\n</TR>";
-       }
-       
-       for ($i=0; $i<sizeof($arr); $i++) {
-               $s .= '<TR>';
-               $a = &$arr[$i];
-               if (is_array($a)) 
-                       for ($j=0; $j<sizeof($a); $j++) {
-                               $val = $a[$j];
-                               if (empty($val)) $val = '&nbsp;';
-                               $s .= " <TD>$val</TD>\n";
-                       }
-               else if ($a) {
-                       $s .=  '        <TD>'.$a."</TD>\n";
-               } else $s .= "  <TD>&nbsp;</TD>\n";
-               $s .= "\n</TR>\n";
-       }
-       $s .= '</TABLE>';
-       print $s;
-}
-
+<?php \r
+/*\r
+  V4.93 10 Oct 2006  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+  \r
+  Some pretty-printing by Chris Oxenreider <oxenreid@state.net>\r
+*/ \r
+  \r
+// specific code for tohtml\r
+GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND;\r
+\r
+$ADODB_ROUND=4; // rounding\r
+$gSQLMaxRows = 1000; // max no of rows to download\r
+$gSQLBlockRows=20; // max no of rows per table block\r
+\r
+// RecordSet to HTML Table\r
+//------------------------------------------------------------\r
+// Convert a recordset to a html table. Multiple tables are generated\r
+// if the number of rows is > $gSQLBlockRows. This is because\r
+// web browsers normally require the whole table to be downloaded\r
+// before it can be rendered, so we break the output into several\r
+// smaller faster rendering tables.\r
+//\r
+// $rs: the recordset\r
+// $ztabhtml: the table tag attributes (optional)\r
+// $zheaderarray: contains the replacement strings for the headers (optional)\r
+//\r
+//  USAGE:\r
+//     include('adodb.inc.php');\r
+//     $db = ADONewConnection('mysql');\r
+//     $db->Connect('mysql','userid','password','database');\r
+//     $rs = $db->Execute('select col1,col2,col3 from table');\r
+//     rs2html($rs, 'BORDER=2', array('Title1', 'Title2', 'Title3'));\r
+//     $rs->Close();\r
+//\r
+// RETURNS: number of rows displayed\r
+\r
+\r
+function rs2html(&$rs,$ztabhtml=false,$zheaderarray=false,$htmlspecialchars=true,$echo = true)\r
+{\r
+$s ='';$rows=0;$docnt = false;\r
+GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND;\r
+\r
+       if (!$rs) {\r
+               printf(ADODB_BAD_RS,'rs2html');\r
+               return false;\r
+       }\r
+       \r
+       if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'";\r
+       //else $docnt = true;\r
+       $typearr = array();\r
+       $ncols = $rs->FieldCount();\r
+       $hdr = "<TABLE COLS=$ncols $ztabhtml><tr>\n\n";\r
+       for ($i=0; $i < $ncols; $i++) { \r
+               $field = $rs->FetchField($i);\r
+               if ($field) {\r
+                       if ($zheaderarray) $fname = $zheaderarray[$i];\r
+                       else $fname = htmlspecialchars($field->name);   \r
+                       $typearr[$i] = $rs->MetaType($field->type,$field->max_length);\r
+                       //print " $field->name $field->type $typearr[$i] ";\r
+               } else {\r
+                       $fname = 'Field '.($i+1);\r
+                       $typearr[$i] = 'C';\r
+               }\r
+               if (strlen($fname)==0) $fname = '&nbsp;';\r
+               $hdr .= "<TH>$fname</TH>";\r
+       }\r
+       $hdr .= "\n</tr>";\r
+       if ($echo) print $hdr."\n\n";\r
+       else $html = $hdr;\r
+       \r
+       // smart algorithm - handles ADODB_FETCH_MODE's correctly by probing...\r
+       $numoffset = isset($rs->fields[0]) ||isset($rs->fields[1]) || isset($rs->fields[2]);\r
+       while (!$rs->EOF) {\r
+               \r
+               $s .= "<TR valign=top>\n";\r
+               \r
+               for ($i=0; $i < $ncols; $i++) {\r
+                       if ($i===0) $v=($numoffset) ? $rs->fields[0] : reset($rs->fields);\r
+                       else $v = ($numoffset) ? $rs->fields[$i] : next($rs->fields);\r
+                       \r
+                       $type = $typearr[$i];\r
+                       switch($type) {\r
+                       case 'D':\r
+                               if (empty($v)) $s .= "<TD> &nbsp; </TD>\n";\r
+                               else if (!strpos($v,':')) {\r
+                                       $s .= " <TD>".$rs->UserDate($v,"D d, M Y") ."&nbsp;</TD>\n";\r
+                               }\r
+                               break;\r
+                       case 'T':\r
+                               if (empty($v)) $s .= "<TD> &nbsp; </TD>\n";\r
+                               else $s .= "    <TD>".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ."&nbsp;</TD>\n";\r
+                       break;\r
+                       \r
+                       case 'N':\r
+                               if (abs(abs($v) - round($v,0)) < 0.00000001)\r
+                                       $v = round($v);\r
+                               else\r
+                                       $v = round($v,$ADODB_ROUND);\r
+                       case 'I':\r
+                               $s .= " <TD align=right>".stripslashes((trim($v))) ."&nbsp;</TD>\n";\r
+                               \r
+                       break;\r
+                       /*\r
+                       case 'B':\r
+                               if (substr($v,8,2)=="BM" ) $v = substr($v,8);\r
+                               $mtime = substr(str_replace(' ','_',microtime()),2);\r
+                               $tmpname = "tmp/".uniqid($mtime).getmypid();\r
+                               $fd = @fopen($tmpname,'a');\r
+                               @ftruncate($fd,0);\r
+                               @fwrite($fd,$v);\r
+                               @fclose($fd);\r
+                               if (!function_exists ("mime_content_type")) {\r
+                                 function mime_content_type ($file) {\r
+                                   return exec("file -bi ".escapeshellarg($file));\r
+                                 }\r
+                               }\r
+                               $t = mime_content_type($tmpname);\r
+                               $s .= (substr($t,0,5)=="image") ? " <td><img src='$tmpname' alt='$t'></td>\\n" : " <td><a\r
+                               href='$tmpname'>$t</a></td>\\n";\r
+                               break;\r
+                       */\r
+\r
+                       default:\r
+                               if ($htmlspecialchars) $v = htmlspecialchars(trim($v));\r
+                               $v = trim($v);\r
+                               if (strlen($v) == 0) $v = '&nbsp;';\r
+                               $s .= " <TD>". str_replace("\n",'<br>',stripslashes($v)) ."</TD>\n";\r
+                         \r
+                       }\r
+               } // for\r
+               $s .= "</TR>\n\n";\r
+                         \r
+               $rows += 1;\r
+               if ($rows >= $gSQLMaxRows) {\r
+                       $rows = "<p>Truncated at $gSQLMaxRows</p>";\r
+                       break;\r
+               } // switch\r
+\r
+               $rs->MoveNext();\r
+       \r
+       // additional EOF check to prevent a widow header\r
+               if (!$rs->EOF && $rows % $gSQLBlockRows == 0) {\r
+       \r
+               //if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP\r
+                       if ($echo) print $s . "</TABLE>\n\n";\r
+                       else $html .= $s ."</TABLE>\n\n";\r
+                       $s = $hdr;\r
+               }\r
+       } // while\r
+\r
+       if ($echo) print $s."</TABLE>\n\n";\r
+       else $html .= $s."</TABLE>\n\n";\r
+       \r
+       if ($docnt) if ($echo) print "<H2>".$rows." Rows</H2>";\r
+       \r
+       return ($echo) ? $rows : $html;\r
+ }\r
\r
+// pass in 2 dimensional array\r
+function arr2html(&$arr,$ztabhtml='',$zheaderarray='')\r
+{\r
+       if (!$ztabhtml) $ztabhtml = 'BORDER=1';\r
+       \r
+       $s = "<TABLE $ztabhtml>";//';print_r($arr);\r
+\r
+       if ($zheaderarray) {\r
+               $s .= '<TR>';\r
+               for ($i=0; $i<sizeof($zheaderarray); $i++) {\r
+                       $s .= " <TH>{$zheaderarray[$i]}</TH>\n";\r
+               }\r
+               $s .= "\n</TR>";\r
+       }\r
+       \r
+       for ($i=0; $i<sizeof($arr); $i++) {\r
+               $s .= '<TR>';\r
+               $a = &$arr[$i];\r
+               if (is_array($a)) \r
+                       for ($j=0; $j<sizeof($a); $j++) {\r
+                               $val = $a[$j];\r
+                               if (empty($val)) $val = '&nbsp;';\r
+                               $s .= " <TD>$val</TD>\n";\r
+                       }\r
+               else if ($a) {\r
+                       $s .=  '        <TD>'.$a."</TD>\n";\r
+               } else $s .= "  <TD>&nbsp;</TD>\n";\r
+               $s .= "\n</TR>\n";\r
+       }\r
+       $s .= '</TABLE>';\r
+       print $s;\r
+}\r
+\r
 ?>
\ No newline at end of file