]> git.mjollnir.org Git - moodle.git/commitdiff
Merged Adodb 4.98 from 1.9 MDL-13474
authormoodler <moodler>
Fri, 15 Feb 2008 07:02:02 +0000 (07:02 +0000)
committermoodler <moodler>
Fri, 15 Feb 2008 07:02:02 +0000 (07:02 +0000)
110 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-time.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/lang/adodb-ar.inc.php
lib/adodb/lang/adodb-bgutf8.inc.php
lib/adodb/lang/adodb-ca.inc.php
lib/adodb/lang/adodb-pt-br.inc.php
lib/adodb/lang/adodb-ro.inc.php
lib/adodb/lang/adodb-uk1251.inc.php
lib/adodb/lang/adodb_th.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 a67b55e40cf507ed32de7b29f5af244054cc6f92..0654828c00d7e163c02637886149688ed85db90e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
 
-@version V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+@version V4.98 13 Feb 2008  (c) 2000-2008 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.08
+  Version 0.09
   
   See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord 
        for info on Ruby on Rails Active Record implementation
 global $_ADODB_ACTIVE_DBS;
 global $ADODB_ACTIVE_CACHESECS; // set to true to enable caching of metadata such as field info
 global $ACTIVE_RECORD_SAFETY; // set to false to disable safety checks
+global $ADODB_ACTIVE_DEFVALS; // use default values of table definition when creating new active record.
 
 // array of ADODB_Active_DB's, indexed by ADODB_Active_Record->_dbat
 $_ADODB_ACTIVE_DBS = array();
 $ACTIVE_RECORD_SAFETY = true;
+$ADODB_ACTIVE_DEFVALS = false;
 
 class ADODB_Active_DB {
        var $db; // ADOConnection
@@ -69,6 +71,14 @@ class ADODB_Active_Record {
        var $_lasterr = false; // last error message
        var $_original = false; // the original values loaded or inserted, refreshed on update
        
+       // should be static
+       function UseDefaultValues($bool=null)
+       {
+       global $ADODB_ACTIVE_DEFVALS;
+               if (isset($bool)) $ADODB_ACTIVE_DEFVALS = $bool;
+               return $ADODB_ACTIVE_DEFVALS;
+       }
+
        // should be static
        function SetDatabaseAdapter(&$db) 
        {
@@ -141,7 +151,8 @@ class ADODB_Active_Record {
        function UpdateActiveTable($pkeys=false,$forceUpdate=false)
        {
        global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS;
-       
+       global $ADODB_ACTIVE_DEFVALS;
+
                $activedb =& $_ADODB_ACTIVE_DBS[$this->_dbat];
 
                $table = $this->_table;
@@ -149,8 +160,12 @@ class ADODB_Active_Record {
                $tableat = $this->_tableat;
                if (!$forceUpdate && !empty($tables[$tableat])) {
                        $tobj =& $tables[$tableat];
-                       foreach($tobj->flds as $name => $fld) 
-                               $this->$name = null;
+                       foreach($tobj->flds as $name => $fld) {
+                               if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) 
+                                       $this->$name = $fld->default_value;
+                               else
+                                       $this->$name = null;
+                       }
                        return;
                }
                
@@ -203,7 +218,10 @@ class ADODB_Active_Record {
                case 0:
                        foreach($cols as $name => $fldobj) {
                                $name = strtolower($name);
-                               $this->$name = null;
+                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
+                    $this->$name = $fldobj->default_value;
+                else
+                                       $this->$name = null;
                                $attr[$name] = $fldobj;
                        }
                        foreach($pkeys as $k => $name) {
@@ -214,7 +232,11 @@ class ADODB_Active_Record {
                case 1: 
                        foreach($cols as $name => $fldobj) {
                                $name = strtoupper($name);
-                               $this->$name = null;
+               
+                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
+                    $this->$name = $fldobj->default_value;
+                else
+                                       $this->$name = null;
                                $attr[$name] = $fldobj;
                        }
                        
@@ -225,7 +247,11 @@ class ADODB_Active_Record {
                default:
                        foreach($cols as $name => $fldobj) {
                                $name = ($fldobj->name);
-                               $this->$name = null;
+                
+                if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
+                    $this->$name = $fldobj->default_value;
+                else
+                                       $this->$name = null;
                                $attr[$name] = $fldobj;
                        }
                        foreach($pkeys as $k => $name) {
@@ -336,17 +362,30 @@ class ADODB_Active_Record {
                
                $table =& $this->TableInfo();
                if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) {
-                       $this->Error("Table structure of $this->_table has changed","Load");
-                       return false;
+            $bad_size = TRUE;
+            if (sizeof($row) == 2 * sizeof($table->flds)) {
+                // Only keep string keys
+                $keys = array_filter(array_keys($row), 'is_string');
+                if (sizeof($keys) == sizeof($table->flds))
+                    $bad_size = FALSE;
+            }
+            if ($bad_size) {
+                               $this->Error("Table structure of $this->_table has changed","Load");
+                               return false;
+                       }
                }
-               
-               $keys = array_keys($row);
-               $cnt = 0;
+        else
+                       $keys = array_keys($row);
+      
+        reset($keys);
+        $this->_original = array();
                foreach($table->flds as $name=>$fld) {
-                       $this->$name = $row[$keys[$cnt]];
-                       $cnt += 1;
+            $value = $row[current($keys)];
+                       $this->$name = $value;
+            $this->_original[] = $value;
+            next($keys);
                }
-               $this->_original = $row;
+        # </AP>
                return true;
        }
        
@@ -533,7 +572,7 @@ class ADODB_Active_Record {
                if ($ADODB_ASSOC_CASE == 0) 
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtolower($v);
-               elseif ($ADODB_ASSOC_CASE == 0
+               elseif ($ADODB_ASSOC_CASE == 1
                        foreach($pkey as $k => $v)
                                $pkey[$k] = strtoupper($v);
                                
index 77c4cc4bde4f962fa8a1d2971add11b525e18b74..c82c965582f5f10e3b7e5eb3f4bc2e3aaa857be4 100644 (file)
@@ -8,7 +8,7 @@ $ADODB_INCLUDED_CSV = 1;
 
 /* 
 
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
@@ -261,6 +261,7 @@ $ADODB_INCLUDED_CSV = 1;
 
        /**
        * Save a file $filename and its $contents (normally for caching) with file locking
+       * Returns true if ok, false if fopen/fwrite error, 0 if rename error (eg. file is locked)
        */
        function adodb_write_file($filename, $contents,$debug=false)
        { 
@@ -280,25 +281,29 @@ $ADODB_INCLUDED_CSV = 1;
                        $mtime = substr(str_replace(' ','_',microtime()),2); 
                        // getmypid() actually returns 0 on Win98 - never mind!
                        $tmpname = $filename.uniqid($mtime).getmypid();
-                       if (!($fd = @fopen($tmpname,'a'))) return false;
-                       $ok = ftruncate($fd,0);                 
-                       if (!fwrite($fd,$contents)) $ok = false;
+                       if (!($fd = @fopen($tmpname,'w'))) return false;
+                       if (fwrite($fd,$contents)) $ok = true;
+                       else $ok = false;
                        fclose($fd);
-                       chmod($tmpname,0644);
-                       // the tricky moment
-                       @unlink($filename);
-                       if (!@rename($tmpname,$filename)) {
-                               unlink($tmpname);
-                               $ok = false;
-                       }
-                       if (!$ok) {
-                               if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
+                       
+                       if ($ok) {
+                               chmod($tmpname,0644);
+                               // the tricky moment
+                               @unlink($filename);
+                               if (!@rename($tmpname,$filename)) {
+                                       unlink($tmpname);
+                                       $ok = 0;
+                               }
+                               if (!$ok) {
+                                       if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
+                               }
                        }
                        return $ok;
                }
                if (!($fd = @fopen($filename, 'a'))) return false;
                if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
-                       $ok = fwrite( $fd, $contents );
+                       if (fwrite( $fd, $contents )) $ok = true;
+                       else $ok = false;
                        fclose($fd);
                        chmod($filename,0644);
                }else {
index 9761763a917ac91f47cc8ff4b74302684087f76a..86961a2bfc3472222136a3978cf7c249f5afdf44 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -981,8 +981,11 @@ 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)) {
-                                       echo "<h3>$this->alterCol cannot be changed to $flds currently</h3>";
+                               // $flds[1] holds the type, $flds[2] holds the size -postnuke addition
+                               if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)
+                                && (isset($flds[0][2]) && is_numeric($flds[0][2]))) {
+                                       if ($this->debug) ADOConnection::outp(sprintf("<h3>%s cannot be changed to %s currently</h3>", $flds[0][0], $flds[0][1]));
+                                       #echo "<h3>$this->alterCol cannot be changed to $flds currently</h3>";
                                        continue;        
                                }
                                $sql[] = $alter . $this->alterCol . ' ' . $v;
index 48e46ff2a3c50b2fa28c81439c34a24009f513ec..f55516116b6ae33949400d9325b75373d0641a52 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /** 
- * @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license. 
  * Whenever there is any discrepancy between the two licenses, 
  * the BSD license will take precedence. 
@@ -92,14 +92,14 @@ function adodb_error_pg($errormsg)
 {
        if (is_numeric($errormsg)) return (integer) $errormsg;
     static $error_regexps = array(
-            '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
-            '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/'      => DB_ERROR_ALREADY_EXISTS,
-            '/divide by zero$/'                     => DB_ERROR_DIVZERO,
-            '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
-            '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
-            '/parser: parse error at or near \"/'   => DB_ERROR_SYNTAX,
-            '/referential integrity violation/'     => DB_ERROR_CONSTRAINT,
-                       '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/'     
+            '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/i' => DB_ERROR_NOSUCHTABLE,
+            '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/i'      => DB_ERROR_ALREADY_EXISTS,
+            '/divide by zero$/i'                     => DB_ERROR_DIVZERO,
+            '/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER,
+            '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/i' => DB_ERROR_NOSUCHFIELD,
+            '/parser: parse error at or near \"/i'   => DB_ERROR_SYNTAX,
+            '/referential integrity violation/i'     => DB_ERROR_CONSTRAINT,
+                       '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/i'     
                                 => DB_ERROR_ALREADY_EXISTS
         );
        reset($error_regexps);
index 3c844b7d59fcca5863d8c005aa1f782b45d5c83a..779cf7f47330d32a80ae8cb605678664628e73fc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @version V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license.
  * Whenever there is any discrepancy between the two licenses,
  * the BSD license will take precedence.
index 36b901c90a08e179cf2dc503120411ee33c55d10..414578ac7ead56929aa3a133e69cbbab77ff3cd7 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /** 
- * @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 53570abfc9abcb9cf8941c3ac5e41b2058db5338..1bbcea0338081f2a2cdacca172d0af21b4a21a6f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * @version V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license.
  * Whenever there is any discrepancy between the two licenses,
  * the BSD license will take precedence.
index 03df76124e5fb4bc28a2347a26d7c0fb41c129bc..e4c6d32319a0f4719aa62d10e98d98c03139ddf2 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 0fda05e43766feb1e5bac72b8b7a3d53d2f6d018..1e1e7e3d5d25f8282edf9536d1db39bdbe634b3b 100644 (file)
@@ -7,7 +7,7 @@ global $ADODB_INCLUDED_LIB;
 $ADODB_INCLUDED_LIB = 1;
 
 /* 
- @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim\@natsoft.com.my). All rights reserved.
+ @version V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim\@natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
@@ -414,8 +414,10 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
                        } else
                                $rewritesql = "SELECT COUNT(*) FROM (".$rewritesql.")"; 
                        
-               } else if (strncmp($zthis->databaseType,'postgres',8) == 0)  {
+               } else if (strncmp($zthis->databaseType,'postgres',8) == 0 || strncmp($zthis->databaseType,'mysql',5) == 0)  {
                        $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
+               } else {
+                       $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) ";
                }
        } else {                
                // now replace SELECT ... FROM with SELECT COUNT(*) FROM
@@ -537,7 +539,7 @@ function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
        return $rsreturn;
 }
 
-// Ivn Oliva version
+// Iván Oliva version
 function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0) 
 {
 
@@ -991,24 +993,23 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields,
                case "D":
                        $val = $zthis->DBDate($arrFields[$fname]);
                        break;
-
-               \r
-               case "T":\r
+               
+               case "T":
                        $val = $zthis->DBTimeStamp($arrFields[$fname]);
-                       break;
-
-// moodle change start - see readme_moodle.txt
-        case "F": //Floating point number
-        case "N": //Numeric or decimal number
-            $val = (float)$arrFields[$fname];
             break;
 
-        case "L": //Integer field suitable for storing booleans (0 or 1)
+        case "F": //Floating point number       // Moodle added
+               case "N":
+                   $val = $arrFields[$fname];
+                       if (!is_numeric($val)) $val = str_replace(',', '.', (float)$val);
+                       break;
+
+        case "L": //Integer field suitable for storing booleans (0 or 1)     // Moodle added
                case "I":
                case "R":
-                   $val = (int) $arrFields[$fname];
+                   $val = $arrFields[$fname];
+                       if (!is_numeric($val)) $val = (integer) $val;
                    break;
-// moodle change end
 
                default:
                        $val = str_replace(array("'"," ","("),"",$arrFields[$fname]); // basic sql injection defence
@@ -1177,4 +1178,4 @@ function _adodb_find_from($sql)
 }
 */
 
-?>
\ No newline at end of file
+?>
index bc6b420bc6452e2fb256005065b0fb5022f2f9b8..31a1c247f3d125aa7976523fbf4682aa3e644ce0 100644 (file)
-<?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
+<?php
+
+// security - hide paths
+if (!defined('ADODB_DIR')) die();
+
+global $ADODB_INCLUDED_MEMCACHE;
+$ADODB_INCLUDED_MEMCACHE = 1;
+
+/* 
+
+  V4.90 8 June 2006  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
+  Released under both BSD license and Lesser GPL library license. 
+  Whenever there is any discrepancy between the two licenses, 
+  the BSD license will take precedence. See License.txt. 
+  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;
+       }
+?>
index f7f6ba0e74c999a61d767dd717c3d2334da42834..fe6bab543c73abc5e5d1026400bbdd106b36e6d9 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-       V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+       V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          Released under both BSD license and Lesser GPL library license. 
          Whenever there is any discrepancy between the two licenses, 
          the BSD license will take precedence. 
index a2684f2073c0d33554b32203e1c34c72f067ad6b..cfdc2f8a987d140109a0905873011ab19b30aa5e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /** 
- * @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license. 
  * Whenever there is any discrepancy between the two licenses, 
  * the BSD license will take precedence. 
index fe070aa9ed7c78ce9afa7bd54f7e8c32316f1b14..cd666dc50dfb28b90a0736d243f3aab9f183eeea 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
@@ -19,6 +19,9 @@ V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights res
 if (!defined('ADODB_DIR')) include_once(dirname(__FILE__).'/adodb.inc.php');
 include_once(ADODB_DIR.'/tohtml.inc.php');
 
+global $ADODB_PERF_MIN;
+$ADODB_PERF_MIN = 0.05; // log only if >= minimum number of secs to run
+
 define( 'ADODB_OPT_HIGH', 2);
 define( 'ADODB_OPT_LOW', 1);
 
@@ -165,7 +168,12 @@ function& adodb_log_sql(&$connx,$sql,$inputarr)
                        if ($dbT == 'db2') $arr['f'] = (float) $arr['f'];
                        $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)";
                }
-               $ok = $conn->Execute($isql,$arr);
+               global $ADODB_PERF_MIN;
+               if ($errN != 0 || $time >= $ADODB_PERF_MIN) {
+                       $ok = $conn->Execute($isql,$arr);
+               } else {
+                       $ok = true;
+               }
                $conn->debug = $saved;
                
                if ($ok) {
@@ -695,6 +703,8 @@ Committed_AS:   348732 kB
        else $form = "<td>&nbsp;</td>";
        
        $allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
+       global $ADODB_PERF_MIN;
+       $app .= " (Min sql timing \$ADODB_PERF_MIN=$ADODB_PERF_MIN secs)";
        
        if  (empty($_GET['hidem']))
        echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2>
index a609770bcc4fd450a4beba552108f91f44bb1dd6..140d28ae879981a1760add7b828e0e18c202065c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 8e93018be6838f3c79847b6d8cd498e09a69c94b..1ae50767c67424a7209d0025296e3fbd2fa4f89a 100644 (file)
@@ -241,6 +241,16 @@ b. Implement daylight savings, which looks awfully complicated, see
 
 
 CHANGELOG
+
+- 11 Feb 2008 0.33
+* Bug in 0.32 fix for hour handling. Fixed.
+
+- 1 Feb 2008 0.32
+* Now adodb_mktime(0,0,0,12+$m,20,2040) works properly. 
+
+- 10 Jan 2008 0.31
+* Now adodb_mktime(0,0,0,24,1,2037) works correctly.
+
 - 15 July 2007 0.30
 Added PHP 5.2.0 compatability fixes. 
  * gmtime behaviour for 1970 has changed. We use the actual date if it is between 1970 to 2038 to get the
@@ -376,7 +386,7 @@ First implementation.
 /*
        Version Number
 */
-define('ADODB_DATE_VERSION',0.30);
+define('ADODB_DATE_VERSION',0.33);
 
 $ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2);
 
@@ -401,7 +411,7 @@ function adodb_date_test_date($y1,$m,$d=13)
        $t = adodb_mktime($h,0,0,$m,$d,$y1);
        $rez = adodb_date('Y-n-j H:i:s',$t);
        if ($h == 0) $h = '00';
-       else if ($h < 10) $h = '0'.$h;
+       else if ($h < 10) $h = '0'.$h;  
        if ("$y1-$m-$d $h:00:00" != $rez) {
                print "<b>$y1 error, expected=$y1-$m-$d $h:00:00, adodb=$rez</b><br>";
                return false;
@@ -422,10 +432,13 @@ function adodb_date_test_strftime($fmt)
 
 /**
         Test Suite
-*/
+*/             
 function adodb_date_test()
 {
        
+       for ($m=-24; $m<=24; $m++)
+               echo "$m :",adodb_date('d-m-Y',adodb_mktime(0,0,0,1+$m,20,2040)),"<br>";
+       
        error_reporting(E_ALL);
        print "<h4>Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION.' PHP='.PHP_VERSION."</h4>";
        @set_time_limit(0);
@@ -688,7 +701,7 @@ function adodb_get_gmt_diff_ts($ts)
                $m = $arr['mon'];
                $d = $arr['mday'];
                return adodb_get_gmt_diff($y,$m,$d);    
-} else {
+       } else {
                return adodb_get_gmt_diff(false,false,false);
        }
        
@@ -714,9 +727,9 @@ global $ADODB_DATETIME_CLASS;
                }
                return -$tzo->getOffset($dt);
        } else {
-       if (isset($TZ)) return $TZ;
-       $y = date('Y');
-       $TZ = mktime(0,0,0,12,2,$y,0) - gmmktime(0,0,0,12,2,$y,0);
+               if (isset($TZ)) return $TZ;
+               $y = date('Y');
+               $TZ = mktime(0,0,0,12,2,$y,0) - gmmktime(0,0,0,12,2,$y,0);
        }
        
        return $TZ;
@@ -1089,7 +1102,7 @@ global $ADODB_DATETIME_CLASS;
                        
                        $dates .= ' '.adodb_tz_offset($gmt,$isphp5);
                        break;
-                               
+                       
                case 'Y': $dates .= $year; break;
                case 'y': $dates .= substr($year,strlen($year)-2,2); break;
                // MONTH
@@ -1202,13 +1215,18 @@ function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=fa
                
                // for windows, we don't check 1970 because with timezone differences, 
                // 1 Jan 1970 could generate negative timestamp, which is illegal
-               if (1971 < $year && $year < 2038
+               $usephpfns = (1971 < $year && $year < 2038
                        || !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038)
-                       ) {
+                       ); 
+                       
+               
+               if ($usephpfns && ($year + $mon/12+$day/365.25+$hr/(24*365.25) >= 2038)) $usephpfns = false;
+                       
+               if ($usephpfns) {
                                return $is_gmt ?
                                        @gmmktime($hr,$min,$sec,$mon,$day,$year):
                                        @mktime($hr,$min,$sec,$mon,$day,$year);
-                       }
+               }
        }
        
        $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$mon,$day);
@@ -1228,7 +1246,7 @@ function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=fa
        $year = adodb_year_digit_check($year);
 
        if ($mon > 12) {
-               $y = floor($mon / 12);
+               $y = floor(($mon-1)/ 12);
                $year += $y;
                $mon -= $y*12;
        } else if ($mon < 1) {
@@ -1405,5 +1423,4 @@ global $ADODB_DATE_LOCALE;
        return $ret;
 }
 
-
 ?>
\ No newline at end of file
index 5648c364a20d8b222e4c0bb1fd0603f74f45c500..c925f0b53d7463fa82f04bd3737e977a69d412a9 100644 (file)
@@ -12,7 +12,7 @@
  *
  * Last Editor: $Author$
  * @author Richard Tango-Lowy & Dan Cech
- * @version $Id$
+ * @version $Revision$
  *
  * @package axmls
  * @tutorial getting_started.pkg
@@ -1209,7 +1209,7 @@ class dbQuerySet extends dbObject {
 * @tutorial getting_started.pkg
 *
 * @author Richard Tango-Lowy & Dan Cech
-* @version $Id$
+* @version $Revision$
 *
 * @package axmls
 */
index 8ba28969d849aa542d0fdd262ec1ef7f7129f75a..cc98bec6bb2c6fd5ce8517fb383e8632fe4c53b0 100644 (file)
@@ -12,7 +12,7 @@
  *
  * Last Editor: $Author$
  * @author Richard Tango-Lowy & Dan Cech
- * @version $Id$
+ * @version $Revision$
  *
  * @package axmls
  * @tutorial getting_started.pkg
@@ -1309,7 +1309,7 @@ class dbQuerySet extends dbObject {
 * @tutorial getting_started.pkg
 *
 * @author Richard Tango-Lowy & Dan Cech
-* @version $Id$
+* @version $Revision$
 *
 * @package axmls
 */
index cb969e92b20b23361bbd0023e3acbcbc9151a73a..092e46ee913d8c55ad4c1dc3f842668b92f46c23 100644 (file)
@@ -1,4 +1,4 @@
-<?php 
+<?php
 /*
  * Set tabs to 4 for best viewing.
  * 
@@ -14,7 +14,7 @@
 /**
        \mainpage       
        
-        @version V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+        @version V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
 
        Released under both BSD license and Lesser GPL library license. You can choose which license
        you prefer.
                /**
                 * ADODB version as a string.
                 */
-               $ADODB_vers = 'V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
+               $ADODB_vers = 'V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
        
                /**
                 * Determines whether recordset->RecordCount() is used. 
        
        function GetCol($sql, $inputarr = false, $trim = false)
        {
-               $rv = false;
+               
                $rs = &$this->Execute($sql, $inputarr);
                if ($rs) {
                        $rv = array();
                                }
                        }
                        $rs->Close();
-               }
+               } else
+                       $rv = false;
                return $rv;
        }
        
        function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false)
        {
-               $rv = false;
                $rs = &$this->CacheExecute($secs, $sql, $inputarr);
                if ($rs) {
+                       $rv = array();
                        if ($trim) {
                                while (!$rs->EOF) {
                                        $rv[] = trim(reset($rs->fields));
                                }
                        }
                        $rs->Close();
-               }
-               return $rv;
+               } else          
+                       $rv = false;
+               
+               return $rv;
        }
        
        function &Transpose(&$rs,$addfieldnames=true)
        {
                $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr);
                if ($rs) {
-                       $arr = false;
+                       $arr = array();
                        if (!$rs->EOF) $arr = $rs->fields;
                        $rs->Close();
                        return $arr;
                        
                if ($createdir && $notSafeMode && !file_exists($dir)) {
                        $oldu = umask(0);
-                       if (!mkdir($dir,0771)) 
-                               if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql");
+                       if (!@mkdir($dir,0771)) 
+                                if(!is_dir($dir) && $this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql");
                        umask($oldu);
                }
                return $dir.'/adodb_'.$m.'.cache';
                                                $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this);
                                        if ($this->debug) ADOConnection::outp( " Cache write error");
                                }
-                       } else
-                       if ($rs) {
+                       } else if ($rs) {
                                $eof = $rs->EOF;
                                $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately
                                $txt = _rs2serialize($rs,false,$sql); // serialize
                
-                               if (!adodb_write_file($md5file,$txt,$this->debug)) {
-                                       if ($fn = $this->raiseErrorFn) {
-                                               $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this);
+                               $ok = adodb_write_file($md5file,$txt,$this->debug);
+                               if (!$ok) {
+                                       if ($ok === false) {
+                                               $em = 'Cache write error';
+                                               $en = -32000;
+                                               
+                                               if ($fn = $this->raiseErrorFn) {
+                                                       $fn($this->databaseType,'CacheExecute', $en, $em, $md5file,$sql,$this);
+                                               }
+                                       } else {
+                                               $em = 'Cache file locked warning';
+                                               $en = -32001;
+                                               // do not call error handling for just a warning
                                        }
-                                       if ($this->debug) ADOConnection::outp( " Cache write error");
+                                       
+                                       if ($this->debug) ADOConnection::outp( " ".$em);
                                }
                                if ($rs->EOF && !$eof) {
                                        $rs->MoveFirst();
@@ -3853,7 +3866,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
                        $mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode;
                        
                        if ($mode & ADODB_FETCH_ASSOC) {
-                               if (!isset($this->fields[$colname])) $colname = strtolower($colname);
+                               if (!isset($this->fields[$colname]) && !is_null($this->fields[$colname])) $colname = strtolower($colname);
                                return $this->fields[$colname];
                        }
                        if (!$this->bind) {
index 908d6917e0664470e8227d9a973bf7302560718b..3ec194e3bf4860b19942f47cf845eeee20e1f36d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index ee2f0ec1e97b4fde2a825b2bec1e2b0ce79425c8..6e03b253fb087eddf527a366d7d9851e90e75128 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index b2870c780510b0fc74fad10f5be61b27b33b5ef7..c49b62444f2dcaf0000e391389a168bbb4144fc8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 902eeffefd332ceeb078019a1caa5a802d5460f4..45639036bd01b2bc5f72ab1a3ccb18c69b3ad2d1 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 043f782d811aab9cdc6312eb5b7756924e5073eb..ac171f509e2f7481509bbe21aef858c0fc1ce536 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 197f4498350c679e57cb8f687ab935649d3890a0..8dae2302bd6ae33e6f9fb8428c0e952a286fa56a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 2cf79f2670e27c6a7fc1dfa15203422e6cfb0409..12753566cca668e355430b5d2759942b3ae1bf02 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 477f36ac64501073ec0d64464ff522845ec402ef..ef4dc8586a6a63809b181cc510d5c7fef9d15649 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 5a2c4e2a162d81262f95efb0f45ba0354df91e95..9f38e1e03bf742f0b6ff01bee26e1826f7748959 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 9421f3de2ec37203395e4c1f8228f218840beaf8..0cee94c09f5ae813bad7ebf48456ec7eba931f9e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -151,6 +151,12 @@ class ADODB2_postgres extends ADODB_DataDict {
                return $sql;
        }
        
+
+       function DropIndexSQL ($idxname, $tabname = NULL)
+       {
+          return array(sprintf($this->dropIndex, $this->TableName($idxname), $this->TableName($tabname)));
+       }
+       
        /**
         * Change the definition of one column
         *
index 37de29ed614eec24c801e00150e01016f83dcdd0..bf52455476c8741e355538056503fbf0bd769888 100644 (file)
-<?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
+<?php
+
+/**
+  V4.50 6 July 2004  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
+  Released under both BSD license and Lesser GPL library license. 
+  Whenever there is any discrepancy between the two licenses, 
+  the BSD license will take precedence.
+       
+  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) . ')' );
+       }       
+}
+
 ?>
\ No newline at end of file
index 50300944ff3bb0b23ac3448a93e23cef51ca6faf..2adbe0035fef0c37d8356b2463e7cc636c69a31a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 0617874649796529d47329685243640c48631908..e13abb6f7e12a03977b8c1e0c47204bae072e516 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index d331a303d9e3ef9ffa5d11b8c98e7da34c8d1f8e..25c03e8024e8096b9e7d73a3a67c3945e57f75fa 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 8ed40afb889a6abf10cefa696b2c75cacedaf1be..5c0bf0f4cd959d74722ad6cc0f059d4bef29f625 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 1b93c69cf32cc25322d4297afaf71d40cb34114a..989a3c40ef50d3d8cddc0f54078fad91529a5266 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
 Released under both BSD license and Lesser GPL library license. 
 Whenever there is any discrepancy between the two licenses, 
 the BSD license will take precedence. See License.txt. 
index 1befc60af779454bb6a353e4e61383a51ad0325b..72a42c064a801f777db56939c20c9862a2c73536 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 7fa75c441294bd00101e72abb4b74b3a328d51fc..99fe6548e528e01792a2ad8290f76ac92a1d0120 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index cb18601659c2022dd6b2e930f66d4323ff444427..764b4b0024e8bdfb2d61517c36020fd578ccdb18 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index acccf9012baf70e5d07357692e3392d0e985d853..228eadb68f24ed432ae7737d1743144af55b476e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-  V4.96 24 Sept 2007  (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (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 042099c173936422a17a2ba14ec125dad30eee92..412534c68a3ebe93f09ff7529ebcd38d1e4f0098 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ @version V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index c67f5934907ca4fbf03ca3370e7a7a0326dfde02..4a1db9ab68137e38887874afd25b0138d8b7d1d6 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 8bb8ca459015f261d61b5667e1f6e996b3b7ff41..146c7b18e044364a7ed6212ed147e56439daba51 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.  
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.  
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index f709cd06b37e9fe40d0781e05e72cec92321ec37..f8766f74c2f060214eb83b92969bad88027c9adb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
-* @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+* @version V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
 * Released under both BSD license and Lesser GPL library license.
 * Whenever there is any discrepancy between the two licenses,
 * the BSD license will take precedence.
index 985c77dd105535db78ea9fca254e719b01b5cf7f..59cf39f8ed5e855bef3698da97b6d56337008135 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim. All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 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 23ec332750e44fd59454e4ed83871a11cdd581bf..147cd9eda40b5d0d70a2c52ef44a08ad9b50d8e1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
    Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index f345b446c68781b089bf7a5eedb540eb3f5e4454..c76c841e91e331adb3e77344b31bac59f632eae5 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
@@ -611,7 +611,7 @@ order by constraint_name, referenced_table_name, keyno";
                if ($type === false) 
                        switch(gettype($var)) {
                        default:
-                       case 'string': $type = SQLCHAR; break;
+                       case 'string': $type = SQLVARCHAR; break;
                        case 'double': $type = SQLFLT8; break;
                        case 'integer': $type = SQLINT4; break;
                        case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0
index 5a4c9deb49214e1eccd589e3236f0c407db62acc..380829828f435c73d87969a1d1a71b442db017a9 100644 (file)
@@ -9,7 +9,7 @@
 // ADOdb  - Database Abstraction Library for PHP                         //
 //          http://adodb.sourceforge.net/                                //
 //                                                                       //
-// Copyright (C) 2000-2007 John Lim (jlim\@natsoft.com.my)               //
+// Copyright (C) 2000-2008 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,  //
index 2a632d2dd9f5c460c1c52f9bcf9c86c80652c301..504bea484d8bd903f0342aa188b1fff2f4b61c77 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
-* @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+* @version V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
 * Released under both BSD license and Lesser GPL library license.
 * Whenever there is any discrepancy between the two licenses,
 * the BSD license will take precedence.
index ac9d8fd00a2afc2a0a3740859bd0b86a22109bf9..7260dfb6beb29f889e559e8fcc34aa120a5053b0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 6c86544567452a7ba744c4f24b147b571f764f1c..3d080e4b5e08fcd3fc243721426abb3944da6f99 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -114,6 +114,7 @@ class ADODB_mysqli extends ADOConnection {
           } else {
                        if ($this->debug) 
                                ADOConnection::outp("Could't connect : "  . $this->ErrorMsg());
+                       $this->_connectionID = null;
                        return false;
           }
        }
@@ -611,16 +612,15 @@ class ADODB_mysqli extends ADOConnection {
                              $nrows = -1,
                              $offset = -1,
                              $inputarr = false, 
-                             $arg3 = false,
                              $secs = 0)
        {
                $offsetStr = ($offset >= 0) ? "$offset," : '';
                if ($nrows < 0) $nrows = '18446744073709551615';
                
                if ($secs)
-                       $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
+                       $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr);
                else
-                       $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
+                       $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr);
                        
                return $rs;
        }
@@ -944,7 +944,7 @@ class ADORecordSet_mysqli extends ADORecordSet{
                 case 'SET': 
                
                case MYSQLI_TYPE_TINY_BLOB :
-               case MYSQLI_TYPE_CHAR :
+               #case MYSQLI_TYPE_CHAR :
                case MYSQLI_TYPE_STRING :
                case MYSQLI_TYPE_ENUM :
                case MYSQLI_TYPE_SET :
@@ -1051,7 +1051,7 @@ class ADORecordSet_array_mysqli extends ADORecordSet_array {
                 case 'SET': 
                
                case MYSQLI_TYPE_TINY_BLOB :
-               case MYSQLI_TYPE_CHAR :
+               #case MYSQLI_TYPE_CHAR :
                case MYSQLI_TYPE_STRING :
                case MYSQLI_TYPE_ENUM :
                case MYSQLI_TYPE_SET :
index fe05a174dc807949d97d7e7f1c42ba2bb6a3518b..6badabdf1ec14f80e67d5be0cc609a7c52dcf2a5 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 66c92d029317eae789a417d632f191146d385b9c..7db95b4b0e4604753e8a8c6f67baaa8c5249ff93 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  
   First cut at the Netezza Driver by Josh Eldridge joshuae74#hotmail.com
  Based on the previous postgres drivers.
index ea84884628dc412a63ac3fbef03ce418628a017b..b4b8e95c8b6af4016b5c9ab767e0957b2c1334a9 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
 
-  version V4.96 24 Sept 2007 (c) 2000-2007 John Lim. All rights reserved.
+  version V4.98 13 Feb 2008 (c) 2000-2008 John Lim. All rights reserved.
 
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
@@ -1295,19 +1295,26 @@ class ADORecordset_oci8 extends ADORecordSet {
                          fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
                          fetchField() is retrieved.            */
 
-       function &_FetchField($fieldOffset = -1)
+       function _FetchField($fieldOffset = -1)
        {
                $fld = new ADOFieldObject;
                $fieldOffset += 1;
                $fld->name =OCIcolumnname($this->_queryID, $fieldOffset);
                $fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
                $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
-               if ($fld->type == 'NUMBER') {
+               switch($fld->type) {
+               case 'NUMBER':
                        $p = OCIColumnPrecision($this->_queryID, $fieldOffset);
                        $sc = OCIColumnScale($this->_queryID, $fieldOffset);
                        if ($p != 0 && $sc == 0) $fld->type = 'INT';
-                       //echo " $this->name ($p.$sc) ";
-               }
+                       break;
+               
+               case 'CLOB':
+               case 'NCLOB':
+               case 'BLOB': 
+                       $fld->max_length = -1;
+                       break;
+               }
                return $fld;
        }
        
index 8d3513fb7b3e144b97effe4c71c9ef4310ac4692..3528c7b062142e759092e3caeec206abbc7e0d10 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /** 
- * @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
  * Released under both BSD license and Lesser GPL library license. 
  * Whenever there is any discrepancy between the two licenses, 
  * the BSD license will take precedence. 
index 521685ad2d9faf6e9a2a5ec387b1f66abd9dc56c..174d15ce3cc1a69f7c37754d58c2679904b3ecf8 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim. All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 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 dff6182b2265ad71be6e0da4738122ea2690e9cb..a524fb75c067bd9a19761a80c40cd89d4cb3f1b3 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 91dec31ffdd8d9b2fdc3321514ba0ddf4b53628e..e5826960d08a7e41e7b0d65838a7a0f3da6c9515 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index e57b18da2347ef931ddcd6afe6969d6fadd56501..7c4c93668e45d9376c11dc10b5e38f40f2dd69a4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 47af47721439b3934e52845e0d0c7eac95547d27..7296e875f5228d4fcda1aaf69724d274f46ab3df 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index e8799739a09aa17953a3913921e37e6c0d6a706f..64def5e2e13227ac198468bf217fa8d80ff3bc34 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence. See License.txt.
index 3c77882eac2e2b7a172daa56adb109135e26ddc8..389f2cba3adb79544aae7e261c8d511522c68778 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-       V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+       V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence. See License.txt.
index 870863bd06b88baec2a2d36919f57a21e909e996..65b04caa6ddc541773e88ead7755de55001a2e96 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 3946107d620fa8486d91802e1afb0ceb800531f9..5d43b587794be4c0b70340fe51d361303e5e1c68 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
@@ -64,41 +64,6 @@ function adodb_pdo_type($t)
 
 
 
-class ADODB_pdo_base extends ADODB_pdo {
-
-       var $sysDate = "'?'";
-       var $sysTimeStamp = "'?'";
-       
-
-       function _init($parentDriver)
-       {
-               $parentDriver->_bindInputArray = true;
-               #$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
-       }
-       
-       function ServerInfo()
-       {
-               return ADOConnection::ServerInfo();
-       }
-       
-       function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
-       {
-               $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
-               return $ret;
-       }
-       
-       function MetaTables()
-       {
-               return false;
-       }
-       
-       function MetaColumns()
-       {
-               return false;
-       }
-}
-
-
 class ADODB_pdo extends ADOConnection {
        var $databaseType = "pdo";      
        var $dataProvider = "pdo";
@@ -390,6 +355,43 @@ class ADODB_pdo extends ADOConnection {
        }
 }
 
+
+
+class ADODB_pdo_base extends ADODB_pdo {
+
+       var $sysDate = "'?'";
+       var $sysTimeStamp = "'?'";
+       
+
+       function _init($parentDriver)
+       {
+               $parentDriver->_bindInputArray = true;
+               #$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
+       }
+       
+       function ServerInfo()
+       {
+               return ADOConnection::ServerInfo();
+       }
+       
+       function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
+       {
+               $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
+               return $ret;
+       }
+       
+       function MetaTables()
+       {
+               return false;
+       }
+       
+       function MetaColumns()
+       {
+               return false;
+       }
+}
+
+
 class ADOPDOStatement {
 
        var $databaseType = "pdo";              
index 3450b4b05b237225f802c6fcbcc06778dd3e46b5..2a9958c7fee6b218caa10695005ab53404b411d6 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 701d7f30ba10e121e08119fe583832087cb3480d..c24c010519d13f7b9ca7c2907369f7180a759f74 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
@@ -15,6 +15,10 @@ class ADODB_pdo_mysql extends ADODB_pdo {
        var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
        var $sysDate = 'CURDATE()';
        var $sysTimeStamp = 'NOW()';
+       var $hasGenID = true;
+       var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
+       var $_dropSeqSQL = "drop table %s";
+       
        var $nameQuote = '`';
 
        function _init($parentDriver)
index 50112db25f2e50766500940e9fa76c1dd41d348e..c3a016d3852a4b908ad68db31fb9bc35ca7d6bd4 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 039bd83f1695d083acea3f83f4310779a3fcbd6a..1215ad8a0684462b0cbe10608d912796b9bc6339 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 7bad1f0a2ecb3a89af522190037cd71868b739fc..c3a30631e4b8f49861dbf4f7fc7fbc93437dedf5 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index ed4a5cce4720fff738d74d725e024f03e95856b3..8b2dea2e2c88d3eda5a44c78501a1afdd4a97080 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index e53999fb288d4b4a972d40bf704e42da3b1453c6..b5c64dcb12636ceef7eef440015904d6c326e035 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 05bccf44dd5120a52cb414c06b42722d54190394..7ab0be770f899c9e75286180b55a5fa0ee47fdeb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 0bada7bdd6e9c9601f03b06bea5fc1374f642603..1eb74f793cfe319353836fe1c8f7c7c377fd0b65 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 57c8972aba3e84d44428914510460ce4d4411ccb..3ee9f10044c00bb9113258c5e4991384bce13944 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index 53dae9979dd8e0a09072b94a4642e067a4d6c528..c842a765259827055719edc8600ff48bba0462d3 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-version V4.96 24 Sept 2007 (c) 2000-2007  John Lim (jlim#natsoft.com.my).  All rights
+version V4.98 13 Feb 2008 (c) 2000-2008  John Lim (jlim#natsoft.com.my).  All rights
 reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
index c5dbacfd88206a02577027e84a887b9722be4e58..b9c45c2e2a08201965c0727c6cda82ad936a6f24 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 436af4b58a99a80e89a6f288656c8420ee7cc1b6..58e071d7f8695dde28d441e7d2c7c6e01909313c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license.
   Whenever there is any discrepancy between the two licenses,
   the BSD license will take precedence.
index 0802669c66aa100d7ab116a8a8b1a1e659669aad..ef6df6be6dc6232dd26f79636dcc984bb6748224 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim. All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 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 84213cd6aca2df913461768a7e76039863a9a434..95cb2d249509046854b65c6315a32fa9cc1ea57f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-  V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index e3cd6518cb45ff71773a463815af22687fcf72c5..92cbb661dd24c0a1ab908180fb17f0cf78d0cc9e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. 
index d4ef68fc44fa979b522859b00fad4a08aa20c9ce..4b7509527c2fc22d7111b33cafe2074699f712c3 100644 (file)
@@ -30,4 +30,4 @@ $ADODB_LANG_ARRAY = array (
            DB_ERROR_NOSUCHDB           => 'áíÓ åäÇáß ÞÇÚÏÉ ÈíÇäÇÊ ÈåÐÇ ÇáÇÓã',
            DB_ERROR_ACCESS_VIOLATION   => 'ÓãÇÍíÇÊ ÛíÑ ßÇÝíÉ'
 );
-?>
+?>
\ No newline at end of file
index d5c7155c609bc820919f436e4fc78e2a90267afe..5281ed53b6513bd16e4bdb91bf73fcaa72e270ef 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php
 /*
        Bulgarian language, v1.0, 25.03.2004, encoding by UTF-8 charset
        contributed by Valentin Sheiretsky <valio#valio.eu.org>
@@ -34,4 +34,4 @@ $ADODB_LANG_ARRAY = array (
             DB_ERROR_NOSUCHDB           => 'несъществуваща база данни',
             DB_ERROR_ACCESS_VIOLATION   => 'нямате достатъчно права'
 );
-?>
+?>
\ No newline at end of file
index 3e6a4496bd30eb5570d60ada02fa2ed143cab2ff..3640ebd0bbb956f6e7bc657c75c40ace97457484 100644 (file)
@@ -1,35 +1,34 @@
-<?php\r
-// Catalan language\r
-// contributed by "Josep Lladonosa" jlladono#pie.xtec.es\r
-$ADODB_LANG_ARRAY = array (\r
-                       'LANG'                      => 'ca',\r
-            DB_ERROR                    => 'error desconegut',\r
-            DB_ERROR_ALREADY_EXISTS     => 'ja existeix',\r
-            DB_ERROR_CANNOT_CREATE      => 'no es pot crear',\r
-            DB_ERROR_CANNOT_DELETE      => 'no es pot esborrar',\r
-            DB_ERROR_CANNOT_DROP        => 'no es pot eliminar',\r
-            DB_ERROR_CONSTRAINT         => 'violació de constraint',\r
-            DB_ERROR_DIVZERO            => 'divisió per zero',\r
-            DB_ERROR_INVALID            => 'no és vàlid',\r
-            DB_ERROR_INVALID_DATE       => 'la data o l\'hora no són vàlides',\r
-            DB_ERROR_INVALID_NUMBER     => 'el nombre no és vàlid',\r
-            DB_ERROR_MISMATCH           => 'no hi ha coincidència',\r
-            DB_ERROR_NODBSELECTED       => 'cap base de dades seleccionada',\r
-            DB_ERROR_NOSUCHFIELD        => 'camp inexistent',\r
-            DB_ERROR_NOSUCHTABLE        => 'taula inexistent',\r
-            DB_ERROR_NOT_CAPABLE        => 'l\'execució secundària de DB no pot',\r
-            DB_ERROR_NOT_FOUND          => 'no trobat',\r
-            DB_ERROR_NOT_LOCKED         => 'no blocat',\r
-            DB_ERROR_SYNTAX             => 'error de sintaxi',\r
-            DB_ERROR_UNSUPPORTED        => 'no suportat',\r
-            DB_ERROR_VALUE_COUNT_ON_ROW => 'el nombre de columnes no coincideix amb el nombre de valors en la fila',\r
-            DB_ERROR_INVALID_DSN        => 'el DSN no és vàlid',\r
-            DB_ERROR_CONNECT_FAILED     => 'connexió fallida',\r
-            0                         => 'cap error', // DB_OK\r
-            DB_ERROR_NEED_MORE_DATA     => 'les dades subministrades són insuficients',\r
-            DB_ERROR_EXTENSION_NOT_FOUND=> 'extensió no trobada',\r
-            DB_ERROR_NOSUCHDB           => 'base de dades inexistent',\r
-            DB_ERROR_ACCESS_VIOLATION   => 'permisos insuficients'\r
-);\r
-?>\r
-               
\ No newline at end of file
+<?php
+// Catalan language
+// contributed by "Josep Lladonosa" jlladono#pie.xtec.es
+$ADODB_LANG_ARRAY = array (
+                       'LANG'                      => 'ca',
+            DB_ERROR                    => 'error desconegut',
+            DB_ERROR_ALREADY_EXISTS     => 'ja existeix',
+            DB_ERROR_CANNOT_CREATE      => 'no es pot crear',
+            DB_ERROR_CANNOT_DELETE      => 'no es pot esborrar',
+            DB_ERROR_CANNOT_DROP        => 'no es pot eliminar',
+            DB_ERROR_CONSTRAINT         => 'violació de constraint',
+            DB_ERROR_DIVZERO            => 'divisió per zero',
+            DB_ERROR_INVALID            => 'no és vàlid',
+            DB_ERROR_INVALID_DATE       => 'la data o l\'hora no són vàlides',
+            DB_ERROR_INVALID_NUMBER     => 'el nombre no és vàlid',
+            DB_ERROR_MISMATCH           => 'no hi ha coincidència',
+            DB_ERROR_NODBSELECTED       => 'cap base de dades seleccionada',
+            DB_ERROR_NOSUCHFIELD        => 'camp inexistent',
+            DB_ERROR_NOSUCHTABLE        => 'taula inexistent',
+            DB_ERROR_NOT_CAPABLE        => 'l\'execució secundària de DB no pot',
+            DB_ERROR_NOT_FOUND          => 'no trobat',
+            DB_ERROR_NOT_LOCKED         => 'no blocat',
+            DB_ERROR_SYNTAX             => 'error de sintaxi',
+            DB_ERROR_UNSUPPORTED        => 'no suportat',
+            DB_ERROR_VALUE_COUNT_ON_ROW => 'el nombre de columnes no coincideix amb el nombre de valors en la fila',
+            DB_ERROR_INVALID_DSN        => 'el DSN no és vàlid',
+            DB_ERROR_CONNECT_FAILED     => 'connexió fallida',
+            0                         => 'cap error', // DB_OK
+            DB_ERROR_NEED_MORE_DATA     => 'les dades subministrades són insuficients',
+            DB_ERROR_EXTENSION_NOT_FOUND=> 'extensió no trobada',
+            DB_ERROR_NOSUCHDB           => 'base de dades inexistent',
+            DB_ERROR_ACCESS_VIOLATION   => 'permisos insuficients'
+);
+?>
\ No newline at end of file
index 3424099a5c8e3f6c330fdf9bcbce850d2320fc24..cd28f7e55cab5b8216511559af12a893f93ea5e4 100644 (file)
@@ -1,35 +1,35 @@
-<?php\r
-// contributed by "Levi Fukumori" levi _AT_ fukumori _DOT_ com _DOT_ br\r
-// portugese (brazilian)\r
-$ADODB_LANG_ARRAY = array (\r
-                       'LANG'                      => 'pt-br',\r
-            DB_ERROR                    => 'erro desconhecido',\r
-            DB_ERROR_ALREADY_EXISTS     => 'já existe',\r
-            DB_ERROR_CANNOT_CREATE      => 'impossível criar',\r
-            DB_ERROR_CANNOT_DELETE      => 'impossível excluír',\r
-            DB_ERROR_CANNOT_DROP        => 'impossível remover',\r
-            DB_ERROR_CONSTRAINT         => 'violação do confinamente',\r
-            DB_ERROR_DIVZERO            => 'divisão por zero',\r
-            DB_ERROR_INVALID            => 'inválido',\r
-            DB_ERROR_INVALID_DATE       => 'data ou hora inválida',\r
-            DB_ERROR_INVALID_NUMBER     => 'número inválido',\r
-            DB_ERROR_MISMATCH           => 'erro',\r
-            DB_ERROR_NODBSELECTED       => 'nenhum banco de dados selecionado',\r
-            DB_ERROR_NOSUCHFIELD        => 'campo inválido',\r
-            DB_ERROR_NOSUCHTABLE        => 'tabela inexistente',\r
-            DB_ERROR_NOT_CAPABLE        => 'capacidade inválida para este BD',\r
-            DB_ERROR_NOT_FOUND          => 'não encontrado',\r
-            DB_ERROR_NOT_LOCKED         => 'não bloqueado',\r
-            DB_ERROR_SYNTAX             => 'erro de sintaxe',\r
-            DB_ERROR_UNSUPPORTED        => \r
-'não suportado',\r
-            DB_ERROR_VALUE_COUNT_ON_ROW => 'a quantidade de colunas não corresponde ao de valores',\r
-            DB_ERROR_INVALID_DSN        => 'DSN inválido',\r
-            DB_ERROR_CONNECT_FAILED     => 'falha na conexão',\r
-            0                          => 'sem erro', // DB_OK\r
-            DB_ERROR_NEED_MORE_DATA     => 'dados insuficientes',\r
-            DB_ERROR_EXTENSION_NOT_FOUND=> 'extensão não encontrada',\r
-            DB_ERROR_NOSUCHDB           => 'banco de dados não encontrado',\r
-            DB_ERROR_ACCESS_VIOLATION   => 'permissão insuficiente'\r
-);\r
-?>\r
+<?php
+// contributed by "Levi Fukumori" levi _AT_ fukumori _DOT_ com _DOT_ br
+// portugese (brazilian)
+$ADODB_LANG_ARRAY = array (
+                       'LANG'                      => 'pt-br',
+            DB_ERROR                    => 'erro desconhecido',
+            DB_ERROR_ALREADY_EXISTS     => 'já existe',
+            DB_ERROR_CANNOT_CREATE      => 'impossível criar',
+            DB_ERROR_CANNOT_DELETE      => 'impossível excluír',
+            DB_ERROR_CANNOT_DROP        => 'impossível remover',
+            DB_ERROR_CONSTRAINT         => 'violação do confinamente',
+            DB_ERROR_DIVZERO            => 'divisão por zero',
+            DB_ERROR_INVALID            => 'inválido',
+            DB_ERROR_INVALID_DATE       => 'data ou hora inválida',
+            DB_ERROR_INVALID_NUMBER     => 'número inválido',
+            DB_ERROR_MISMATCH           => 'erro',
+            DB_ERROR_NODBSELECTED       => 'nenhum banco de dados selecionado',
+            DB_ERROR_NOSUCHFIELD        => 'campo inválido',
+            DB_ERROR_NOSUCHTABLE        => 'tabela inexistente',
+            DB_ERROR_NOT_CAPABLE        => 'capacidade inválida para este BD',
+            DB_ERROR_NOT_FOUND          => 'não encontrado',
+            DB_ERROR_NOT_LOCKED         => 'não bloqueado',
+            DB_ERROR_SYNTAX             => 'erro de sintaxe',
+            DB_ERROR_UNSUPPORTED        => 
+'não suportado',
+            DB_ERROR_VALUE_COUNT_ON_ROW => 'a quantidade de colunas não corresponde ao de valores',
+            DB_ERROR_INVALID_DSN        => 'DSN inválido',
+            DB_ERROR_CONNECT_FAILED     => 'falha na conexão',
+            0                          => 'sem erro', // DB_OK
+            DB_ERROR_NEED_MORE_DATA     => 'dados insuficientes',
+            DB_ERROR_EXTENSION_NOT_FOUND=> 'extensão não encontrada',
+            DB_ERROR_NOSUCHDB           => 'banco de dados não encontrado',
+            DB_ERROR_ACCESS_VIOLATION   => 'permissão insuficiente'
+);
+?>
\ No newline at end of file
index 8263d822b4270d4a5dc9d7dd43d5a987a627dec6..bcd7d13228cf25988075b8e2fcd55e92becff5b2 100644 (file)
@@ -32,4 +32,4 @@ $ADODB_LANG_ARRAY = array (
             DB_ERROR_NOSUCHDB           => 'nu exista baza de date',
             DB_ERROR_ACCESS_VIOLATION   => 'permisiuni insuficiente'
 );
-?>
+?>
\ No newline at end of file
index 9fa32ed5b46186828a90a31821bf17b695324935..675016d125e404cf604df8f7dc4753b2baa5fe47 100644 (file)
@@ -32,4 +32,4 @@ $ADODB_LANG_ARRAY = array (
             DB_ERROR_NOSUCHDB           => 'íå ³ñíóº ÁÄ',
             DB_ERROR_ACCESS_VIOLATION   => 'íåäîñòàòíüî ïðàâ äîñòóïà'
 );
-?>
+?>
\ No newline at end of file
index a7288efb57c851964b0bec585a95e5976ad5cba9..3fdd99705f7a7dff5dc893a62425172d8aa42fcb 100644 (file)
@@ -30,4 +30,4 @@ $ADODB_LANG_ARRAY = array (
             DB_ERROR_NOSUCHDB           => 'ไม่มีข้อมูลนี้',
             DB_ERROR_ACCESS_VIOLATION   => 'permissions ไม่พอ'
 );
-?>
+?>
\ No newline at end of file
index ca02cb554ec7d42bfd7e2e30db7efc573348ea6b..ea6d3b4c9343cfe4c4188011b21d26cc9ec84d74 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index 9893a515efd7cdcf09e64e3a02f3ed5648de516e..aa8bad65864a1687e265debde4b20aef08894eb2 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index b737e1ffede4bf7e6e968d64e33e6de5ddb3327e..c7d6c9155463701f169f62c1f29261b03858e4f4 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index a5f44072e518b3fc03296eee01a28215e61f27c5..001802bdb1edfffa03a62c7cbdf03d4f66422692 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index cf560f06f3cfb6be279af65e992199647bb39072..b3869378a20948d2ec60ca9599bdac1c17aceca8 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index fa8b2ca5afa43a988168cbbf689973fb4a01ae7a..2f351da1c1c4d21fe99d8544f9949bdb49b22809 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /* 
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
index 0e0e7b1f985684cb96268a73074887a1ed1a8d33..628ad3c1725f67a17834c5a75258fc948119fd3e 100644 (file)
-<?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
+<?php
+/** 
+ * @version V4.93 10 Oct 2006 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * Released under both BSD license and Lesser GPL library license. 
+ * Whenever there is any discrepancy between the two licenses, 
+ * the BSD license will take precedence. 
+ *
+ * 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
+ */
+}
 ?>
\ No newline at end of file
index 45d08c4edddef492259e74bb5b883620a9996c36..f96e9023adfbf7fc3731130e15b57a42e3b15621 100644 (file)
@@ -1,4 +1,4 @@
-Description of ADODB v4.96a library import into Moodle
+Description of ADODB v4.98 library import into Moodle
 
 Removed:
  * contrib/
@@ -13,16 +13,13 @@ Added:
  * readme_moodle.txt - this file ;-)
 
 Our changes:
- * adodb-lib.inc.php - forced conversion to proper numeric type in _adodb_column_sql()
+ * adodb-lib.inc.php - added support for "F" and "L" types in  _adodb_column_sql()
  * adodb-lib.inc.php - modify some debug output to be correct XHTML. MDL-12378.
        Reported to ADOdb at: http://phplens.com/lens/lensforum/msgs.php?id=17133
        Once fixed by adodb guys, we'll return to their official distro.
- * lang/adodb-ar.inc.php lang/adodb-bg.inc.php lang/adodb-bgutf8.inc.php 
-   lang/adodb-en.inc.php lang/adodb-pl.inc.php lang/adodb-ro.inc.php
-   lang/adodb_th.inc.php - Removed leading white space outside PHP open/close tags
-   (see http://tracker.moodle.org/browse/MDL-11632).
+
+skodak, iarenaza, moodler
 
 
-skodak, iarenaza
 
 $Id$
index 29662a215eb7809a5a5f3d3bd5b5cea8c75213db..cf705c90738d1f04bee33bb119714a7a1e76a94e 100644 (file)
@@ -1,61 +1,61 @@
-<?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
+<?php
+/** 
+ * @version V4.93 10 Oct 2006 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * Released under both BSD license and Lesser GPL library license. 
+ * Whenever there is any discrepancy between the two licenses, 
+ * the BSD license will take precedence. 
+ *
+ * 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;
+}
 ?>
\ No newline at end of file
index cbb5c4e16f72c20fd0e27f382aa8a32d041e4d10..c58428b4ff033603f151a577734d9a01e355bb5c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 d39ef0ec6b0c13f0d5c7ea0fe939df8a0ed3ec2a..de0ad8b697d3585b1aa50fec22cae173caf27741 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 2d7240bc873439699d8100de1c26813991e9ecf0..600e89e51887bc55b37a30b9e2240a8870dca6a1 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 379a850bc4b99fae3c4f730858217b29a9ebd1fe..92961ef715b8b91005ad01e9a8f7ff9bb5bcba75 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 a88b537073eee5058a80f9f684e53ccad4406753..63f7dbc625ec8bf6938b92efa028c93c8f5ceb18 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 2e0d0d0340c298a2ca8d35ddf7f7b4c0ee0a31cb..4044079b211cc8f9168f53be3fdcc864bc077153 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 b7798eecb083312a6675a6821dcc440d4aa893c3..5446b5764080b0024202912fcdd796ac73798aac 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 ec0fcd11fcf32384037a21e4dd230041c718ee1a..8abd32faeac685d7dcab18602b1881021166d4fb 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 484e555b6727a8344467591e83b35cca44c0429f..1c4efd17b1401c1bc2c8cf6bb89e3cb476fced53 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 d24089e48dede52b9374a0fc630abb9d98add415..5f6d33f90b171efde5a5aebb9acb830e4e733942 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 c36f5a3fa873d0fcca8e44fb6a792d590e9ed536..f765891138e84f5dd4dbc633ab982537babbf41d 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
          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 316c722314f16d10f7d884ee125be9a134a83ffa..7c2232dae7174068a8b9b4df21f0859b81607880 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-V4.96 24 Sept 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence.
index 788e184a94e2cf0add10bf1dcb24892cc04c5022..fd760441d00ccd2a1db88060ac160a7f572baaa5 100644 (file)
-<?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
+<?php
+/*
+  V4.93 10 Oct 2006  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
+  Released under both BSD license and Lesser GPL library license. 
+  Whenever there is any discrepancy between the two licenses, 
+  the BSD license will take precedence.
+         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);
+}
+
+?>
index 6fc9b2fe05e3e0b237716287ab059a4198377640..deec3105a0292f573af12b6200f91138f81c1559 100644 (file)
-<?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
+<?php
+/*
+V4.93 10 Oct 2006  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
+  Released under both BSD license and Lesser GPL library license. 
+  Whenever there is any discrepancy between the two licenses, 
+  the BSD license will take precedence.
+         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);
+}
+
 ?>
\ No newline at end of file
index ba3f37a21cbe85d3a6d98f88831f40e139f6a4b3..8be7d2e3d3941a9e137dafc2ba058bd72350cc31 100644 (file)
-<?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
+<?php
+
+/** 
+ * @version V4.93 10 Oct 2006 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * Released under both BSD license and Lesser GPL library license. 
+ * Whenever there is any discrepancy between the two licenses, 
+ * the BSD license will take precedence. 
+ *
+ * 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;
+}
 ?>
\ No newline at end of file
index b9bef03f57a3ed46957f0735905b6a74b90c6df7..44267d2a6f6e6b18d60d85180bd6ce736b02932a 100644 (file)
-<?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
+<?php 
+/*
+  V4.93 10 Oct 2006  (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
+  Released under both BSD license and Lesser GPL library license. 
+  Whenever there is any discrepancy between the two licenses, 
+  the BSD license will take precedence.
+  
+  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;
+}
+
 ?>
\ No newline at end of file