Update to latest ADOdb version, finally get rid of ->f .
authorsoranzo <soranzo>
Tue, 24 Apr 2007 13:04:13 +0000 (13:04 +0000)
committersoranzo <soranzo>
Tue, 24 Apr 2007 13:04:13 +0000 (13:04 +0000)
libraries/adodb/adodb-lib.inc.php
libraries/adodb/adodb.inc.php

index 920ea38ba2f2f6ca1867f661449ce7ce9f430d81..2a67f28d4f12c39028f59c447eb263e8eaa1e2d5 100644 (file)
@@ -7,7 +7,7 @@ global $ADODB_INCLUDED_LIB;
 $ADODB_INCLUDED_LIB = 1;
 
 /* 
- @version V4.65 22 July 2005 (c) 2000-2005 John Lim (jlim\@natsoft.com.my). All rights reserved.
+ @version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim\@natsoft.com.my). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
   the BSD license will take precedence. See License.txt. 
@@ -16,6 +16,75 @@ $ADODB_INCLUDED_LIB = 1;
   Less commonly used functions are placed here to reduce size of adodb.inc.php. 
 */ 
 
+function adodb_probetypes(&$array,&$types,$probe=8)
+{
+// probe and guess the type
+       $types = array();
+       if ($probe > sizeof($array)) $max = sizeof($array);
+       else $max = $probe;
+       
+       
+       for ($j=0;$j < $max; $j++) {
+               $row =& $array[$j];
+               if (!$row) break;
+               $i = -1;
+               foreach($row as $v) {
+                       $i += 1;
+
+                       if (isset($types[$i]) && $types[$i]=='C') continue;
+                       
+                       //print " ($i ".$types[$i]. "$v) ";
+                       $v = trim($v);
+                       
+                       if (!preg_match('/^[+-]{0,1}[0-9\.]+$/',$v)) {
+                               $types[$i] = 'C'; // once C, always C
+                               
+                               continue;
+                       }
+                       if ($j == 0) { 
+                       // If empty string, we presume is character
+                       // test for integer for 1st row only
+                       // after that it is up to testing other rows to prove
+                       // that it is not an integer
+                               if (strlen($v) == 0) $types[$i] = 'C';
+                               if (strpos($v,'.') !== false) $types[$i] = 'N';
+                               else  $types[$i] = 'I';
+                               continue;
+                       }
+                       
+                       if (strpos($v,'.') !== false) $types[$i] = 'N';
+                       
+               }
+       }
+       
+}
+
+function  adodb_transpose(&$arr, &$newarr, &$hdr, &$fobjs)
+{
+       $oldX = sizeof(reset($arr));
+       $oldY = sizeof($arr);   
+       
+       if ($hdr) {
+               $startx = 1;
+               $hdr = array('Fields');
+               for ($y = 0; $y < $oldY; $y++) {
+                       $hdr[] = $arr[$y][0];
+               }
+       } else
+               $startx = 0;
+
+       for ($x = $startx; $x < $oldX; $x++) {
+               if ($fobjs) {
+                       $o = $fobjs[$x];
+                       $newarr[] = array($o->name);
+               } else
+                       $newarr[] = array();
+                       
+               for ($y = 0; $y < $oldY; $y++) {
+                       $newarr[$x-$startx][] = $arr[$y][$x];
+               }
+       }
+}
 
 // Force key to upper. 
 // See also http://www.php.net/manual/en/function.array-change-key-case.php
@@ -42,7 +111,7 @@ function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_
                        $keyCol = array($keyCol);
                }
                foreach($fieldArray as $k => $v) {
-                       if ($autoQuote && !is_numeric($v) and strncmp($v,"'",1) !== 0 and strcasecmp($v,'null')!=0) {
+                       if ($autoQuote && !is_numeric($v) and strncmp($v,"'",1) !== 0 and strcasecmp($v,$zthis->null2null)!=0) {
                                $v = $zthis->qstr($v);
                                $fieldArray[$k] = $v;
                        }
@@ -57,8 +126,10 @@ function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_
                 
                $where = false;
                foreach ($keyCol as $v) {
-                       if ($where) $where .= " and $v=$fieldArray[$v]";
-                       else $where = "$v=$fieldArray[$v]";
+                       if (isset($fieldArray[$v])) {
+                               if ($where) $where .= ' and '.$v.'='.$fieldArray[$v];
+                               else $where = $v.'='.$fieldArray[$v];
+                       }
                }
                
                if ($uSet && $where) {
@@ -154,7 +225,7 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
                if ($fieldsize > 2) {
             $group = rtrim($zthis->fields[2]);
         }
+/* 
         if ($optgroup != $group) {
             $optgroup = $group;
             if ($firstgroup) {
@@ -165,7 +236,7 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
                 $s .="\n<optgroup label='". htmlspecialchars($group) ."'>";
             }
                }
-       
+*/
                if ($hasvalue) 
                        $value = " value='".htmlspecialchars($zval2)."'";
                
@@ -281,22 +352,28 @@ function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multipl
 
 /*
        Count the number of records this sql statement will return by using
-       query rewriting techniques...
+       query rewriting heuristics...
        
        Does not work with UNIONs, except with postgresql and oracle.
+       
+       Usage:
+       
+       $conn->Connect(...);
+       $cnt = _adodb_getcount($conn, $sql);
+       
 */
 function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0) 
 {
        $qryRecs = 0;
        
-        if (preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) || 
+        if (!empty($zthis->_nestedSQL) || preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) || 
                preg_match('/\s+GROUP\s+BY\s+/is',$sql) || 
                preg_match('/\s+UNION\s+/is',$sql)) {
                // ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias
                // but this is only supported by oracle and postgresql...
                if ($zthis->dataProvider == 'oci8') {
                        
-                       $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
+                       $rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
                        
                        // Allow Oracle hints to be used for query optimization, Chris Wrye
                        if (preg_match('#/\\*+.*?\\*\\/#', $sql, $hint)) {
@@ -305,24 +382,30 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
                                $rewritesql = "SELECT COUNT(*) FROM (".$rewritesql.")"; 
                        
                } else if (strncmp($zthis->databaseType,'postgres',8) == 0)  {
-                       
-                       $info = $zthis->ServerInfo();
-                       if (substr($info['version'],0,3) >= 7.1) { // good till version 999
-                               $rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
-                               $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
-                       }
+                       $rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$sql);
+                       $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
                }
        } else {
                // now replace SELECT ... FROM with SELECT COUNT(*) FROM
                $rewritesql = preg_replace(
                                        '/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);
 
+               
+               
                // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails 
                // with mssql, access and postgresql. Also a good speedup optimization - skips sorting!
-               $rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$rewritesql);
+               // also see http://phplens.com/lens/lensforum/msgs.php?id=12752
+               if (preg_match('/\sORDER\s+BY\s*\(/i',$rewritesql))
+                       $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql);
+               else
+                       $rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$rewritesql);
        }
        
+       
+       
        if (isset($rewritesql) && $rewritesql != $sql) {
+               if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[1];
+                
                if ($secs2cache) {
                        // we only use half the time of secs2cache because the count can quickly
                        // become inaccurate if new records are added
@@ -341,6 +424,8 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
        if (preg_match('/\s*UNION\s*/is', $sql)) $rewritesql = $sql;
        else $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); 
        
+       if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[0];
+               
        $rstest = &$zthis->Execute($rewritesql,$inputarr);
        if (!$rstest) $rstest = $zthis->Execute($sql,$inputarr);
        
@@ -363,7 +448,6 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
                $rstest->Close();
                if ($qryRecs == -1) return 0;
        }
-       
        return $qryRecs;
 }
 
@@ -482,6 +566,8 @@ function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputar
 
 function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=2)
 {
+       global $ADODB_QUOTE_FIELDNAMES;
+
                if (!$rs) {
                        printf(ADODB_BAD_RS,'GetUpdateSQL');
                        return false;
@@ -528,7 +614,7 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
                                                $type = 'C';
                                        }
                                        
-                                       if (strpos($upperfname,' ') !== false)
+                                       if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
                                                $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
                                        else
                                                $fnameq = $upperfname;
@@ -538,7 +624,7 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
                 //********************************************************//
                 if (is_null($arrFields[$upperfname])
                                        || (empty($arrFields[$upperfname]) && strlen($arrFields[$upperfname]) == 0)
-                    || $arrFields[$upperfname] === 'null'
+                    || $arrFields[$upperfname] === $zthis->null2null
                     )
                 {
                     switch ($force) {
@@ -560,7 +646,7 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
                                                default:
                         case 3:
                             //Set the value that was given in array, so you can give both null and empty values
-                            if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === 'null') {
+                            if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === $zthis->null2null) {
                                 $setFields .= $field->name . " = null, ";
                             } else {
                                 $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, $fnameq,$arrFields, $magicq);
@@ -595,9 +681,11 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
                        $discard = false;
                        // not a good hack, improvements?
                        if ($whereClause) {
+                       #var_dump($whereClause);
                                if (preg_match('/\s(ORDER\s.*)/is', $whereClause[1], $discard));
                                else if (preg_match('/\s(LIMIT\s.*)/is', $whereClause[1], $discard));
-                               else preg_match('/\s(FOR UPDATE.*)/is', $whereClause[1], $discard);
+                               else if (preg_match('/\s(FOR UPDATE.*)/is', $whereClause[1], $discard));
+                               else preg_match('/\s.*(\) WHERE .*)/is', $whereClause[1], $discard); # see http://sourceforge.net/tracker/index.php?func=detail&aid=1379638&group_id=42718&atid=433976
                        } else
                                $whereClause = array(false,false);
                                
@@ -640,6 +728,7 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false,$force=2)
 static $cacheRS = false;
 static $cacheSig = 0;
 static $cacheCols;
+       global $ADODB_QUOTE_FIELDNAMES;
 
        $tableName = '';
        $values = '';
@@ -689,7 +778,7 @@ static $cacheCols;
                $upperfname = strtoupper($field->name);
                if (adodb_key_exists($upperfname,$arrFields,$force)) {
                        $bad = false;
-                       if (strpos($upperfname,' ') !== false)
+                       if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
                                $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
                        else
                                $fnameq = $upperfname;
@@ -699,7 +788,7 @@ static $cacheCols;
             /********************************************************/
             if (is_null($arrFields[$upperfname])
                 || (empty($arrFields[$upperfname]) && strlen($arrFields[$upperfname]) == 0)
-                || $arrFields[$upperfname] === 'null'
+                || $arrFields[$upperfname] === $zthis->null2null
                                )
                {
                     switch ($force) {
@@ -721,7 +810,7 @@ static $cacheCols;
                                                default:
                         case 3:
                             //Set the value that was given in array, so you can give both null and empty values
-                                                       if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === 'null') { 
+                                                       if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === $zthis->null2null) { 
                                                                $values  .= "null, ";
                                                        } else {
                                        $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq, $arrFields, $magicq);
@@ -919,11 +1008,13 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
        $dbt = $zthis->databaseType;
        if (isset($zthis->dsnType)) $dbt .= '-'.$zthis->dsnType;
        if ($inBrowser) {
-               $ss = htmlspecialchars($ss);
+               if ($ss) {
+                       $ss = '<code>'.htmlspecialchars($ss).'</code>';
+               }
                if ($zthis->debug === -1)
-                       ADOConnection::outp( "<br>\n($dbt): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<br>\n",false);
+                       ADOConnection::outp( "<br />\n($dbt): ".htmlspecialchars($sqlTxt)." &nbsp; $ss\n<br />\n",false);
                else 
-                       ADOConnection::outp( "<hr>\n($dbt): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<hr>\n",false);
+                       ADOConnection::outp( "<hr />\n($dbt): ".htmlspecialchars($sqlTxt)." &nbsp; $ss\n<hr />\n",false);
        } else {
                ADOConnection::outp("-----\n($dbt): ".$sqlTxt."\n-----\n",false);
        }
@@ -947,10 +1038,10 @@ function _adodb_debug_execute(&$zthis, $sql, $inputarr)
        return $qID;
 }
 
-
+# pretty print the debug_backtrace function
 function _adodb_backtrace($printOrArr=true,$levels=9999,$skippy=0)
 {
-       if ((float) PHPVERSION() < 4.3) return '';
+       if (!function_exists('debug_backtrace')) return '';
         
        $html =  (isset($_SERVER['HTTP_USER_AGENT']));
        $fmt =  ($html) ? "</font><font color=#808080 size=-1> %% line %4d, file: <a href=\"file:/%s\">%s</a></font>" : "%% line %4d, file: %s";
@@ -1000,5 +1091,47 @@ function _adodb_backtrace($printOrArr=true,$levels=9999,$skippy=0)
        
        return $s;
 }
+/*
+function _adodb_find_from($sql) 
+{
+
+       $sql = str_replace(array("\n","\r"), ' ', $sql);
+       $charCount = strlen($sql);
+       
+       $inString = false;
+       $quote = '';
+       $parentheseCount = 0;
+       $prevChars = '';
+       $nextChars = '';
+       
+
+       for($i = 0; $i < $charCount; $i++) {
+
+       $char = substr($sql,$i,1);
+           $prevChars = substr($sql,0,$i);
+       $nextChars = substr($sql,$i+1);
+
+               if((($char == "'" || $char == '"' || $char == '`') && substr($prevChars,-1,1) != '\\') && $inString === false) {
+                       $quote = $char;
+                       $inString = true;
+               }
+
+               elseif((($char == "'" || $char == '"' || $char == '`') && substr($prevChars,-1,1) != '\\') && $inString === true && $quote == $char) {
+                       $quote = "";
+                       $inString = false;
+               }
+
+               elseif($char == "(" && $inString === false)
+                       $parentheseCount++;
+
+               elseif($char == ")" && $inString === false && $parentheseCount > 0)
+                       $parentheseCount--;
+
+               elseif($parentheseCount <= 0 && $inString === false && $char == " " && strtoupper(substr($prevChars,-5,5)) == " FROM")
+                       return $i;
+
+       }
+}
+*/
 
 ?>
\ No newline at end of file
index 91796effd644e0e052a4766dff7c5a38dc97f254..5567f7898ffa4517d8db719e2db045e9cbedd188 100755 (executable)
-<?php \r
-/*\r
- * Set tabs to 4 for best viewing.\r
- * \r
- * Latest version is available at http://adodb.sourceforge.net\r
- * \r
- * This is the main include file for ADOdb.\r
- * Database specific drivers are stored in the adodb/drivers/adodb-*.inc.php\r
- *\r
- * The ADOdb files are formatted so that doxygen can be used to generate documentation.\r
- * Doxygen is a documentation generation tool and can be downloaded from http://doxygen.org/\r
- */\r
-\r
-/**\r
-       \mainpage       \r
-       \r
-        @version V4.65 22 July 2005  (c) 2000-2005 John Lim (jlim#natsoft.com.my). All rights reserved.\r
-\r
-       Released under both BSD license and Lesser GPL library license. You can choose which license\r
-       you prefer.\r
-       \r
-       PHP's database access functions are not standardised. This creates a need for a database \r
-       class library to hide the differences between the different database API's (encapsulate \r
-       the differences) so we can easily switch databases.\r
-\r
-       We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, DB2,\r
-       Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access,\r
-       ADO, SAP DB, SQLite and ODBC. We have had successful reports of connecting to Progress and\r
-       other databases via ODBC.\r
-\r
-       Latest Download at http://php.weblogs.com/adodb<br>\r
-       Manual is at http://php.weblogs.com/adodb_manual\r
-         \r
- */\r
\r
- if (!defined('_ADODB_LAYER')) {\r
-       define('_ADODB_LAYER',1);\r
-       \r
-       //==============================================================================================        \r
-       // CONSTANT DEFINITIONS\r
-       //==============================================================================================        \r
-\r
-\r
-       /** \r
-        * Set ADODB_DIR to the directory where this file resides...\r
-        * This constant was formerly called $ADODB_RootPath\r
-        */\r
-       if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));\r
-       \r
-       //==============================================================================================        \r
-       // GLOBAL VARIABLES\r
-       //==============================================================================================        \r
-\r
-       GLOBAL \r
-               $ADODB_vers,            // database version\r
-               $ADODB_COUNTRECS,       // count number of records returned - slows down query\r
-               $ADODB_CACHE_DIR,       // directory to cache recordsets\r
-               $ADODB_EXTENSION,   // ADODB extension installed\r
-               $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF\r
-               $ADODB_FETCH_MODE;      // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...\r
-       \r
-       //==============================================================================================        \r
-       // GLOBAL SETUP\r
-       //==============================================================================================        \r
-       \r
-       $ADODB_EXTENSION = defined('ADODB_EXTENSION');\r
-       \r
-       //********************************************************//\r
-       /*\r
-       Controls $ADODB_FORCE_TYPE mode. Default is ADODB_FORCE_VALUE (3).\r
-       Used in GetUpdateSql and GetInsertSql functions. Thx to Niko, nuko#mbnet.fi\r
-\r
-               0 = ignore empty fields. All empty fields in array are ignored.\r
-               1 = force null. All empty, php null and string 'null' fields are changed to sql NULL values.\r
-               2 = force empty. All empty, php null and string 'null' fields are changed to sql empty '' or 0 values.\r
-               3 = force value. Value is left as it is. Php null and string 'null' are set to sql NULL values and empty fields '' are set to empty '' sql values.\r
-       */\r
-        define('ADODB_FORCE_IGNORE',0);\r
-        define('ADODB_FORCE_NULL',1);\r
-        define('ADODB_FORCE_EMPTY',2);\r
-        define('ADODB_FORCE_VALUE',3);\r
-    //********************************************************//\r
-\r
-\r
-       if (!$ADODB_EXTENSION || ADODB_EXTENSION < 4.0) {\r
-               \r
-               define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>');\r
-       \r
-       // allow [ ] @ ` " and . in table names\r
-               define('ADODB_TABLE_REGEX','([]0-9a-z_\:\"\`\.\@\[-]*)');\r
-       \r
-       // prefetching used by oracle\r
-               if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);\r
-       \r
-       \r
-       /*\r
-       Controls ADODB_FETCH_ASSOC field-name case. Default is 2, use native case-names.\r
-       This currently works only with mssql, odbc, oci8po and ibase derived drivers.\r
-       \r
-               0 = assoc lowercase field names. $rs->fields['orderid']\r
-               1 = assoc uppercase field names. $rs->fields['ORDERID']\r
-               2 = use native-case field names. $rs->fields['OrderID']\r
-       */\r
-       \r
-               define('ADODB_FETCH_DEFAULT',0);\r
-               define('ADODB_FETCH_NUM',1);\r
-               define('ADODB_FETCH_ASSOC',2);\r
-               define('ADODB_FETCH_BOTH',3);\r
-               \r
-               if (!defined('TIMESTAMP_FIRST_YEAR')) define('TIMESTAMP_FIRST_YEAR',100);\r
-       \r
-               // PHP's version scheme makes converting to numbers difficult - workaround\r
-               $_adodb_ver = (float) PHP_VERSION;\r
-               if ($_adodb_ver >= 5.0) {\r
-                       define('ADODB_PHPVER',0x5000);\r
-               } else if ($_adodb_ver > 4.299999) { # 4.3\r
-                       define('ADODB_PHPVER',0x4300);\r
-               } else if ($_adodb_ver > 4.199999) { # 4.2\r
-                       define('ADODB_PHPVER',0x4200);\r
-               } else if (strnatcmp(PHP_VERSION,'4.0.5')>=0) {\r
-                       define('ADODB_PHPVER',0x4050);\r
-               } else {\r
-                       define('ADODB_PHPVER',0x4000);\r
-               }\r
-       }\r
-       \r
-       //if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);\r
-\r
-       \r
-       /**\r
-               Accepts $src and $dest arrays, replacing string $data\r
-       */\r
-       function ADODB_str_replace($src, $dest, $data)\r
-       {\r
-               if (ADODB_PHPVER >= 0x4050) return str_replace($src,$dest,$data);\r
-               \r
-               $s = reset($src);\r
-               $d = reset($dest);\r
-               while ($s !== false) {\r
-                       $data = str_replace($s,$d,$data);\r
-                       $s = next($src);\r
-                       $d = next($dest);\r
-               }\r
-               return $data;\r
-       }\r
-       \r
-       function ADODB_Setup()\r
-       {\r
-       GLOBAL \r
-               $ADODB_vers,            // database version\r
-               $ADODB_COUNTRECS,       // count number of records returned - slows down query\r
-               $ADODB_CACHE_DIR,       // directory to cache recordsets\r
-               $ADODB_FETCH_MODE,\r
-               $ADODB_FORCE_TYPE;\r
-               \r
-               $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;\r
-               $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE;\r
-\r
-\r
-               if (!isset($ADODB_CACHE_DIR)) {\r
-                       $ADODB_CACHE_DIR = '/tmp'; //(isset($_ENV['TMP'])) ? $_ENV['TMP'] : '/tmp';\r
-               } else {\r
-                       // do not accept url based paths, eg. http:/ or ftp:/\r
-                       if (strpos($ADODB_CACHE_DIR,'://') !== false) \r
-                               die("Illegal path http:// or ftp://");\r
-               }\r
-               \r
-                       \r
-               // Initialize random number generator for randomizing cache flushes\r
-               srand(((double)microtime())*1000000);\r
-               \r
-               /**\r
-                * ADODB version as a string.\r
-                */\r
-               $ADODB_vers = 'V4.65 22 July 2005  (c) 2000-2005 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';\r
-       \r
-               /**\r
-                * Determines whether recordset->RecordCount() is used. \r
-                * Set to false for highest performance -- RecordCount() will always return -1 then\r
-                * for databases that provide "virtual" recordcounts...\r
-                */\r
-               if (!isset($ADODB_COUNTRECS)) $ADODB_COUNTRECS = true; \r
-       }\r
-       \r
-       \r
-       //==============================================================================================        \r
-       // CHANGE NOTHING BELOW UNLESS YOU ARE DESIGNING ADODB\r
-       //==============================================================================================        \r
-       \r
-       ADODB_Setup();\r
-\r
-       //==============================================================================================        \r
-       // CLASS ADOFieldObject\r
-       //==============================================================================================        \r
-       /**\r
-        * Helper class for FetchFields -- holds info on a column\r
-        */\r
-       class ADOFieldObject { \r
-               var $name = '';\r
-               var $max_length=0;\r
-               var $type="";\r
-/*\r
-               // additional fields by dannym... (danny_milo@yahoo.com)\r
-               var $not_null = false; \r
-               // actually, this has already been built-in in the postgres, fbsql AND mysql module? ^-^\r
-               // so we can as well make not_null standard (leaving it at "false" does not harm anyways)\r
-\r
-               var $has_default = false; // this one I have done only in mysql and postgres for now ... \r
-                       // others to come (dannym)\r
-               var $default_value; // default, if any, and supported. Check has_default first.\r
-*/\r
-       }\r
-       \r
-\r
-       \r
-       function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)\r
-       {\r
-               //print "Errorno ($fn errno=$errno m=$errmsg) ";\r
-               $thisConnection->_transOK = false;\r
-               if ($thisConnection->_oldRaiseFn) {\r
-                       $fn = $thisConnection->_oldRaiseFn;\r
-                       $fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection);\r
-               }\r
-       }\r
-       \r
-       //==============================================================================================        \r
-       // CLASS ADOConnection\r
-       //==============================================================================================        \r
-       \r
-       /**\r
-        * Connection object. For connecting to databases, and executing queries.\r
-        */ \r
-       class ADOConnection {\r
-       //\r
-       // PUBLIC VARS \r
-       //\r
-       var $dataProvider = 'native';\r
-       var $databaseType = '';         /// RDBMS currently in use, eg. odbc, mysql, mssql                                      \r
-       var $database = '';                     /// Name of database to be used.        \r
-       var $host = '';                         /// The hostname of the database server \r
-       var $user = '';                         /// The username which is used to connect to the database server. \r
-       var $password = '';             /// Password for the username. For security, we no longer store it.\r
-       var $debug = false;             /// if set to true will output sql statements\r
-       var $maxblobsize = 262144;      /// maximum size of blobs or large text fields (262144 = 256K)-- some db's die otherwise like foxpro\r
-       var $concat_operator = '+'; /// default concat operator -- change to || for Oracle/Interbase    \r
-       var $substr = 'substr';         /// substring operator\r
-       var $length = 'length';         /// string length ofperator\r
-       var $random = 'rand()';         /// random function\r
-       var $upperCase = 'upper';               /// uppercase function\r
-       var $fmtDate = "'Y-m-d'";       /// used by DBDate() as the default date format used by the database\r
-       var $fmtTimeStamp = "'Y-m-d, h:i:s A'"; /// used by DBTimeStamp as the default timestamp fmt.\r
-       var $true = '1';                        /// string that represents TRUE for a database\r
-       var $false = '0';                       /// string that represents FALSE for a database\r
-       var $replaceQuote = "\\'";      /// string to use to replace quotes\r
-       var $nameQuote = '"';           /// string to use to quote identifiers and names\r
-       var $charSet=false;             /// character set to use - only for interbase, postgres and oci8\r
-       var $metaDatabasesSQL = '';\r
-       var $metaTablesSQL = '';\r
-       var $uniqueOrderBy = false; /// All order by columns have to be unique\r
-       var $emptyDate = '&nbsp;';\r
-       var $emptyTimeStamp = '&nbsp;';\r
-       var $lastInsID = false;\r
-       //--\r
-       var $hasInsertID = false;               /// supports autoincrement ID?\r
-       var $hasAffectedRows = false;   /// supports affected rows for update/delete?\r
-       var $hasTop = false;                    /// support mssql/access SELECT TOP 10 * FROM TABLE\r
-       var $hasLimit = false;                  /// support pgsql/mysql SELECT * FROM TABLE LIMIT 10\r
-       var $readOnly = false;                  /// this is a readonly database - used by phpLens\r
-       var $hasMoveFirst = false;  /// has ability to run MoveFirst(), scrolling backwards\r
-       var $hasGenID = false;          /// can generate sequences using GenID();\r
-       var $hasTransactions = true; /// has transactions\r
-       //--\r
-       var $genID = 0;                         /// sequence id used by GenID();\r
-       var $raiseErrorFn = false;      /// error function to call\r
-       var $isoDates = false; /// accepts dates in ISO format\r
-       var $cacheSecs = 3600; /// cache for 1 hour\r
-       var $sysDate = false; /// name of function that returns the current date\r
-       var $sysTimeStamp = false; /// name of function that returns the current timestamp\r
-       var $arrayClass = 'ADORecordSet_array'; /// name of class used to generate array recordsets, which are pre-downloaded recordsets\r
-       \r
-       var $noNullStrings = false; /// oracle specific stuff - if true ensures that '' is converted to ' '\r
-       var $numCacheHits = 0; \r
-       var $numCacheMisses = 0;\r
-       var $pageExecuteCountRows = true;\r
-       var $uniqueSort = false; /// indicates that all fields in order by must be unique\r
-       var $leftOuter = false; /// operator to use for left outer join in WHERE clause\r
-       var $rightOuter = false; /// operator to use for right outer join in WHERE clause\r
-       var $ansiOuter = false; /// whether ansi outer join syntax supported\r
-       var $autoRollback = false; // autoRollback on PConnect().\r
-       var $poorAffectedRows = false; // affectedRows not working or unreliable\r
-       \r
-       var $fnExecute = false;\r
-       var $fnCacheExecute = false;\r
-       var $blobEncodeType = false; // false=not required, 'I'=encode to integer, 'C'=encode to char\r
-       var $rsPrefix = "ADORecordSet_";\r
-       \r
-       var $autoCommit = true;         /// do not modify this yourself - actually private\r
-       var $transOff = 0;                      /// temporarily disable transactions\r
-       var $transCnt = 0;                      /// count of nested transactions\r
-       \r
-       var $fetchMode=false;\r
-        //\r
-        // PRIVATE VARS\r
-        //\r
-       var $_oldRaiseFn =  false;\r
-       var $_transOK = null;\r
-       var $_connectionID      = false;        /// The returned link identifier whenever a successful database connection is made.     \r
-       var $_errorMsg = false;         /// A variable which was used to keep the returned last error message.  The value will\r
-                                                               /// then returned by the errorMsg() function    \r
-       var $_errorCode = false;        /// Last error code, not guaranteed to be used - only by oci8                                   \r
-       var $_queryID = false;          /// This variable keeps the last created result link identifier\r
-       \r
-       var $_isPersistentConnection = false;   /// A boolean variable to state whether its a persistent connection or normal connection.       */\r
-       var $_bindInputArray = false; /// set to true if ADOConnection.Execute() permits binding of array parameters.\r
-       var $_evalAll = false;\r
-       var $_affected = false;\r
-       var $_logsql = false;\r
-       \r
-\r
-       \r
-       /**\r
-        * Constructor\r
-        */\r
-       function ADOConnection()                        \r
-       {\r
-               die('Virtual Class -- cannot instantiate');\r
-       }\r
-       \r
-       function Version()\r
-       {\r
-       global $ADODB_vers;\r
-       \r
-               return (float) substr($ADODB_vers,1);\r
-       }\r
-       \r
-       /**\r
-               Get server version info...\r
-               \r
-               @returns An array with 2 elements: $arr['string'] is the description string, \r
-                       and $arr[version] is the version (also a string).\r
-       */\r
-       function ServerInfo()\r
-       {\r
-               return array('description' => '', 'version' => '');\r
-       }\r
-       \r
-       function IsConnected()\r
-       {\r
-       return !empty($this->_connectionID);\r
-       }\r
-       \r
-       function _findvers($str)\r
-       {\r
-               if (preg_match('/([0-9]+\.([0-9\.])+)/',$str, $arr)) return $arr[1];\r
-               else return '';\r
-       }\r
-       \r
-       /**\r
-       * All error messages go through this bottleneck function.\r
-       * You can define your own handler by defining the function name in ADODB_OUTP.\r
-       */\r
-       function outp($msg,$newline=true)\r
-       {\r
-       global $ADODB_FLUSH,$ADODB_OUTP;\r
-       \r
-               if (defined('ADODB_OUTP')) {\r
-                       $fn = ADODB_OUTP;\r
-                       $fn($msg,$newline);\r
-                       return;\r
-               } else if (isset($ADODB_OUTP)) {\r
-                       $fn = $ADODB_OUTP;\r
-                       $fn($msg,$newline);\r
-                       return;\r
-               }\r
-               \r
-               if ($newline) $msg .= "<br>\n";\r
-               \r
-               if (isset($_SERVER['HTTP_USER_AGENT']) || !$newline) echo $msg;\r
-               else echo strip_tags($msg);\r
-       \r
-               \r
-               if (!empty($ADODB_FLUSH) && ob_get_length() !== false) flush(); //  do not flush if output buffering enabled - useless - thx to Jesse Mullan \r
-               \r
-       }\r
-       \r
-       function Time()\r
-       {\r
-               $rs =& $this->_Execute("select $this->sysTimeStamp");\r
-               if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields));\r
-               \r
-               return false;\r
-       }\r
-       \r
-       /**\r
-        * Connect to database\r
-        *\r
-        * @param [argHostname]         Host to connect to\r
-        * @param [argUsername]         Userid to login\r
-        * @param [argPassword]         Associated password\r
-        * @param [argDatabaseName]     database\r
-        * @param [forceNew]            force new connection\r
-        *\r
-        * @return true or false\r
-        */       \r
-       function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "", $forceNew = false) \r
-       {\r
-               if ($argHostname != "") $this->host = $argHostname;\r
-               if ($argUsername != "") $this->user = $argUsername;\r
-               if ($argPassword != "") $this->password = $argPassword; // not stored for security reasons\r
-               if ($argDatabaseName != "") $this->database = $argDatabaseName;         \r
-               \r
-               $this->_isPersistentConnection = false; \r
-               if ($forceNew) {\r
-                       if ($rez=$this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
-               } else {\r
-                        if ($rez=$this->_connect($this->host, $this->user, $this->password, $this->database)) return true;\r
-               }\r
-               if (isset($rez)) {\r
-                       $err = $this->ErrorMsg();\r
-                       if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";\r
-                       $ret = false;\r
-               } else {\r
-                       $err = "Missing extension for ".$this->dataProvider;\r
-                       $ret = 0;\r
-               }\r
-               if ($fn = $this->raiseErrorFn) \r
-                       $fn($this->databaseType,'CONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);\r
-               \r
-               \r
-               $this->_connectionID = false;\r
-               if ($this->debug) ADOConnection::outp( $this->host.': '.$err);\r
-               return $ret;\r
-       }       \r
-       \r
-       function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName)\r
-       {\r
-               return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName);\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Always force a new connection to database - currently only works with oracle\r
-        *\r
-        * @param [argHostname]         Host to connect to\r
-        * @param [argUsername]         Userid to login\r
-        * @param [argPassword]         Associated password\r
-        * @param [argDatabaseName]     database\r
-        *\r
-        * @return true or false\r
-        */       \r
-       function NConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") \r
-       {\r
-               return $this->Connect($argHostname, $argUsername, $argPassword, $argDatabaseName, true);\r
-       }\r
-       \r
-       /**\r
-        * Establish persistent connect to database\r
-        *\r
-        * @param [argHostname]         Host to connect to\r
-        * @param [argUsername]         Userid to login\r
-        * @param [argPassword]         Associated password\r
-        * @param [argDatabaseName]     database\r
-        *\r
-        * @return return true or false\r
-        */     \r
-       function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "")\r
-       {\r
-               if (defined('ADODB_NEVER_PERSIST')) \r
-                       return $this->Connect($argHostname,$argUsername,$argPassword,$argDatabaseName);\r
-               \r
-               if ($argHostname != "") $this->host = $argHostname;\r
-               if ($argUsername != "") $this->user = $argUsername;\r
-               if ($argPassword != "") $this->password = $argPassword;\r
-               if ($argDatabaseName != "") $this->database = $argDatabaseName;         \r
-                       \r
-               $this->_isPersistentConnection = true;  \r
-               if ($rez = $this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
-               if (isset($rez)) {\r
-                       $err = $this->ErrorMsg();\r
-                       if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";\r
-                       $ret = false;\r
-               } else {\r
-                       $err = "Missing extension for ".$this->dataProvider;\r
-                       $ret = 0;\r
-               }\r
-               if ($fn = $this->raiseErrorFn) {\r
-                       $fn($this->databaseType,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);\r
-               }\r
-               \r
-               $this->_connectionID = false;\r
-               if ($this->debug) ADOConnection::outp( $this->host.': '.$err);\r
-               return $ret;\r
-       }\r
-\r
-       // Format date column in sql string given an input format that understands Y M D\r
-       function SQLDate($fmt, $col=false)\r
-       {       \r
-               if (!$col) $col = $this->sysDate;\r
-               return $col; // child class implement\r
-       }\r
-       \r
-       /**\r
-        * Should prepare the sql statement and return the stmt resource.\r
-        * For databases that do not support this, we return the $sql. To ensure\r
-        * compatibility with databases that do not support prepare:\r
-        *\r
-        *   $stmt = $db->Prepare("insert into table (id, name) values (?,?)");\r
-        *   $db->Execute($stmt,array(1,'Jill')) or die('insert failed');\r
-        *   $db->Execute($stmt,array(2,'Joe')) or die('insert failed');\r
-        *\r
-        * @param sql   SQL to send to database\r
-        *\r
-        * @return return FALSE, or the prepared statement, or the original sql if\r
-        *                      if the database does not support prepare.\r
-        *\r
-        */     \r
-       function Prepare($sql)\r
-       {\r
-               return $sql;\r
-       }\r
-       \r
-       /**\r
-        * Some databases, eg. mssql require a different function for preparing\r
-        * stored procedures. So we cannot use Prepare().\r
-        *\r
-        * Should prepare the stored procedure  and return the stmt resource.\r
-        * For databases that do not support this, we return the $sql. To ensure\r
-        * compatibility with databases that do not support prepare:\r
-        *\r
-        * @param sql   SQL to send to database\r
-        *\r
-        * @return return FALSE, or the prepared statement, or the original sql if\r
-        *                      if the database does not support prepare.\r
-        *\r
-        */     \r
-       function PrepareSP($sql,$param=true)\r
-       {\r
-               return $this->Prepare($sql,$param);\r
-       }\r
-       \r
-       /**\r
-       * PEAR DB Compat\r
-       */\r
-       function Quote($s)\r
-       {\r
-               return $this->qstr($s,false);\r
-       }\r
-       \r
-       /**\r
-        Requested by "Karsten Dambekalns" <k.dambekalns@fishfarm.de>\r
-       */\r
-       function QMagic($s)\r
-       {\r
-               return $this->qstr($s,get_magic_quotes_gpc());\r
-       }\r
-\r
-       function q(&$s)\r
-       {\r
-               $s = $this->qstr($s,false);\r
-       }\r
-       \r
-       /**\r
-       * PEAR DB Compat - do not use internally. \r
-       */\r
-       function ErrorNative()\r
-       {\r
-               return $this->ErrorNo();\r
-       }\r
-\r
-       \r
-   /**\r
-       * PEAR DB Compat - do not use internally. \r
-       */\r
-       function nextId($seq_name)\r
-       {\r
-               return $this->GenID($seq_name);\r
-       }\r
-\r
-       /**\r
-       *        Lock a row, will escalate and lock the table if row locking not supported\r
-       *       will normally free the lock at the end of the transaction\r
-       *\r
-       *  @param $table        name of table to lock\r
-       *  @param $where        where clause to use, eg: "WHERE row=12". If left empty, will escalate to table lock\r
-       */\r
-       function RowLock($table,$where)\r
-       {\r
-               return false;\r
-       }\r
-       \r
-       function CommitLock($table)\r
-       {\r
-               return $this->CommitTrans();\r
-       }\r
-       \r
-       function RollbackLock($table)\r
-       {\r
-               return $this->RollbackTrans();\r
-       }\r
-       \r
-       /**\r
-       * PEAR DB Compat - do not use internally. \r
-       *\r
-       * The fetch modes for NUMERIC and ASSOC for PEAR DB and ADODB are identical\r
-       *       for easy porting :-)\r
-       *\r
-       * @param mode   The fetchmode ADODB_FETCH_ASSOC or ADODB_FETCH_NUM\r
-       * @returns              The previous fetch mode\r
-       */\r
-       function SetFetchMode($mode)\r
-       {       \r
-               $old = $this->fetchMode;\r
-               $this->fetchMode = $mode;\r
-               \r
-               if ($old === false) {\r
-               global $ADODB_FETCH_MODE;\r
-                       return $ADODB_FETCH_MODE;\r
-               }\r
-               return $old;\r
-       }\r
-       \r
-\r
-       /**\r
-       * PEAR DB Compat - do not use internally. \r
-       */\r
-       function &Query($sql, $inputarr=false)\r
-       {\r
-               $rs = &$this->Execute($sql, $inputarr);\r
-               if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();\r
-               return $rs;\r
-       }\r
-\r
-       \r
-       /**\r
-       * PEAR DB Compat - do not use internally\r
-       */\r
-       function &LimitQuery($sql, $offset, $count, $params=false)\r
-       {\r
-               $rs = &$this->SelectLimit($sql, $count, $offset, $params); \r
-               if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();\r
-               return $rs;\r
-       }\r
-\r
-       \r
-       /**\r
-       * PEAR DB Compat - do not use internally\r
-       */\r
-       function Disconnect()\r
-       {\r
-               return $this->Close();\r
-       }\r
-       \r
-       /*\r
-                Returns placeholder for parameter, eg.\r
-                $DB->Param('a')\r
-                \r
-                will return ':a' for Oracle, and '?' for most other databases...\r
-                \r
-                For databases that require positioned params, eg $1, $2, $3 for postgresql,\r
-                       pass in Param(false) before setting the first parameter.\r
-       */\r
-       function Param($name,$type='C')\r
-       {\r
-               return '?';\r
-       }\r
-       \r
-       /*\r
-               InParameter and OutParameter are self-documenting versions of Parameter().\r
-       */\r
-       function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)\r
-       {\r
-               return $this->Parameter($stmt,$var,$name,false,$maxLen,$type);\r
-       }\r
-       \r
-       /*\r
-       */\r
-       function OutParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)\r
-       {\r
-               return $this->Parameter($stmt,$var,$name,true,$maxLen,$type);\r
-       \r
-       }\r
-       \r
-       /* \r
-       Usage in oracle\r
-               $stmt = $db->Prepare('select * from table where id =:myid and group=:group');\r
-               $db->Parameter($stmt,$id,'myid');\r
-               $db->Parameter($stmt,$group,'group',64);\r
-               $db->Execute();\r
-               \r
-               @param $stmt Statement returned by Prepare() or PrepareSP().\r
-               @param $var PHP variable to bind to\r
-               @param $name Name of stored procedure variable name to bind to.\r
-               @param [$isOutput] Indicates direction of parameter 0/false=IN  1=OUT  2= IN/OUT. This is ignored in oci8.\r
-               @param [$maxLen] Holds an maximum length of the variable.\r
-               @param [$type] The data type of $var. Legal values depend on driver.\r
-\r
-       */\r
-       function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false)\r
-       {\r
-               return false;\r
-       }\r
-       \r
-       /**\r
-               Improved method of initiating a transaction. Used together with CompleteTrans().\r
-               Advantages include:\r
-               \r
-               a. StartTrans/CompleteTrans is nestable, unlike BeginTrans/CommitTrans/RollbackTrans.\r
-                  Only the outermost block is treated as a transaction.<br>\r
-               b. CompleteTrans auto-detects SQL errors, and will rollback on errors, commit otherwise.<br>\r
-               c. All BeginTrans/CommitTrans/RollbackTrans inside a StartTrans/CompleteTrans block\r
-                  are disabled, making it backward compatible.\r
-       */\r
-       function StartTrans($errfn = 'ADODB_TransMonitor')\r
-       {\r
-               if ($this->transOff > 0) {\r
-                       $this->transOff += 1;\r
-                       return;\r
-               }\r
-               \r
-               $this->_oldRaiseFn = $this->raiseErrorFn;\r
-               $this->raiseErrorFn = $errfn;\r
-               $this->_transOK = true;\r
-               \r
-               if ($this->debug && $this->transCnt > 0) ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans");\r
-               $this->BeginTrans();\r
-               $this->transOff = 1;\r
-       }\r
-       \r
-       \r
-       /**\r
-               Used together with StartTrans() to end a transaction. Monitors connection\r
-               for sql errors, and will commit or rollback as appropriate.\r
-               \r
-               @autoComplete if true, monitor sql errors and commit and rollback as appropriate, \r
-               and if set to false force rollback even if no SQL error detected.\r
-               @returns true on commit, false on rollback.\r
-       */\r
-       function CompleteTrans($autoComplete = true)\r
-       {\r
-               if ($this->transOff > 1) {\r
-                       $this->transOff -= 1;\r
-                       return true;\r
-               }\r
-               $this->raiseErrorFn = $this->_oldRaiseFn;\r
-               \r
-               $this->transOff = 0;\r
-               if ($this->_transOK && $autoComplete) {\r
-                       if (!$this->CommitTrans()) {\r
-                               $this->_transOK = false;\r
-                               if ($this->debug) ADOConnection::outp("Smart Commit failed");\r
-                       } else\r
-                               if ($this->debug) ADOConnection::outp("Smart Commit occurred");\r
-               } else {\r
-                       $this->_transOK = false;\r
-                       $this->RollbackTrans();\r
-                       if ($this->debug) ADOCOnnection::outp("Smart Rollback occurred");\r
-               }\r
-               \r
-               return $this->_transOK;\r
-       }\r
-       \r
-       /*\r
-               At the end of a StartTrans/CompleteTrans block, perform a rollback.\r
-       */\r
-       function FailTrans()\r
-       {\r
-               if ($this->debug) \r
-                       if ($this->transOff == 0) {\r
-                               ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans");\r
-                       } else {\r
-                               ADOConnection::outp("FailTrans was called");\r
-                               adodb_backtrace();\r
-                       }\r
-               $this->_transOK = false;\r
-       }\r
-       \r
-       /**\r
-               Check if transaction has failed, only for Smart Transactions.\r
-       */\r
-       function HasFailedTrans()\r
-       {\r
-               if ($this->transOff > 0) return $this->_transOK == false;\r
-               return false;\r
-       }\r
-       \r
-       /**\r
-        * Execute SQL \r
-        *\r
-        * @param sql           SQL statement to execute, or possibly an array holding prepared statement ($sql[0] will hold sql text)\r
-        * @param [inputarr]    holds the input data to bind to. Null elements will be set to null.\r
-        * @return              RecordSet or false\r
-        */\r
-       function &Execute($sql,$inputarr=false) \r
-       {\r
-               if ($this->fnExecute) {\r
-                       $fn = $this->fnExecute;\r
-                       $ret =& $fn($this,$sql,$inputarr);\r
-                       if (isset($ret)) return $ret;\r
-               }\r
-               if ($inputarr) {\r
-                       if (!is_array($inputarr)) $inputarr = array($inputarr);\r
-                       \r
-                       $element0 = reset($inputarr);\r
-                       # is_object check because oci8 descriptors can be passed in\r
-                       $array_2d = is_array($element0) && !is_object(reset($element0));\r
-                       \r
-                       if (!is_array($sql) && !$this->_bindInputArray) {\r
-                               $sqlarr = explode('?',$sql);\r
-                                       \r
-                               if (!$array_2d) $inputarr = array($inputarr);\r
-                               foreach($inputarr as $arr) {\r
-                                       $sql = ''; $i = 0;\r
-                                       foreach($arr as $v) {\r
-                                               $sql .= $sqlarr[$i];\r
-                                               // from Ron Baldwin <ron.baldwin#sourceprose.com>\r
-                                               // Only quote string types      \r
-                                               $typ = gettype($v);\r
-                                               if ($typ == 'string')\r
-                                                       $sql .= $this->qstr($v);\r
-                                               else if ($typ == 'double')\r
-                                                       $sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1\r
-                                               else if ($typ == 'boolean')\r
-                                                       $sql .= $v ? $this->true : $this->false;\r
-                                               else if ($v === null)\r
-                                                       $sql .= 'NULL';\r
-                                               else\r
-                                                       $sql .= $v;\r
-                                               $i += 1;\r
-                                       }\r
-                                       if (isset($sqlarr[$i])) {\r
-                                               $sql .= $sqlarr[$i];\r
-                                               if ($i+1 != sizeof($sqlarr)) ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql));\r
-                                       } else if ($i != sizeof($sqlarr))       \r
-                                               ADOConnection::outp( "Input array does not match ?: ".htmlspecialchars($sql));\r
-               \r
-                                       $ret =& $this->_Execute($sql);\r
-                                       if (!$ret) return $ret;\r
-                               }       \r
-                       } else {\r
-                               if ($array_2d) {\r
-                                       if (is_string($sql))\r
-                                               $stmt = $this->Prepare($sql);\r
-                                       else\r
-                                               $stmt = $sql;\r
-                                               \r
-                                       foreach($inputarr as $arr) {\r
-                                               $ret =& $this->_Execute($stmt,$arr);\r
-                                               if (!$ret) return $ret;\r
-                                       }\r
-                               } else {\r
-                                       $ret =& $this->_Execute($sql,$inputarr);\r
-                               }\r
-                       }\r
-               } else {\r
-                       $ret =& $this->_Execute($sql,false);\r
-               }\r
-\r
-               return $ret;\r
-       }\r
-       \r
-       \r
-       function &_Execute($sql,$inputarr=false)\r
-       {\r
-\r
-               if ($this->debug) {\r
-                       global $ADODB_INCLUDED_LIB;\r
-                       if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-                       $this->_queryID = _adodb_debug_execute($this, $sql,$inputarr);\r
-               } else {\r
-                       $this->_queryID = @$this->_query($sql,$inputarr);\r
-               }\r
-               \r
-               /************************\r
-               // OK, query executed\r
-               *************************/\r
-\r
-               if ($this->_queryID === false) { // error handling if query fails\r
-                       if ($this->debug == 99) adodb_backtrace(true,5);        \r
-                       $fn = $this->raiseErrorFn;\r
-                       if ($fn) {\r
-                               $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr,$this);\r
-                       } \r
-                       $false = false;\r
-                       return $false;\r
-               } \r
-               \r
-               if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead\r
-                       $rs =& new ADORecordSet_empty();\r
-                       return $rs;\r
-               }\r
-               \r
-               // return real recordset from select statement\r
-               $rsclass = $this->rsPrefix.$this->databaseType;\r
-               $rs = new $rsclass($this->_queryID,$this->fetchMode);\r
-               $rs->connection = &$this; // Pablo suggestion\r
-               $rs->Init();\r
-               if (is_array($sql)) $rs->sql = $sql[0];\r
-               else $rs->sql = $sql;\r
-               if ($rs->_numOfRows <= 0) {\r
-               global $ADODB_COUNTRECS;\r
-                       if ($ADODB_COUNTRECS) {\r
-                               if (!$rs->EOF) { \r
-                                       $rs = &$this->_rs2rs($rs,-1,-1,!is_array($sql));\r
-                                       $rs->_queryID = $this->_queryID;\r
-                               } else\r
-                                       $rs->_numOfRows = 0;\r
-                       }\r
-               }\r
-               return $rs;\r
-       }\r
-\r
-       function CreateSequence($seqname='adodbseq',$startID=1)\r
-       {\r
-               if (empty($this->_genSeqSQL)) return false;\r
-               return $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID));\r
-       }\r
-\r
-       function DropSequence($seqname='adodbseq')\r
-       {\r
-               if (empty($this->_dropSeqSQL)) return false;\r
-               return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));\r
-       }\r
-\r
-       /**\r
-        * Generates a sequence id and stores it in $this->genID;\r
-        * GenID is only available if $this->hasGenID = true;\r
-        *\r
-        * @param seqname               name of sequence to use\r
-        * @param startID               if sequence does not exist, start at this ID\r
-        * @return              0 if not supported, otherwise a sequence id\r
-        */\r
-       function GenID($seqname='adodbseq',$startID=1)\r
-       {\r
-               if (!$this->hasGenID) {\r
-                       return 0; // formerly returns false pre 1.60\r
-               }\r
-               \r
-               $getnext = sprintf($this->_genIDSQL,$seqname);\r
-               \r
-               $holdtransOK = $this->_transOK;\r
-               \r
-               $save_handler = $this->raiseErrorFn;\r
-               $this->raiseErrorFn = '';\r
-               @($rs = $this->Execute($getnext));\r
-               $this->raiseErrorFn = $save_handler;\r
-               \r
-               if (!$rs) {\r
-                       $this->_transOK = $holdtransOK; //if the status was ok before reset\r
-                       $createseq = $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID));\r
-                       $rs = $this->Execute($getnext);\r
-               }\r
-               if ($rs && !$rs->EOF) $this->genID = reset($rs->fields);\r
-               else $this->genID = 0; // false\r
-       \r
-               if ($rs) $rs->Close();\r
-\r
-               return $this->genID;\r
-       }       \r
-\r
-       /**\r
-        * @param $table string name of the table, not needed by all databases (eg. mysql), default ''\r
-        * @param $column string name of the column, not needed by all databases (eg. mysql), default ''\r
-        * @return  the last inserted ID. Not all databases support this.\r
-        */ \r
-       function Insert_ID($table='',$column='')\r
-       {\r
-               if ($this->_logsql && $this->lastInsID) return $this->lastInsID;\r
-               if ($this->hasInsertID) return $this->_insertid($table,$column);\r
-               if ($this->debug) {\r
-                       ADOConnection::outp( '<p>Insert_ID error</p>');\r
-                       adodb_backtrace();\r
-               }\r
-               return false;\r
-       }\r
-\r
-\r
-       /**\r
-        * Portable Insert ID. Pablo Roca <pabloroca#mvps.org>\r
-        *\r
-        * @return  the last inserted ID. All databases support this. But aware possible\r
-        * problems in multiuser environments. Heavy test this before deploying.\r
-        */ \r
-       function PO_Insert_ID($table="", $id="") \r
-       {\r
-          if ($this->hasInsertID){\r
-                  return $this->Insert_ID($table,$id);\r
-          } else {\r
-                  return $this->GetOne("SELECT MAX($id) FROM $table");\r
-          }\r
-       }\r
-\r
-       /**\r
-       * @return # rows affected by UPDATE/DELETE\r
-       */ \r
-       function Affected_Rows()\r
-       {\r
-               if ($this->hasAffectedRows) {\r
-                       if ($this->fnExecute === 'adodb_log_sql') {\r
-                               if ($this->_logsql && $this->_affected !== false) return $this->_affected;\r
-                       }\r
-                       $val = $this->_affectedrows();\r
-                       return ($val < 0) ? false : $val;\r
-               }\r
-                                 \r
-               if ($this->debug) ADOConnection::outp( '<p>Affected_Rows error</p>',false);\r
-               return false;\r
-       }\r
-       \r
-       \r
-       /**\r
-        * @return  the last error message\r
-        */\r
-       function ErrorMsg()\r
-       {\r
-               if ($this->_errorMsg) return '!! '.strtoupper($this->dataProvider.' '.$this->databaseType).': '.$this->_errorMsg;\r
-               else return '';\r
-       }\r
-       \r
-       \r
-       /**\r
-        * @return the last error number. Normally 0 means no error.\r
-        */\r
-       function ErrorNo() \r
-       {\r
-               return ($this->_errorMsg) ? -1 : 0;\r
-       }\r
-       \r
-       function MetaError($err=false)\r
-       {\r
-               include_once(ADODB_DIR."/adodb-error.inc.php");\r
-               if ($err === false) $err = $this->ErrorNo();\r
-               return adodb_error($this->dataProvider,$this->databaseType,$err);\r
-       }\r
-       \r
-       function MetaErrorMsg($errno)\r
-       {\r
-               include_once(ADODB_DIR."/adodb-error.inc.php");\r
-               return adodb_errormsg($errno);\r
-       }\r
-       \r
-       /**\r
-        * @returns an array with the primary key columns in it.\r
-        */\r
-       function MetaPrimaryKeys($table, $owner=false)\r
-       {\r
-       // owner not used in base class - see oci8\r
-               $p = array();\r
-               $objs =& $this->MetaColumns($table);\r
-               if ($objs) {\r
-                       foreach($objs as $v) {\r
-                               if (!empty($v->primary_key))\r
-                                       $p[] = $v->name;\r
-                       }\r
-               }\r
-               if (sizeof($p)) return $p;\r
-               if (function_exists('ADODB_VIEW_PRIMARYKEYS'))\r
-                       return ADODB_VIEW_PRIMARYKEYS($this->databaseType, $this->database, $table, $owner);\r
-               return false;\r
-       }\r
-       \r
-       /**\r
-        * @returns assoc array where keys are tables, and values are foreign keys\r
-        */\r
-       function MetaForeignKeys($table, $owner=false, $upper=false)\r
-       {\r
-               return false;\r
-       }\r
-       /**\r
-        * Choose a database to connect to. Many databases do not support this.\r
-        *\r
-        * @param dbName        is the name of the database to select\r
-        * @return              true or false\r
-        */\r
-       function SelectDB($dbName) \r
-       {return false;}\r
-       \r
-       \r
-       /**\r
-       * Will select, getting rows from $offset (1-based), for $nrows. \r
-       * This simulates the MySQL "select * from table limit $offset,$nrows" , and\r
-       * the PostgreSQL "select * from table limit $nrows offset $offset". Note that\r
-       * MySQL and PostgreSQL parameter ordering is the opposite of the other.\r
-       * eg. \r
-       *  SelectLimit('select * from table',3); will return rows 1 to 3 (1-based)\r
-       *  SelectLimit('select * from table',3,2); will return rows 3 to 5 (1-based)\r
-       *\r
-       * Uses SELECT TOP for Microsoft databases (when $this->hasTop is set)\r
-       * BUG: Currently SelectLimit fails with $sql with LIMIT or TOP clause already set\r
-       *\r
-       * @param sql\r
-       * @param [offset]       is the row to start calculations from (1-based)\r
-       * @param [nrows]                is the number of rows to get\r
-       * @param [inputarr]     array of bind variables\r
-       * @param [secs2cache]           is a private parameter only used by jlim\r
-       * @return               the recordset ($rs->databaseType == 'array')\r
-       */\r
-       function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)\r
-       {\r
-               if ($this->hasTop && $nrows > 0) {\r
-               // suggested by Reinhard Balling. Access requires top after distinct \r
-                // Informix requires first before distinct - F Riosa\r
-                       $ismssql = (strpos($this->databaseType,'mssql') !== false);\r
-                       if ($ismssql) $isaccess = false;\r
-                       else $isaccess = (strpos($this->databaseType,'access') !== false);\r
-                       \r
-                       if ($offset <= 0) {\r
-                               \r
-                                       // access includes ties in result\r
-                                       if ($isaccess) {\r
-                                               $sql = preg_replace(\r
-                                               '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.$nrows.' ',$sql);\r
-\r
-                                               if ($secs2cache>0) {\r
-                                                       $ret =& $this->CacheExecute($secs2cache, $sql,$inputarr);\r
-                                               } else {\r
-                                                       $ret =& $this->Execute($sql,$inputarr);\r
-                                               }\r
-                                               return $ret; // PHP5 fix\r
-                                       } else if ($ismssql){\r
-                                               $sql = preg_replace(\r
-                                               '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.$nrows.' ',$sql);\r
-                                       } else {\r
-                                               $sql = preg_replace(\r
-                                               '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.$nrows.' ',$sql);\r
-                                       }\r
-                       } else {\r
-                               $nn = $nrows + $offset;\r
-                               if ($isaccess || $ismssql) {\r
-                                       $sql = preg_replace(\r
-                                       '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql);\r
-                               } else {\r
-                                       $sql = preg_replace(\r
-                                       '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql);\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               // if $offset>0, we want to skip rows, and $ADODB_COUNTRECS is set, we buffer  rows\r
-               // 0 to offset-1 which will be discarded anyway. So we disable $ADODB_COUNTRECS.\r
-               global $ADODB_COUNTRECS;\r
-               \r
-               $savec = $ADODB_COUNTRECS;\r
-               $ADODB_COUNTRECS = false;\r
-                       \r
-               if ($offset>0){\r
-                       if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);\r
-                       else $rs = &$this->Execute($sql,$inputarr);\r
-               } else {\r
-                       if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);\r
-                       else $rs = &$this->Execute($sql,$inputarr);\r
-               }\r
-               $ADODB_COUNTRECS = $savec;\r
-               if ($rs && !$rs->EOF) {\r
-                       $rs =& $this->_rs2rs($rs,$nrows,$offset);\r
-               }\r
-               //print_r($rs);\r
-               return $rs;\r
-       }\r
-       \r
-       /**\r
-       * Create serializable recordset. Breaks rs link to connection.\r
-       *\r
-       * @param rs                     the recordset to serialize\r
-       */\r
-       function &SerializableRS(&$rs)\r
-       {\r
-               $rs2 =& $this->_rs2rs($rs);\r
-               $ignore = false;\r
-               $rs2->connection =& $ignore;\r
-               \r
-               return $rs2;\r
-       }\r
-       \r
-       /**\r
-       * Convert database recordset to an array recordset\r
-       * input recordset's cursor should be at beginning, and\r
-       * old $rs will be closed.\r
-       *\r
-       * @param rs                     the recordset to copy\r
-       * @param [nrows]        number of rows to retrieve (optional)\r
-       * @param [offset]       offset by number of rows (optional)\r
-       * @return                       the new recordset\r
-       */\r
-       function &_rs2rs(&$rs,$nrows=-1,$offset=-1,$close=true)\r
-       {\r
-               if (! $rs) {\r
-                       $false = false;\r
-                       return $false;\r
-               }\r
-               $dbtype = $rs->databaseType;\r
-               if (!$dbtype) {\r
-                       $rs = &$rs;  // required to prevent crashing in 4.2.1, but does not happen in 4.3.1 -- why ?\r
-                       return $rs;\r
-               }\r
-               if (($dbtype == 'array' || $dbtype == 'csv') && $nrows == -1 && $offset == -1) {\r
-                       $rs->MoveFirst();\r
-                       $rs = &$rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1-- why ?\r
-                       return $rs;\r
-               }\r
-               $flds = array();\r
-               for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {\r
-                       $flds[] = $rs->FetchField($i);\r
-               }\r
-\r
-               $arr =& $rs->GetArrayLimit($nrows,$offset);\r
-               //print_r($arr);\r
-               if ($close) $rs->Close();\r
-               \r
-               $arrayClass = $this->arrayClass;\r
-               \r
-               $rs2 = new $arrayClass();\r
-               $rs2->connection = &$this;\r
-               $rs2->sql = $rs->sql;\r
-               $rs2->dataProvider = $this->dataProvider;\r
-               $rs2->InitArrayFields($arr,$flds);\r
-               $rs2->fetchMode = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;\r
-               return $rs2;\r
-       }\r
-       \r
-       /*\r
-       * Return all rows. Compat with PEAR DB\r
-       */\r
-       function &GetAll($sql, $inputarr=false)\r
-       {\r
-               $arr =& $this->GetArray($sql,$inputarr);\r
-               return $arr;\r
-       }\r
-       \r
-       function &GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false)\r
-       {\r
-               $rs =& $this->Execute($sql, $inputarr);\r
-               if (!$rs) {\r
-                       $false = false;\r
-                       return $false;\r
-               }\r
-               $arr =& $rs->GetAssoc($force_array,$first2cols);\r
-               return $arr;\r
-       }\r
-       \r
-       function &CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false)\r
-       {\r
-               if (!is_numeric($secs2cache)) {\r
-                       $first2cols = $force_array;\r
-                       $force_array = $inputarr;\r
-               }\r
-               $rs =& $this->CacheExecute($secs2cache, $sql, $inputarr);\r
-               if (!$rs) {\r
-                       $false = false;\r
-                       return $false;\r
-               }\r
-               $arr =& $rs->GetAssoc($force_array,$first2cols);\r
-               return $arr;\r
-       }\r
-       \r
-       /**\r
-       * Return first element of first row of sql statement. Recordset is disposed\r
-       * for you.\r
-       *\r
-       * @param sql                    SQL statement\r
-       * @param [inputarr]             input bind array\r
-       */\r
-       function GetOne($sql,$inputarr=false)\r
-       {\r
-       global $ADODB_COUNTRECS;\r
-               $crecs = $ADODB_COUNTRECS;\r
-               $ADODB_COUNTRECS = false;\r
-               \r
-               $ret = false;\r
-               $rs = &$this->Execute($sql,$inputarr);\r
-               if ($rs) {      \r
-                       if (!$rs->EOF) $ret = reset($rs->fields);\r
-                       $rs->Close();\r
-               }\r
-               $ADODB_COUNTRECS = $crecs;\r
-               return $ret;\r
-       }\r
-       \r
-       function CacheGetOne($secs2cache,$sql=false,$inputarr=false)\r
-       {\r
-               $ret = false;\r
-               $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);\r
-               if ($rs) {              \r
-                       if (!$rs->EOF) $ret = reset($rs->fields);\r
-                       $rs->Close();\r
-               } \r
-               \r
-               return $ret;\r
-       }\r
-       \r
-       function GetCol($sql, $inputarr = false, $trim = false)\r
-       {\r
-               $rv = false;\r
-               $rs = &$this->Execute($sql, $inputarr);\r
-               if ($rs) {\r
-                       $rv = array();\r
-                       if ($trim) {\r
-                               while (!$rs->EOF) {\r
-                                       $rv[] = trim(reset($rs->fields));\r
-                                       $rs->MoveNext();\r
-                               }\r
-                       } else {\r
-                               while (!$rs->EOF) {\r
-                                       $rv[] = reset($rs->fields);\r
-                                       $rs->MoveNext();\r
-                               }\r
-                       }\r
-                       $rs->Close();\r
-               }\r
-               return $rv;\r
-       }\r
-       \r
-       function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false)\r
-       {\r
-               $rv = false;\r
-               $rs = &$this->CacheExecute($secs, $sql, $inputarr);\r
-               if ($rs) {\r
-                       if ($trim) {\r
-                               while (!$rs->EOF) {\r
-                                       $rv[] = trim(reset($rs->fields));\r
-                                       $rs->MoveNext();\r
-                               }\r
-                       } else {\r
-                               while (!$rs->EOF) {\r
-                                       $rv[] = reset($rs->fields);\r
-                                       $rs->MoveNext();\r
-                               }\r
-                       }\r
-                       $rs->Close();\r
-               }\r
-               return $rv;\r
-       }\r
\r
-       /*\r
-               Calculate the offset of a date for a particular database and generate\r
-                       appropriate SQL. Useful for calculating future/past dates and storing\r
-                       in a database.\r
-                       \r
-               If dayFraction=1.5 means 1.5 days from now, 1.0/24 for 1 hour.\r
-       */\r
-       function OffsetDate($dayFraction,$date=false)\r
-       {               \r
-               if (!$date) $date = $this->sysDate;\r
-               return  '('.$date.'+'.$dayFraction.')';\r
-       }\r
-       \r
-       \r
-       /**\r
-       *\r
-       * @param sql                    SQL statement\r
-       * @param [inputarr]             input bind array\r
-       */\r
-       function &GetArray($sql,$inputarr=false)\r
-       {\r
-       global $ADODB_COUNTRECS;\r
-               \r
-               $savec = $ADODB_COUNTRECS;\r
-               $ADODB_COUNTRECS = false;\r
-               $rs =& $this->Execute($sql,$inputarr);\r
-               $ADODB_COUNTRECS = $savec;\r
-               if (!$rs) \r
-                       if (defined('ADODB_PEAR')) return ADODB_PEAR_Error();\r
-                       else {\r
-                               $false = false;\r
-                               return $false;\r
-                       }\r
-               $arr =& $rs->GetArray();\r
-               $rs->Close();\r
-               return $arr;\r
-       }\r
-       \r
-       function &CacheGetAll($secs2cache,$sql=false,$inputarr=false)\r
-       {\r
-               return $this->CacheGetArray($secs2cache,$sql,$inputarr);\r
-       }\r
-       \r
-       function &CacheGetArray($secs2cache,$sql=false,$inputarr=false)\r
-       {\r
-       global $ADODB_COUNTRECS;\r
-               \r
-               $savec = $ADODB_COUNTRECS;\r
-               $ADODB_COUNTRECS = false;\r
-               $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr);\r
-               $ADODB_COUNTRECS = $savec;\r
-               \r
-               if (!$rs) \r
-                       if (defined('ADODB_PEAR')) return ADODB_PEAR_Error();\r
-                       else {\r
-                               $false = false;\r
-                               return $false;\r
-                       }\r
-               $arr =& $rs->GetArray();\r
-               $rs->Close();\r
-               return $arr;\r
-       }\r
-       \r
-       \r
-       \r
-       /**\r
-       * Return one row of sql statement. Recordset is disposed for you.\r
-       *\r
-       * @param sql                    SQL statement\r
-       * @param [inputarr]             input bind array\r
-       */\r
-       function &GetRow($sql,$inputarr=false)\r
-       {\r
-       global $ADODB_COUNTRECS;\r
-               $crecs = $ADODB_COUNTRECS;\r
-               $ADODB_COUNTRECS = false;\r
-               \r
-               $rs =& $this->Execute($sql,$inputarr);\r
-               \r
-               $ADODB_COUNTRECS = $crecs;\r
-               if ($rs) {\r
-                       if (!$rs->EOF) $arr = $rs->fields;\r
-                       else $arr = array();\r
-                       $rs->Close();\r
-                       return $arr;\r
-               }\r
-               \r
-               $false = false;\r
-               return $false;\r
-       }\r
-       \r
-       function &CacheGetRow($secs2cache,$sql=false,$inputarr=false)\r
-       {\r
-               $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr);\r
-               if ($rs) {\r
-                       $arr = false;\r
-                       if (!$rs->EOF) $arr = $rs->fields;\r
-                       $rs->Close();\r
-                       return $arr;\r
-               }\r
-               $false = false;\r
-               return $false;\r
-       }\r
-       \r
-       /**\r
-       * Insert or replace a single record. Note: this is not the same as MySQL's replace. \r
-       * ADOdb's Replace() uses update-insert semantics, not insert-delete-duplicates of MySQL.\r
-       * Also note that no table locking is done currently, so it is possible that the\r
-       * record be inserted twice by two programs...\r
-       *\r
-       * $this->Replace('products', array('prodname' =>"'Nails'","price" => 3.99), 'prodname');\r
-       *\r
-       * $table                table name\r
-       * $fieldArray   associative array of data (you must quote strings yourself).\r
-       * $keyCol               the primary key field name or if compound key, array of field names\r
-       * autoQuote             set to true to use a hueristic to quote strings. Works with nulls and numbers\r
-       *                                       but does not work with dates nor SQL functions.\r
-       * has_autoinc   the primary key is an auto-inc field, so skip in insert.\r
-       *\r
-       * Currently blob replace not supported\r
-       *\r
-       * returns 0 = fail, 1 = update, 2 = insert \r
-       */\r
-       \r
-       function Replace($table, $fieldArray, $keyCol, $autoQuote=false, $has_autoinc=false)\r
-       {\r
-               global $ADODB_INCLUDED_LIB;\r
-               if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               \r
-               return _adodb_replace($this, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc);\r
-       }\r
-       \r
-       \r
-       /**\r
-       * Will select, getting rows from $offset (1-based), for $nrows. \r
-       * This simulates the MySQL "select * from table limit $offset,$nrows" , and\r
-       * the PostgreSQL "select * from table limit $nrows offset $offset". Note that\r
-       * MySQL and PostgreSQL parameter ordering is the opposite of the other.\r
-       * eg. \r
-       *  CacheSelectLimit(15,'select * from table',3); will return rows 1 to 3 (1-based)\r
-       *  CacheSelectLimit(15,'select * from table',3,2); will return rows 3 to 5 (1-based)\r
-       *\r
-       * BUG: Currently CacheSelectLimit fails with $sql with LIMIT or TOP clause already set\r
-       *\r
-       * @param [secs2cache]   seconds to cache data, set to 0 to force query. This is optional\r
-       * @param sql\r
-       * @param [offset]       is the row to start calculations from (1-based)\r
-       * @param [nrows]        is the number of rows to get\r
-       * @param [inputarr]     array of bind variables\r
-       * @return               the recordset ($rs->databaseType == 'array')\r
-       */\r
-       function &CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false)\r
-       {       \r
-               if (!is_numeric($secs2cache)) {\r
-                       if ($sql === false) $sql = -1;\r
-                       if ($offset == -1) $offset = false;\r
-                                                                         // sql,       nrows, offset,inputarr\r
-                       $rs =& $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$this->cacheSecs);\r
-               } else {\r
-                       if ($sql === false) ADOConnection::outp( "Warning: \$sql missing from CacheSelectLimit()");\r
-                       $rs =& $this->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);\r
-               }\r
-               return $rs;\r
-       }\r
-       \r
-       /**\r
-       * Flush cached recordsets that match a particular $sql statement. \r
-       * If $sql == false, then we purge all files in the cache.\r
-       */\r
-       function CacheFlush($sql=false,$inputarr=false)\r
-       {\r
-       global $ADODB_CACHE_DIR;\r
-       \r
-               if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) {\r
-                       if (strncmp(PHP_OS,'WIN',3) === 0) {\r
-                               $cmd = 'del /s '.str_replace('/','\\',$ADODB_CACHE_DIR).'\adodb_*.cache';\r
-                       } else {\r
-                               //$cmd = 'find "'.$ADODB_CACHE_DIR.'" -type f -maxdepth 1 -print0 | xargs -0 rm -f';\r
-                               $cmd = 'rm -rf '.$ADODB_CACHE_DIR.'/[0-9a-f][0-9a-f]/'; \r
-                               // old version 'rm -f `find '.$ADODB_CACHE_DIR.' -name adodb_*.cache`';\r
-                       }\r
-                       if ($this->debug) {\r
-                               ADOConnection::outp( "CacheFlush: $cmd<br><pre>\n", system($cmd),"</pre>");\r
-                       } else {\r
-                               exec($cmd);\r
-                       }\r
-                       return;\r
-               } \r
-               \r
-               global $ADODB_INCLUDED_CSV;\r
-               if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');\r
-               \r
-               $f = $this->_gencachename($sql.serialize($inputarr),false);\r
-               adodb_write_file($f,''); // is adodb_write_file needed?\r
-               if (!@unlink($f)) {\r
-                       if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f");\r
-               }\r
-       }\r
-       \r
-       /**\r
-       * Private function to generate filename for caching.\r
-       * Filename is generated based on:\r
-       *\r
-       *  - sql statement\r
-       *  - database type (oci8, ibase, ifx, etc)\r
-       *  - database name\r
-       *  - userid\r
-       *  - setFetchMode (adodb 4.23)\r
-       *\r
-       * When not in safe mode, we create 256 sub-directories in the cache directory ($ADODB_CACHE_DIR). \r
-       * Assuming that we can have 50,000 files per directory with good performance, \r
-       * then we can scale to 12.8 million unique cached recordsets. Wow!\r
-       */\r
-       function _gencachename($sql,$createdir)\r
-       {\r
-       global $ADODB_CACHE_DIR;\r
-       static $notSafeMode;\r
-               \r
-               if ($this->fetchMode === false) { \r
-               global $ADODB_FETCH_MODE;\r
-                       $mode = $ADODB_FETCH_MODE;\r
-               } else {\r
-                       $mode = $this->fetchMode;\r
-               }\r
-               $m = md5($sql.$this->databaseType.$this->database.$this->user.$mode);\r
-               \r
-               if (!isset($notSafeMode)) $notSafeMode = !ini_get('safe_mode');\r
-               $dir = ($notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($m,0,2) : $ADODB_CACHE_DIR;\r
-                       \r
-               if ($createdir && $notSafeMode && !file_exists($dir)) {\r
-                       $oldu = umask(0);\r
-                       if (!mkdir($dir,0771)) \r
-                               if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql");\r
-                       umask($oldu);\r
-               }\r
-               return $dir.'/adodb_'.$m.'.cache';\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Execute SQL, caching recordsets.\r
-        *\r
-        * @param [secs2cache]  seconds to cache data, set to 0 to force query. \r
-        *                                        This is an optional parameter.\r
-        * @param sql           SQL statement to execute\r
-        * @param [inputarr]    holds the input data  to bind to\r
-        * @return              RecordSet or false\r
-        */\r
-       function &CacheExecute($secs2cache,$sql=false,$inputarr=false)\r
-       {\r
-\r
-                       \r
-               if (!is_numeric($secs2cache)) {\r
-                       $inputarr = $sql;\r
-                       $sql = $secs2cache;\r
-                       $secs2cache = $this->cacheSecs;\r
-               }\r
-               \r
-               if (is_array($sql)) {\r
-                       $sqlparam = $sql;\r
-                       $sql = $sql[0];\r
-               } else\r
-                       $sqlparam = $sql;\r
-                       \r
-               global $ADODB_INCLUDED_CSV;\r
-               if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');\r
-               \r
-               $md5file = $this->_gencachename($sql.serialize($inputarr),true);\r
-               $err = '';\r
-               \r
-               if ($secs2cache > 0){\r
-                       $rs = &csv2rs($md5file,$err,$secs2cache,$this->arrayClass);\r
-                       $this->numCacheHits += 1;\r
-               } else {\r
-                       $err='Timeout 1';\r
-                       $rs = false;\r
-                       $this->numCacheMisses += 1;\r
-               }\r
-               if (!$rs) {\r
-               // no cached rs found\r
-                       if ($this->debug) {\r
-                               if (get_magic_quotes_runtime()) {\r
-                                       ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :(");\r
-                               }\r
-                               if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (see sql below)");\r
-                       }\r
-                       \r
-                       $rs = &$this->Execute($sqlparam,$inputarr);\r
-\r
-                       if ($rs) {\r
-                               $eof = $rs->EOF;\r
-                               $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately\r
-                               $txt = _rs2serialize($rs,false,$sql); // serialize\r
-               \r
-                               if (!adodb_write_file($md5file,$txt,$this->debug)) {\r
-                                       if ($fn = $this->raiseErrorFn) {\r
-                                               $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this);\r
-                                       }\r
-                                       if ($this->debug) ADOConnection::outp( " Cache write error");\r
-                               }\r
-                               if ($rs->EOF && !$eof) {\r
-                                       $rs->MoveFirst();\r
-                                       //$rs = &csv2rs($md5file,$err);         \r
-                                       $rs->connection = &$this; // Pablo suggestion\r
-                               }  \r
-                               \r
-                       } else\r
-                               @unlink($md5file);\r
-               } else {\r
-                       $this->_errorMsg = '';\r
-                       $this->_errorCode = 0;\r
-                       \r
-                       if ($this->fnCacheExecute) {\r
-                               $fn = $this->fnCacheExecute;\r
-                               $fn($this, $secs2cache, $sql, $inputarr);\r
-                       }\r
-               // ok, set cached object found\r
-                       $rs->connection = &$this; // Pablo suggestion\r
-                       if ($this->debug){ \r
-                                       \r
-                               $inBrowser = isset($_SERVER['HTTP_USER_AGENT']);\r
-                               $ttl = $rs->timeCreated + $secs2cache - time();\r
-                               $s = is_array($sql) ? $sql[0] : $sql;\r
-                               if ($inBrowser) $s = '<i>'.htmlspecialchars($s).'</i>';\r
-                               \r
-                               ADOConnection::outp( " $md5file reloaded, ttl=$ttl [ $s ]");\r
-                       }\r
-               }\r
-               return $rs;\r
-       }\r
-       \r
-       \r
-       /* \r
-               Similar to PEAR DB's autoExecute(), except that \r
-               $mode can be 'INSERT' or 'UPDATE' or DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE\r
-               If $mode == 'UPDATE', then $where is compulsory as a safety measure.\r
-               \r
-               $forceUpdate means that even if the data has not changed, perform update.\r
-        */\r
-       function& AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false) \r
-       {\r
-               $sql = 'SELECT * FROM '.$table;  \r
-               if ($where!==FALSE) $sql .= ' WHERE '.$where;\r
-               else if ($mode == 'UPDATE') {\r
-                       ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause');\r
-                       return false;\r
-               }\r
-\r
-               $rs =& $this->SelectLimit($sql,1);\r
-               if (!$rs) return false; // table does not exist\r
-               $rs->tableName = $table;\r
-               \r
-               switch((string) $mode) {\r
-               case 'UPDATE':\r
-               case '2':\r
-                       $sql = $this->GetUpdateSQL($rs, $fields_values, $forceUpdate, $magicq);\r
-                       break;\r
-               case 'INSERT':\r
-               case '1':\r
-                       $sql = $this->GetInsertSQL($rs, $fields_values, $magicq);\r
-                       break;\r
-               default:\r
-                       ADOConnection::outp("AutoExecute: Unknown mode=$mode");\r
-                       return false;\r
-               }\r
-               $ret = false;\r
-               if ($sql) $ret = $this->Execute($sql);\r
-               if ($ret) $ret = true;\r
-               return $ret;\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Generates an Update Query based on an existing recordset.\r
-        * $arrFields is an associative array of fields with the value\r
-        * that should be assigned.\r
-        *\r
-        * Note: This function should only be used on a recordset\r
-        *         that is run against a single table and sql should only \r
-        *               be a simple select stmt with no groupby/orderby/limit\r
-        *\r
-        * "Jonathan Younger" <jyounger@unilab.com>\r
-        */\r
-       function GetUpdateSQL(&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=null)\r
-       {\r
-               global $ADODB_INCLUDED_LIB;\r
-\r
-        //********************************************************//\r
-        //This is here to maintain compatibility\r
-        //with older adodb versions. Sets force type to force nulls if $forcenulls is set.\r
-               if (!isset($force)) {\r
-                               global $ADODB_FORCE_TYPE;\r
-                           $force = $ADODB_FORCE_TYPE;\r
-               }\r
-               //********************************************************//\r
-\r
-               if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq,$force);\r
-       }\r
-\r
-       \r
-       \r
-\r
-       /**\r
-        * Generates an Insert Query based on an existing recordset.\r
-        * $arrFields is an associative array of fields with the value\r
-        * that should be assigned.\r
-        *\r
-        * Note: This function should only be used on a recordset\r
-        *         that is run against a single table.\r
-        */\r
-       function GetInsertSQL(&$rs, $arrFields,$magicq=false,$force=null)\r
-       {       \r
-               global $ADODB_INCLUDED_LIB;\r
-               if (!isset($force)) {\r
-                       global $ADODB_FORCE_TYPE;\r
-                       $force = $ADODB_FORCE_TYPE;\r
-                       \r
-               }\r
-               if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force);\r
-       }\r
-       \r
-\r
-       /**\r
-       * Update a blob column, given a where clause. There are more sophisticated\r
-       * blob handling functions that we could have implemented, but all require\r
-       * a very complex API. Instead we have chosen something that is extremely\r
-       * simple to understand and use. \r
-       *\r
-       * Note: $blobtype supports 'BLOB' and 'CLOB', default is BLOB of course.\r
-       *\r
-       * Usage to update a $blobvalue which has a primary key blob_id=1 into a \r
-       * field blobtable.blobcolumn:\r
-       *\r
-       *       UpdateBlob('blobtable', 'blobcolumn', $blobvalue, 'blob_id=1');\r
-       *\r
-       * Insert example:\r
-       *\r
-       *       $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');\r
-       *       $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');\r
-       */\r
-       \r
-       function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')\r
-       {\r
-               return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;\r
-       }\r
-\r
-       /**\r
-       * Usage:\r
-       *       UpdateBlob('TABLE', 'COLUMN', '/path/to/file', 'ID=1');\r
-       *       \r
-       *       $blobtype supports 'BLOB' and 'CLOB'\r
-       *\r
-       *       $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');\r
-       *       $conn->UpdateBlob('blobtable','blobcol',$blobpath,'id=1');\r
-       */\r
-       function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB')\r
-       {\r
-               $fd = fopen($path,'rb');\r
-               if ($fd === false) return false;\r
-               $val = fread($fd,filesize($path));\r
-               fclose($fd);\r
-               return $this->UpdateBlob($table,$column,$val,$where,$blobtype);\r
-       }\r
-       \r
-       function BlobDecode($blob)\r
-       {\r
-               return $blob;\r
-       }\r
-       \r
-       function BlobEncode($blob)\r
-       {\r
-               return $blob;\r
-       }\r
-       \r
-       function SetCharSet($charset)\r
-       {\r
-               return false;\r
-       }\r
-       \r
-       function IfNull( $field, $ifNull ) \r
-       {\r
-               return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";\r
-       }\r
-       \r
-       function LogSQL($enable=true)\r
-       {\r
-               include_once(ADODB_DIR.'/adodb-perf.inc.php');\r
-               \r
-               if ($enable) $this->fnExecute = 'adodb_log_sql';\r
-               else $this->fnExecute = false;\r
-               \r
-               $old = $this->_logsql;  \r
-               $this->_logsql = $enable;\r
-               if ($enable && !$old) $this->_affected = false;\r
-               return $old;\r
-       }\r
-       \r
-       function GetCharSet()\r
-       {\r
-               return false;\r
-       }\r
-       \r
-       /**\r
-       * Usage:\r
-       *       UpdateClob('TABLE', 'COLUMN', $var, 'ID=1', 'CLOB');\r
-       *\r
-       *       $conn->Execute('INSERT INTO clobtable (id, clobcol) VALUES (1, null)');\r
-       *       $conn->UpdateClob('clobtable','clobcol',$clob,'id=1');\r
-       */\r
-       function UpdateClob($table,$column,$val,$where)\r
-       {\r
-               return $this->UpdateBlob($table,$column,$val,$where,'CLOB');\r
-       }\r
-       \r
-       // not the fastest implementation - quick and dirty - jlim\r
-       // for best performance, use the actual $rs->MetaType().\r
-       function MetaType($t,$len=-1,$fieldobj=false)\r
-       {\r
-               \r
-               if (empty($this->_metars)) {\r
-                       $rsclass = $this->rsPrefix.$this->databaseType;\r
-                       $this->_metars =& new $rsclass(false,$this->fetchMode); \r
-               }\r
-               \r
-               return $this->_metars->MetaType($t,$len,$fieldobj);\r
-       }\r
-       \r
-       \r
-       /**\r
-       *  Change the SQL connection locale to a specified locale.\r
-       *  This is used to get the date formats written depending on the client locale.\r
-       */\r
-       function SetDateLocale($locale = 'En')\r
-       {\r
-               $this->locale = $locale;\r
-               switch (strtoupper($locale))\r
-               {\r
-                       case 'EN':\r
-                               $this->fmtDate="'Y-m-d'";\r
-                               $this->fmtTimeStamp = "'Y-m-d H:i:s'";\r
-                               break;\r
-                               \r
-                       case 'US':\r
-                               $this->fmtDate = "'m-d-Y'";\r
-                               $this->fmtTimeStamp = "'m-d-Y H:i:s'";\r
-                               break;\r
-                               \r
-                       case 'NL':\r
-                       case 'FR':\r
-                       case 'RO':\r
-                       case 'IT':\r
-                               $this->fmtDate="'d-m-Y'";\r
-                               $this->fmtTimeStamp = "'d-m-Y H:i:s'";\r
-                               break;\r
-                               \r
-                       case 'GE':\r
-                               $this->fmtDate="'d.m.Y'";\r
-                               $this->fmtTimeStamp = "'d.m.Y H:i:s'";\r
-                               break;\r
-                               \r
-                       default:\r
-                               $this->fmtDate="'Y-m-d'";\r
-                               $this->fmtTimeStamp = "'Y-m-d H:i:s'";\r
-                               break;\r
-               }\r
-       }\r
-\r
-       \r
-       /**\r
-        * Close Connection\r
-        */\r
-       function Close()\r
-       {\r
-               $rez = $this->_close();\r
-               $this->_connectionID = false;\r
-               return $rez;\r
-       }\r
-       \r
-       /**\r
-        * Begin a Transaction. Must be followed by CommitTrans() or RollbackTrans().\r
-        *\r
-        * @return true if succeeded or false if database does not support transactions\r
-        */\r
-       function BeginTrans() {return false;}\r
-       \r
-       \r
-       /**\r
-        * If database does not support transactions, always return true as data always commited\r
-        *\r
-        * @param $ok  set to false to rollback transaction, true to commit\r
-        *\r
-        * @return true/false.\r
-        */\r
-       function CommitTrans($ok=true) \r
-       { return true;}\r
-       \r
-       \r
-       /**\r
-        * If database does not support transactions, rollbacks always fail, so return false\r
-        *\r
-        * @return true/false.\r
-        */\r
-       function RollbackTrans() \r
-       { return false;}\r
-\r
-\r
-       /**\r
-        * return the databases that the driver can connect to. \r
-        * Some databases will return an empty array.\r
-        *\r
-        * @return an array of database names.\r
-        */\r
-               function MetaDatabases() \r
-               {\r
-               global $ADODB_FETCH_MODE;\r
-               \r
-                       if ($this->metaDatabasesSQL) {\r
-                               $save = $ADODB_FETCH_MODE; \r
-                               $ADODB_FETCH_MODE = ADODB_FETCH_NUM; \r
-                               \r
-                               if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);\r
-                               \r
-                               $arr = $this->GetCol($this->metaDatabasesSQL);\r
-                               if (isset($savem)) $this->SetFetchMode($savem);\r
-                               $ADODB_FETCH_MODE = $save; \r
-                       \r
-                               return $arr;\r
-                       }\r
-                       \r
-                       return false;\r
-               }\r
-               \r
-       /**\r
-        * @param ttype can either be 'VIEW' or 'TABLE' or false. \r
-        *              If false, both views and tables are returned.\r
-        *              "VIEW" returns only views\r
-        *              "TABLE" returns only tables\r
-        * @param showSchema returns the schema/user with the table name, eg. USER.TABLE\r
-        * @param mask  is the input mask - only supported by oci8 and postgresql\r
-        *\r
-        * @return  array of tables for current database.\r
-        */ \r
-       function &MetaTables($ttype=false,$showSchema=false,$mask=false) \r
-       {\r
-       global $ADODB_FETCH_MODE;\r
-       \r
-               \r
-               $false = false;\r
-               if ($mask) {\r
-                       return $false;\r
-               }\r
-               if ($this->metaTablesSQL) {\r
-                       $save = $ADODB_FETCH_MODE; \r
-                       $ADODB_FETCH_MODE = ADODB_FETCH_NUM; \r
-                       \r
-                       if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);\r
-                       \r
-                       $rs = $this->Execute($this->metaTablesSQL);\r
-                       if (isset($savem)) $this->SetFetchMode($savem);\r
-                       $ADODB_FETCH_MODE = $save; \r
-                       \r
-                       if ($rs === false) return $false;\r
-                       $arr =& $rs->GetArray();\r
-                       $arr2 = array();\r
-                       \r
-                       if ($hast = ($ttype && isset($arr[0][1]))) { \r
-                               $showt = strncmp($ttype,'T',1);\r
-                       }\r
-                       \r
-                       for ($i=0; $i < sizeof($arr); $i++) {\r
-                               if ($hast) {\r
-                                       if ($showt == 0) {\r
-                                               if (strncmp($arr[$i][1],'T',1) == 0) $arr2[] = trim($arr[$i][0]);\r
-                                       } else {\r
-                                               if (strncmp($arr[$i][1],'V',1) == 0) $arr2[] = trim($arr[$i][0]);\r
-                                       }\r
-                               } else\r
-                                       $arr2[] = trim($arr[$i][0]);\r
-                       }\r
-                       $rs->Close();\r
-                       return $arr2;\r
-               }\r
-               return $false;\r
-       }\r
-       \r
-       \r
-       function _findschema(&$table,&$schema)\r
-       {\r
-               if (!$schema && ($at = strpos($table,'.')) !== false) {\r
-                       $schema = substr($table,0,$at);\r
-                       $table = substr($table,$at+1);\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * List columns in a database as an array of ADOFieldObjects. \r
-        * See top of file for definition of object.\r
-        *\r
-        * @param table table name to query\r
-        * @param upper uppercase table name (required by some databases)\r
-        * @schema is optional database schema to use - not supported by all databases.\r
-        *\r
-        * @return  array of ADOFieldObjects for current table.\r
-        */\r
-       function &MetaColumns($table,$upper=true) \r
-       {\r
-       global $ADODB_FETCH_MODE;\r
-               \r
-               $false = false;\r
-               \r
-               if (!empty($this->metaColumnsSQL)) {\r
-               \r
-                       $schema = false;\r
-                       $this->_findschema($table,$schema);\r
-               \r
-                       $save = $ADODB_FETCH_MODE;\r
-                       $ADODB_FETCH_MODE = ADODB_FETCH_NUM;\r
-                       if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);\r
-                       $rs = $this->Execute(sprintf($this->metaColumnsSQL,($upper)?strtoupper($table):$table));\r
-                       if (isset($savem)) $this->SetFetchMode($savem);\r
-                       $ADODB_FETCH_MODE = $save;\r
-                       if ($rs === false || $rs->EOF) return $false;\r
-\r
-                       $retarr = array();\r
-                       while (!$rs->EOF) { //print_r($rs->fields);\r
-                               $fld = new ADOFieldObject();\r
-                               $fld->name = $rs->fields[0];\r
-                               $fld->type = $rs->fields[1];\r
-                               if (isset($rs->fields[3]) && $rs->fields[3]) {\r
-                                       if ($rs->fields[3]>0) $fld->max_length = $rs->fields[3];\r
-                                       $fld->scale = $rs->fields[4];\r
-                                       if ($fld->scale>0) $fld->max_length += 1;\r
-                               } else\r
-                                       $fld->max_length = $rs->fields[2];\r
-                                       \r
-                               if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;     \r
-                               else $retarr[strtoupper($fld->name)] = $fld;\r
-                               $rs->MoveNext();\r
-                       }\r
-                       $rs->Close();\r
-                       return $retarr; \r
-               }\r
-               return $false;\r
-       }\r
-       \r
-    /**\r
-      * List indexes on a table as an array.\r
-      * @param table  table name to query\r
-      * @param primary true to only show primary keys. Not actually used for most databases\r
-         *\r
-      * @return array of indexes on current table. Each element represents an index, and is itself an associative array.\r
-         \r
-                Array (\r
-                   [name_of_index] => Array\r
-                     (\r
-                 [unique] => true or false\r
-                 [columns] => Array\r
-                 (\r
-                       [0] => firstname\r
-                       [1] => lastname\r
-                 )\r
-               )               \r
-      */\r
-     function &MetaIndexes($table, $primary = false, $owner = false)\r
-     {\r
-                       $false = false;\r
-            return $false;\r
-     }\r
-\r
-       /**\r
-        * List columns names in a table as an array. \r
-        * @param table table name to query\r
-        *\r
-        * @return  array of column names for current table.\r
-        */ \r
-       function &MetaColumnNames($table, $numIndexes=false) \r
-       {\r
-               $objarr =& $this->MetaColumns($table);\r
-               if (!is_array($objarr)) {\r
-                       $false = false;\r
-                       return $false;\r
-               }\r
-               $arr = array();\r
-               if ($numIndexes) {\r
-                       $i = 0;\r
-                       foreach($objarr as $v) $arr[$i++] = $v->name;\r
-               } else\r
-                       foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name;\r
-               \r
-               return $arr;\r
-       }\r
-                       \r
-       /**\r
-        * Different SQL databases used different methods to combine strings together.\r
-        * This function provides a wrapper. \r
-        * \r
-        * param s      variable number of string parameters\r
-        *\r
-        * Usage: $db->Concat($str1,$str2);\r
-        * \r
-        * @return concatenated string\r
-        */      \r
-       function Concat()\r
-       {       \r
-               $arr = func_get_args();\r
-               return implode($this->concat_operator, $arr);\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Converts a date "d" to a string that the database can understand.\r
-        *\r
-        * @param d     a date in Unix date time format.\r
-        *\r
-        * @return  date string in database date format\r
-        */\r
-       function DBDate($d)\r
-       {\r
-               if (empty($d) && $d !== 0) return 'null';\r
-\r
-               if (is_string($d) && !is_numeric($d)) {\r
-                       if ($d === 'null' || strncmp($d,"'",1) === 0) return $d;\r
-                       if ($this->isoDates) return "'$d'";\r
-                       $d = ADOConnection::UnixDate($d);\r
-               }\r
-\r
-               return adodb_date($this->fmtDate,$d);\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Converts a timestamp "ts" to a string that the database can understand.\r
-        *\r
-        * @param ts    a timestamp in Unix date time format.\r
-        *\r
-        * @return  timestamp string in database timestamp format\r
-        */\r
-       function DBTimeStamp($ts)\r
-       {\r
-               if (empty($ts) && $ts !== 0) return 'null';\r
-\r
-               # strlen(14) allows YYYYMMDDHHMMSS format\r
-               if (!is_string($ts) || (is_numeric($ts) && strlen($ts)<14)) \r
-                       return adodb_date($this->fmtTimeStamp,$ts);\r
-               \r
-               if ($ts === 'null') return $ts;\r
-               if ($this->isoDates && strlen($ts) !== 14) return "'$ts'";\r
-               \r
-               $ts = ADOConnection::UnixTimeStamp($ts);\r
-               return adodb_date($this->fmtTimeStamp,$ts);\r
-       }\r
-       \r
-       /**\r
-        * Also in ADORecordSet.\r
-        * @param $v is a date string in YYYY-MM-DD format\r
-        *\r
-        * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format\r
-        */\r
-       function UnixDate($v)\r
-       {\r
-               if (is_object($v)) {\r
-               // odbtp support\r
-               //( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )\r
-                       return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year);\r
-               }\r
-       \r
-               if (is_numeric($v) && strlen($v) !== 8) return $v;\r
-               if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|", \r
-                       ($v), $rr)) return false;\r
-\r
-               if ($rr[1] <= TIMESTAMP_FIRST_YEAR) return 0;\r
-               // h-m-s-MM-DD-YY\r
-               return @adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]);\r
-       }\r
-       \r
-\r
-       /**\r
-        * Also in ADORecordSet.\r
-        * @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format\r
-        *\r
-        * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format\r
-        */\r
-       function UnixTimeStamp($v)\r
-       {\r
-               if (is_object($v)) {\r
-               // odbtp support\r
-               //( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )\r
-                       return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year);\r
-               }\r
-               \r
-               if (!preg_match( \r
-                       "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ ,-]*(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", \r
-                       ($v), $rr)) return false;\r
-                       \r
-               if ($rr[1] <= TIMESTAMP_FIRST_YEAR && $rr[2]<= 1) return 0;\r
-       \r
-               // h-m-s-MM-DD-YY\r
-               if (!isset($rr[5])) return  adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]);\r
-               return  @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]);\r
-       }\r
-       \r
-       /**\r
-        * Also in ADORecordSet.\r
-        *\r
-        * Format database date based on user defined format.\r
-        *\r
-        * @param v     is the character date in YYYY-MM-DD format, returned by database\r
-        * @param fmt   is the format to apply to it, using date()\r
-        *\r
-        * @return a date formated as user desires\r
-        */\r
-        \r
-       function UserDate($v,$fmt='Y-m-d',$gmt=false)\r
-       {\r
-               $tt = $this->UnixDate($v);\r
-\r
-               // $tt == -1 if pre TIMESTAMP_FIRST_YEAR\r
-               if (($tt === false || $tt == -1) && $v != false) return $v;\r
-               else if ($tt == 0) return $this->emptyDate;\r
-               else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR\r
-               }\r
-               \r
-               return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);\r
-       \r
-       }\r
-       \r
-               /**\r
-        *\r
-        * @param v     is the character timestamp in YYYY-MM-DD hh:mm:ss format\r
-        * @param fmt   is the format to apply to it, using date()\r
-        *\r
-        * @return a timestamp formated as user desires\r
-        */\r
-       function UserTimeStamp($v,$fmt='Y-m-d H:i:s',$gmt=false)\r
-       {\r
-               if (!isset($v)) return $this->emptyTimeStamp;\r
-               # strlen(14) allows YYYYMMDDHHMMSS format\r
-               if (is_numeric($v) && strlen($v)<14) return ($gmt) ? adodb_gmdate($fmt,$v) : adodb_date($fmt,$v);\r
-               $tt = $this->UnixTimeStamp($v);\r
-               // $tt == -1 if pre TIMESTAMP_FIRST_YEAR\r
-               if (($tt === false || $tt == -1) && $v != false) return $v;\r
-               if ($tt == 0) return $this->emptyTimeStamp;\r
-               return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);\r
-       }\r
-       \r
-       function escape($s,$magic_quotes=false)\r
-       {\r
-               return $this->addq($s,$magic_quotes);\r
-       }\r
-       \r
-       /**\r
-       * Quotes a string, without prefixing nor appending quotes. \r
-       */\r
-       function addq($s,$magic_quotes=false)\r
-       {\r
-               if (!$magic_quotes) {\r
-               \r
-                       if ($this->replaceQuote[0] == '\\'){\r
-                               // only since php 4.0.5\r
-                               $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);\r
-                               //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s));\r
-                       }\r
-                       return  str_replace("'",$this->replaceQuote,$s);\r
-               }\r
-               \r
-               // undo magic quotes for "\r
-               $s = str_replace('\\"','"',$s);\r
-               \r
-               if ($this->replaceQuote == "\\'")  // ' already quoted, no need to change anything\r
-                       return $s;\r
-               else {// change \' to '' for sybase/mssql\r
-                       $s = str_replace('\\\\','\\',$s);\r
-                       return str_replace("\\'",$this->replaceQuote,$s);\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * Correctly quotes a string so that all strings are escaped. We prefix and append\r
-        * to the string single-quotes.\r
-        * An example is  $db->qstr("Don't bother",magic_quotes_runtime());\r
-        * \r
-        * @param s                     the string to quote\r
-        * @param [magic_quotes]        if $s is GET/POST var, set to get_magic_quotes_gpc().\r
-        *                              This undoes the stupidity of magic quotes for GPC.\r
-        *\r
-        * @return  quoted string to be sent back to database\r
-        */\r
-       function qstr($s,$magic_quotes=false)\r
-       {       \r
-               if (!$magic_quotes) {\r
-               \r
-                       if ($this->replaceQuote[0] == '\\'){\r
-                               // only since php 4.0.5\r
-                               $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);\r
-                               //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s));\r
-                       }\r
-                       return  "'".str_replace("'",$this->replaceQuote,$s)."'";\r
-               }\r
-               \r
-               // undo magic quotes for "\r
-               $s = str_replace('\\"','"',$s);\r
-               \r
-               if ($this->replaceQuote == "\\'")  // ' already quoted, no need to change anything\r
-                       return "'$s'";\r
-               else {// change \' to '' for sybase/mssql\r
-                       $s = str_replace('\\\\','\\',$s);\r
-                       return "'".str_replace("\\'",$this->replaceQuote,$s)."'";\r
-               }\r
-       }\r
-       \r
-       \r
-       /**\r
-       * Will select the supplied $page number from a recordset, given that it is paginated in pages of \r
-       * $nrows rows per page. It also saves two boolean values saying if the given page is the first \r
-       * and/or last one of the recordset. Added by Iván Oliva to provide recordset pagination.\r
-       *\r
-       * See readme.htm#ex8 for an example of usage.\r
-       *\r
-       * @param sql\r
-       * @param nrows          is the number of rows per page to get\r
-       * @param page           is the page number to get (1-based)\r
-       * @param [inputarr]     array of bind variables\r
-       * @param [secs2cache]           is a private parameter only used by jlim\r
-       * @return               the recordset ($rs->databaseType == 'array')\r
-       *\r
-       * NOTE: phpLens uses a different algorithm and does not use PageExecute().\r
-       *\r
-       */\r
-       function &PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0) \r
-       {\r
-               global $ADODB_INCLUDED_LIB;\r
-               if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               if ($this->pageExecuteCountRows) $rs =& _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache);\r
-               else $rs =& _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache);\r
-               return $rs;\r
-       }\r
-       \r
-               \r
-       /**\r
-       * Will select the supplied $page number from a recordset, given that it is paginated in pages of \r
-       * $nrows rows per page. It also saves two boolean values saying if the given page is the first \r
-       * and/or last one of the recordset. Added by Iván Oliva to provide recordset pagination.\r
-       *\r
-       * @param secs2cache     seconds to cache data, set to 0 to force query\r
-       * @param sql\r
-       * @param nrows          is the number of rows per page to get\r
-       * @param page           is the page number to get (1-based)\r
-       * @param [inputarr]     array of bind variables\r
-       * @return               the recordset ($rs->databaseType == 'array')\r
-       */\r
-       function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false) \r
-       {\r
-               /*switch($this->dataProvider) {\r
-               case 'postgres':\r
-               case 'mysql': \r
-                       break;\r
-               default: $secs2cache = 0; break;\r
-               }*/\r
-               $rs =& $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache);\r
-               return $rs;\r
-       }\r
-\r
-} // end class ADOConnection\r
-       \r
-       \r
-       \r
-       //==============================================================================================        \r
-       // CLASS ADOFetchObj\r
-       //==============================================================================================        \r
-               \r
-       /**\r
-       * Internal placeholder for record objects. Used by ADORecordSet->FetchObj().\r
-       */\r
-       class ADOFetchObj {\r
-       };\r
-       \r
-       //==============================================================================================        \r
-       // CLASS ADORecordSet_empty\r
-       //==============================================================================================        \r
-       \r
-       /**\r
-       * Lightweight recordset when there are no records to be returned\r
-       */\r
-       class ADORecordSet_empty\r
-       {\r
-               var $dataProvider = 'empty';\r
-               var $databaseType = false;\r
-               var $EOF = true;\r
-               var $_numOfRows = 0;\r
-               var $fields = false;\r
-               var $f = false;\r
-               var $connection = false;\r
-               function RowCount() {return 0;}\r
-               function RecordCount() {return 0;}\r
-               function PO_RecordCount(){return 0;}\r
-               function Close(){return true;}\r
-               function FetchRow() {return false;}\r
-               function FieldCount(){ return 0;}\r
-               function Init() {}\r
-       }\r
-       \r
-       //==============================================================================================        \r
-       // DATE AND TIME FUNCTIONS\r
-       //==============================================================================================        \r
-       include_once(ADODB_DIR.'/adodb-time.inc.php');\r
-       \r
-       //==============================================================================================        \r
-       // CLASS ADORecordSet\r
-       //==============================================================================================        \r
-\r
-       if (PHP_VERSION < 5) include_once(ADODB_DIR.'/adodb-php4.inc.php');\r
-       else include_once(ADODB_DIR.'/adodb-iterator.inc.php');\r
-   /**\r
-        * RecordSet class that represents the dataset returned by the database.\r
-        * To keep memory overhead low, this class holds only the current row in memory.\r
-        * No prefetching of data is done, so the RecordCount() can return -1 ( which\r
-        * means recordcount not known).\r
-        */\r
-       class ADORecordSet extends ADODB_BASE_RS {\r
-       /*\r
-        * public variables     \r
-        */\r
-       var $dataProvider = "native";\r
-       var $fields = false;    /// holds the current row data\r
-       var $blobSize = 100;    /// any varchar/char field this size or greater is treated as a blob\r
-                                                       /// in other words, we use a text area for editing.\r
-       var $canSeek = false;   /// indicates that seek is supported\r
-       var $sql;                               /// sql text\r
-       var $EOF = false;               /// Indicates that the current record position is after the last record in a Recordset object. \r
-       \r
-       var $emptyTimeStamp = '&nbsp;'; /// what to display when $time==0\r
-       var $emptyDate = '&nbsp;'; /// what to display when $time==0\r
-       var $debug = false;\r
-       var $timeCreated=0;     /// datetime in Unix format rs created -- for cached recordsets\r
-\r
-       var $bind = false;              /// used by Fields() to hold array - should be private?\r
-       var $fetchMode;                 /// default fetch mode\r
-       var $connection = false; /// the parent connection\r
-       /*\r
-        *      private variables       \r
-        */\r
-       var $_numOfRows = -1;   /** number of rows, or -1 */\r
-       var $_numOfFields = -1; /** number of fields in recordset */\r
-       var $_queryID = -1;             /** This variable keeps the result link identifier.     */\r
-       var $_currentRow = -1;  /** This variable keeps the current row in the Recordset.       */\r
-       var $_closed = false;   /** has recordset been closed */\r
-       var $_inited = false;   /** Init() should only be called once */\r
-       var $_obj;                              /** Used by FetchObj */\r
-       var $_names;                    /** Used by FetchObj */\r
-       \r
-       var $_currentPage = -1; /** Added by Iván Oliva to implement recordset pagination */\r
-       var $_atFirstPage = false;      /** Added by Iván Oliva to implement recordset pagination */\r
-       var $_atLastPage = false;       /** Added by Iván Oliva to implement recordset pagination */\r
-       var $_lastPageNo = -1; \r
-       var $_maxRecordCount = 0;\r
-       var $datetime = false;\r
-       \r
-       /**\r
-        * Constructor\r
-        *\r
-        * @param queryID       this is the queryID returned by ADOConnection->_query()\r
-        *\r
-        */\r
-       function ADORecordSet($queryID) \r
-       {\r
-               $this->_queryID = $queryID;\r
-               $this->f = &$this->fields;\r
-       }\r
-       \r
-       \r
-       \r
-       function Init()\r
-       {\r
-               if ($this->_inited) return;\r
-               $this->_inited = true;\r
-               if ($this->_queryID) @$this->_initrs();\r
-               else {\r
-                       $this->_numOfRows = 0;\r
-                       $this->_numOfFields = 0;\r
-               }\r
-               if ($this->_numOfRows != 0 && $this->_numOfFields && $this->_currentRow == -1) {\r
-                       \r
-                       $this->_currentRow = 0;\r
-                       if ($this->EOF = ($this->_fetch() === false)) {\r
-                               $this->_numOfRows = 0; // _numOfRows could be -1\r
-                       }\r
-               } else {\r
-                       $this->EOF = true;\r
-               }\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Generate a SELECT tag string from a recordset, and return the string.\r
-        * If the recordset has 2 cols, we treat the 1st col as the containing \r
-        * the text to display to the user, and 2nd col as the return value. Default\r
-        * strings are compared with the FIRST column.\r
-        *\r
-        * @param name                  name of SELECT tag\r
-        * @param [defstr]              the value to hilite. Use an array for multiple hilites for listbox.\r
-        * @param [blank1stItem]        true to leave the 1st item in list empty\r
-        * @param [multiple]            true for listbox, false for popup\r
-        * @param [size]                #rows to show for listbox. not used by popup\r
-        * @param [selectAttr]          additional attributes to defined for SELECT tag.\r
-        *                              useful for holding javascript onChange='...' handlers.\r
-        & @param [compareFields0]      when we have 2 cols in recordset, we compare the defstr with \r
-        *                              column 0 (1st col) if this is true. This is not documented.\r
-        *\r
-        * @return HTML\r
-        *\r
-        * changes by glen.davies@cce.ac.nz to support multiple hilited items\r
-        */\r
-       function GetMenu($name,$defstr='',$blank1stItem=true,$multiple=false,\r
-                       $size=0, $selectAttr='',$compareFields0=true)\r
-       {\r
-               global $ADODB_INCLUDED_LIB;\r
-               if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_getmenu($this, $name,$defstr,$blank1stItem,$multiple,\r
-                       $size, $selectAttr,$compareFields0);\r
-       }\r
-       \r
-\r
-       \r
-       /**\r
-        * Generate a SELECT tag string from a recordset, and return the string.\r
-        * If the recordset has 2 cols, we treat the 1st col as the containing \r
-        * the text to display to the user, and 2nd col as the return value. Default\r
-        * strings are compared with the SECOND column.\r
-        *\r
-        */\r
-       function GetMenu2($name,$defstr='',$blank1stItem=true,$multiple=false,$size=0, $selectAttr='')  \r
-       {\r
-               return $this->GetMenu($name,$defstr,$blank1stItem,$multiple,\r
-                       $size, $selectAttr,false);\r
-       }\r
-       \r
-       /*\r
-               Grouped Menu\r
-       */\r
-       function GetMenu3($name,$defstr='',$blank1stItem=true,$multiple=false,\r
-                       $size=0, $selectAttr='')\r
-       {\r
-               global $ADODB_INCLUDED_LIB;\r
-               if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_getmenu_gp($this, $name,$defstr,$blank1stItem,$multiple,\r
-                       $size, $selectAttr,false);\r
-       }\r
-\r
-       /**\r
-        * return recordset as a 2-dimensional array.\r
-        *\r
-        * @param [nRows]  is the number of rows to return. -1 means every row.\r
-        *\r
-        * @return an array indexed by the rows (0-based) from the recordset\r
-        */\r
-       function &GetArray($nRows = -1) \r
-       {\r
-       global $ADODB_EXTENSION; if ($ADODB_EXTENSION) return adodb_getall($this,$nRows);\r
-               \r
-               $results = array();\r
-               $cnt = 0;\r
-               while (!$this->EOF && $nRows != $cnt) {\r
-                       $results[] = $this->fields;\r
-                       $this->MoveNext();\r
-                       $cnt++;\r
-               }\r
-               return $results;\r
-       }\r
-       \r
-       function &GetAll($nRows = -1)\r
-       {\r
-               $arr =& $this->GetArray($nRows);\r
-               return $arr;\r
-       }\r
-       \r
-       /*\r
-       * Some databases allow multiple recordsets to be returned. This function\r
-       * will return true if there is a next recordset, or false if no more.\r
-       */\r
-       function NextRecordSet()\r
-       {\r
-               return false;\r
-       }\r
-       \r
-       /**\r
-        * return recordset as a 2-dimensional array. \r
-        * Helper function for ADOConnection->SelectLimit()\r
-        *\r
-        * @param offset        is the row to start calculations from (1-based)\r
-        * @param [nrows]       is the number of rows to return\r
-        *\r
-        * @return an array indexed by the rows (0-based) from the recordset\r
-        */\r
-       function &GetArrayLimit($nrows,$offset=-1) \r
-       {       \r
-               if ($offset <= 0) {\r
-                       $arr =& $this->GetArray($nrows);\r
-                       return $arr;\r
-               } \r
-               \r
-               $this->Move($offset);\r
-               \r
-               $results = array();\r
-               $cnt = 0;\r
-               while (!$this->EOF && $nrows != $cnt) {\r
-                       $results[$cnt++] = $this->fields;\r
-                       $this->MoveNext();\r
-               }\r
-               \r
-               return $results;\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Synonym for GetArray() for compatibility with ADO.\r
-        *\r
-        * @param [nRows]  is the number of rows to return. -1 means every row.\r
-        *\r
-        * @return an array indexed by the rows (0-based) from the recordset\r
-        */\r
-       function &GetRows($nRows = -1) \r
-       {\r
-               $arr =& $this->GetArray($nRows);\r
-               return $arr;\r
-       }\r
-       \r
-       /**\r
-        * return whole recordset as a 2-dimensional associative array if there are more than 2 columns. \r
-        * The first column is treated as the key and is not included in the array. \r
-        * If there is only 2 columns, it will return a 1 dimensional array of key-value pairs unless\r
-        * $force_array == true.\r
-        *\r
-        * @param [force_array] has only meaning if we have 2 data columns. If false, a 1 dimensional\r
-        *      array is returned, otherwise a 2 dimensional array is returned. If this sounds confusing,\r
-        *      read the source.\r
-        *\r
-        * @param [first2cols] means if there are more than 2 cols, ignore the remaining cols and \r
-        * instead of returning array[col0] => array(remaining cols), return array[col0] => col1\r
-        *\r
-        * @return an associative array indexed by the first column of the array, \r
-        *      or false if the  data has less than 2 cols.\r
-        */\r
-       function &GetAssoc($force_array = false, $first2cols = false) \r
-       {\r
-       global $ADODB_EXTENSION;\r
-       \r
-               $cols = $this->_numOfFields;\r
-               if ($cols < 2) {\r
-                       $false = false;\r
-                       return $false;\r
-               }\r
-               $numIndex = isset($this->fields[0]);\r
-               $results = array();\r
-               \r
-               if (!$first2cols && ($cols > 2 || $force_array)) {\r
-                       if ($ADODB_EXTENSION) {\r
-                               if ($numIndex) {\r
-                                       while (!$this->EOF) {\r
-                                               $results[trim($this->fields[0])] = array_slice($this->fields, 1);\r
-                                               adodb_movenext($this);\r
-                                       }\r
-                               } else {\r
-                                       while (!$this->EOF) {\r
-                                               $results[trim(reset($this->fields))] = array_slice($this->fields, 1);\r
-                                               adodb_movenext($this);\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               if ($numIndex) {\r
-                                       while (!$this->EOF) {\r
-                                               $results[trim($this->fields[0])] = array_slice($this->fields, 1);\r
-                                               $this->MoveNext();\r
-                                       }\r
-                               } else {\r
-                                       while (!$this->EOF) {\r
-                                               $results[trim(reset($this->fields))] = array_slice($this->fields, 1);\r
-                                               $this->MoveNext();\r
-                                       }\r
-                               }\r
-                       }\r
-               } else {\r
-                       if ($ADODB_EXTENSION) {\r
-                               // return scalar values\r
-                               if ($numIndex) {\r
-                                       while (!$this->EOF) {\r
-                                       // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string\r
-                                               $results[trim(($this->fields[0]))] = $this->fields[1];\r
-                                               adodb_movenext($this);\r
-                                       }\r
-                               } else {\r
-                                       while (!$this->EOF) {\r
-                                       // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string\r
-                                               $v1 = trim(reset($this->fields));\r
-                                               $v2 = ''.next($this->fields); \r
-                                               $results[$v1] = $v2;\r
-                                               adodb_movenext($this);\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               if ($numIndex) {\r
-                                       while (!$this->EOF) {\r
-                                       // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string\r
-                                               $results[trim(($this->fields[0]))] = $this->fields[1];\r
-                                               $this->MoveNext();\r
-                                       }\r
-                               } else {\r
-                                       while (!$this->EOF) {\r
-                                       // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string\r
-                                               $v1 = trim(reset($this->fields));\r
-                                               $v2 = ''.next($this->fields); \r
-                                               $results[$v1] = $v2;\r
-                                               $this->MoveNext();\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               return $results; \r
-       }\r
-       \r
-       \r
-       /**\r
-        *\r
-        * @param v     is the character timestamp in YYYY-MM-DD hh:mm:ss format\r
-        * @param fmt   is the format to apply to it, using date()\r
-        *\r
-        * @return a timestamp formated as user desires\r
-        */\r
-       function UserTimeStamp($v,$fmt='Y-m-d H:i:s')\r
-       {\r
-               if (is_numeric($v) && strlen($v)<14) return adodb_date($fmt,$v);\r
-               $tt = $this->UnixTimeStamp($v);\r
-               // $tt == -1 if pre TIMESTAMP_FIRST_YEAR\r
-               if (($tt === false || $tt == -1) && $v != false) return $v;\r
-               if ($tt === 0) return $this->emptyTimeStamp;\r
-               return adodb_date($fmt,$tt);\r
-       }\r
-       \r
-       \r
-       /**\r
-        * @param v     is the character date in YYYY-MM-DD format, returned by database\r
-        * @param fmt   is the format to apply to it, using date()\r
-        *\r
-        * @return a date formated as user desires\r
-        */\r
-       function UserDate($v,$fmt='Y-m-d')\r
-       {\r
-               $tt = $this->UnixDate($v);\r
-               // $tt == -1 if pre TIMESTAMP_FIRST_YEAR\r
-               if (($tt === false || $tt == -1) && $v != false) return $v;\r
-               else if ($tt == 0) return $this->emptyDate;\r
-               else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR\r
-               }\r
-               return adodb_date($fmt,$tt);\r
-       }\r
-       \r
-       \r
-       /**\r
-        * @param $v is a date string in YYYY-MM-DD format\r
-        *\r
-        * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format\r
-        */\r
-       function UnixDate($v)\r
-       {\r
-               return ADOConnection::UnixDate($v);\r
-       }\r
-       \r
-\r
-       /**\r
-        * @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format\r
-        *\r
-        * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format\r
-        */\r
-       function UnixTimeStamp($v)\r
-       {\r
-               return ADOConnection::UnixTimeStamp($v);\r
-       }\r
-       \r
-       \r
-       /**\r
-       * PEAR DB Compat - do not use internally\r
-       */\r
-       function Free()\r
-       {\r
-               return $this->Close();\r
-       }\r
-       \r
-       \r
-       /**\r
-       * PEAR DB compat, number of rows\r
-       */\r
-       function NumRows()\r
-       {\r
-               return $this->_numOfRows;\r
-       }\r
-       \r
-       \r
-       /**\r
-       * PEAR DB compat, number of cols\r
-       */\r
-       function NumCols()\r
-       {\r
-               return $this->_numOfFields;\r
-       }\r
-       \r
-       /**\r
-       * Fetch a row, returning false if no more rows. \r
-       * This is PEAR DB compat mode.\r
-       *\r
-       * @return false or array containing the current record\r
-       */\r
-       function &FetchRow()\r
-       {\r
-               if ($this->EOF) {\r
-                       $false = false;\r
-                       return $false;\r
-               }\r
-               $arr = $this->fields;\r
-               $this->_currentRow++;\r
-               if (!$this->_fetch()) $this->EOF = true;\r
-               return $arr;\r
-       }\r
-       \r
-       \r
-       /**\r
-       * Fetch a row, returning PEAR_Error if no more rows. \r
-       * This is PEAR DB compat mode.\r
-       *\r
-       * @return DB_OK or error object\r
-       */\r
-       function FetchInto(&$arr)\r
-       {\r
-               if ($this->EOF) return (defined('PEAR_ERROR_RETURN')) ? new PEAR_Error('EOF',-1): false;\r
-               $arr = $this->fields;\r
-               $this->MoveNext();\r
-               return 1; // DB_OK\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Move to the first row in the recordset. Many databases do NOT support this.\r
-        *\r
-        * @return true or false\r
-        */\r
-       function MoveFirst() \r
-       {\r
-               if ($this->_currentRow == 0) return true;\r
-               return $this->Move(0);                  \r
-       }                       \r
-\r
-       \r
-       /**\r
-        * Move to the last row in the recordset. \r
-        *\r
-        * @return true or false\r
-        */\r
-       function MoveLast() \r
-       {\r
-               if ($this->_numOfRows >= 0) return $this->Move($this->_numOfRows-1);\r
-               if ($this->EOF) return false;\r
-               while (!$this->EOF) {\r
-                       $f = $this->fields;\r
-                       $this->MoveNext();\r
-               }\r
-               $this->fields = $f;\r
-               $this->EOF = false;\r
-               return true;\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Move to next record in the recordset.\r
-        *\r
-        * @return true if there still rows available, or false if there are no more rows (EOF).\r
-        */\r
-       function MoveNext() \r
-       {\r
-               if (!$this->EOF) {\r
-                       $this->_currentRow++;\r
-                       if ($this->_fetch()) return true;\r
-               }\r
-               $this->EOF = true;\r
-               /* -- tested error handling when scrolling cursor -- seems useless.\r
-               $conn = $this->connection;\r
-               if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) {\r
-                       $fn = $conn->raiseErrorFn;\r
-                       $fn($conn->databaseType,'MOVENEXT',$errno,$conn->ErrorMsg().' ('.$this->sql.')',$conn->host,$conn->database);\r
-               }\r
-               */\r
-               return false;\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Random access to a specific row in the recordset. Some databases do not support\r
-        * access to previous rows in the databases (no scrolling backwards).\r
-        *\r
-        * @param rowNumber is the row to move to (0-based)\r
-        *\r
-        * @return true if there still rows available, or false if there are no more rows (EOF).\r
-        */\r
-       function Move($rowNumber = 0) \r
-       {\r
-               $this->EOF = false;\r
-               if ($rowNumber == $this->_currentRow) return true;\r
-               if ($rowNumber >= $this->_numOfRows)\r
-                       if ($this->_numOfRows != -1) $rowNumber = $this->_numOfRows-2;\r
-                               \r
-               if ($this->canSeek) { \r
-       \r
-                       if ($this->_seek($rowNumber)) {\r
-                               $this->_currentRow = $rowNumber;\r
-                               if ($this->_fetch()) {\r
-                                       return true;\r
-                               }\r
-                       } else {\r
-                               $this->EOF = true;\r
-                               return false;\r
-                       }\r
-               } else {\r
-                       if ($rowNumber < $this->_currentRow) return false;\r
-                       global $ADODB_EXTENSION;\r
-                       if ($ADODB_EXTENSION) {\r
-                               while (!$this->EOF && $this->_currentRow < $rowNumber) {\r
-                                       adodb_movenext($this);\r
-                               }\r
-                       } else {\r
-                       \r
-                               while (! $this->EOF && $this->_currentRow < $rowNumber) {\r
-                                       $this->_currentRow++;\r
-                                       \r
-                                       if (!$this->_fetch()) $this->EOF = true;\r
-                               }\r
-                       }\r
-                       return !($this->EOF);\r
-               }\r
-               \r
-               $this->fields = false;  \r
-               $this->EOF = true;\r
-               return false;\r
-       }\r
-       \r
-               \r
-       /**\r
-        * Get the value of a field in the current row by column name.\r
-        * Will not work if ADODB_FETCH_MODE is set to ADODB_FETCH_NUM.\r
-        * \r
-        * @param colname  is the field to access\r
-        *\r
-        * @return the value of $colname column\r
-        */\r
-       function Fields($colname)\r
-       {\r
-               return $this->fields[$colname];\r
-       }\r
-       \r
-       function GetAssocKeys($upper=true)\r
-       {\r
-               $this->bind = array();\r
-               for ($i=0; $i < $this->_numOfFields; $i++) {\r
-                       $o = $this->FetchField($i);\r
-                       if ($upper === 2) $this->bind[$o->name] = $i;\r
-                       else $this->bind[($upper) ? strtoupper($o->name) : strtolower($o->name)] = $i;\r
-               }\r
-       }\r
-       \r
-  /**\r
-   * Use associative array to get fields array for databases that do not support\r
-   * associative arrays. Submitted by Paolo S. Asioli paolo.asioli#libero.it\r
-   *\r
-   * If you don't want uppercase cols, set $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC\r
-   * before you execute your SQL statement, and access $rs->fields['col'] directly.\r
-   *\r
-   * $upper  0 = lowercase, 1 = uppercase, 2 = whatever is returned by FetchField\r
-   */\r
-       function &GetRowAssoc($upper=1)\r
-       {\r
-               $record = array();\r
-        //     if (!$this->fields) return $record;\r
-               \r
-               if (!$this->bind) {\r
-                       $this->GetAssocKeys($upper);\r
-               }\r
-               \r
-               foreach($this->bind as $k => $v) {\r
-                       $record[$k] = $this->fields[$v];\r
-               }\r
-\r
-               return $record;\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Clean up recordset\r
-        *\r
-        * @return true or false\r
-        */\r
-       function Close() \r
-       {\r
-               // free connection object - this seems to globally free the object\r
-               // and not merely the reference, so don't do this...\r
-               // $this->connection = false; \r
-               if (!$this->_closed) {\r
-                       $this->_closed = true;\r
-                       return $this->_close();         \r
-               } else\r
-                       return true;\r
-       }\r
-       \r
-       /**\r
-        * synonyms RecordCount and RowCount    \r
-        *\r
-        * @return the number of rows or -1 if this is not supported\r
-        */\r
-       function RecordCount() {return $this->_numOfRows;}\r
-       \r
-       \r
-       /*\r
-       * If we are using PageExecute(), this will return the maximum possible rows\r
-       * that can be returned when paging a recordset.\r
-       */\r
-       function MaxRecordCount()\r
-       {\r
-               return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount();\r
-       }\r
-       \r
-       /**\r
-        * synonyms RecordCount and RowCount    \r
-        *\r
-        * @return the number of rows or -1 if this is not supported\r
-        */\r
-       function RowCount() {return $this->_numOfRows;} \r
-       \r
-\r
-        /**\r
-        * Portable RecordCount. Pablo Roca <pabloroca@mvps.org>\r
-        *\r
-        * @return  the number of records from a previous SELECT. All databases support this.\r
-        *\r
-        * But aware possible problems in multiuser environments. For better speed the table\r
-        * must be indexed by the condition. Heavy test this before deploying.\r
-        */ \r
-       function PO_RecordCount($table="", $condition="") {\r
-               \r
-               $lnumrows = $this->_numOfRows;\r
-               // the database doesn't support native recordcount, so we do a workaround\r
-               if ($lnumrows == -1 && $this->connection) {\r
-                       IF ($table) {\r
-                               if ($condition) $condition = " WHERE " . $condition; \r
-                               $resultrows = &$this->connection->Execute("SELECT COUNT(*) FROM $table $condition");\r
-                               if ($resultrows) $lnumrows = reset($resultrows->fields);\r
-                       }\r
-               }\r
-               return $lnumrows;\r
-       }\r
-       \r
-       /**\r
-        * @return the current row in the recordset. If at EOF, will return the last row. 0-based.\r
-        */\r
-       function CurrentRow() {return $this->_currentRow;}\r
-       \r
-       /**\r
-        * synonym for CurrentRow -- for ADO compat\r
-        *\r
-        * @return the current row in the recordset. If at EOF, will return the last row. 0-based.\r
-        */\r
-       function AbsolutePosition() {return $this->_currentRow;}\r
-       \r
-       /**\r
-        * @return the number of columns in the recordset. Some databases will set this to 0\r
-        * if no records are returned, others will return the number of columns in the query.\r
-        */\r
-       function FieldCount() {return $this->_numOfFields;}   \r
-\r
-\r
-       /**\r
-        * Get the ADOFieldObject of a specific column.\r
-        *\r
-        * @param fieldoffset   is the column position to access(0-based).\r
-        *\r
-        * @return the ADOFieldObject for that column, or false.\r
-        */\r
-       function &FetchField($fieldoffset) \r
-       {\r
-               // must be defined by child class\r
-       }       \r
-       \r
-       /**\r
-        * Get the ADOFieldObjects of all columns in an array.\r
-        *\r
-        */\r
-       function& FieldTypesArray()\r
-       {\r
-               $arr = array();\r
-               for ($i=0, $max=$this->_numOfFields; $i < $max; $i++) \r
-                       $arr[] = $this->FetchField($i);\r
-               return $arr;\r
-       }\r
-       \r
-       /**\r
-       * Return the fields array of the current row as an object for convenience.\r
-       * The default case is lowercase field names.\r
-       *\r
-       * @return the object with the properties set to the fields of the current row\r
-       */\r
-       function &FetchObj()\r
-       {\r
-               $o =& $this->FetchObject(false);\r
-               return $o;\r
-       }\r
-       \r
-       /**\r
-       * Return the fields array of the current row as an object for convenience.\r
-       * The default case is uppercase.\r
-       * \r
-       * @param $isupper to set the object property names to uppercase\r
-       *\r
-       * @return the object with the properties set to the fields of the current row\r
-       */\r
-       function &FetchObject($isupper=true)\r
-       {\r
-               if (empty($this->_obj)) {\r
-                       $this->_obj = new ADOFetchObj();\r
-                       $this->_names = array();\r
-                       for ($i=0; $i <$this->_numOfFields; $i++) {\r
-                               $f = $this->FetchField($i);\r
-                               $this->_names[] = $f->name;\r
-                       }\r
-               }\r
-               $i = 0;\r
-               if (PHP_VERSION >= 5) $o = clone($this->_obj);\r
-               else $o = $this->_obj;\r
-       \r
-               for ($i=0; $i <$this->_numOfFields; $i++) {\r
-                       $name = $this->_names[$i];\r
-                       if ($isupper) $n = strtoupper($name);\r
-                       else $n = $name;\r
-                       \r
-                       $o->$n = $this->Fields($name);\r
-               }\r
-               return $o;\r
-       }\r
-       \r
-       /**\r
-       * Return the fields array of the current row as an object for convenience.\r
-       * The default is lower-case field names.\r
-       * \r
-       * @return the object with the properties set to the fields of the current row,\r
-       *       or false if EOF\r
-       *\r
-       * Fixed bug reported by tim@orotech.net\r
-       */\r
-       function &FetchNextObj()\r
-       {\r
-               $o =& $this->FetchNextObject(false);\r
-               return $o;\r
-       }\r
-       \r
-       \r
-       /**\r
-       * Return the fields array of the current row as an object for convenience. \r
-       * The default is upper case field names.\r
-       * \r
-       * @param $isupper to set the object property names to uppercase\r
-       *\r
-       * @return the object with the properties set to the fields of the current row,\r
-       *       or false if EOF\r
-       *\r
-       * Fixed bug reported by tim@orotech.net\r
-       */\r
-       function &FetchNextObject($isupper=true)\r
-       {\r
-               $o = false;\r
-               if ($this->_numOfRows != 0 && !$this->EOF) {\r
-                       $o = $this->FetchObject($isupper);      \r
-                       $this->_currentRow++;\r
-                       if ($this->_fetch()) return $o;\r
-               }\r
-               $this->EOF = true;\r
-               return $o;\r
-       }\r
-       \r
-       /**\r
-        * Get the metatype of the column. This is used for formatting. This is because\r
-        * many databases use different names for the same type, so we transform the original\r
-        * type to our standardised version which uses 1 character codes:\r
-        *\r
-        * @param t  is the type passed in. Normally is ADOFieldObject->type.\r
-        * @param len is the maximum length of that field. This is because we treat character\r
-        *      fields bigger than a certain size as a 'B' (blob).\r
-        * @param fieldobj is the field object returned by the database driver. Can hold\r
-        *      additional info (eg. primary_key for mysql).\r
-        * \r
-        * @return the general type of the data: \r
-        *      C for character < 250 chars\r
-        *      X for teXt (>= 250 chars)\r
-        *      B for Binary\r
-        *      N for numeric or floating point\r
-        *      D for date\r
-        *      T for timestamp\r
-        *      L for logical/Boolean\r
-        *      I for integer\r
-        *      R for autoincrement counter/integer\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
-       // changed in 2.32 to hashing instead of switch stmt for speed...\r
-       static $typeMap = array(\r
-               'VARCHAR' => 'C',\r
-               'VARCHAR2' => 'C',\r
-               'CHAR' => 'C',\r
-               'C' => 'C',\r
-               'STRING' => 'C',\r
-               'NCHAR' => 'C',\r
-               'NVARCHAR' => 'C',\r
-               'VARYING' => 'C',\r
-               'BPCHAR' => 'C',\r
-               'CHARACTER' => 'C',\r
-               'INTERVAL' => 'C',  # Postgres\r
-               ##\r
-               'LONGCHAR' => 'X',\r
-               'TEXT' => 'X',\r
-               'NTEXT' => 'X',\r
-               'M' => 'X',\r
-               'X' => 'X',\r
-               'CLOB' => 'X',\r
-               'NCLOB' => 'X',\r
-               'LVARCHAR' => 'X',\r
-               ##\r
-               'BLOB' => 'B',\r
-               'IMAGE' => 'B',\r
-               'BINARY' => 'B',\r
-               'VARBINARY' => 'B',\r
-               'LONGBINARY' => 'B',\r
-               'B' => 'B',\r
-               ##\r
-               'YEAR' => 'D', // mysql\r
-               'DATE' => 'D',\r
-               'D' => 'D',\r
-               ##\r
-               'TIME' => 'T',\r
-               'TIMESTAMP' => 'T',\r
-               'DATETIME' => 'T',\r
-               'TIMESTAMPTZ' => 'T',\r
-               'T' => 'T',\r
-               ##\r
-               'BOOL' => 'L',\r
-               'BOOLEAN' => 'L', \r
-               'BIT' => 'L',\r
-               'L' => 'L',\r
-               ##\r
-               'COUNTER' => 'R',\r
-               'R' => 'R',\r
-               'SERIAL' => 'R', // ifx\r
-               'INT IDENTITY' => 'R',\r
-               ##\r
-               'INT' => 'I',\r
-               'INT2' => 'I',\r
-               'INT4' => 'I',\r
-               'INT8' => 'I',\r
-               'INTEGER' => 'I',\r
-               'INTEGER UNSIGNED' => 'I',\r
-               'SHORT' => 'I',\r
-               'TINYINT' => 'I',\r
-               'SMALLINT' => 'I',\r
-               'I' => 'I',\r
-               ##\r
-               'LONG' => 'N', // interbase is numeric, oci8 is blob\r
-               'BIGINT' => 'N', // this is bigger than PHP 32-bit integers\r
-               'DECIMAL' => 'N',\r
-               'DEC' => 'N',\r
-               'REAL' => 'N',\r
-               'DOUBLE' => 'N',\r
-               'DOUBLE PRECISION' => 'N',\r
-               'SMALLFLOAT' => 'N',\r
-               'FLOAT' => 'N',\r
-               'NUMBER' => 'N',\r
-               'NUM' => 'N',\r
-               'NUMERIC' => 'N',\r
-               'MONEY' => 'N',\r
-               \r
-               ## informix 9.2\r
-               'SQLINT' => 'I', \r
-               'SQLSERIAL' => 'I', \r
-               'SQLSMINT' => 'I', \r
-               'SQLSMFLOAT' => 'N', \r
-               'SQLFLOAT' => 'N', \r
-               'SQLMONEY' => 'N', \r
-               'SQLDECIMAL' => 'N', \r
-               'SQLDATE' => 'D', \r
-               'SQLVCHAR' => 'C', \r
-               'SQLCHAR' => 'C', \r
-               'SQLDTIME' => 'T', \r
-               'SQLINTERVAL' => 'N', \r
-               'SQLBYTES' => 'B', \r
-               'SQLTEXT' => 'X' \r
-               );\r
-               \r
-               $tmap = false;\r
-               $t = strtoupper($t);\r
-               $tmap = (isset($typeMap[$t])) ? $typeMap[$t] : 'N';\r
-               switch ($tmap) {\r
-               case 'C':\r
-               \r
-                       // is the char field is too long, return as text field... \r
-                       if ($this->blobSize >= 0) {\r
-                               if ($len > $this->blobSize) return 'X';\r
-                       } else if ($len > 250) {\r
-                               return 'X';\r
-                       }\r
-                       return 'C';\r
-                       \r
-               case 'I':\r
-                       if (!empty($fieldobj->primary_key)) return 'R';\r
-                       return 'I';\r
-               \r
-               case false:\r
-                       return 'N';\r
-                       \r
-               case 'B':\r
-                        if (isset($fieldobj->binary)) \r
-                                return ($fieldobj->binary) ? 'B' : 'X';\r
-                       return 'B';\r
-               \r
-               case 'D':\r
-                       if (!empty($this->datetime)) return 'T';\r
-                       return 'D';\r
-                       \r
-               default: \r
-                       if ($t == 'LONG' && $this->dataProvider == 'oci8') return 'B';\r
-                       return $tmap;\r
-               }\r
-       }\r
-       \r
-       function _close() {}\r
-       \r
-       /**\r
-        * set/returns the current recordset page when paginating\r
-        */\r
-       function AbsolutePage($page=-1)\r
-       {\r
-               if ($page != -1) $this->_currentPage = $page;\r
-               return $this->_currentPage;\r
-       }\r
-       \r
-       /**\r
-        * set/returns the status of the atFirstPage flag when paginating\r
-        */\r
-       function AtFirstPage($status=false)\r
-       {\r
-               if ($status != false) $this->_atFirstPage = $status;\r
-               return $this->_atFirstPage;\r
-       }\r
-       \r
-       function LastPageNo($page = false)\r
-       {\r
-               if ($page != false) $this->_lastPageNo = $page;\r
-               return $this->_lastPageNo;\r
-       }\r
-       \r
-       /**\r
-        * set/returns the status of the atLastPage flag when paginating\r
-        */\r
-       function AtLastPage($status=false)\r
-       {\r
-               if ($status != false) $this->_atLastPage = $status;\r
-               return $this->_atLastPage;\r
-       }\r
-       \r
-} // end class ADORecordSet\r
-       \r
-       //==============================================================================================        \r
-       // CLASS ADORecordSet_array\r
-       //==============================================================================================        \r
-       \r
-       /**\r
-        * This class encapsulates the concept of a recordset created in memory\r
-        * as an array. This is useful for the creation of cached recordsets.\r
-        * \r
-        * Note that the constructor is different from the standard ADORecordSet\r
-        */\r
-       \r
-       class ADORecordSet_array extends ADORecordSet\r
-       {\r
-               var $databaseType = 'array';\r
-\r
-               var $_array;    // holds the 2-dimensional data array\r
-               var $_types;    // the array of types of each column (C B I L M)\r
-               var $_colnames; // names of each column in array\r
-               var $_skiprow1; // skip 1st row because it holds column names\r
-               var $_fieldarr; // holds array of field objects\r
-               var $canSeek = true;\r
-               var $affectedrows = false;\r
-               var $insertid = false;\r
-               var $sql = '';\r
-               var $compat = false;\r
-               /**\r
-                * Constructor\r
-                *\r
-                */\r
-               function ADORecordSet_array($fakeid=1)\r
-               {\r
-               global $ADODB_FETCH_MODE,$ADODB_COMPAT_FETCH;\r
-               \r
-                       // fetch() on EOF does not delete $this->fields\r
-                       $this->compat = !empty($ADODB_COMPAT_FETCH);\r
-                       $this->ADORecordSet($fakeid); // fake queryID           \r
-                       $this->fetchMode = $ADODB_FETCH_MODE;\r
-               }\r
-               \r
-               \r
-               /**\r
-                * Setup the array.\r
-                *\r
-                * @param array         is a 2-dimensional array holding the data.\r
-                *                      The first row should hold the column names \r
-                *                      unless paramter $colnames is used.\r
-                * @param typearr       holds an array of types. These are the same types \r
-                *                      used in MetaTypes (C,B,L,I,N).\r
-                * @param [colnames]    array of column names. If set, then the first row of\r
-                *                      $array should not hold the column names.\r
-                */\r
-               function InitArray($array,$typearr,$colnames=false)\r
-               {\r
-                       $this->_array = $array;\r
-                       $this->_types = $typearr;       \r
-                       if ($colnames) {\r
-                               $this->_skiprow1 = false;\r
-                               $this->_colnames = $colnames;\r
-                       } else  {\r
-                               $this->_skiprow1 = true;\r
-                               $this->_colnames = $array[0];\r
-                       }\r
-                       $this->Init();\r
-               }\r
-               /**\r
-                * Setup the Array and datatype file objects\r
-                *\r
-                * @param array         is a 2-dimensional array holding the data.\r
-                *                      The first row should hold the column names \r
-                *                      unless paramter $colnames is used.\r
-                * @param fieldarr      holds an array of ADOFieldObject's.\r
-                */\r
-               function InitArrayFields(&$array,&$fieldarr)\r
-               {\r
-                       $this->_array =& $array;\r
-                       $this->_skiprow1= false;\r
-                       if ($fieldarr) {\r
-                               $this->_fieldobjects =& $fieldarr;\r
-                       } \r
-                       $this->Init();\r
-               }\r
-               \r
-               function &GetArray($nRows=-1)\r
-               {\r
-                       if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) {\r
-                               return $this->_array;\r
-                       } else {\r
-                               $arr =& ADORecordSet::GetArray($nRows);\r
-                               return $arr;\r
-                       }\r
-               }\r
-               \r
-               function _initrs()\r
-               {\r
-                       $this->_numOfRows =  sizeof($this->_array);\r
-                       if ($this->_skiprow1) $this->_numOfRows -= 1;\r
-               \r
-                       $this->_numOfFields =(isset($this->_fieldobjects)) ?\r
-                                sizeof($this->_fieldobjects):sizeof($this->_types);\r
-               }\r
-               \r
-               /* Use associative array to get fields array */\r
-               function Fields($colname)\r
-               {\r
-                       $mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode;\r
-                       \r
-                       if ($mode & ADODB_FETCH_ASSOC) {\r
-                               if (!isset($this->fields[$colname])) $colname = strtolower($colname);\r
-                               return $this->fields[$colname];\r
-                       }\r
-                       if (!$this->bind) {\r
-                               $this->bind = array();\r
-                               for ($i=0; $i < $this->_numOfFields; $i++) {\r
-                                       $o = $this->FetchField($i);\r
-                                       $this->bind[strtoupper($o->name)] = $i;\r
-                               }\r
-                       }\r
-                       return $this->fields[$this->bind[strtoupper($colname)]];\r
-               }\r
-               \r
-               function &FetchField($fieldOffset = -1) \r
-               {\r
-                       if (isset($this->_fieldobjects)) {\r
-                               return $this->_fieldobjects[$fieldOffset];\r
-                       }\r
-                       $o =  new ADOFieldObject();\r
-                       $o->name = $this->_colnames[$fieldOffset];\r
-                       $o->type =  $this->_types[$fieldOffset];\r
-                       $o->max_length = -1; // length not known\r
-                       \r
-                       return $o;\r
-               }\r
-                       \r
-               function _seek($row)\r
-               {\r
-                       if (sizeof($this->_array) && 0 <= $row && $row < $this->_numOfRows) {\r
-                               $this->_currentRow = $row;\r
-                               if ($this->_skiprow1) $row += 1;\r
-                               $this->fields = $this->_array[$row];\r
-                               return true;\r
-                       }\r
-                       return false;\r
-               }\r
-               \r
-               function MoveNext() \r
-               {\r
-                       if (!$this->EOF) {              \r
-                               $this->_currentRow++;\r
-                               \r
-                               $pos = $this->_currentRow;\r
-                               \r
-                               if ($this->_numOfRows <= $pos) {\r
-                                       if (!$this->compat) $this->fields = false;\r
-                               } else {\r
-                                       if ($this->_skiprow1) $pos += 1;\r
-                                       $this->fields = $this->_array[$pos];\r
-                                       return true;\r
-                               }               \r
-                               $this->EOF = true;\r
-                       }\r
-                       \r
-                       return false;\r
-               }       \r
-       \r
-               function _fetch()\r
-               {\r
-                       $pos = $this->_currentRow;\r
-                       \r
-                       if ($this->_numOfRows <= $pos) {\r
-                               if (!$this->compat) $this->fields = false;\r
-                               return false;\r
-                       }\r
-                       if ($this->_skiprow1) $pos += 1;\r
-                       $this->fields = $this->_array[$pos];\r
-                       return true;\r
-               }\r
-               \r
-               function _close() \r
-               {\r
-                       return true;    \r
-               }\r
-       \r
-       } // ADORecordSet_array\r
-\r
-       //==============================================================================================        \r
-       // HELPER FUNCTIONS\r
-       //==============================================================================================                        \r
-       \r
-       /**\r
-        * Synonym for ADOLoadCode. Private function. Do not use.\r
-        *\r
-        * @deprecated\r
-        */\r
-       function ADOLoadDB($dbType) \r
-       { \r
-               return ADOLoadCode($dbType);\r
-       }\r
-               \r
-       /**\r
-        * Load the code for a specific database driver. Private function. Do not use.\r
-        */\r
-       function ADOLoadCode($dbType) \r
-       {\r
-       global $ADODB_LASTDB;\r
-       \r
-               if (!$dbType) return false;\r
-               $db = strtolower($dbType);\r
-               switch ($db) {\r
-                       case 'ado': \r
-                               if (PHP_VERSION >= 5) $db = 'ado5';\r
-                               $class = 'ado'; \r
-                               break;\r
-                       case 'ifx':\r
-                       case 'maxsql': $class = $db = 'mysqlt'; break;\r
-                       case 'postgres':\r
-                       case 'postgres8':\r
-                       case 'pgsql': $class = $db = 'postgres7'; break;\r
-                       default:\r
-                               $class = $db; break;\r
-               }\r
-               \r
-               $file = ADODB_DIR."/drivers/adodb-".$db.".inc.php";\r
-               @include_once($file);\r
-               $ADODB_LASTDB = $class;\r
-               if (class_exists("ADODB_" . $class)) return $class;\r
-               \r
-               //ADOConnection::outp(adodb_pr(get_declared_classes(),true));\r
-               if (!file_exists($file)) ADOConnection::outp("Missing file: $file");\r
-               else ADOConnection::outp("Syntax error in file: $file");\r
-               return false;\r
-       }\r
-\r
-       /**\r
-        * synonym for ADONewConnection for people like me who cannot remember the correct name\r
-        */\r
-       function &NewADOConnection($db='')\r
-       {\r
-               $tmp =& ADONewConnection($db);\r
-               return $tmp;\r
-       }\r
-       \r
-       /**\r
-        * Instantiate a new Connection class for a specific database driver.\r
-        *\r
-        * @param [db]  is the database Connection object to create. If undefined,\r
-        *      use the last database driver that was loaded by ADOLoadCode().\r
-        *\r
-        * @return the freshly created instance of the Connection class.\r
-        */\r
-       function &ADONewConnection($db='')\r
-       {\r
-       GLOBAL $ADODB_NEWCONNECTION, $ADODB_LASTDB;\r
-               \r
-               if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);\r
-               $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false;\r
-               $false = false;\r
-               if (strpos($db,'://')) {\r
-                       $origdsn = $db;\r
-                       $dsna = @parse_url($db);\r
-                       \r
-                       if (!$dsna) {\r
-                               // special handling of oracle, which might not have host\r
-                               $db = str_replace('@/','@adodb-fakehost/',$db);\r
-                               $dsna = parse_url($db);\r
-                               if (!$dsna) return $false;\r
-                               $dsna['host'] = '';\r
-                       }\r
-                       $db = @$dsna['scheme'];\r
-                       if (!$db) return $false;\r
-                       $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : '';\r
-                       $dsna['user'] = isset($dsna['user']) ? rawurldecode($dsna['user']) : '';\r
-                       $dsna['pass'] = isset($dsna['pass']) ? rawurldecode($dsna['pass']) : '';\r
-                       $dsna['path'] = isset($dsna['path']) ? rawurldecode(substr($dsna['path'],1)) : ''; # strip off initial /\r
-                       \r
-                       if (isset($dsna['query'])) {\r
-                               $opt1 = explode('&',$dsna['query']);\r
-                               foreach($opt1 as $k => $v) {\r
-                                       $arr = explode('=',$v);\r
-                                       $opt[$arr[0]] = isset($arr[1]) ? rawurldecode($arr[1]) : 1;\r
-                               }\r
-                       } else $opt = array();\r
-               }\r
-               \r
-       /*\r
-        *  phptype: Database backend used in PHP (mysql, odbc etc.)\r
-        *  dbsyntax: Database used with regards to SQL syntax etc.\r
-        *  protocol: Communication protocol to use (tcp, unix etc.)\r
-        *  hostspec: Host specification (hostname[:port])\r
-        *  database: Database to use on the DBMS server\r
-        *  username: User name for login\r
-        *  password: Password for login\r
-        */\r
-               if (!empty($ADODB_NEWCONNECTION)) {\r
-                       $obj = $ADODB_NEWCONNECTION($db);\r
-\r
-               } else {\r
-               \r
-                       if (!isset($ADODB_LASTDB)) $ADODB_LASTDB = '';\r
-                       if (empty($db)) $db = $ADODB_LASTDB;\r
-                       \r
-                       if ($db != $ADODB_LASTDB) $db = ADOLoadCode($db);\r
-                       \r
-                       if (!$db) {\r
-                               if (isset($origdsn)) $db = $origdsn;\r
-                               if ($errorfn) {\r
-                                       // raise an error\r
-                                       $ignore = false;\r
-                                       $errorfn('ADONewConnection', 'ADONewConnection', -998,\r
-                                                        "could not load the database driver for '$db'",\r
-                                                        $db,false,$ignore);\r
-                               } else\r
-                                        ADOConnection::outp( "<p>ADONewConnection: Unable to load database driver '$db'</p>",false);\r
-                                       \r
-                               return $false;\r
-                       }\r
-                       \r
-                       $cls = 'ADODB_'.$db;\r
-                       if (!class_exists($cls)) {\r
-                               adodb_backtrace();\r
-                               return $false;\r
-                       }\r
-                       \r
-                       $obj = new $cls();\r
-               }\r
-               \r
-               # constructor should not fail\r
-               if ($obj) {\r
-                       if ($errorfn)  $obj->raiseErrorFn = $errorfn;\r
-                       if (isset($dsna)) {\r
-                               if (isset($dsna['port'])) $obj->port = $dsna['port'];\r
-                               foreach($opt as $k => $v) {\r
-                                       switch(strtolower($k)) {\r
-                                       case 'persist':\r
-                                       case 'persistent':      $persist = $v; break;\r
-                                       case 'debug':           $obj->debug = (integer) $v; break;\r
-                                       #ibase\r
-                                       case 'role':            $obj->role = $v; break;\r
-                                       case 'dialect':         $obj->dialect = (integer) $v; break;\r
-                                       case 'charset':         $obj->charset = $v; $obj->charSet=$v; break;\r
-                                       case 'buffers':         $obj->buffers = $v; break;\r
-                                       case 'fetchmode':   $obj->SetFetchMode($v); break;\r
-                                       #ado\r
-                                       case 'charpage':        $obj->charPage = $v; break;\r
-                                       #mysql, mysqli\r
-                                       case 'clientflags': $obj->clientFlags = $v; break;\r
-                                       #mysql, mysqli, postgres\r
-                                       case 'port': $obj->port = $v; break;\r
-                                       #mysqli\r
-                                       case 'socket': $obj->socket = $v; break;\r
-                                       #oci8\r
-                                       case 'nls_date_format': $obj->NLS_DATE_FORMAT = $v; break;\r
-                                       }\r
-                               }\r
-                               if (empty($persist))\r
-                                       $ok = $obj->Connect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);\r
-                               else\r
-                                       $ok = $obj->PConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);\r
-                                       \r
-                               if (!$ok) return $false;\r
-                       }\r
-               }\r
-               return $obj;\r
-       }\r
-       \r
-       \r
-       \r
-       // $perf == true means called by NewPerfMonitor(), otherwise for data dictionary\r
-       function _adodb_getdriver($provider,$drivername,$perf=false)\r
-       {\r
-               switch ($provider) {\r
-               case 'odbtp':   if (strncmp('odbtp_',$drivername,6)==0) return substr($drivername,6); \r
-               case 'odbc' :   if (strncmp('odbc_',$drivername,5)==0) return substr($drivername,5); \r
-               case 'ado'  :   if (strncmp('ado_',$drivername,4)==0) return substr($drivername,4);\r
-               case 'native':  break;\r
-               default:\r
-                       return $provider;\r
-               }\r
-               \r
-               switch($drivername) {\r
-               case 'firebird15': $drivername = 'firebird'; break;\r
-               case 'oracle': $drivername = 'oci8'; break;\r
-               case 'access': if ($perf) $drivername = ''; break;\r
-               case 'db2'   : break;\r
-               case 'sapdb' : break;\r
-               default:\r
-                       $drivername = 'generic';\r
-                       break;\r
-               }\r
-               return $drivername;\r
-       }\r
-       \r
-       function &NewPerfMonitor(&$conn)\r
-       {\r
-               $false = false;\r
-               $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType,true);\r
-               if (!$drivername || $drivername == 'generic') return $false;\r
-               include_once(ADODB_DIR.'/adodb-perf.inc.php');\r
-               @include_once(ADODB_DIR."/perf/perf-$drivername.inc.php");\r
-               $class = "Perf_$drivername";\r
-               if (!class_exists($class)) return $false;\r
-               $perf = new $class($conn);\r
-               \r
-               return $perf;\r
-       }\r
-       \r
-       function &NewDataDictionary(&$conn,$drivername=false)\r
-       {\r
-               $false = false;\r
-               if (!$drivername) $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType);\r
-\r
-               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               include_once(ADODB_DIR.'/adodb-datadict.inc.php');\r
-               $path = ADODB_DIR."/datadict/datadict-$drivername.inc.php";\r
-\r
-               if (!file_exists($path)) {\r
-                       ADOConnection::outp("Database driver '$path' not available");\r
-                       return $false;\r
-               }\r
-               include_once($path);\r
-               $class = "ADODB2_$drivername";\r
-               $dict = new $class();\r
-               $dict->dataProvider = $conn->dataProvider;\r
-               $dict->connection = &$conn;\r
-               $dict->upperName = strtoupper($drivername);\r
-               $dict->quote = $conn->nameQuote;\r
-               if (!empty($conn->_connectionID))\r
-                       $dict->serverInfo = $conn->ServerInfo();\r
-               \r
-               return $dict;\r
-       }\r
-\r
-\r
-       \r
-       /*\r
-               Perform a print_r, with pre tags for better formatting.\r
-       */\r
-       function adodb_pr($var,$as_string=false)\r
-       {\r
-               if ($as_string) ob_start();\r
-               \r
-               if (isset($_SERVER['HTTP_USER_AGENT'])) { \r
-                       echo " <pre>\n";print_r($var);echo "</pre>\n";\r
-               } else\r
-                       print_r($var);\r
-                       \r
-               if ($as_string) {\r
-                       $s = ob_get_contents();\r
-                       ob_end_clean();\r
-                       return $s;\r
-               }\r
-       }\r
-       \r
-       /*\r
-               Perform a stack-crawl and pretty print it.\r
-               \r
-               @param printOrArr  Pass in a boolean to indicate print, or an $exception->trace array (assumes that print is true then).\r
-               @param levels Number of levels to display\r
-       */\r
-       function adodb_backtrace($printOrArr=true,$levels=9999)\r
-       {\r
-               global $ADODB_INCLUDED_LIB;\r
-               if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_backtrace($printOrArr,$levels);\r
-       }\r
-       \r
-} // defined\r
-?>
\ No newline at end of file
+<?php 
+/*
+ * Set tabs to 4 for best viewing.
+ * 
+ * Latest version is available at http://adodb.sourceforge.net
+ * 
+ * This is the main include file for ADOdb.
+ * Database specific drivers are stored in the adodb/drivers/adodb-*.inc.php
+ *
+ * The ADOdb files are formatted so that doxygen can be used to generate documentation.
+ * Doxygen is a documentation generation tool and can be downloaded from http://doxygen.org/
+ */
+
+/**
+       \mainpage       
+       
+        @version V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+
+       Released under both BSD license and Lesser GPL library license. You can choose which license
+       you prefer.
+       
+       PHP's database access functions are not standardised. This creates a need for a database 
+       class library to hide the differences between the different database API's (encapsulate 
+       the differences) so we can easily switch databases.
+
+       We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, DB2,
+       Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access,
+       ADO, SAP DB, SQLite and ODBC. We have had successful reports of connecting to Progress and
+       other databases via ODBC.
+
+       Latest Download at http://adodb.sourceforge.net/
+         
+ */
+ if (!defined('_ADODB_LAYER')) {
+       define('_ADODB_LAYER',1);
+       
+       //==============================================================================================        
+       // CONSTANT DEFINITIONS
+       //==============================================================================================        
+
+
+       /** 
+        * Set ADODB_DIR to the directory where this file resides...
+        * This constant was formerly called $ADODB_RootPath
+        */
+       if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));
+       
+       //==============================================================================================        
+       // GLOBAL VARIABLES
+       //==============================================================================================        
+
+       GLOBAL 
+               $ADODB_vers,            // database version
+               $ADODB_COUNTRECS,       // count number of records returned - slows down query
+               $ADODB_CACHE_DIR,       // directory to cache recordsets
+               $ADODB_EXTENSION,   // ADODB extension installed
+               $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF
+               $ADODB_FETCH_MODE,      // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
+               $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql.    
+       
+       //==============================================================================================        
+       // GLOBAL SETUP
+       //==============================================================================================        
+       
+       $ADODB_EXTENSION = defined('ADODB_EXTENSION');
+       
+       //********************************************************//
+       /*
+       Controls $ADODB_FORCE_TYPE mode. Default is ADODB_FORCE_VALUE (3).
+       Used in GetUpdateSql and GetInsertSql functions. Thx to Niko, nuko#mbnet.fi
+
+               0 = ignore empty fields. All empty fields in array are ignored.
+               1 = force null. All empty, php null and string 'null' fields are changed to sql NULL values.
+               2 = force empty. All empty, php null and string 'null' fields are changed to sql empty '' or 0 values.
+               3 = force value. Value is left as it is. Php null and string 'null' are set to sql NULL values and empty fields '' are set to empty '' sql values.
+       */
+        define('ADODB_FORCE_IGNORE',0);
+        define('ADODB_FORCE_NULL',1);
+        define('ADODB_FORCE_EMPTY',2);
+        define('ADODB_FORCE_VALUE',3);
+    //********************************************************//
+
+
+       if (!$ADODB_EXTENSION || ADODB_EXTENSION < 4.0) {
+               
+               define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>');
+       
+       // allow [ ] @ ` " and . in table names
+               define('ADODB_TABLE_REGEX','([]0-9a-z_\:\"\`\.\@\[-]*)');
+       
+       // prefetching used by oracle
+               if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);
+       
+       
+       /*
+       Controls ADODB_FETCH_ASSOC field-name case. Default is 2, use native case-names.
+       This currently works only with mssql, odbc, oci8po and ibase derived drivers.
+       
+               0 = assoc lowercase field names. $rs->fields['orderid']
+               1 = assoc uppercase field names. $rs->fields['ORDERID']
+               2 = use native-case field names. $rs->fields['OrderID']
+       */
+       
+               define('ADODB_FETCH_DEFAULT',0);
+               define('ADODB_FETCH_NUM',1);
+               define('ADODB_FETCH_ASSOC',2);
+               define('ADODB_FETCH_BOTH',3);
+               
+               if (!defined('TIMESTAMP_FIRST_YEAR')) define('TIMESTAMP_FIRST_YEAR',100);
+       
+               // PHP's version scheme makes converting to numbers difficult - workaround
+               $_adodb_ver = (float) PHP_VERSION;
+               if ($_adodb_ver >= 5.2) {
+                       define('ADODB_PHPVER',0x5200);
+               } else if ($_adodb_ver >= 5.0) {
+                       define('ADODB_PHPVER',0x5000);
+               } else if ($_adodb_ver > 4.299999) { # 4.3
+                       define('ADODB_PHPVER',0x4300);
+               } else if ($_adodb_ver > 4.199999) { # 4.2
+                       define('ADODB_PHPVER',0x4200);
+               } else if (strnatcmp(PHP_VERSION,'4.0.5')>=0) {
+                       define('ADODB_PHPVER',0x4050);
+               } else {
+                       define('ADODB_PHPVER',0x4000);
+               }
+       }
+       
+       //if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);
+
+       
+       /**
+               Accepts $src and $dest arrays, replacing string $data
+       */
+       function ADODB_str_replace($src, $dest, $data)
+       {
+               if (ADODB_PHPVER >= 0x4050) return str_replace($src,$dest,$data);
+               
+               $s = reset($src);
+               $d = reset($dest);
+               while ($s !== false) {
+                       $data = str_replace($s,$d,$data);
+                       $s = next($src);
+                       $d = next($dest);
+               }
+               return $data;
+       }
+       
+       function ADODB_Setup()
+       {
+       GLOBAL 
+               $ADODB_vers,            // database version
+               $ADODB_COUNTRECS,       // count number of records returned - slows down query
+               $ADODB_CACHE_DIR,       // directory to cache recordsets
+               $ADODB_FETCH_MODE,
+               $ADODB_FORCE_TYPE,
+               $ADODB_QUOTE_FIELDNAMES;
+               
+               $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;
+               $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE;
+
+
+               if (!isset($ADODB_CACHE_DIR)) {
+                       $ADODB_CACHE_DIR = '/tmp'; //(isset($_ENV['TMP'])) ? $_ENV['TMP'] : '/tmp';
+               } else {
+                       // do not accept url based paths, eg. http:/ or ftp:/
+                       if (strpos($ADODB_CACHE_DIR,'://') !== false) 
+                               die("Illegal path http:// or ftp://");
+               }
+               
+                       
+               // Initialize random number generator for randomizing cache flushes
+               // -- note Since PHP 4.2.0, the seed  becomes optional and defaults to a random value if omitted.
+               srand(((double)microtime())*1000000);
+               
+               /**
+                * ADODB version as a string.
+                */
+               $ADODB_vers = 'V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
+       
+               /**
+                * Determines whether recordset->RecordCount() is used. 
+                * Set to false for highest performance -- RecordCount() will always return -1 then
+                * for databases that provide "virtual" recordcounts...
+                */
+               if (!isset($ADODB_COUNTRECS)) $ADODB_COUNTRECS = true; 
+       }
+       
+       
+       //==============================================================================================        
+       // CHANGE NOTHING BELOW UNLESS YOU ARE DESIGNING ADODB
+       //==============================================================================================        
+       
+       ADODB_Setup();
+
+       //==============================================================================================        
+       // CLASS ADOFieldObject
+       //==============================================================================================        
+       /**
+        * Helper class for FetchFields -- holds info on a column
+        */
+       class ADOFieldObject { 
+               var $name = '';
+               var $max_length=0;
+               var $type="";
+/*
+               // additional fields by dannym... (danny_milo@yahoo.com)
+               var $not_null = false; 
+               // actually, this has already been built-in in the postgres, fbsql AND mysql module? ^-^
+               // so we can as well make not_null standard (leaving it at "false" does not harm anyways)
+
+               var $has_default = false; // this one I have done only in mysql and postgres for now ... 
+                       // others to come (dannym)
+               var $default_value; // default, if any, and supported. Check has_default first.
+*/
+       }
+       
+
+       
+       function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)
+       {
+               //print "Errorno ($fn errno=$errno m=$errmsg) ";
+               $thisConnection->_transOK = false;
+               if ($thisConnection->_oldRaiseFn) {
+                       $fn = $thisConnection->_oldRaiseFn;
+                       $fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection);
+               }
+       }
+       
+       //==============================================================================================        
+       // CLASS ADOConnection
+       //==============================================================================================        
+       
+       /**
+        * Connection object. For connecting to databases, and executing queries.
+        */ 
+       class ADOConnection {
+       //
+       // PUBLIC VARS 
+       //
+       var $dataProvider = 'native';
+       var $databaseType = '';         /// RDBMS currently in use, eg. odbc, mysql, mssql                                      
+       var $database = '';                     /// Name of database to be used.        
+       var $host = '';                         /// The hostname of the database server 
+       var $user = '';                         /// The username which is used to connect to the database server. 
+       var $password = '';             /// Password for the username. For security, we no longer store it.
+       var $debug = false;             /// if set to true will output sql statements
+       var $maxblobsize = 262144;      /// maximum size of blobs or large text fields (262144 = 256K)-- some db's die otherwise like foxpro
+       var $concat_operator = '+'; /// default concat operator -- change to || for Oracle/Interbase    
+       var $substr = 'substr';         /// substring operator
+       var $length = 'length';         /// string length ofperator
+       var $random = 'rand()';         /// random function
+       var $upperCase = 'upper';               /// uppercase function
+       var $fmtDate = "'Y-m-d'";       /// used by DBDate() as the default date format used by the database
+       var $fmtTimeStamp = "'Y-m-d, h:i:s A'"; /// used by DBTimeStamp as the default timestamp fmt.
+       var $true = '1';                        /// string that represents TRUE for a database
+       var $false = '0';                       /// string that represents FALSE for a database
+       var $replaceQuote = "\\'";      /// string to use to replace quotes
+       var $nameQuote = '"';           /// string to use to quote identifiers and names
+       var $charSet=false;             /// character set to use - only for interbase, postgres and oci8
+       var $metaDatabasesSQL = '';
+       var $metaTablesSQL = '';
+       var $uniqueOrderBy = false; /// All order by columns have to be unique
+       var $emptyDate = '&nbsp;';
+       var $emptyTimeStamp = '&nbsp;';
+       var $lastInsID = false;
+       //--
+       var $hasInsertID = false;               /// supports autoincrement ID?
+       var $hasAffectedRows = false;   /// supports affected rows for update/delete?
+       var $hasTop = false;                    /// support mssql/access SELECT TOP 10 * FROM TABLE
+       var $hasLimit = false;                  /// support pgsql/mysql SELECT * FROM TABLE LIMIT 10
+       var $readOnly = false;                  /// this is a readonly database - used by phpLens
+       var $hasMoveFirst = false;  /// has ability to run MoveFirst(), scrolling backwards
+       var $hasGenID = false;          /// can generate sequences using GenID();
+       var $hasTransactions = true; /// has transactions
+       //--
+       var $genID = 0;                         /// sequence id used by GenID();
+       var $raiseErrorFn = false;      /// error function to call
+       var $isoDates = false; /// accepts dates in ISO format
+       var $cacheSecs = 3600; /// cache for 1 hour
+
+       // memcache
+       var $memCache = false; /// should we use memCache instead of caching in files
+       var $memCacheHost; /// memCache host
+       var $memCachePort = 11211; /// memCache port
+       var $memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib)
+
+       var $sysDate = false; /// name of function that returns the current date
+       var $sysTimeStamp = false; /// name of function that returns the current timestamp
+       var $arrayClass = 'ADORecordSet_array'; /// name of class used to generate array recordsets, which are pre-downloaded recordsets
+       
+       var $noNullStrings = false; /// oracle specific stuff - if true ensures that '' is converted to ' '
+       var $numCacheHits = 0; 
+       var $numCacheMisses = 0;
+       var $pageExecuteCountRows = true;
+       var $uniqueSort = false; /// indicates that all fields in order by must be unique
+       var $leftOuter = false; /// operator to use for left outer join in WHERE clause
+       var $rightOuter = false; /// operator to use for right outer join in WHERE clause
+       var $ansiOuter = false; /// whether ansi outer join syntax supported
+       var $autoRollback = false; // autoRollback on PConnect().
+       var $poorAffectedRows = false; // affectedRows not working or unreliable
+       
+       var $fnExecute = false;
+       var $fnCacheExecute = false;
+       var $blobEncodeType = false; // false=not required, 'I'=encode to integer, 'C'=encode to char
+       var $rsPrefix = "ADORecordSet_";
+       
+       var $autoCommit = true;         /// do not modify this yourself - actually private
+       var $transOff = 0;                      /// temporarily disable transactions
+       var $transCnt = 0;                      /// count of nested transactions
+       
+       var $fetchMode=false;
+       
+       var $null2null = 'null'; // in autoexecute/getinsertsql/getupdatesql, this value will be converted to a null
+        //
+        // PRIVATE VARS
+        //
+       var $_oldRaiseFn =  false;
+       var $_transOK = null;
+       var $_connectionID      = false;        /// The returned link identifier whenever a successful database connection is made.     
+       var $_errorMsg = false;         /// A variable which was used to keep the returned last error message.  The value will
+                                                               /// then returned by the errorMsg() function    
+       var $_errorCode = false;        /// Last error code, not guaranteed to be used - only by oci8                                   
+       var $_queryID = false;          /// This variable keeps the last created result link identifier
+       
+       var $_isPersistentConnection = false;   /// A boolean variable to state whether its a persistent connection or normal connection.       */
+       var $_bindInputArray = false; /// set to true if ADOConnection.Execute() permits binding of array parameters.
+       var $_evalAll = false;
+       var $_affected = false;
+       var $_logsql = false;
+       var $_transmode = ''; // transaction mode
+       
+
+       
+       /**
+        * Constructor
+        */
+       function ADOConnection()                        
+       {
+               die('Virtual Class -- cannot instantiate');
+       }
+       
+       function Version()
+       {
+       global $ADODB_vers;
+       
+               return (float) substr($ADODB_vers,1);
+       }
+       
+       /**
+               Get server version info...
+               
+               @returns An array with 2 elements: $arr['string'] is the description string, 
+                       and $arr[version] is the version (also a string).
+       */
+       function ServerInfo()
+       {
+               return array('description' => '', 'version' => '');
+       }
+       
+       function IsConnected()
+       {
+       return !empty($this->_connectionID);
+       }
+       
+       function _findvers($str)
+       {
+               if (preg_match('/([0-9]+\.([0-9\.])+)/',$str, $arr)) return $arr[1];
+               else return '';
+       }
+       
+       /**
+       * All error messages go through this bottleneck function.
+       * You can define your own handler by defining the function name in ADODB_OUTP.
+       */
+       function outp($msg,$newline=true)
+       {
+       global $ADODB_FLUSH,$ADODB_OUTP;
+       
+               if (defined('ADODB_OUTP')) {
+                       $fn = ADODB_OUTP;
+                       $fn($msg,$newline);
+                       return;
+               } else if (isset($ADODB_OUTP)) {
+                       $fn = $ADODB_OUTP;
+                       $fn($msg,$newline);
+                       return;
+               }
+               
+               if ($newline) $msg .= "<br>\n";
+               
+               if (isset($_SERVER['HTTP_USER_AGENT']) || !$newline) echo $msg;
+               else echo strip_tags($msg);
+       
+               
+               if (!empty($ADODB_FLUSH) && ob_get_length() !== false) flush(); //  do not flush if output buffering enabled - useless - thx to Jesse Mullan 
+               
+       }
+       
+       function Time()
+       {
+               $rs =& $this->_Execute("select $this->sysTimeStamp");
+               if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields));
+               
+               return false;
+       }
+       
+       /**
+        * Connect to database
+        *
+        * @param [argHostname]         Host to connect to
+        * @param [argUsername]         Userid to login
+        * @param [argPassword]         Associated password
+        * @param [argDatabaseName]     database
+        * @param [forceNew]            force new connection
+        *
+        * @return true or false
+        */       
+       function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "", $forceNew = false) 
+       {
+               if ($argHostname != "") $this->host = $argHostname;
+               if ($argUsername != "") $this->user = $argUsername;
+               if ($argPassword != "") $this->password = $argPassword; // not stored for security reasons
+               if ($argDatabaseName != "") $this->database = $argDatabaseName;         
+               
+               $this->_isPersistentConnection = false; 
+               if ($forceNew) {
+                       if ($rez=$this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;
+               } else {
+                        if ($rez=$this->_connect($this->host, $this->user, $this->password, $this->database)) return true;
+               }
+               if (isset($rez)) {
+                       $err = $this->ErrorMsg();
+                       if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";
+                       $ret = false;
+               } else {
+                       $err = "Missing extension for ".$this->dataProvider;
+                       $ret = 0;
+               }
+               if ($fn = $this->raiseErrorFn) 
+                       $fn($this->databaseType,'CONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);
+               
+               
+               $this->_connectionID = false;
+               if ($this->debug) ADOConnection::outp( $this->host.': '.$err);
+               return $ret;
+       }       
+       
+       function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName)
+       {
+               return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName);
+       }
+       
+       
+       /**
+        * Always force a new connection to database - currently only works with oracle
+        *
+        * @param [argHostname]         Host to connect to
+        * @param [argUsername]         Userid to login
+        * @param [argPassword]         Associated password
+        * @param [argDatabaseName]     database
+        *
+        * @return true or false
+        */       
+       function NConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") 
+       {
+               return $this->Connect($argHostname, $argUsername, $argPassword, $argDatabaseName, true);
+       }
+       
+       /**
+        * Establish persistent connect to database
+        *
+        * @param [argHostname]         Host to connect to
+        * @param [argUsername]         Userid to login
+        * @param [argPassword]         Associated password
+        * @param [argDatabaseName]     database
+        *
+        * @return return true or false
+        */     
+       function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "")
+       {
+               if (defined('ADODB_NEVER_PERSIST')) 
+                       return $this->Connect($argHostname,$argUsername,$argPassword,$argDatabaseName);
+               
+               if ($argHostname != "") $this->host = $argHostname;
+               if ($argUsername != "") $this->user = $argUsername;
+               if ($argPassword != "") $this->password = $argPassword;
+               if ($argDatabaseName != "") $this->database = $argDatabaseName;         
+                       
+               $this->_isPersistentConnection = true;  
+               if ($rez = $this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;
+               if (isset($rez)) {
+                       $err = $this->ErrorMsg();
+                       if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";
+                       $ret = false;
+               } else {
+                       $err = "Missing extension for ".$this->dataProvider;
+                       $ret = 0;
+               }
+               if ($fn = $this->raiseErrorFn) {
+                       $fn($this->databaseType,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);
+               }
+               
+               $this->_connectionID = false;
+               if ($this->debug) ADOConnection::outp( $this->host.': '.$err);
+               return $ret;
+       }
+
+       // Format date column in sql string given an input format that understands Y M D
+       function SQLDate($fmt, $col=false)
+       {       
+               if (!$col) $col = $this->sysDate;
+               return $col; // child class implement
+       }
+       
+       /**
+        * Should prepare the sql statement and return the stmt resource.
+        * For databases that do not support this, we return the $sql. To ensure
+        * compatibility with databases that do not support prepare:
+        *
+        *   $stmt = $db->Prepare("insert into table (id, name) values (?,?)");
+        *   $db->Execute($stmt,array(1,'Jill')) or die('insert failed');
+        *   $db->Execute($stmt,array(2,'Joe')) or die('insert failed');
+        *
+        * @param sql   SQL to send to database
+        *
+        * @return return FALSE, or the prepared statement, or the original sql if
+        *                      if the database does not support prepare.
+        *
+        */     
+       function Prepare($sql)
+       {
+               return $sql;
+       }
+       
+       /**
+        * Some databases, eg. mssql require a different function for preparing
+        * stored procedures. So we cannot use Prepare().
+        *
+        * Should prepare the stored procedure  and return the stmt resource.
+        * For databases that do not support this, we return the $sql. To ensure
+        * compatibility with databases that do not support prepare:
+        *
+        * @param sql   SQL to send to database
+        *
+        * @return return FALSE, or the prepared statement, or the original sql if
+        *                      if the database does not support prepare.
+        *
+        */     
+       function PrepareSP($sql,$param=true)
+       {
+               return $this->Prepare($sql,$param);
+       }
+       
+       /**
+       * PEAR DB Compat
+       */
+       function Quote($s)
+       {
+               return $this->qstr($s,false);
+       }
+       
+       /**
+        Requested by "Karsten Dambekalns" <k.dambekalns@fishfarm.de>
+       */
+       function QMagic($s)
+       {
+               return $this->qstr($s,get_magic_quotes_gpc());
+       }
+
+       function q(&$s)
+       {
+               $s = $this->qstr($s,false);
+       }
+       
+       /**
+       * PEAR DB Compat - do not use internally. 
+       */
+       function ErrorNative()
+       {
+               return $this->ErrorNo();
+       }
+
+       
+   /**
+       * PEAR DB Compat - do not use internally. 
+       */
+       function nextId($seq_name)
+       {
+               return $this->GenID($seq_name);
+       }
+
+       /**
+       *        Lock a row, will escalate and lock the table if row locking not supported
+       *       will normally free the lock at the end of the transaction
+       *
+       *  @param $table        name of table to lock
+       *  @param $where        where clause to use, eg: "WHERE row=12". If left empty, will escalate to table lock
+       */
+       function RowLock($table,$where)
+       {
+               return false;
+       }
+       
+       function CommitLock($table)
+       {
+               return $this->CommitTrans();
+       }
+       
+       function RollbackLock($table)
+       {
+               return $this->RollbackTrans();
+       }
+       
+       /**
+       * PEAR DB Compat - do not use internally. 
+       *
+       * The fetch modes for NUMERIC and ASSOC for PEAR DB and ADODB are identical
+       *       for easy porting :-)
+       *
+       * @param mode   The fetchmode ADODB_FETCH_ASSOC or ADODB_FETCH_NUM
+       * @returns              The previous fetch mode
+       */
+       function SetFetchMode($mode)
+       {       
+               $old = $this->fetchMode;
+               $this->fetchMode = $mode;
+               
+               if ($old === false) {
+               global $ADODB_FETCH_MODE;
+                       return $ADODB_FETCH_MODE;
+               }
+               return $old;
+       }
+       
+
+       /**
+       * PEAR DB Compat - do not use internally. 
+       */
+       function &Query($sql, $inputarr=false)
+       {
+               $rs = &$this->Execute($sql, $inputarr);
+               if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();
+               return $rs;
+       }
+
+       
+       /**
+       * PEAR DB Compat - do not use internally
+       */
+       function &LimitQuery($sql, $offset, $count, $params=false)
+       {
+               $rs = &$this->SelectLimit($sql, $count, $offset, $params); 
+               if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();
+               return $rs;
+       }
+
+       
+       /**
+       * PEAR DB Compat - do not use internally
+       */
+       function Disconnect()
+       {
+               return $this->Close();
+       }
+       
+       /*
+                Returns placeholder for parameter, eg.
+                $DB->Param('a')
+                
+                will return ':a' for Oracle, and '?' for most other databases...
+                
+                For databases that require positioned params, eg $1, $2, $3 for postgresql,
+                       pass in Param(false) before setting the first parameter.
+       */
+       function Param($name,$type='C')
+       {
+               return '?';
+       }
+       
+       /*
+               InParameter and OutParameter are self-documenting versions of Parameter().
+       */
+       function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
+       {
+               return $this->Parameter($stmt,$var,$name,false,$maxLen,$type);
+       }
+       
+       /*
+       */
+       function OutParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
+       {
+               return $this->Parameter($stmt,$var,$name,true,$maxLen,$type);
+       
+       }
+
+       
+       /* 
+       Usage in oracle
+               $stmt = $db->Prepare('select * from table where id =:myid and group=:group');
+               $db->Parameter($stmt,$id,'myid');
+               $db->Parameter($stmt,$group,'group',64);
+               $db->Execute();
+               
+               @param $stmt Statement returned by Prepare() or PrepareSP().
+               @param $var PHP variable to bind to
+               @param $name Name of stored procedure variable name to bind to.
+               @param [$isOutput] Indicates direction of parameter 0/false=IN  1=OUT  2= IN/OUT. This is ignored in oci8.
+               @param [$maxLen] Holds an maximum length of the variable.
+               @param [$type] The data type of $var. Legal values depend on driver.
+
+       */
+       function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false)
+       {
+               return false;
+       }
+       
+       
+       function IgnoreErrors($saveErrs=false)
+       {
+               if (!$saveErrs) {
+                       $saveErrs = array($this->raiseErrorFn,$this->_transOK);
+                       $this->raiseErrorFn = false;
+                       return $saveErrs;
+               } else {
+                       $this->raiseErrorFn = $saveErrs[0];
+                       $this->_transOK = $saveErrs[1];
+               }
+       }
+       
+       /**
+               Improved method of initiating a transaction. Used together with CompleteTrans().
+               Advantages include:
+               
+               a. StartTrans/CompleteTrans is nestable, unlike BeginTrans/CommitTrans/RollbackTrans.
+                  Only the outermost block is treated as a transaction.<br>
+               b. CompleteTrans auto-detects SQL errors, and will rollback on errors, commit otherwise.<br>
+               c. All BeginTrans/CommitTrans/RollbackTrans inside a StartTrans/CompleteTrans block
+                  are disabled, making it backward compatible.
+       */
+       function StartTrans($errfn = 'ADODB_TransMonitor')
+       {
+               if ($this->transOff > 0) {
+                       $this->transOff += 1;
+                       return;
+               }
+               
+               $this->_oldRaiseFn = $this->raiseErrorFn;
+               $this->raiseErrorFn = $errfn;
+               $this->_transOK = true;
+               
+               if ($this->debug && $this->transCnt > 0) ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans");
+               $this->BeginTrans();
+               $this->transOff = 1;
+       }
+       
+       
+       /**
+               Used together with StartTrans() to end a transaction. Monitors connection
+               for sql errors, and will commit or rollback as appropriate.
+               
+               @autoComplete if true, monitor sql errors and commit and rollback as appropriate, 
+               and if set to false force rollback even if no SQL error detected.
+               @returns true on commit, false on rollback.
+       */
+       function CompleteTrans($autoComplete = true)
+       {
+               if ($this->transOff > 1) {
+                       $this->transOff -= 1;
+                       return true;
+               }
+               $this->raiseErrorFn = $this->_oldRaiseFn;
+               
+               $this->transOff = 0;
+               if ($this->_transOK && $autoComplete) {
+                       if (!$this->CommitTrans()) {
+                               $this->_transOK = false;
+                               if ($this->debug) ADOConnection::outp("Smart Commit failed");
+                       } else
+                               if ($this->debug) ADOConnection::outp("Smart Commit occurred");
+               } else {
+                       $this->_transOK = false;
+                       $this->RollbackTrans();
+                       if ($this->debug) ADOCOnnection::outp("Smart Rollback occurred");
+               }
+               
+               return $this->_transOK;
+       }
+       
+       /*
+               At the end of a StartTrans/CompleteTrans block, perform a rollback.
+       */
+       function FailTrans()
+       {
+               if ($this->debug) 
+                       if ($this->transOff == 0) {
+                               ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans");
+                       } else {
+                               ADOConnection::outp("FailTrans was called");
+                               adodb_backtrace();
+                       }
+               $this->_transOK = false;
+       }
+       
+       /**
+               Check if transaction has failed, only for Smart Transactions.
+       */
+       function HasFailedTrans()
+       {
+               if ($this->transOff > 0) return $this->_transOK == false;
+               return false;
+       }
+       
+       /**
+        * Execute SQL 
+        *
+        * @param sql           SQL statement to execute, or possibly an array holding prepared statement ($sql[0] will hold sql text)
+        * @param [inputarr]    holds the input data to bind to. Null elements will be set to null.
+        * @return              RecordSet or false
+        */
+       function &Execute($sql,$inputarr=false) 
+       {
+               if ($this->fnExecute) {
+                       $fn = $this->fnExecute;
+                       $ret =& $fn($this,$sql,$inputarr);
+                       if (isset($ret)) return $ret;
+               }
+               if ($inputarr) {
+                       if (!is_array($inputarr)) $inputarr = array($inputarr);
+                       
+                       $element0 = reset($inputarr);
+                       # is_object check because oci8 descriptors can be passed in
+                       $array_2d = is_array($element0) && !is_object(reset($element0));
+                       //remove extra memory copy of input -mikefedyk
+                       unset($element0);
+                       
+                       if (!is_array($sql) && !$this->_bindInputArray) {
+                               $sqlarr = explode('?',$sql);
+                                       
+                               if (!$array_2d) $inputarr = array($inputarr);
+                               foreach($inputarr as $arr) {
+                                       $sql = ''; $i = 0;
+                                       //Use each() instead of foreach to reduce memory usage -mikefedyk
+                                       while(list(, $v) = each($arr)) {
+                                               $sql .= $sqlarr[$i];
+                                               // from Ron Baldwin <ron.baldwin#sourceprose.com>
+                                               // Only quote string types      
+                                               $typ = gettype($v);
+                                               if ($typ == 'string')
+                                                       //New memory copy of input created here -mikefedyk
+                                                       $sql .= $this->qstr($v);
+                                               else if ($typ == 'double')
+                                                       $sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1
+                                               else if ($typ == 'boolean')
+                                                       $sql .= $v ? $this->true : $this->false;
+                                               else if ($typ == 'object') {
+                                                       if (method_exists($v, '__toString')) $sql .= $this->qstr($v->__toString());
+                                                       else $sql .= $this->qstr((string) $v);
+                                               } else if ($v === null)
+                                                       $sql .= 'NULL';
+                                               else
+                                                       $sql .= $v;
+                                               $i += 1;
+                                       }
+                                       if (isset($sqlarr[$i])) {
+                                               $sql .= $sqlarr[$i];
+                                               if ($i+1 != sizeof($sqlarr)) ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql));
+                                       } else if ($i != sizeof($sqlarr))       
+                                               ADOConnection::outp( "Input array does not match ?: ".htmlspecialchars($sql));
+               
+                                       $ret =& $this->_Execute($sql);
+                                       if (!$ret) return $ret;
+                               }       
+                       } else {
+                               if ($array_2d) {
+                                       if (is_string($sql))
+                                               $stmt = $this->Prepare($sql);
+                                       else
+                                               $stmt = $sql;
+                                               
+                                       foreach($inputarr as $arr) {
+                                               $ret =& $this->_Execute($stmt,$arr);
+                                               if (!$ret) return $ret;
+                                       }
+                               } else {
+                                       $ret =& $this->_Execute($sql,$inputarr);
+                               }
+                       }
+               } else {
+                       $ret =& $this->_Execute($sql,false);
+               }
+
+               return $ret;
+       }
+       
+       
+       function &_Execute($sql,$inputarr=false)
+       {
+               if ($this->debug) {
+                       global $ADODB_INCLUDED_LIB;
+                       if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+                       $this->_queryID = _adodb_debug_execute($this, $sql,$inputarr);
+               } else {
+                       $this->_queryID = @$this->_query($sql,$inputarr);
+               }
+               
+               /************************
+               // OK, query executed
+               *************************/
+
+               if ($this->_queryID === false) { // error handling if query fails
+                       if ($this->debug == 99) adodb_backtrace(true,5);        
+                       $fn = $this->raiseErrorFn;
+                       if ($fn) {
+                               $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr,$this);
+                       } 
+                       $false = false;
+                       return $false;
+               } 
+               
+               if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead
+                       $rs = new ADORecordSet_empty();
+                       return $rs;
+               }
+               
+               // return real recordset from select statement
+               $rsclass = $this->rsPrefix.$this->databaseType;
+               $rs = new $rsclass($this->_queryID,$this->fetchMode);
+               $rs->connection = &$this; // Pablo suggestion
+               $rs->Init();
+               if (is_array($sql)) $rs->sql = $sql[0];
+               else $rs->sql = $sql;
+               if ($rs->_numOfRows <= 0) {
+               global $ADODB_COUNTRECS;
+                       if ($ADODB_COUNTRECS) {
+                               if (!$rs->EOF) { 
+                                       $rs = &$this->_rs2rs($rs,-1,-1,!is_array($sql));
+                                       $rs->_queryID = $this->_queryID;
+                               } else
+                                       $rs->_numOfRows = 0;
+                       }
+               }
+               return $rs;
+       }
+
+       function CreateSequence($seqname='adodbseq',$startID=1)
+       {
+               if (empty($this->_genSeqSQL)) return false;
+               return $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID));
+       }
+
+       function DropSequence($seqname='adodbseq')
+       {
+               if (empty($this->_dropSeqSQL)) return false;
+               return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
+       }
+
+       /**
+        * Generates a sequence id and stores it in $this->genID;
+        * GenID is only available if $this->hasGenID = true;
+        *
+        * @param seqname               name of sequence to use
+        * @param startID               if sequence does not exist, start at this ID
+        * @return              0 if not supported, otherwise a sequence id
+        */
+       function GenID($seqname='adodbseq',$startID=1)
+       {
+               if (!$this->hasGenID) {
+                       return 0; // formerly returns false pre 1.60
+               }
+               
+               $getnext = sprintf($this->_genIDSQL,$seqname);
+               
+               $holdtransOK = $this->_transOK;
+               
+               $save_handler = $this->raiseErrorFn;
+               $this->raiseErrorFn = '';
+               @($rs = $this->Execute($getnext));
+               $this->raiseErrorFn = $save_handler;
+               
+               if (!$rs) {
+                       $this->_transOK = $holdtransOK; //if the status was ok before reset
+                       $createseq = $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID));
+                       $rs = $this->Execute($getnext);
+               }
+               if ($rs && !$rs->EOF) $this->genID = reset($rs->fields);
+               else $this->genID = 0; // false
+       
+               if ($rs) $rs->Close();
+
+               return $this->genID;
+       }       
+
+       /**
+        * @param $table string name of the table, not needed by all databases (eg. mysql), default ''
+        * @param $column string name of the column, not needed by all databases (eg. mysql), default ''
+        * @return  the last inserted ID. Not all databases support this.
+        */ 
+       function Insert_ID($table='',$column='')
+       {
+               if ($this->_logsql && $this->lastInsID) return $this->lastInsID;
+               if ($this->hasInsertID) return $this->_insertid($table,$column);
+               if ($this->debug) {
+                       ADOConnection::outp( '<p>Insert_ID error</p>');
+                       adodb_backtrace();
+               }
+               return false;
+       }
+
+
+       /**
+        * Portable Insert ID. Pablo Roca <pabloroca#mvps.org>
+        *
+        * @return  the last inserted ID. All databases support this. But aware possible
+        * problems in multiuser environments. Heavy test this before deploying.
+        */ 
+       function PO_Insert_ID($table="", $id="") 
+       {
+          if ($this->hasInsertID){
+                  return $this->Insert_ID($table,$id);
+          } else {
+                  return $this->GetOne("SELECT MAX($id) FROM $table");
+          }
+       }
+
+       /**
+       * @return # rows affected by UPDATE/DELETE
+       */ 
+       function Affected_Rows()
+       {
+               if ($this->hasAffectedRows) {
+                       if ($this->fnExecute === 'adodb_log_sql') {
+                               if ($this->_logsql && $this->_affected !== false) return $this->_affected;
+                       }
+                       $val = $this->_affectedrows();
+                       return ($val < 0) ? false : $val;
+               }
+                                 
+               if ($this->debug) ADOConnection::outp( '<p>Affected_Rows error</p>',false);
+               return false;
+       }
+       
+       
+       /**
+        * @return  the last error message
+        */
+       function ErrorMsg()
+       {
+               if ($this->_errorMsg) return '!! '.strtoupper($this->dataProvider.' '.$this->databaseType).': '.$this->_errorMsg;
+               else return '';
+       }
+       
+       
+       /**
+        * @return the last error number. Normally 0 means no error.
+        */
+       function ErrorNo() 
+       {
+               return ($this->_errorMsg) ? -1 : 0;
+       }
+       
+       function MetaError($err=false)
+       {
+               include_once(ADODB_DIR."/adodb-error.inc.php");
+               if ($err === false) $err = $this->ErrorNo();
+               return adodb_error($this->dataProvider,$this->databaseType,$err);
+       }
+       
+       function MetaErrorMsg($errno)
+       {
+               include_once(ADODB_DIR."/adodb-error.inc.php");
+               return adodb_errormsg($errno);
+       }
+       
+       /**
+        * @returns an array with the primary key columns in it.
+        */
+       function MetaPrimaryKeys($table, $owner=false)
+       {
+       // owner not used in base class - see oci8
+               $p = array();
+               $objs =& $this->MetaColumns($table);
+               if ($objs) {
+                       foreach($objs as $v) {
+                               if (!empty($v->primary_key))
+                                       $p[] = $v->name;
+                       }
+               }
+               if (sizeof($p)) return $p;
+               if (function_exists('ADODB_VIEW_PRIMARYKEYS'))
+                       return ADODB_VIEW_PRIMARYKEYS($this->databaseType, $this->database, $table, $owner);
+               return false;
+       }
+       
+       /**
+        * @returns assoc array where keys are tables, and values are foreign keys
+        */
+       function MetaForeignKeys($table, $owner=false, $upper=false)
+       {
+               return false;
+       }
+       /**
+        * Choose a database to connect to. Many databases do not support this.
+        *
+        * @param dbName        is the name of the database to select
+        * @return              true or false
+        */
+       function SelectDB($dbName) 
+       {return false;}
+       
+       
+       /**
+       * Will select, getting rows from $offset (1-based), for $nrows. 
+       * This simulates the MySQL "select * from table limit $offset,$nrows" , and
+       * the PostgreSQL "select * from table limit $nrows offset $offset". Note that
+       * MySQL and PostgreSQL parameter ordering is the opposite of the other.
+       * eg. 
+       *  SelectLimit('select * from table',3); will return rows 1 to 3 (1-based)
+       *  SelectLimit('select * from table',3,2); will return rows 3 to 5 (1-based)
+       *
+       * Uses SELECT TOP for Microsoft databases (when $this->hasTop is set)
+       * BUG: Currently SelectLimit fails with $sql with LIMIT or TOP clause already set
+       *
+       * @param sql
+       * @param [offset]       is the row to start calculations from (1-based)
+       * @param [nrows]                is the number of rows to get
+       * @param [inputarr]     array of bind variables
+       * @param [secs2cache]           is a private parameter only used by jlim
+       * @return               the recordset ($rs->databaseType == 'array')
+       */
+       function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)
+       {
+               if ($this->hasTop && $nrows > 0) {
+               // suggested by Reinhard Balling. Access requires top after distinct 
+                // Informix requires first before distinct - F Riosa
+                       $ismssql = (strpos($this->databaseType,'mssql') !== false);
+                       if ($ismssql) $isaccess = false;
+                       else $isaccess = (strpos($this->databaseType,'access') !== false);
+                       
+                       if ($offset <= 0) {
+                               
+                                       // access includes ties in result
+                                       if ($isaccess) {
+                                               $sql = preg_replace(
+                                               '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql);
+
+                                               if ($secs2cache != 0) {
+                                                       $ret =& $this->CacheExecute($secs2cache, $sql,$inputarr);
+                                               } else {
+                                                       $ret =& $this->Execute($sql,$inputarr);
+                                               }
+                                               return $ret; // PHP5 fix
+                                       } else if ($ismssql){
+                                               $sql = preg_replace(
+                                               '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql);
+                                       } else {
+                                               $sql = preg_replace(
+                                               '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql);
+                                       }
+                       } else {
+                               $nn = $nrows + $offset;
+                               if ($isaccess || $ismssql) {
+                                       $sql = preg_replace(
+                                       '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql);
+                               } else {
+                                       $sql = preg_replace(
+                                       '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql);
+                               }
+                       }
+               }
+               
+               // if $offset>0, we want to skip rows, and $ADODB_COUNTRECS is set, we buffer  rows
+               // 0 to offset-1 which will be discarded anyway. So we disable $ADODB_COUNTRECS.
+               global $ADODB_COUNTRECS;
+               
+               $savec = $ADODB_COUNTRECS;
+               $ADODB_COUNTRECS = false;
+                       
+               if ($offset>0){
+                       if ($secs2cache != 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);
+                       else $rs = &$this->Execute($sql,$inputarr);
+               } else {
+                       if ($secs2cache != 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);
+                       else $rs = &$this->Execute($sql,$inputarr);
+               }
+               $ADODB_COUNTRECS = $savec;
+               if ($rs && !$rs->EOF) {
+                       $rs =& $this->_rs2rs($rs,$nrows,$offset);
+               }
+               //print_r($rs);
+               return $rs;
+       }
+       
+       /**
+       * Create serializable recordset. Breaks rs link to connection.
+       *
+       * @param rs                     the recordset to serialize
+       */
+       function &SerializableRS(&$rs)
+       {
+               $rs2 =& $this->_rs2rs($rs);
+               $ignore = false;
+               $rs2->connection =& $ignore;
+               
+               return $rs2;
+       }
+       
+       /**
+       * Convert database recordset to an array recordset
+       * input recordset's cursor should be at beginning, and
+       * old $rs will be closed.
+       *
+       * @param rs                     the recordset to copy
+       * @param [nrows]        number of rows to retrieve (optional)
+       * @param [offset]       offset by number of rows (optional)
+       * @return                       the new recordset
+       */
+       function &_rs2rs(&$rs,$nrows=-1,$offset=-1,$close=true)
+       {
+               if (! $rs) {
+                       $false = false;
+                       return $false;
+               }
+               $dbtype = $rs->databaseType;
+               if (!$dbtype) {
+                       $rs = &$rs;  // required to prevent crashing in 4.2.1, but does not happen in 4.3.1 -- why ?
+                       return $rs;
+               }
+               if (($dbtype == 'array' || $dbtype == 'csv') && $nrows == -1 && $offset == -1) {
+                       $rs->MoveFirst();
+                       $rs = &$rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1-- why ?
+                       return $rs;
+               }
+               $flds = array();
+               for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
+                       $flds[] = $rs->FetchField($i);
+               }
+
+               $arr =& $rs->GetArrayLimit($nrows,$offset);
+               //print_r($arr);
+               if ($close) $rs->Close();
+               
+               $arrayClass = $this->arrayClass;
+               
+               $rs2 = new $arrayClass();
+               $rs2->connection = &$this;
+               $rs2->sql = $rs->sql;
+               $rs2->dataProvider = $this->dataProvider;
+               $rs2->InitArrayFields($arr,$flds);
+               $rs2->fetchMode = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
+               return $rs2;
+       }
+       
+       /*
+       * Return all rows. Compat with PEAR DB
+       */
+       function &GetAll($sql, $inputarr=false)
+       {
+               $arr =& $this->GetArray($sql,$inputarr);
+               return $arr;
+       }
+       
+       function &GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false)
+       {
+               $rs =& $this->Execute($sql, $inputarr);
+               if (!$rs) {
+                       $false = false;
+                       return $false;
+               }
+               $arr =& $rs->GetAssoc($force_array,$first2cols);
+               return $arr;
+       }
+       
+       function &CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false)
+       {
+               if (!is_numeric($secs2cache)) {
+                       $first2cols = $force_array;
+                       $force_array = $inputarr;
+               }
+               $rs =& $this->CacheExecute($secs2cache, $sql, $inputarr);
+               if (!$rs) {
+                       $false = false;
+                       return $false;
+               }
+               $arr =& $rs->GetAssoc($force_array,$first2cols);
+               return $arr;
+       }
+       
+       /**
+       * Return first element of first row of sql statement. Recordset is disposed
+       * for you.
+       *
+       * @param sql                    SQL statement
+       * @param [inputarr]             input bind array
+       */
+       function GetOne($sql,$inputarr=false)
+       {
+       global $ADODB_COUNTRECS;
+               $crecs = $ADODB_COUNTRECS;
+               $ADODB_COUNTRECS = false;
+               
+               $ret = false;
+               $rs = &$this->Execute($sql,$inputarr);
+               if ($rs) {      
+                       if (!$rs->EOF) $ret = reset($rs->fields);
+                       $rs->Close();
+               }
+               $ADODB_COUNTRECS = $crecs;
+               return $ret;
+       }
+       
+       function CacheGetOne($secs2cache,$sql=false,$inputarr=false)
+       {
+               $ret = false;
+               $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);
+               if ($rs) {              
+                       if (!$rs->EOF) $ret = reset($rs->fields);
+                       $rs->Close();
+               } 
+               
+               return $ret;
+       }
+       
+       function GetCol($sql, $inputarr = false, $trim = false)
+       {
+               $rv = false;
+               $rs = &$this->Execute($sql, $inputarr);
+               if ($rs) {
+                       $rv = array();
+                       if ($trim) {
+                               while (!$rs->EOF) {
+                                       $rv[] = trim(reset($rs->fields));
+                                       $rs->MoveNext();
+                               }
+                       } else {
+                               while (!$rs->EOF) {
+                                       $rv[] = reset($rs->fields);
+                                       $rs->MoveNext();
+                               }
+                       }
+                       $rs->Close();
+               }
+               return $rv;
+       }
+       
+       function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false)
+       {
+               $rv = false;
+               $rs = &$this->CacheExecute($secs, $sql, $inputarr);
+               if ($rs) {
+                       if ($trim) {
+                               while (!$rs->EOF) {
+                                       $rv[] = trim(reset($rs->fields));
+                                       $rs->MoveNext();
+                               }
+                       } else {
+                               while (!$rs->EOF) {
+                                       $rv[] = reset($rs->fields);
+                                       $rs->MoveNext();
+                               }
+                       }
+                       $rs->Close();
+               }
+               return $rv;
+       }
+       
+       function &Transpose(&$rs,$addfieldnames=true)
+       {
+               $rs2 =& $this->_rs2rs($rs);
+               $false = false;
+               if (!$rs2) return $false;
+               
+               $rs2->_transpose($addfieldnames);
+               return $rs2;
+       }
+       /*
+               Calculate the offset of a date for a particular database and generate
+                       appropriate SQL. Useful for calculating future/past dates and storing
+                       in a database.
+                       
+               If dayFraction=1.5 means 1.5 days from now, 1.0/24 for 1 hour.
+       */
+       function OffsetDate($dayFraction,$date=false)
+       {               
+               if (!$date) $date = $this->sysDate;
+               return  '('.$date.'+'.$dayFraction.')';
+       }
+       
+       
+       /**
+       *
+       * @param sql                    SQL statement
+       * @param [inputarr]             input bind array
+       */
+       function &GetArray($sql,$inputarr=false)
+       {
+       global $ADODB_COUNTRECS;
+               
+               $savec = $ADODB_COUNTRECS;
+               $ADODB_COUNTRECS = false;
+               $rs =& $this->Execute($sql,$inputarr);
+               $ADODB_COUNTRECS = $savec;
+               if (!$rs) 
+                       if (defined('ADODB_PEAR')) {
+                               $cls = ADODB_PEAR_Error();
+                               return $cls;
+                       } else {
+                               $false = false;
+                               return $false;
+                       }
+               $arr =& $rs->GetArray();
+               $rs->Close();
+               return $arr;
+       }
+       
+       function &CacheGetAll($secs2cache,$sql=false,$inputarr=false)
+       {
+               $arr =& $this->CacheGetArray($secs2cache,$sql,$inputarr);
+               return $arr;
+       }
+       
+       function &CacheGetArray($secs2cache,$sql=false,$inputarr=false)
+       {
+       global $ADODB_COUNTRECS;
+               
+               $savec = $ADODB_COUNTRECS;
+               $ADODB_COUNTRECS = false;
+               $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr);
+               $ADODB_COUNTRECS = $savec;
+               
+               if (!$rs) 
+                       if (defined('ADODB_PEAR')) {
+                               $cls = ADODB_PEAR_Error();
+                               return $cls;
+                       } else {
+                               $false = false;
+                               return $false;
+                       }
+               $arr =& $rs->GetArray();
+               $rs->Close();
+               return $arr;
+       }
+       
+       
+       
+       /**
+       * Return one row of sql statement. Recordset is disposed for you.
+       *
+       * @param sql                    SQL statement
+       * @param [inputarr]             input bind array
+       */
+       function &GetRow($sql,$inputarr=false)
+       {
+       global $ADODB_COUNTRECS;
+               $crecs = $ADODB_COUNTRECS;
+               $ADODB_COUNTRECS = false;
+               
+               $rs =& $this->Execute($sql,$inputarr);
+               
+               $ADODB_COUNTRECS = $crecs;
+               if ($rs) {
+                       if (!$rs->EOF) $arr = $rs->fields;
+                       else $arr = array();
+                       $rs->Close();
+                       return $arr;
+               }
+               
+               $false = false;
+               return $false;
+       }
+       
+       function &CacheGetRow($secs2cache,$sql=false,$inputarr=false)
+       {
+               $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr);
+               if ($rs) {
+                       $arr = false;
+                       if (!$rs->EOF) $arr = $rs->fields;
+                       $rs->Close();
+                       return $arr;
+               }
+               $false = false;
+               return $false;
+       }
+       
+       /**
+       * Insert or replace a single record. Note: this is not the same as MySQL's replace. 
+       * ADOdb's Replace() uses update-insert semantics, not insert-delete-duplicates of MySQL.
+       * Also note that no table locking is done currently, so it is possible that the
+       * record be inserted twice by two programs...
+       *
+       * $this->Replace('products', array('prodname' =>"'Nails'","price" => 3.99), 'prodname');
+       *
+       * $table                table name
+       * $fieldArray   associative array of data (you must quote strings yourself).
+       * $keyCol               the primary key field name or if compound key, array of field names
+       * autoQuote             set to true to use a hueristic to quote strings. Works with nulls and numbers
+       *                                       but does not work with dates nor SQL functions.
+       * has_autoinc   the primary key is an auto-inc field, so skip in insert.
+       *
+       * Currently blob replace not supported
+       *
+       * returns 0 = fail, 1 = update, 2 = insert 
+       */
+       
+       function Replace($table, $fieldArray, $keyCol, $autoQuote=false, $has_autoinc=false)
+       {
+               global $ADODB_INCLUDED_LIB;
+               if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+               
+               return _adodb_replace($this, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc);
+       }
+       
+       
+       /**
+       * Will select, getting rows from $offset (1-based), for $nrows. 
+       * This simulates the MySQL "select * from table limit $offset,$nrows" , and
+       * the PostgreSQL "select * from table limit $nrows offset $offset". Note that
+       * MySQL and PostgreSQL parameter ordering is the opposite of the other.
+       * eg. 
+       *  CacheSelectLimit(15,'select * from table',3); will return rows 1 to 3 (1-based)
+       *  CacheSelectLimit(15,'select * from table',3,2); will return rows 3 to 5 (1-based)
+       *
+       * BUG: Currently CacheSelectLimit fails with $sql with LIMIT or TOP clause already set
+       *
+       * @param [secs2cache]   seconds to cache data, set to 0 to force query. This is optional
+       * @param sql
+       * @param [offset]       is the row to start calculations from (1-based)
+       * @param [nrows]        is the number of rows to get
+       * @param [inputarr]     array of bind variables
+       * @return               the recordset ($rs->databaseType == 'array')
+       */
+       function &CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false)
+       {       
+               if (!is_numeric($secs2cache)) {
+                       if ($sql === false) $sql = -1;
+                       if ($offset == -1) $offset = false;
+                                                                         // sql,       nrows, offset,inputarr
+                       $rs =& $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$this->cacheSecs);
+               } else {
+                       if ($sql === false) ADOConnection::outp( "Warning: \$sql missing from CacheSelectLimit()");
+                       $rs =& $this->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
+               }
+               return $rs;
+       }
+       
+       
+       /**
+       * Flush cached recordsets that match a particular $sql statement. 
+       * If $sql == false, then we purge all files in the cache.
+       */
+       function CacheFlush($sql=false,$inputarr=false)
+       {
+       global $ADODB_CACHE_DIR;
+       
+               if ($this->memCache) {
+               global $ADODB_INCLUDED_MEMCACHE;
+               
+                       $key = false;
+                       if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php');
+                       if ($sql) $key = $this->_gencachename($sql.serialize($inputarr),false,true);
+                       FlushMemCache($key, $this->memCacheHost, $this->memCachePort, $this->debug);
+                       return;
+               }
+       
+               if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) {
+                       /*if (strncmp(PHP_OS,'WIN',3) === 0)
+                       $dir = str_replace('/', '\\', $ADODB_CACHE_DIR);
+                       else */
+                       $dir = $ADODB_CACHE_DIR;
+                       
+                       if ($this->debug)
+                               ADOConnection::outp( "CacheFlush: $dir<br><pre>\n", $this->_dirFlush($dir),"</pre>");
+                       else
+                               $this->_dirFlush($dir);
+                       return;
+               }
+               
+               global $ADODB_INCLUDED_CSV;
+               if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');
+               
+               $f = $this->_gencachename($sql.serialize($inputarr),false);
+               adodb_write_file($f,''); // is adodb_write_file needed?
+               if (!@unlink($f))
+                       if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f");
+       }
+       
+       /**
+       * Private function to erase all of the files and subdirectories in a directory.
+       *
+       * Just specify the directory, and tell it if you want to delete the directory or just clear it out.
+       * Note: $kill_top_level is used internally in the function to flush subdirectories.
+       */
+       function _dirFlush($dir, $kill_top_level = false) {
+               if(!$dh = @opendir($dir)) return;
+               
+               while (($obj = readdir($dh))) {
+                       if($obj=='.' || $obj=='..')
+                               continue;
+
+                       if (!@unlink($dir.'/'.$obj))
+                               $this->_dirFlush($dir.'/'.$obj, true);
+               }
+               if ($kill_top_level === true)
+                       @rmdir($dir);
+               return true;
+       }
+       
+       
+       function xCacheFlush($sql=false,$inputarr=false)
+       {
+       global $ADODB_CACHE_DIR;
+       
+               if ($this->memCache) {
+                       global $ADODB_INCLUDED_MEMCACHE;
+                       $key = false;
+                       if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php');
+                       if ($sql) $key = $this->_gencachename($sql.serialize($inputarr),false,true);
+                       flushmemCache($key, $this->memCacheHost, $this->memCachePort, $this->debug);
+                       return;
+               }
+
+               if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) {
+                       if (strncmp(PHP_OS,'WIN',3) === 0) {
+                               $cmd = 'del /s '.str_replace('/','\\',$ADODB_CACHE_DIR).'\adodb_*.cache';
+                       } else {
+                               //$cmd = 'find "'.$ADODB_CACHE_DIR.'" -type f -maxdepth 1 -print0 | xargs -0 rm -f';
+                               $cmd = 'rm -rf '.$ADODB_CACHE_DIR.'/[0-9a-f][0-9a-f]/'; 
+                               // old version 'rm -f `find '.$ADODB_CACHE_DIR.' -name adodb_*.cache`';
+                       }
+                       if ($this->debug) {
+                               ADOConnection::outp( "CacheFlush: $cmd<br><pre>\n", system($cmd),"</pre>");
+                       } else {
+                               exec($cmd);
+                       }
+                       return;
+               } 
+               
+               global $ADODB_INCLUDED_CSV;
+               if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');
+               
+               $f = $this->_gencachename($sql.serialize($inputarr),false);
+               adodb_write_file($f,''); // is adodb_write_file needed?
+               if (!@unlink($f)) {
+                       if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f");
+               }
+       }
+       
+       /**
+       * Private function to generate filename for caching.
+       * Filename is generated based on:
+       *
+       *  - sql statement
+       *  - database type (oci8, ibase, ifx, etc)
+       *  - database name
+       *  - userid
+       *  - setFetchMode (adodb 4.23)
+       *
+       * When not in safe mode, we create 256 sub-directories in the cache directory ($ADODB_CACHE_DIR). 
+       * Assuming that we can have 50,000 files per directory with good performance, 
+       * then we can scale to 12.8 million unique cached recordsets. Wow!
+       */
+       function _gencachename($sql,$createdir,$memcache=false)
+       {
+       global $ADODB_CACHE_DIR;
+       static $notSafeMode;
+               
+               if ($this->fetchMode === false) { 
+               global $ADODB_FETCH_MODE;
+                       $mode = $ADODB_FETCH_MODE;
+               } else {
+                       $mode = $this->fetchMode;
+               }
+               $m = md5($sql.$this->databaseType.$this->database.$this->user.$mode);
+               if ($memcache) return $m;
+               
+               if (!isset($notSafeMode)) $notSafeMode = !ini_get('safe_mode');
+               $dir = ($notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($m,0,2) : $ADODB_CACHE_DIR;
+                       
+               if ($createdir && $notSafeMode && !file_exists($dir)) {
+                       $oldu = umask(0);
+                       if (!mkdir($dir,0771)) 
+                               if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql");
+                       umask($oldu);
+               }
+               return $dir.'/adodb_'.$m.'.cache';
+       }
+       
+       
+       /**
+        * Execute SQL, caching recordsets.
+        *
+        * @param [secs2cache]  seconds to cache data, set to 0 to force query. 
+        *                                        This is an optional parameter.
+        * @param sql           SQL statement to execute
+        * @param [inputarr]    holds the input data  to bind to
+        * @return              RecordSet or false
+        */
+       function &CacheExecute($secs2cache,$sql=false,$inputarr=false)
+       {
+
+                       
+               if (!is_numeric($secs2cache)) {
+                       $inputarr = $sql;
+                       $sql = $secs2cache;
+                       $secs2cache = $this->cacheSecs;
+               }
+               
+               if (is_array($sql)) {
+                       $sqlparam = $sql;
+                       $sql = $sql[0];
+               } else
+                       $sqlparam = $sql;
+                       
+               if ($this->memCache) {
+                       global $ADODB_INCLUDED_MEMCACHE;
+                       if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php');
+                       $md5file = $this->_gencachename($sql.serialize($inputarr),false,true);
+               } else {
+               global $ADODB_INCLUDED_CSV;
+                       if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');
+                       $md5file = $this->_gencachename($sql.serialize($inputarr),true);
+               }
+
+               $err = '';
+               
+               if ($secs2cache > 0){
+                       if ($this->memCache)
+                               $rs = &getmemCache($md5file,$err,$secs2cache, $this->memCacheHost, $this->memCachePort);
+                       else
+                               $rs = &csv2rs($md5file,$err,$secs2cache,$this->arrayClass);
+                       $this->numCacheHits += 1;
+               } else {
+                       $err='Timeout 1';
+                       $rs = false;
+                       $this->numCacheMisses += 1;
+               }
+               if (!$rs) {
+               // no cached rs found
+                       if ($this->debug) {
+                               if (get_magic_quotes_runtime() && !$this->memCache) {
+                                       ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :(");
+                               }
+                               if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (see sql below)");
+                       }
+                       
+                       $rs = &$this->Execute($sqlparam,$inputarr);
+
+                       if ($rs && $this->memCache) {
+                               $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately
+                               if(!putmemCache($md5file, $rs, $this->memCacheHost, $this->memCachePort, $this->memCacheCompress, $this->debug)) {
+                                       if ($fn = $this->raiseErrorFn)
+                                               $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this);
+                                       if ($this->debug) ADOConnection::outp( " Cache write error");
+                               }
+                       } 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);
+                                       }
+                                       if ($this->debug) ADOConnection::outp( " Cache write error");
+                               }
+                               if ($rs->EOF && !$eof) {
+                                       $rs->MoveFirst();
+                                       //$rs = &csv2rs($md5file,$err);         
+                                       $rs->connection = &$this; // Pablo suggestion
+                               }  
+                               
+                       } else if (!$this->memCache)
+                               @unlink($md5file);
+               } else {
+                       $this->_errorMsg = '';
+                       $this->_errorCode = 0;
+                       
+                       if ($this->fnCacheExecute) {
+                               $fn = $this->fnCacheExecute;
+                               $fn($this, $secs2cache, $sql, $inputarr);
+                       }
+               // ok, set cached object found
+                       $rs->connection = &$this; // Pablo suggestion
+                       if ($this->debug){ 
+                                       
+                               $inBrowser = isset($_SERVER['HTTP_USER_AGENT']);
+                               $ttl = $rs->timeCreated + $secs2cache - time();
+                               $s = is_array($sql) ? $sql[0] : $sql;
+                               if ($inBrowser) $s = '<i>'.htmlspecialchars($s).'</i>';
+                               
+                               ADOConnection::outp( " $md5file reloaded, ttl=$ttl [ $s ]");
+                       }
+               }
+               return $rs;
+       }
+       
+       
+       /* 
+               Similar to PEAR DB's autoExecute(), except that 
+               $mode can be 'INSERT' or 'UPDATE' or DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE
+               If $mode == 'UPDATE', then $where is compulsory as a safety measure.
+               
+               $forceUpdate means that even if the data has not changed, perform update.
+        */
+       function& AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false) 
+       {
+               $false = false;
+               $sql = 'SELECT * FROM '.$table;  
+               if ($where!==FALSE) $sql .= ' WHERE '.$where;
+               else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) {
+                       ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause');
+                       return $false;
+               }
+
+               $rs =& $this->SelectLimit($sql,1);
+               if (!$rs) return $false; // table does not exist
+               $rs->tableName = $table;
+               
+               switch((string) $mode) {
+               case 'UPDATE':
+               case '2':
+                       $sql = $this->GetUpdateSQL($rs, $fields_values, $forceUpdate, $magicq);
+                       break;
+               case 'INSERT':
+               case '1':
+                       $sql = $this->GetInsertSQL($rs, $fields_values, $magicq);
+                       break;
+               default:
+                       ADOConnection::outp("AutoExecute: Unknown mode=$mode");
+                       return $false;
+               }
+               $ret = false;
+               if ($sql) $ret = $this->Execute($sql);
+               if ($ret) $ret = true;
+               return $ret;
+       }
+       
+       
+       /**
+        * Generates an Update Query based on an existing recordset.
+        * $arrFields is an associative array of fields with the value
+        * that should be assigned.
+        *
+        * Note: This function should only be used on a recordset
+        *         that is run against a single table and sql should only 
+        *               be a simple select stmt with no groupby/orderby/limit
+        *
+        * "Jonathan Younger" <jyounger@unilab.com>
+        */
+       function GetUpdateSQL(&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=null)
+       {
+               global $ADODB_INCLUDED_LIB;
+
+        //********************************************************//
+        //This is here to maintain compatibility
+        //with older adodb versions. Sets force type to force nulls if $forcenulls is set.
+               if (!isset($force)) {
+                               global $ADODB_FORCE_TYPE;
+                           $force = $ADODB_FORCE_TYPE;
+               }
+               //********************************************************//
+
+               if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+               return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq,$force);
+       }
+
+       /**
+        * Generates an Insert Query based on an existing recordset.
+        * $arrFields is an associative array of fields with the value
+        * that should be assigned.
+        *
+        * Note: This function should only be used on a recordset
+        *         that is run against a single table.
+        */
+       function GetInsertSQL(&$rs, $arrFields,$magicq=false,$force=null)
+       {       
+               global $ADODB_INCLUDED_LIB;
+               if (!isset($force)) {
+                       global $ADODB_FORCE_TYPE;
+                       $force = $ADODB_FORCE_TYPE;
+                       
+               }
+               if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+               return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force);
+       }
+       
+
+       /**
+       * Update a blob column, given a where clause. There are more sophisticated
+       * blob handling functions that we could have implemented, but all require
+       * a very complex API. Instead we have chosen something that is extremely
+       * simple to understand and use. 
+       *
+       * Note: $blobtype supports 'BLOB' and 'CLOB', default is BLOB of course.
+       *
+       * Usage to update a $blobvalue which has a primary key blob_id=1 into a 
+       * field blobtable.blobcolumn:
+       *
+       *       UpdateBlob('blobtable', 'blobcolumn', $blobvalue, 'blob_id=1');
+       *
+       * Insert example:
+       *
+       *       $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
+       *       $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
+       */
+       
+       function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
+       {
+               return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;
+       }
+
+       /**
+       * Usage:
+       *       UpdateBlob('TABLE', 'COLUMN', '/path/to/file', 'ID=1');
+       *       
+       *       $blobtype supports 'BLOB' and 'CLOB'
+       *
+       *       $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
+       *       $conn->UpdateBlob('blobtable','blobcol',$blobpath,'id=1');
+       */
+       function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB')
+       {
+               $fd = fopen($path,'rb');
+               if ($fd === false) return false;
+               $val = fread($fd,filesize($path));
+               fclose($fd);
+               return $this->UpdateBlob($table,$column,$val,$where,$blobtype);
+       }
+       
+       function BlobDecode($blob)
+       {
+               return $blob;
+       }
+       
+       function BlobEncode($blob)
+       {
+               return $blob;
+       }
+       
+       function SetCharSet($charset)
+       {
+               return false;
+       }
+       
+       function IfNull( $field, $ifNull ) 
+       {
+               return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
+       }
+       
+       function LogSQL($enable=true)
+       {
+               include_once(ADODB_DIR.'/adodb-perf.inc.php');
+               
+               if ($enable) $this->fnExecute = 'adodb_log_sql';
+               else $this->fnExecute = false;
+               
+               $old = $this->_logsql;  
+               $this->_logsql = $enable;
+               if ($enable && !$old) $this->_affected = false;
+               return $old;
+       }
+       
+       function GetCharSet()
+       {
+               return false;
+       }
+       
+       /**
+       * Usage:
+       *       UpdateClob('TABLE', 'COLUMN', $var, 'ID=1', 'CLOB');
+       *
+       *       $conn->Execute('INSERT INTO clobtable (id, clobcol) VALUES (1, null)');
+       *       $conn->UpdateClob('clobtable','clobcol',$clob,'id=1');
+       */
+       function UpdateClob($table,$column,$val,$where)
+       {
+               return $this->UpdateBlob($table,$column,$val,$where,'CLOB');
+       }
+       
+       // not the fastest implementation - quick and dirty - jlim
+       // for best performance, use the actual $rs->MetaType().
+       function MetaType($t,$len=-1,$fieldobj=false)
+       {
+               
+               if (empty($this->_metars)) {
+                       $rsclass = $this->rsPrefix.$this->databaseType;
+                       $this->_metars = new $rsclass(false,$this->fetchMode); 
+                       $this->_metars->connection =& $this;
+               }
+               return $this->_metars->MetaType($t,$len,$fieldobj);
+       }
+       
+       
+       /**
+       *  Change the SQL connection locale to a specified locale.
+       *  This is used to get the date formats written depending on the client locale.
+       */
+       function SetDateLocale($locale = 'En')
+       {
+               $this->locale = $locale;
+               switch (strtoupper($locale))
+               {
+                       case 'EN':
+                               $this->fmtDate="'Y-m-d'";
+                               $this->fmtTimeStamp = "'Y-m-d H:i:s'";
+                               break;
+                               
+                       case 'US':
+                               $this->fmtDate = "'m-d-Y'";
+                               $this->fmtTimeStamp = "'m-d-Y H:i:s'";
+                               break;
+                               
+                       case 'PT_BR':   
+                       case 'NL':
+                       case 'FR':
+                       case 'RO':
+                       case 'IT':
+                               $this->fmtDate="'d-m-Y'";
+                               $this->fmtTimeStamp = "'d-m-Y H:i:s'";
+                               break;
+                               
+                       case 'GE':
+                               $this->fmtDate="'d.m.Y'";
+                               $this->fmtTimeStamp = "'d.m.Y H:i:s'";
+                               break;
+                               
+                       default:
+                               $this->fmtDate="'Y-m-d'";
+                               $this->fmtTimeStamp = "'Y-m-d H:i:s'";
+                               break;
+               }
+       }
+
+       function &GetActiveRecordsClass($class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false)
+       {
+       global $_ADODB_ACTIVE_DBS;
+       
+               $save = $this->SetFetchMode(ADODB_FETCH_NUM);
+               if (empty($whereOrderBy)) $whereOrderBy = '1=1';
+               $rows = $this->GetAll("select * from ".$table.' WHERE '.$whereOrderBy,$bindarr);
+               $this->SetFetchMode($save);
+               
+               $false = false;
+               
+               if ($rows === false) {  
+                       return $false;
+               }
+               
+               
+               if (!isset($_ADODB_ACTIVE_DBS)) {
+                       include(ADODB_DIR.'/adodb-active-record.inc.php');
+               }       
+               if (!class_exists($class)) {
+                       ADOConnection::outp("Unknown class $class in GetActiveRcordsClass()");
+                       return $false;
+               }
+               $arr = array();
+               foreach($rows as $row) {
+               
+                       $obj = new $class($table,$primkeyArr,$this);
+                       if ($obj->ErrorMsg()){
+                               $this->_errorMsg = $obj->ErrorMsg();
+                               return $false;
+                       }
+                       $obj->Set($row);
+                       $arr[] = $obj;
+               }
+               return $arr;
+       }
+       
+       function &GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false)
+       {
+               $arr =& $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr);
+               return $arr;
+       }
+       
+       /**
+        * Close Connection
+        */
+       function Close()
+       {
+               $rez = $this->_close();
+               $this->_connectionID = false;
+               return $rez;
+       }
+       
+       /**
+        * Begin a Transaction. Must be followed by CommitTrans() or RollbackTrans().
+        *
+        * @return true if succeeded or false if database does not support transactions
+        */
+       function BeginTrans() 
+       {
+               if ($this->debug) ADOConnection::outp("BeginTrans: Transactions not supported for this driver");
+               return false;
+       }
+       
+       /* set transaction mode */
+       function SetTransactionMode( $transaction_mode ) 
+       {
+               $transaction_mode = $this->MetaTransaction($transaction_mode, $this->dataProvider);
+               $this->_transmode  = $transaction_mode;
+       }
+/*
+http://msdn2.microsoft.com/en-US/ms173763.aspx
+http://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-isolation.html
+http://www.postgresql.org/docs/8.1/interactive/sql-set-transaction.html
+http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_10005.htm
+*/
+       function MetaTransaction($mode,$db)
+       {
+               $mode = strtoupper($mode);
+               $mode = str_replace('ISOLATION LEVEL ','',$mode);
+               
+               switch($mode) {
+
+               case 'READ UNCOMMITTED':
+                       switch($db) { 
+                       case 'oci8':
+                       case 'oracle':
+                               return 'ISOLATION LEVEL READ COMMITTED';
+                       default:
+                               return 'ISOLATION LEVEL READ UNCOMMITTED';
+                       }
+                       break;
+                                       
+               case 'READ COMMITTED':
+                               return 'ISOLATION LEVEL READ COMMITTED';
+                       break;
+                       
+               case 'REPEATABLE READ':
+                       switch($db) {
+                       case 'oci8':
+                       case 'oracle':
+                               return 'ISOLATION LEVEL SERIALIZABLE';
+                       default:
+                               return 'ISOLATION LEVEL REPEATABLE READ';
+                       }
+                       break;
+                       
+               case 'SERIALIZABLE':
+                               return 'ISOLATION LEVEL SERIALIZABLE';
+                       break;
+                       
+               default:
+                       return $mode;
+               }
+       }
+       
+       /**
+        * If database does not support transactions, always return true as data always commited
+        *
+        * @param $ok  set to false to rollback transaction, true to commit
+        *
+        * @return true/false.
+        */
+       function CommitTrans($ok=true) 
+       { return true;}
+       
+       
+       /**
+        * If database does not support transactions, rollbacks always fail, so return false
+        *
+        * @return true/false.
+        */
+       function RollbackTrans() 
+       { return false;}
+
+
+       /**
+        * return the databases that the driver can connect to. 
+        * Some databases will return an empty array.
+        *
+        * @return an array of database names.
+        */
+       function MetaDatabases() 
+       {
+       global $ADODB_FETCH_MODE;
+               
+               if ($this->metaDatabasesSQL) {
+                       $save = $ADODB_FETCH_MODE;
+                       $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+                       
+                       if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
+                       
+                       $arr = $this->GetCol($this->metaDatabasesSQL);
+                       if (isset($savem)) $this->SetFetchMode($savem);
+                       $ADODB_FETCH_MODE = $save;
+                       
+                       return $arr;
+               }
+               
+               return false;
+       }
+       
+       
+       /**
+        * @param ttype can either be 'VIEW' or 'TABLE' or false. 
+        *              If false, both views and tables are returned.
+        *              "VIEW" returns only views
+        *              "TABLE" returns only tables
+        * @param showSchema returns the schema/user with the table name, eg. USER.TABLE
+        * @param mask  is the input mask - only supported by oci8 and postgresql
+        *
+        * @return  array of tables for current database.
+        */ 
+       function &MetaTables($ttype=false,$showSchema=false,$mask=false) 
+       {
+       global $ADODB_FETCH_MODE;
+       
+               
+               $false = false;
+               if ($mask) {
+                       return $false;
+               }
+               if ($this->metaTablesSQL) {
+                       $save = $ADODB_FETCH_MODE; 
+                       $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 
+                       
+                       if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
+                       
+                       $rs = $this->Execute($this->metaTablesSQL);
+                       if (isset($savem)) $this->SetFetchMode($savem);
+                       $ADODB_FETCH_MODE = $save; 
+                       
+                       if ($rs === false) return $false;
+                       $arr =& $rs->GetArray();
+                       $arr2 = array();
+                       
+                       if ($hast = ($ttype && isset($arr[0][1]))) { 
+                               $showt = strncmp($ttype,'T',1);
+                       }
+                       
+                       for ($i=0; $i < sizeof($arr); $i++) {
+                               if ($hast) {
+                                       if ($showt == 0) {
+                                               if (strncmp($arr[$i][1],'T',1) == 0) $arr2[] = trim($arr[$i][0]);
+                                       } else {
+                                               if (strncmp($arr[$i][1],'V',1) == 0) $arr2[] = trim($arr[$i][0]);
+                                       }
+                               } else
+                                       $arr2[] = trim($arr[$i][0]);
+                       }
+                       $rs->Close();
+                       return $arr2;
+               }
+               return $false;
+       }
+       
+       
+       function _findschema(&$table,&$schema)
+       {
+               if (!$schema && ($at = strpos($table,'.')) !== false) {
+                       $schema = substr($table,0,$at);
+                       $table = substr($table,$at+1);
+               }
+       }
+       
+       /**
+        * List columns in a database as an array of ADOFieldObjects. 
+        * See top of file for definition of object.
+        *
+        * @param $table        table name to query
+        * @param $normalize    makes table name case-insensitive (required by some databases)
+        * @schema is optional database schema to use - not supported by all databases.
+        *
+        * @return  array of ADOFieldObjects for current table.
+        */
+       function &MetaColumns($table,$normalize=true) 
+       {
+       global $ADODB_FETCH_MODE;
+               
+               $false = false;
+               
+               if (!empty($this->metaColumnsSQL)) {
+               
+                       $schema = false;
+                       $this->_findschema($table,$schema);
+               
+                       $save = $ADODB_FETCH_MODE;
+                       $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+                       if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
+                       $rs = $this->Execute(sprintf($this->metaColumnsSQL,($normalize)?strtoupper($table):$table));
+                       if (isset($savem)) $this->SetFetchMode($savem);
+                       $ADODB_FETCH_MODE = $save;
+                       if ($rs === false || $rs->EOF) return $false;
+
+                       $retarr = array();
+                       while (!$rs->EOF) { //print_r($rs->fields);
+                               $fld = new ADOFieldObject();
+                               $fld->name = $rs->fields[0];
+                               $fld->type = $rs->fields[1];
+                               if (isset($rs->fields[3]) && $rs->fields[3]) {
+                                       if ($rs->fields[3]>0) $fld->max_length = $rs->fields[3];
+                                       $fld->scale = $rs->fields[4];
+                                       if ($fld->scale>0) $fld->max_length += 1;
+                               } else
+                                       $fld->max_length = $rs->fields[2];
+                                       
+                               if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;     
+                               else $retarr[strtoupper($fld->name)] = $fld;
+                               $rs->MoveNext();
+                       }
+                       $rs->Close();
+                       return $retarr; 
+               }
+               return $false;
+       }
+       
+    /**
+      * List indexes on a table as an array.
+      * @param table  table name to query
+      * @param primary true to only show primary keys. Not actually used for most databases
+         *
+      * @return array of indexes on current table. Each element represents an index, and is itself an associative array.
+         
+                Array (
+                   [name_of_index] => Array
+                     (
+                 [unique] => true or false
+                 [columns] => Array
+                 (
+                       [0] => firstname
+                       [1] => lastname
+                 )
+               )               
+      */
+     function &MetaIndexes($table, $primary = false, $owner = false)
+     {
+                       $false = false;
+            return $false;
+     }
+
+       /**
+        * List columns names in a table as an array. 
+        * @param table table name to query
+        *
+        * @return  array of column names for current table.
+        */ 
+       function &MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */) 
+       {
+               $objarr =& $this->MetaColumns($table);
+               if (!is_array($objarr)) {
+                       $false = false;
+                       return $false;
+               }
+               $arr = array();
+               if ($numIndexes) {
+                       $i = 0;
+                       if ($useattnum) {
+                               foreach($objarr as $v) 
+                                       $arr[$v->attnum] = $v->name;
+                               
+                       } else
+                               foreach($objarr as $v) $arr[$i++] = $v->name;
+               } else
+                       foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name;
+               
+               return $arr;
+       }
+                       
+       /**
+        * Different SQL databases used different methods to combine strings together.
+        * This function provides a wrapper. 
+        * 
+        * param s      variable number of string parameters
+        *
+        * Usage: $db->Concat($str1,$str2);
+        * 
+        * @return concatenated string
+        */      
+       function Concat()
+       {       
+               $arr = func_get_args();
+               return implode($this->concat_operator, $arr);
+       }
+       
+       
+       /**
+        * Converts a date "d" to a string that the database can understand.
+        *
+        * @param d     a date in Unix date time format.
+        *
+        * @return  date string in database date format
+        */
+       function DBDate($d)
+       {
+               if (empty($d) && $d !== 0) return 'null';
+
+               if (is_string($d) && !is_numeric($d)) {
+                       if ($d === 'null' || strncmp($d,"'",1) === 0) return $d;
+                       if ($this->isoDates) return "'$d'";
+                       $d = ADOConnection::UnixDate($d);
+               }
+
+               return adodb_date($this->fmtDate,$d);
+       }
+       
+       function BindDate($d)
+       {
+               $d = $this->DBDate($d);
+               if (strncmp($d,"'",1)) return $d;
+               
+               return substr($d,1,strlen($d)-2);
+       }
+       
+       function BindTimeStamp($d)
+       {
+               $d = $this->DBTimeStamp($d);
+               if (strncmp($d,"'",1)) return $d;
+               
+               return substr($d,1,strlen($d)-2);
+       }
+       
+       
+       /**
+        * Converts a timestamp "ts" to a string that the database can understand.
+        *
+        * @param ts    a timestamp in Unix date time format.
+        *
+        * @return  timestamp string in database timestamp format
+        */
+       function DBTimeStamp($ts)
+       {
+               if (empty($ts) && $ts !== 0) return 'null';
+
+               # strlen(14) allows YYYYMMDDHHMMSS format
+               if (!is_string($ts) || (is_numeric($ts) && strlen($ts)<14)) 
+                       return adodb_date($this->fmtTimeStamp,$ts);
+               
+               if ($ts === 'null') return $ts;
+               if ($this->isoDates && strlen($ts) !== 14) return "'$ts'";
+               
+               $ts = ADOConnection::UnixTimeStamp($ts);
+               return adodb_date($this->fmtTimeStamp,$ts);
+       }
+       
+       /**
+        * Also in ADORecordSet.
+        * @param $v is a date string in YYYY-MM-DD format
+        *
+        * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
+        */
+       function UnixDate($v)
+       {
+               if (is_object($v)) {
+               // odbtp support
+               //( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )
+                       return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year);
+               }
+       
+               if (is_numeric($v) && strlen($v) !== 8) return $v;
+               if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|", 
+                       ($v), $rr)) return false;
+
+               if ($rr[1] <= TIMESTAMP_FIRST_YEAR) return 0;
+               // h-m-s-MM-DD-YY
+               return @adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]);
+       }
+       
+
+       /**
+        * Also in ADORecordSet.
+        * @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format
+        *
+        * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
+        */
+       function UnixTimeStamp($v)
+       {
+               if (is_object($v)) {
+               // odbtp support
+               //( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )
+                       return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year);
+               }
+               
+               if (!preg_match( 
+                       "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ ,-]*(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", 
+                       ($v), $rr)) return false;
+                       
+               if ($rr[1] <= TIMESTAMP_FIRST_YEAR && $rr[2]<= 1) return 0;
+       
+               // h-m-s-MM-DD-YY
+               if (!isset($rr[5])) return  adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]);
+               return  @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]);
+       }
+       
+       /**
+        * Also in ADORecordSet.
+        *
+        * Format database date based on user defined format.
+        *
+        * @param v     is the character date in YYYY-MM-DD format, returned by database
+        * @param fmt   is the format to apply to it, using date()
+        *
+        * @return a date formated as user desires
+        */
+        
+       function UserDate($v,$fmt='Y-m-d',$gmt=false)
+       {
+               $tt = $this->UnixDate($v);
+
+               // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
+               if (($tt === false || $tt == -1) && $v != false) return $v;
+               else if ($tt == 0) return $this->emptyDate;
+               else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR
+               }
+               
+               return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);
+       
+       }
+       
+               /**
+        *
+        * @param v     is the character timestamp in YYYY-MM-DD hh:mm:ss format
+        * @param fmt   is the format to apply to it, using date()
+        *
+        * @return a timestamp formated as user desires
+        */
+       function UserTimeStamp($v,$fmt='Y-m-d H:i:s',$gmt=false)
+       {
+               if (!isset($v)) return $this->emptyTimeStamp;
+               # strlen(14) allows YYYYMMDDHHMMSS format
+               if (is_numeric($v) && strlen($v)<14) return ($gmt) ? adodb_gmdate($fmt,$v) : adodb_date($fmt,$v);
+               $tt = $this->UnixTimeStamp($v);
+               // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
+               if (($tt === false || $tt == -1) && $v != false) return $v;
+               if ($tt == 0) return $this->emptyTimeStamp;
+               return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);
+       }
+       
+       function escape($s,$magic_quotes=false)
+       {
+               return $this->addq($s,$magic_quotes);
+       }
+       
+       /**
+       * Quotes a string, without prefixing nor appending quotes. 
+       */
+       function addq($s,$magic_quotes=false)
+       {
+               if (!$magic_quotes) {
+               
+                       if ($this->replaceQuote[0] == '\\'){
+                               // only since php 4.0.5
+                               $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
+                               //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s));
+                       }
+                       return  str_replace("'",$this->replaceQuote,$s);
+               }
+               
+               // undo magic quotes for "
+               $s = str_replace('\\"','"',$s);
+               
+               if ($this->replaceQuote == "\\'")  // ' already quoted, no need to change anything
+                       return $s;
+               else {// change \' to '' for sybase/mssql
+                       $s = str_replace('\\\\','\\',$s);
+                       return str_replace("\\'",$this->replaceQuote,$s);
+               }
+       }
+       
+       /**
+        * Correctly quotes a string so that all strings are escaped. We prefix and append
+        * to the string single-quotes.
+        * An example is  $db->qstr("Don't bother",magic_quotes_runtime());
+        * 
+        * @param s                     the string to quote
+        * @param [magic_quotes]        if $s is GET/POST var, set to get_magic_quotes_gpc().
+        *                              This undoes the stupidity of magic quotes for GPC.
+        *
+        * @return  quoted string to be sent back to database
+        */
+       function qstr($s,$magic_quotes=false)
+       {       
+               if (!$magic_quotes) {
+               
+                       if ($this->replaceQuote[0] == '\\'){
+                               // only since php 4.0.5
+                               $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
+                               //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s));
+                       }
+                       return  "'".str_replace("'",$this->replaceQuote,$s)."'";
+               }
+               
+               // undo magic quotes for "
+               $s = str_replace('\\"','"',$s);
+               
+               if ($this->replaceQuote == "\\'")  // ' already quoted, no need to change anything
+                       return "'$s'";
+               else {// change \' to '' for sybase/mssql
+                       $s = str_replace('\\\\','\\',$s);
+                       return "'".str_replace("\\'",$this->replaceQuote,$s)."'";
+               }
+       }
+       
+       
+       /**
+       * Will select the supplied $page number from a recordset, given that it is paginated in pages of 
+       * $nrows rows per page. It also saves two boolean values saying if the given page is the first 
+       * and/or last one of the recordset. Added by Iván Oliva to provide recordset pagination.
+       *
+       * See readme.htm#ex8 for an example of usage.
+       *
+       * @param sql
+       * @param nrows          is the number of rows per page to get
+       * @param page           is the page number to get (1-based)
+       * @param [inputarr]     array of bind variables
+       * @param [secs2cache]           is a private parameter only used by jlim
+       * @return               the recordset ($rs->databaseType == 'array')
+       *
+       * NOTE: phpLens uses a different algorithm and does not use PageExecute().
+       *
+       */
+       function &PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0) 
+       {
+               global $ADODB_INCLUDED_LIB;
+               if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+               if ($this->pageExecuteCountRows) $rs =& _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache);
+               else $rs =& _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache);
+               return $rs;
+       }
+       
+               
+       /**
+       * Will select the supplied $page number from a recordset, given that it is paginated in pages of 
+       * $nrows rows per page. It also saves two boolean values saying if the given page is the first 
+       * and/or last one of the recordset. Added by Iván Oliva to provide recordset pagination.
+       *
+       * @param secs2cache     seconds to cache data, set to 0 to force query
+       * @param sql
+       * @param nrows          is the number of rows per page to get
+       * @param page           is the page number to get (1-based)
+       * @param [inputarr]     array of bind variables
+       * @return               the recordset ($rs->databaseType == 'array')
+       */
+       function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false) 
+       {
+               /*switch($this->dataProvider) {
+               case 'postgres':
+               case 'mysql': 
+                       break;
+               default: $secs2cache = 0; break;
+               }*/
+               $rs =& $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache);
+               return $rs;
+       }
+
+} // end class ADOConnection
+       
+       
+       
+       //==============================================================================================        
+       // CLASS ADOFetchObj
+       //==============================================================================================        
+               
+       /**
+       * Internal placeholder for record objects. Used by ADORecordSet->FetchObj().
+       */
+       class ADOFetchObj {
+       };
+       
+       //==============================================================================================        
+       // CLASS ADORecordSet_empty
+       //==============================================================================================        
+       
+       /**
+       * Lightweight recordset when there are no records to be returned
+       */
+       class ADORecordSet_empty
+       {
+               var $dataProvider = 'empty';
+               var $databaseType = false;
+               var $EOF = true;
+               var $_numOfRows = 0;
+               var $fields = false;
+               var $connection = false;
+               function RowCount() {return 0;}
+               function RecordCount() {return 0;}
+               function PO_RecordCount(){return 0;}
+               function Close(){return true;}
+               function FetchRow() {return false;}
+               function FieldCount(){ return 0;}
+               function Init() {}
+       }
+       
+       //==============================================================================================        
+       // DATE AND TIME FUNCTIONS
+       //==============================================================================================        
+       if (!defined('ADODB_DATE_VERSION')) include(ADODB_DIR.'/adodb-time.inc.php');
+       
+       //==============================================================================================        
+       // CLASS ADORecordSet
+       //==============================================================================================        
+
+       if (PHP_VERSION < 5) include_once(ADODB_DIR.'/adodb-php4.inc.php');
+       else include_once(ADODB_DIR.'/adodb-iterator.inc.php');
+   /**
+        * RecordSet class that represents the dataset returned by the database.
+        * To keep memory overhead low, this class holds only the current row in memory.
+        * No prefetching of data is done, so the RecordCount() can return -1 ( which
+        * means recordcount not known).
+        */
+       class ADORecordSet extends ADODB_BASE_RS {
+       /*
+        * public variables     
+        */
+       var $dataProvider = "native";
+       var $fields = false;    /// holds the current row data
+       var $blobSize = 100;    /// any varchar/char field this size or greater is treated as a blob
+                                                       /// in other words, we use a text area for editing.
+       var $canSeek = false;   /// indicates that seek is supported
+       var $sql;                               /// sql text
+       var $EOF = false;               /// Indicates that the current record position is after the last record in a Recordset object. 
+       
+       var $emptyTimeStamp = '&nbsp;'; /// what to display when $time==0
+       var $emptyDate = '&nbsp;'; /// what to display when $time==0
+       var $debug = false;
+       var $timeCreated=0;     /// datetime in Unix format rs created -- for cached recordsets
+
+       var $bind = false;              /// used by Fields() to hold array - should be private?
+       var $fetchMode;                 /// default fetch mode
+       var $connection = false; /// the parent connection
+       /*
+        *      private variables       
+        */
+       var $_numOfRows = -1;   /** number of rows, or -1 */
+       var $_numOfFields = -1; /** number of fields in recordset */
+       var $_queryID = -1;             /** This variable keeps the result link identifier.     */
+       var $_currentRow = -1;  /** This variable keeps the current row in the Recordset.       */
+       var $_closed = false;   /** has recordset been closed */
+       var $_inited = false;   /** Init() should only be called once */
+       var $_obj;                              /** Used by FetchObj */
+       var $_names;                    /** Used by FetchObj */
+       
+       var $_currentPage = -1; /** Added by Iván Oliva to implement recordset pagination */
+       var $_atFirstPage = false;      /** Added by Iván Oliva to implement recordset pagination */
+       var $_atLastPage = false;       /** Added by Iván Oliva to implement recordset pagination */
+       var $_lastPageNo = -1; 
+       var $_maxRecordCount = 0;
+       var $datetime = false;
+       
+       /**
+        * Constructor
+        *
+        * @param queryID       this is the queryID returned by ADOConnection->_query()
+        *
+        */
+       function ADORecordSet($queryID) 
+       {
+               $this->_queryID = $queryID;
+       }
+       
+       
+       
+       function Init()
+       {
+               if ($this->_inited) return;
+               $this->_inited = true;
+               if ($this->_queryID) @$this->_initrs();
+               else {
+                       $this->_numOfRows = 0;
+                       $this->_numOfFields = 0;
+               }
+               if ($this->_numOfRows != 0 && $this->_numOfFields && $this->_currentRow == -1) {
+                       
+                       $this->_currentRow = 0;
+                       if ($this->EOF = ($this->_fetch() === false)) {
+                               $this->_numOfRows = 0; // _numOfRows could be -1
+                       }
+               } else {
+                       $this->EOF = true;
+               }
+       }
+       
+       
+       /**
+        * Generate a SELECT tag string from a recordset, and return the string.
+        * If the recordset has 2 cols, we treat the 1st col as the containing 
+        * the text to display to the user, and 2nd col as the return value. Default
+        * strings are compared with the FIRST column.
+        *
+        * @param name                  name of SELECT tag
+        * @param [defstr]              the value to hilite. Use an array for multiple hilites for listbox.
+        * @param [blank1stItem]        true to leave the 1st item in list empty
+        * @param [multiple]            true for listbox, false for popup
+        * @param [size]                #rows to show for listbox. not used by popup
+        * @param [selectAttr]          additional attributes to defined for SELECT tag.
+        *                              useful for holding javascript onChange='...' handlers.
+        & @param [compareFields0]      when we have 2 cols in recordset, we compare the defstr with 
+        *                              column 0 (1st col) if this is true. This is not documented.
+        *
+        * @return HTML
+        *
+        * changes by glen.davies@cce.ac.nz to support multiple hilited items
+        */
+       function GetMenu($name,$defstr='',$blank1stItem=true,$multiple=false,
+                       $size=0, $selectAttr='',$compareFields0=true)
+       {
+               global $ADODB_INCLUDED_LIB;
+               if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+               return _adodb_getmenu($this, $name,$defstr,$blank1stItem,$multiple,
+                       $size, $selectAttr,$compareFields0);
+       }
+       
+
+       
+       /**
+        * Generate a SELECT tag string from a recordset, and return the string.
+        * If the recordset has 2 cols, we treat the 1st col as the containing 
+        * the text to display to the user, and 2nd col as the return value. Default
+        * strings are compared with the SECOND column.
+        *
+        */
+       function GetMenu2($name,$defstr='',$blank1stItem=true,$multiple=false,$size=0, $selectAttr='')  
+       {
+               return $this->GetMenu($name,$defstr,$blank1stItem,$multiple,
+                       $size, $selectAttr,false);
+       }
+       
+       /*
+               Grouped Menu
+       */
+       function GetMenu3($name,$defstr='',$blank1stItem=true,$multiple=false,
+                       $size=0, $selectAttr='')
+       {
+               global $ADODB_INCLUDED_LIB;
+               if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+               return _adodb_getmenu_gp($this, $name,$defstr,$blank1stItem,$multiple,
+                       $size, $selectAttr,false);
+       }
+
+       /**
+        * return recordset as a 2-dimensional array.
+        *
+        * @param [nRows]  is the number of rows to return. -1 means every row.
+        *
+        * @return an array indexed by the rows (0-based) from the recordset
+        */
+       function &GetArray($nRows = -1) 
+       {
+       global $ADODB_EXTENSION;
+               if ($ADODB_EXTENSION) {
+                       $results = adodb_getall($this,$nRows);
+                       return $results;
+               }
+               $results = array();
+               $cnt = 0;
+               while (!$this->EOF && $nRows != $cnt) {
+                       $results[] = $this->fields;
+                       $this->MoveNext();
+                       $cnt++;
+               }
+               return $results;
+       }
+       
+       function &GetAll($nRows = -1)
+       {
+               $arr =& $this->GetArray($nRows);
+               return $arr;
+       }
+       
+       /*
+       * Some databases allow multiple recordsets to be returned. This function
+       * will return true if there is a next recordset, or false if no more.
+       */
+       function NextRecordSet()
+       {
+               return false;
+       }
+       
+       /**
+        * return recordset as a 2-dimensional array. 
+        * Helper function for ADOConnection->SelectLimit()
+        *
+        * @param offset        is the row to start calculations from (1-based)
+        * @param [nrows]       is the number of rows to return
+        *
+        * @return an array indexed by the rows (0-based) from the recordset
+        */
+       function &GetArrayLimit($nrows,$offset=-1) 
+       {       
+               if ($offset <= 0) {
+                       $arr =& $this->GetArray($nrows);
+                       return $arr;
+               } 
+               
+               $this->Move($offset);
+               
+               $results = array();
+               $cnt = 0;
+               while (!$this->EOF && $nrows != $cnt) {
+                       $results[$cnt++] = $this->fields;
+                       $this->MoveNext();
+               }
+               
+               return $results;
+       }
+       
+       
+       /**
+        * Synonym for GetArray() for compatibility with ADO.
+        *
+        * @param [nRows]  is the number of rows to return. -1 means every row.
+        *
+        * @return an array indexed by the rows (0-based) from the recordset
+        */
+       function &GetRows($nRows = -1) 
+       {
+               $arr =& $this->GetArray($nRows);
+               return $arr;
+       }
+       
+       /**
+        * return whole recordset as a 2-dimensional associative array if there are more than 2 columns. 
+        * The first column is treated as the key and is not included in the array. 
+        * If there is only 2 columns, it will return a 1 dimensional array of key-value pairs unless
+        * $force_array == true.
+        *
+        * @param [force_array] has only meaning if we have 2 data columns. If false, a 1 dimensional
+        *      array is returned, otherwise a 2 dimensional array is returned. If this sounds confusing,
+        *      read the source.
+        *
+        * @param [first2cols] means if there are more than 2 cols, ignore the remaining cols and 
+        * instead of returning array[col0] => array(remaining cols), return array[col0] => col1
+        *
+        * @return an associative array indexed by the first column of the array, 
+        *      or false if the  data has less than 2 cols.
+        */
+       function &GetAssoc($force_array = false, $first2cols = false) 
+       {
+       global $ADODB_EXTENSION;
+       
+               $cols = $this->_numOfFields;
+               if ($cols < 2) {
+                       $false = false;
+                       return $false;
+               }
+               $numIndex = isset($this->fields[0]);
+               $results = array();
+               
+               if (!$first2cols && ($cols > 2 || $force_array)) {
+                       if ($ADODB_EXTENSION) {
+                               if ($numIndex) {
+                                       while (!$this->EOF) {
+                                               $results[trim($this->fields[0])] = array_slice($this->fields, 1);
+                                               adodb_movenext($this);
+                                       }
+                               } else {
+                                       while (!$this->EOF) {
+                                       // Fix for array_slice re-numbering numeric associative keys
+                                               $keys = array_slice(array_keys($this->fields), 1);
+                                               $sliced_array = array();
+
+                                               foreach($keys as $key) {
+                                                       $sliced_array[$key] = $this->fields[$key];
+                                               }
+                                               
+                                               $results[trim(reset($this->fields))] = $sliced_array;
+                                               adodb_movenext($this);
+                                       }
+                               }
+                       } else {
+                               if ($numIndex) {
+                                       while (!$this->EOF) {
+                                               $results[trim($this->fields[0])] = array_slice($this->fields, 1);
+                                               $this->MoveNext();
+                                       }
+                               } else {
+                                       while (!$this->EOF) {
+                                       // Fix for array_slice re-numbering numeric associative keys
+                                               $keys = array_slice(array_keys($this->fields), 1);
+                                               $sliced_array = array();
+
+                                               foreach($keys as $key) {
+                                                       $sliced_array[$key] = $this->fields[$key];
+                                               }
+                                               
+                                               $results[trim(reset($this->fields))] = $sliced_array;
+                                               $this->MoveNext();
+                                       }
+                               }
+                       }
+               } else {
+                       if ($ADODB_EXTENSION) {
+                               // return scalar values
+                               if ($numIndex) {
+                                       while (!$this->EOF) {
+                                       // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
+                                               $results[trim(($this->fields[0]))] = $this->fields[1];
+                                               adodb_movenext($this);
+                                       }
+                               } else {
+                                       while (!$this->EOF) {
+                                       // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
+                                               $v1 = trim(reset($this->fields));
+                                               $v2 = ''.next($this->fields); 
+                                               $results[$v1] = $v2;
+                                               adodb_movenext($this);
+                                       }
+                               }
+                       } else {
+                               if ($numIndex) {
+                                       while (!$this->EOF) {
+                                       // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
+                                               $results[trim(($this->fields[0]))] = $this->fields[1];
+                                               $this->MoveNext();
+                                       }
+                               } else {
+                                       while (!$this->EOF) {
+                                       // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string
+                                               $v1 = trim(reset($this->fields));
+                                               $v2 = ''.next($this->fields); 
+                                               $results[$v1] = $v2;
+                                               $this->MoveNext();
+                                       }
+                               }
+                       }
+               }
+               
+               $ref =& $results; # workaround accelerator incompat with PHP 4.4 :(
+               return $ref; 
+       }
+       
+       
+       /**
+        *
+        * @param v     is the character timestamp in YYYY-MM-DD hh:mm:ss format
+        * @param fmt   is the format to apply to it, using date()
+        *
+        * @return a timestamp formated as user desires
+        */
+       function UserTimeStamp($v,$fmt='Y-m-d H:i:s')
+       {
+               if (is_numeric($v) && strlen($v)<14) return adodb_date($fmt,$v);
+               $tt = $this->UnixTimeStamp($v);
+               // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
+               if (($tt === false || $tt == -1) && $v != false) return $v;
+               if ($tt === 0) return $this->emptyTimeStamp;
+               return adodb_date($fmt,$tt);
+       }
+       
+       
+       /**
+        * @param v     is the character date in YYYY-MM-DD format, returned by database
+        * @param fmt   is the format to apply to it, using date()
+        *
+        * @return a date formated as user desires
+        */
+       function UserDate($v,$fmt='Y-m-d')
+       {
+               $tt = $this->UnixDate($v);
+               // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
+               if (($tt === false || $tt == -1) && $v != false) return $v;
+               else if ($tt == 0) return $this->emptyDate;
+               else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR
+               }
+               return adodb_date($fmt,$tt);
+       }
+       
+       
+       /**
+        * @param $v is a date string in YYYY-MM-DD format
+        *
+        * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
+        */
+       function UnixDate($v)
+       {
+               return ADOConnection::UnixDate($v);
+       }
+       
+
+       /**
+        * @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format
+        *
+        * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
+        */
+       function UnixTimeStamp($v)
+       {
+               return ADOConnection::UnixTimeStamp($v);
+       }
+       
+       
+       /**
+       * PEAR DB Compat - do not use internally
+       */
+       function Free()
+       {
+               return $this->Close();
+       }
+       
+       
+       /**
+       * PEAR DB compat, number of rows
+       */
+       function NumRows()
+       {
+               return $this->_numOfRows;
+       }
+       
+       
+       /**
+       * PEAR DB compat, number of cols
+       */
+       function NumCols()
+       {
+               return $this->_numOfFields;
+       }
+       
+       /**
+       * Fetch a row, returning false if no more rows. 
+       * This is PEAR DB compat mode.
+       *
+       * @return false or array containing the current record
+       */
+       function &FetchRow()
+       {
+               if ($this->EOF) {
+                       $false = false;
+                       return $false;
+               }
+               $arr = $this->fields;
+               $this->_currentRow++;
+               if (!$this->_fetch()) $this->EOF = true;
+               return $arr;
+       }
+       
+       
+       /**
+       * Fetch a row, returning PEAR_Error if no more rows. 
+       * This is PEAR DB compat mode.
+       *
+       * @return DB_OK or error object
+       */
+       function FetchInto(&$arr)
+       {
+               if ($this->EOF) return (defined('PEAR_ERROR_RETURN')) ? new PEAR_Error('EOF',-1): false;
+               $arr = $this->fields;
+               $this->MoveNext();
+               return 1; // DB_OK
+       }
+       
+       
+       /**
+        * Move to the first row in the recordset. Many databases do NOT support this.
+        *
+        * @return true or false
+        */
+       function MoveFirst() 
+       {
+               if ($this->_currentRow == 0) return true;
+               return $this->Move(0);                  
+       }                       
+
+       
+       /**
+        * Move to the last row in the recordset. 
+        *
+        * @return true or false
+        */
+       function MoveLast() 
+       {
+               if ($this->_numOfRows >= 0) return $this->Move($this->_numOfRows-1);
+               if ($this->EOF) return false;
+               while (!$this->EOF) {
+                       $f = $this->fields;
+                       $this->MoveNext();
+               }
+               $this->fields = $f;
+               $this->EOF = false;
+               return true;
+       }
+       
+       
+       /**
+        * Move to next record in the recordset.
+        *
+        * @return true if there still rows available, or false if there are no more rows (EOF).
+        */
+       function MoveNext() 
+       {
+               if (!$this->EOF) {
+                       $this->_currentRow++;
+                       if ($this->_fetch()) return true;
+               }
+               $this->EOF = true;
+               /* -- tested error handling when scrolling cursor -- seems useless.
+               $conn = $this->connection;
+               if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) {
+                       $fn = $conn->raiseErrorFn;
+                       $fn($conn->databaseType,'MOVENEXT',$errno,$conn->ErrorMsg().' ('.$this->sql.')',$conn->host,$conn->database);
+               }
+               */
+               return false;
+       }
+       
+       
+       /**
+        * Random access to a specific row in the recordset. Some databases do not support
+        * access to previous rows in the databases (no scrolling backwards).
+        *
+        * @param rowNumber is the row to move to (0-based)
+        *
+        * @return true if there still rows available, or false if there are no more rows (EOF).
+        */
+       function Move($rowNumber = 0) 
+       {
+               $this->EOF = false;
+               if ($rowNumber == $this->_currentRow) return true;
+               if ($rowNumber >= $this->_numOfRows)
+                       if ($this->_numOfRows != -1) $rowNumber = $this->_numOfRows-2;
+                               
+               if ($this->canSeek) { 
+       
+                       if ($this->_seek($rowNumber)) {
+                               $this->_currentRow = $rowNumber;
+                               if ($this->_fetch()) {
+                                       return true;
+                               }
+                       } else {
+                               $this->EOF = true;
+                               return false;
+                       }
+               } else {
+                       if ($rowNumber < $this->_currentRow) return false;
+                       global $ADODB_EXTENSION;
+                       if ($ADODB_EXTENSION) {
+                               while (!$this->EOF && $this->_currentRow < $rowNumber) {
+                                       adodb_movenext($this);
+                               }
+                       } else {
+                       
+                               while (! $this->EOF && $this->_currentRow < $rowNumber) {
+                                       $this->_currentRow++;
+                                       
+                                       if (!$this->_fetch()) $this->EOF = true;
+                               }
+                       }
+                       return !($this->EOF);
+               }
+               
+               $this->fields = false;  
+               $this->EOF = true;
+               return false;
+       }
+       
+               
+       /**
+        * Get the value of a field in the current row by column name.
+        * Will not work if ADODB_FETCH_MODE is set to ADODB_FETCH_NUM.
+        * 
+        * @param colname  is the field to access
+        *
+        * @return the value of $colname column
+        */
+       function Fields($colname)
+       {
+               return $this->fields[$colname];
+       }
+       
+       function GetAssocKeys($upper=true)
+       {
+               $this->bind = array();
+               for ($i=0; $i < $this->_numOfFields; $i++) {
+                       $o = $this->FetchField($i);
+                       if ($upper === 2) $this->bind[$o->name] = $i;
+                       else $this->bind[($upper) ? strtoupper($o->name) : strtolower($o->name)] = $i;
+               }
+       }
+       
+  /**
+   * Use associative array to get fields array for databases that do not support
+   * associative arrays. Submitted by Paolo S. Asioli paolo.asioli#libero.it
+   *
+   * If you don't want uppercase cols, set $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC
+   * before you execute your SQL statement, and access $rs->fields['col'] directly.
+   *
+   * $upper  0 = lowercase, 1 = uppercase, 2 = whatever is returned by FetchField
+   */
+       function &GetRowAssoc($upper=1)
+       {
+               $record = array();
+        //     if (!$this->fields) return $record;
+               
+               if (!$this->bind) {
+                       $this->GetAssocKeys($upper);
+               }
+               
+               foreach($this->bind as $k => $v) {
+                       $record[$k] = $this->fields[$v];
+               }
+
+               return $record;
+       }
+       
+       
+       /**
+        * Clean up recordset
+        *
+        * @return true or false
+        */
+       function Close() 
+       {
+               // free connection object - this seems to globally free the object
+               // and not merely the reference, so don't do this...
+               // $this->connection = false; 
+               if (!$this->_closed) {
+                       $this->_closed = true;
+                       return $this->_close();         
+               } else
+                       return true;
+       }
+       
+       /**
+        * synonyms RecordCount and RowCount    
+        *
+        * @return the number of rows or -1 if this is not supported
+        */
+       function RecordCount() {return $this->_numOfRows;}
+       
+       
+       /*
+       * If we are using PageExecute(), this will return the maximum possible rows
+       * that can be returned when paging a recordset.
+       */
+       function MaxRecordCount()
+       {
+               return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount();
+       }
+       
+       /**
+        * synonyms RecordCount and RowCount    
+        *
+        * @return the number of rows or -1 if this is not supported
+        */
+       function RowCount() {return $this->_numOfRows;} 
+       
+
+        /**
+        * Portable RecordCount. Pablo Roca <pabloroca@mvps.org>
+        *
+        * @return  the number of records from a previous SELECT. All databases support this.
+        *
+        * But aware possible problems in multiuser environments. For better speed the table
+        * must be indexed by the condition. Heavy test this before deploying.
+        */ 
+       function PO_RecordCount($table="", $condition="") {
+               
+               $lnumrows = $this->_numOfRows;
+               // the database doesn't support native recordcount, so we do a workaround
+               if ($lnumrows == -1 && $this->connection) {
+                       IF ($table) {
+                               if ($condition) $condition = " WHERE " . $condition; 
+                               $resultrows = &$this->connection->Execute("SELECT COUNT(*) FROM $table $condition");
+                               if ($resultrows) $lnumrows = reset($resultrows->fields);
+                       }
+               }
+               return $lnumrows;
+       }
+       
+       
+       /**
+        * @return the current row in the recordset. If at EOF, will return the last row. 0-based.
+        */
+       function CurrentRow() {return $this->_currentRow;}
+       
+       /**
+        * synonym for CurrentRow -- for ADO compat
+        *
+        * @return the current row in the recordset. If at EOF, will return the last row. 0-based.
+        */
+       function AbsolutePosition() {return $this->_currentRow;}
+       
+       /**
+        * @return the number of columns in the recordset. Some databases will set this to 0
+        * if no records are returned, others will return the number of columns in the query.
+        */
+       function FieldCount() {return $this->_numOfFields;}   
+
+
+       /**
+        * Get the ADOFieldObject of a specific column.
+        *
+        * @param fieldoffset   is the column position to access(0-based).
+        *
+        * @return the ADOFieldObject for that column, or false.
+        */
+       function &FetchField($fieldoffset = -1) 
+       {
+               // must be defined by child class
+               
+               $false = false;
+               return $false;
+       }       
+       
+       /**
+        * Get the ADOFieldObjects of all columns in an array.
+        *
+        */
+       function& FieldTypesArray()
+       {
+               $arr = array();
+               for ($i=0, $max=$this->_numOfFields; $i < $max; $i++) 
+                       $arr[] = $this->FetchField($i);
+               return $arr;
+       }
+       
+       /**
+       * Return the fields array of the current row as an object for convenience.
+       * The default case is lowercase field names.
+       *
+       * @return the object with the properties set to the fields of the current row
+       */
+       function &FetchObj()
+       {
+               $o =& $this->FetchObject(false);
+               return $o;
+       }
+       
+       /**
+       * Return the fields array of the current row as an object for convenience.
+       * The default case is uppercase.
+       * 
+       * @param $isupper to set the object property names to uppercase
+       *
+       * @return the object with the properties set to the fields of the current row
+       */
+       function &FetchObject($isupper=true)
+       {
+               if (empty($this->_obj)) {
+                       $this->_obj = new ADOFetchObj();
+                       $this->_names = array();
+                       for ($i=0; $i <$this->_numOfFields; $i++) {
+                               $f = $this->FetchField($i);
+                               $this->_names[] = $f->name;
+                       }
+               }
+               $i = 0;
+               if (PHP_VERSION >= 5) $o = clone($this->_obj);
+               else $o = $this->_obj;
+       
+               for ($i=0; $i <$this->_numOfFields; $i++) {
+                       $name = $this->_names[$i];
+                       if ($isupper) $n = strtoupper($name);
+                       else $n = $name;
+                       
+                       $o->$n = $this->Fields($name);
+               }
+               return $o;
+       }
+       
+       /**
+       * Return the fields array of the current row as an object for convenience.
+       * The default is lower-case field names.
+       * 
+       * @return the object with the properties set to the fields of the current row,
+       *       or false if EOF
+       *
+       * Fixed bug reported by tim@orotech.net
+       */
+       function &FetchNextObj()
+       {
+               $o =& $this->FetchNextObject(false);
+               return $o;
+       }
+       
+       
+       /**
+       * Return the fields array of the current row as an object for convenience. 
+       * The default is upper case field names.
+       * 
+       * @param $isupper to set the object property names to uppercase
+       *
+       * @return the object with the properties set to the fields of the current row,
+       *       or false if EOF
+       *
+       * Fixed bug reported by tim@orotech.net
+       */
+       function &FetchNextObject($isupper=true)
+       {
+               $o = false;
+               if ($this->_numOfRows != 0 && !$this->EOF) {
+                       $o = $this->FetchObject($isupper);      
+                       $this->_currentRow++;
+                       if ($this->_fetch()) return $o;
+               }
+               $this->EOF = true;
+               return $o;
+       }
+       
+       /**
+        * Get the metatype of the column. This is used for formatting. This is because
+        * many databases use different names for the same type, so we transform the original
+        * type to our standardised version which uses 1 character codes:
+        *
+        * @param t  is the type passed in. Normally is ADOFieldObject->type.
+        * @param len is the maximum length of that field. This is because we treat character
+        *      fields bigger than a certain size as a 'B' (blob).
+        * @param fieldobj is the field object returned by the database driver. Can hold
+        *      additional info (eg. primary_key for mysql).
+        * 
+        * @return the general type of the data: 
+        *      C for character < 250 chars
+        *      X for teXt (>= 250 chars)
+        *      B for Binary
+        *      N for numeric or floating point
+        *      D for date
+        *      T for timestamp
+        *      L for logical/Boolean
+        *      I for integer
+        *      R for autoincrement counter/integer
+        * 
+        *
+       */
+       function MetaType($t,$len=-1,$fieldobj=false)
+       {
+               if (is_object($t)) {
+                       $fieldobj = $t;
+                       $t = $fieldobj->type;
+                       $len = $fieldobj->max_length;
+               }
+       // changed in 2.32 to hashing instead of switch stmt for speed...
+       static $typeMap = array(
+               'VARCHAR' => 'C',
+               'VARCHAR2' => 'C',
+               'CHAR' => 'C',
+               'C' => 'C',
+               'STRING' => 'C',
+               'NCHAR' => 'C',
+               'NVARCHAR' => 'C',
+               'VARYING' => 'C',
+               'BPCHAR' => 'C',
+               'CHARACTER' => 'C',
+               'INTERVAL' => 'C',  # Postgres
+               'MACADDR' => 'C', # postgres
+               ##
+               'LONGCHAR' => 'X',
+               'TEXT' => 'X',
+               'NTEXT' => 'X',
+               'M' => 'X',
+               'X' => 'X',
+               'CLOB' => 'X',
+               'NCLOB' => 'X',
+               'LVARCHAR' => 'X',
+               ##
+               'BLOB' => 'B',
+               'IMAGE' => 'B',
+               'BINARY' => 'B',
+               'VARBINARY' => 'B',
+               'LONGBINARY' => 'B',
+               'B' => 'B',
+               ##
+               'YEAR' => 'D', // mysql
+               'DATE' => 'D',
+               'D' => 'D',
+               ##
+               'UNIQUEIDENTIFIER' => 'C', # MS SQL Server
+               ##
+               'TIME' => 'T',
+               'TIMESTAMP' => 'T',
+               'DATETIME' => 'T',
+               'TIMESTAMPTZ' => 'T',
+               'T' => 'T',
+               'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql
+               ##
+               'BOOL' => 'L',
+               'BOOLEAN' => 'L', 
+               'BIT' => 'L',
+               'L' => 'L',
+               ##
+               'COUNTER' => 'R',
+               'R' => 'R',
+               'SERIAL' => 'R', // ifx
+               'INT IDENTITY' => 'R',
+               ##
+               'INT' => 'I',
+               'INT2' => 'I',
+               'INT4' => 'I',
+               'INT8' => 'I',
+               'INTEGER' => 'I',
+               'INTEGER UNSIGNED' => 'I',
+               'SHORT' => 'I',
+               'TINYINT' => 'I',
+               'SMALLINT' => 'I',
+               'I' => 'I',
+               ##
+               'LONG' => 'N', // interbase is numeric, oci8 is blob
+               'BIGINT' => 'N', // this is bigger than PHP 32-bit integers
+               'DECIMAL' => 'N',
+               'DEC' => 'N',
+               'REAL' => 'N',
+               'DOUBLE' => 'N',
+               'DOUBLE PRECISION' => 'N',
+               'SMALLFLOAT' => 'N',
+               'FLOAT' => 'N',
+               'NUMBER' => 'N',
+               'NUM' => 'N',
+               'NUMERIC' => 'N',
+               'MONEY' => 'N',
+               
+               ## informix 9.2
+               'SQLINT' => 'I', 
+               'SQLSERIAL' => 'I', 
+               'SQLSMINT' => 'I', 
+               'SQLSMFLOAT' => 'N', 
+               'SQLFLOAT' => 'N', 
+               'SQLMONEY' => 'N', 
+               'SQLDECIMAL' => 'N', 
+               'SQLDATE' => 'D', 
+               'SQLVCHAR' => 'C', 
+               'SQLCHAR' => 'C', 
+               'SQLDTIME' => 'T', 
+               'SQLINTERVAL' => 'N', 
+               'SQLBYTES' => 'B', 
+               'SQLTEXT' => 'X',
+                ## informix 10
+               "SQLINT8" => 'I8',
+               "SQLSERIAL8" => 'I8',
+               "SQLNCHAR" => 'C',
+               "SQLNVCHAR" => 'C',
+               "SQLLVARCHAR" => 'X',
+               "SQLBOOL" => 'L'
+               );
+               
+               $tmap = false;
+               $t = strtoupper($t);
+               $tmap = (isset($typeMap[$t])) ? $typeMap[$t] : 'N';
+               switch ($tmap) {
+               case 'C':
+               
+                       // is the char field is too long, return as text field... 
+                       if ($this->blobSize >= 0) {
+                               if ($len > $this->blobSize) return 'X';
+                       } else if ($len > 250) {
+                               return 'X';
+                       }
+                       return 'C';
+                       
+               case 'I':
+                       if (!empty($fieldobj->primary_key)) return 'R';
+                       return 'I';
+               
+               case false:
+                       return 'N';
+                       
+               case 'B':
+                        if (isset($fieldobj->binary)) 
+                                return ($fieldobj->binary) ? 'B' : 'X';
+                       return 'B';
+               
+               case 'D':
+                       if (!empty($this->connection) && !empty($this->connection->datetime)) return 'T';
+                       return 'D';
+                       
+               default: 
+                       if ($t == 'LONG' && $this->dataProvider == 'oci8') return 'B';
+                       return $tmap;
+               }
+       }
+       
+       
+       function _close() {}
+       
+       /**
+        * set/returns the current recordset page when paginating
+        */
+       function AbsolutePage($page=-1)
+       {
+               if ($page != -1) $this->_currentPage = $page;
+               return $this->_currentPage;
+       }
+       
+       /**
+        * set/returns the status of the atFirstPage flag when paginating
+        */
+       function AtFirstPage($status=false)
+       {
+               if ($status != false) $this->_atFirstPage = $status;
+               return $this->_atFirstPage;
+       }
+       
+       function LastPageNo($page = false)
+       {
+               if ($page != false) $this->_lastPageNo = $page;
+               return $this->_lastPageNo;
+       }
+       
+       /**
+        * set/returns the status of the atLastPage flag when paginating
+        */
+       function AtLastPage($status=false)
+       {
+               if ($status != false) $this->_atLastPage = $status;
+               return $this->_atLastPage;
+       }
+       
+} // end class ADORecordSet
+       
+       //==============================================================================================        
+       // CLASS ADORecordSet_array
+       //==============================================================================================        
+       
+       /**
+        * This class encapsulates the concept of a recordset created in memory
+        * as an array. This is useful for the creation of cached recordsets.
+        * 
+        * Note that the constructor is different from the standard ADORecordSet
+        */
+       
+       class ADORecordSet_array extends ADORecordSet
+       {
+               var $databaseType = 'array';
+
+               var $_array;    // holds the 2-dimensional data array
+               var $_types;    // the array of types of each column (C B I L M)
+               var $_colnames; // names of each column in array
+               var $_skiprow1; // skip 1st row because it holds column names
+               var $_fieldobjects; // holds array of field objects
+               var $canSeek = true;
+               var $affectedrows = false;
+               var $insertid = false;
+               var $sql = '';
+               var $compat = false;
+               /**
+                * Constructor
+                *
+                */
+               function ADORecordSet_array($fakeid=1)
+               {
+               global $ADODB_FETCH_MODE,$ADODB_COMPAT_FETCH;
+               
+                       // fetch() on EOF does not delete $this->fields
+                       $this->compat = !empty($ADODB_COMPAT_FETCH);
+                       $this->ADORecordSet($fakeid); // fake queryID           
+                       $this->fetchMode = $ADODB_FETCH_MODE;
+               }
+               
+               function _transpose($addfieldnames=true)
+               {
+               global $ADODB_INCLUDED_LIB;
+                       
+                       if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+                       $hdr = true;
+                       
+                       $fobjs = $addfieldnames ? $this->_fieldobjects : false;
+                       adodb_transpose($this->_array, $newarr, $hdr, $fobjs);
+                       //adodb_pr($newarr);
+                       
+                       $this->_skiprow1 = false;
+                       $this->_array =& $newarr;
+                       $this->_colnames = $hdr;
+                       
+                       adodb_probetypes($newarr,$this->_types);
+               
+                       $this->_fieldobjects = array();
+                       
+                       foreach($hdr as $k => $name) {
+                               $f = new ADOFieldObject();
+                               $f->name = $name;
+                               $f->type = $this->_types[$k];
+                               $f->max_length = -1;
+                               $this->_fieldobjects[] = $f;
+                       }
+                       $this->fields = reset($this->_array);
+                       
+                       $this->_initrs();
+                       
+               }
+               
+               /**
+                * Setup the array.
+                *
+                * @param array         is a 2-dimensional array holding the data.
+                *                      The first row should hold the column names 
+                *                      unless paramter $colnames is used.
+                * @param typearr       holds an array of types. These are the same types 
+                *                      used in MetaTypes (C,B,L,I,N).
+                * @param [colnames]    array of column names. If set, then the first row of
+                *                      $array should not hold the column names.
+                */
+               function InitArray($array,$typearr,$colnames=false)
+               {
+                       $this->_array = $array;
+                       $this->_types = $typearr;       
+                       if ($colnames) {
+                               $this->_skiprow1 = false;
+                               $this->_colnames = $colnames;
+                       } else  {
+                               $this->_skiprow1 = true;
+                               $this->_colnames = $array[0];
+                       }
+                       $this->Init();
+               }
+               /**
+                * Setup the Array and datatype file objects
+                *
+                * @param array         is a 2-dimensional array holding the data.
+                *                      The first row should hold the column names 
+                *                      unless paramter $colnames is used.
+                * @param fieldarr      holds an array of ADOFieldObject's.
+                */
+               function InitArrayFields(&$array,&$fieldarr)
+               {
+                       $this->_array =& $array;
+                       $this->_skiprow1= false;
+                       if ($fieldarr) {
+                               $this->_fieldobjects =& $fieldarr;
+                       } 
+                       $this->Init();
+               }
+               
+               function &GetArray($nRows=-1)
+               {
+                       if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) {
+                               return $this->_array;
+                       } else {
+                               $arr =& ADORecordSet::GetArray($nRows);
+                               return $arr;
+                       }
+               }
+               
+               function _initrs()
+               {
+                       $this->_numOfRows =  sizeof($this->_array);
+                       if ($this->_skiprow1) $this->_numOfRows -= 1;
+               
+                       $this->_numOfFields =(isset($this->_fieldobjects)) ?
+                                sizeof($this->_fieldobjects):sizeof($this->_types);
+               }
+               
+               /* Use associative array to get fields array */
+               function Fields($colname)
+               {
+                       $mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode;
+                       
+                       if ($mode & ADODB_FETCH_ASSOC) {
+                               if (!isset($this->fields[$colname])) $colname = strtolower($colname);
+                               return $this->fields[$colname];
+                       }
+                       if (!$this->bind) {
+                               $this->bind = array();
+                               for ($i=0; $i < $this->_numOfFields; $i++) {
+                                       $o = $this->FetchField($i);
+                                       $this->bind[strtoupper($o->name)] = $i;
+                               }
+                       }
+                       return $this->fields[$this->bind[strtoupper($colname)]];
+               }
+               
+               function &FetchField($fieldOffset = -1) 
+               {
+                       if (isset($this->_fieldobjects)) {
+                               return $this->_fieldobjects[$fieldOffset];
+                       }
+                       $o =  new ADOFieldObject();
+                       $o->name = $this->_colnames[$fieldOffset];
+                       $o->type =  $this->_types[$fieldOffset];
+                       $o->max_length = -1; // length not known
+                       
+                       return $o;
+               }
+                       
+               function _seek($row)
+               {
+                       if (sizeof($this->_array) && 0 <= $row && $row < $this->_numOfRows) {
+                               $this->_currentRow = $row;
+                               if ($this->_skiprow1) $row += 1;
+                               $this->fields = $this->_array[$row];
+                               return true;
+                       }
+                       return false;
+               }
+               
+               function MoveNext() 
+               {
+                       if (!$this->EOF) {              
+                               $this->_currentRow++;
+                               
+                               $pos = $this->_currentRow;
+                               
+                               if ($this->_numOfRows <= $pos) {
+                                       if (!$this->compat) $this->fields = false;
+                               } else {
+                                       if ($this->_skiprow1) $pos += 1;
+                                       $this->fields = $this->_array[$pos];
+                                       return true;
+                               }               
+                               $this->EOF = true;
+                       }
+                       
+                       return false;
+               }       
+       
+               function _fetch()
+               {
+                       $pos = $this->_currentRow;
+                       
+                       if ($this->_numOfRows <= $pos) {
+                               if (!$this->compat) $this->fields = false;
+                               return false;
+                       }
+                       if ($this->_skiprow1) $pos += 1;
+                       $this->fields = $this->_array[$pos];
+                       return true;
+               }
+               
+               function _close() 
+               {
+                       return true;    
+               }
+       
+       } // ADORecordSet_array
+
+       //==============================================================================================        
+       // HELPER FUNCTIONS
+       //==============================================================================================                        
+       
+       /**
+        * Synonym for ADOLoadCode. Private function. Do not use.
+        *
+        * @deprecated
+        */
+       function ADOLoadDB($dbType) 
+       { 
+               return ADOLoadCode($dbType);
+       }
+               
+       /**
+        * Load the code for a specific database driver. Private function. Do not use.
+        */
+       function ADOLoadCode($dbType) 
+       {
+       global $ADODB_LASTDB;
+       
+               if (!$dbType) return false;
+               $db = strtolower($dbType);
+               switch ($db) {
+                       case 'ado': 
+                               if (PHP_VERSION >= 5) $db = 'ado5';
+                               $class = 'ado'; 
+                               break;
+                       case 'ifx':
+                       case 'maxsql': $class = $db = 'mysqlt'; break;
+                       case 'postgres':
+                       case 'postgres8':
+                       case 'pgsql': $class = $db = 'postgres7'; break;
+                       default:
+                               $class = $db; break;
+               }
+               
+               $file = ADODB_DIR."/drivers/adodb-".$db.".inc.php";
+               @include_once($file);
+               $ADODB_LASTDB = $class;
+               if (class_exists("ADODB_" . $class)) return $class;
+               
+               //ADOConnection::outp(adodb_pr(get_declared_classes(),true));
+               if (!file_exists($file)) ADOConnection::outp("Missing file: $file");
+               else ADOConnection::outp("Syntax error in file: $file");
+               return false;
+       }
+
+       /**
+        * synonym for ADONewConnection for people like me who cannot remember the correct name
+        */
+       function &NewADOConnection($db='')
+       {
+               $tmp =& ADONewConnection($db);
+               return $tmp;
+       }
+       
+       /**
+        * Instantiate a new Connection class for a specific database driver.
+        *
+        * @param [db]  is the database Connection object to create. If undefined,
+        *      use the last database driver that was loaded by ADOLoadCode().
+        *
+        * @return the freshly created instance of the Connection class.
+        */
+       function &ADONewConnection($db='')
+       {
+       GLOBAL $ADODB_NEWCONNECTION, $ADODB_LASTDB;
+               
+               if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);
+               $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false;
+               $false = false;
+               if ($at = strpos($db,'://')) {
+                       $origdsn = $db;
+                       if (PHP_VERSION < 5) $dsna = @parse_url($db);
+                       else {
+                               $fakedsn = 'fake'.substr($db,$at);
+                               $dsna = @parse_url($fakedsn);
+                               $dsna['scheme'] = substr($db,0,$at);
+                       
+                               if (strncmp($db,'pdo',3) == 0) {
+                                       $sch = explode('_',$dsna['scheme']);
+                                       if (sizeof($sch)>1) {
+                                               $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : '';
+                                               $dsna['host'] = rawurlencode($sch[1].':host='.rawurldecode($dsna['host']));
+                                               $dsna['scheme'] = 'pdo';
+                                       }
+                               }
+                       }
+                       
+                       if (!$dsna) {
+                               // special handling of oracle, which might not have host
+                               $db = str_replace('@/','@adodb-fakehost/',$db);
+                               $dsna = parse_url($db);
+                               if (!$dsna) return $false;
+                               $dsna['host'] = '';
+                       }
+                       $db = @$dsna['scheme'];
+                       if (!$db) return $false;
+                       $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : '';
+                       $dsna['user'] = isset($dsna['user']) ? rawurldecode($dsna['user']) : '';
+                       $dsna['pass'] = isset($dsna['pass']) ? rawurldecode($dsna['pass']) : '';
+                       $dsna['path'] = isset($dsna['path']) ? rawurldecode(substr($dsna['path'],1)) : ''; # strip off initial /
+                       
+                       if (isset($dsna['query'])) {
+                               $opt1 = explode('&',$dsna['query']);
+                               foreach($opt1 as $k => $v) {
+                                       $arr = explode('=',$v);
+                                       $opt[$arr[0]] = isset($arr[1]) ? rawurldecode($arr[1]) : 1;
+                               }
+                       } else $opt = array();
+               }
+       /*
+        *  phptype: Database backend used in PHP (mysql, odbc etc.)
+        *  dbsyntax: Database used with regards to SQL syntax etc.
+        *  protocol: Communication protocol to use (tcp, unix etc.)
+        *  hostspec: Host specification (hostname[:port])
+        *  database: Database to use on the DBMS server
+        *  username: User name for login
+        *  password: Password for login
+        */
+               if (!empty($ADODB_NEWCONNECTION)) {
+                       $obj = $ADODB_NEWCONNECTION($db);
+
+               } else {
+               
+                       if (!isset($ADODB_LASTDB)) $ADODB_LASTDB = '';
+                       if (empty($db)) $db = $ADODB_LASTDB;
+                       
+                       if ($db != $ADODB_LASTDB) $db = ADOLoadCode($db);
+                       
+                       if (!$db) {
+                               if (isset($origdsn)) $db = $origdsn;
+                               if ($errorfn) {
+                                       // raise an error
+                                       $ignore = false;
+                                       $errorfn('ADONewConnection', 'ADONewConnection', -998,
+                                                        "could not load the database driver for '$db'",
+                                                        $db,false,$ignore);
+                               } else
+                                        ADOConnection::outp( "<p>ADONewConnection: Unable to load database driver '$db'</p>",false);
+                                       
+                               return $false;
+                       }
+                       
+                       $cls = 'ADODB_'.$db;
+                       if (!class_exists($cls)) {
+                               adodb_backtrace();
+                               return $false;
+                       }
+                       
+                       $obj = new $cls();
+               }
+               
+               # constructor should not fail
+               if ($obj) {
+                       if ($errorfn)  $obj->raiseErrorFn = $errorfn;
+                       if (isset($dsna)) {
+                               if (isset($dsna['port'])) $obj->port = $dsna['port'];
+                               foreach($opt as $k => $v) {
+                                       switch(strtolower($k)) {
+                                       case 'new':             $nconnect = true; $persist = true; break;
+                                       case 'persist':
+                                       case 'persistent':      $persist = $v; break;
+                                       case 'debug':           $obj->debug = (integer) $v; break;
+                                       #ibase
+                                       case 'role':            $obj->role = $v; break;
+                                       case 'dialect':         $obj->dialect = (integer) $v; break;
+                                       case 'charset':         $obj->charset = $v; $obj->charSet=$v; break;
+                                       case 'buffers':         $obj->buffers = $v; break;
+                                       case 'fetchmode':   $obj->SetFetchMode($v); break;
+                                       #ado
+                                       case 'charpage':        $obj->charPage = $v; break;
+                                       #mysql, mysqli
+                                       case 'clientflags': $obj->clientFlags = $v; break;
+                                       #mysql, mysqli, postgres
+                                       case 'port': $obj->port = $v; break;
+                                       #mysqli
+                                       case 'socket': $obj->socket = $v; break;
+                                       #oci8
+                                       case 'nls_date_format': $obj->NLS_DATE_FORMAT = $v; break;
+                                       }
+                               }
+                               if (empty($persist))
+                                       $ok = $obj->Connect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
+                               else if (empty($nconnect))
+                                       $ok = $obj->PConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
+                               else
+                                       $ok = $obj->NConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
+                                       
+                               if (!$ok) return $false;
+                       }
+               }
+               return $obj;
+       }
+       
+       
+       
+       // $perf == true means called by NewPerfMonitor(), otherwise for data dictionary
+       function _adodb_getdriver($provider,$drivername,$perf=false)
+       {
+               switch ($provider) {
+               case 'odbtp':   if (strncmp('odbtp_',$drivername,6)==0) return substr($drivername,6); 
+               case 'odbc' :   if (strncmp('odbc_',$drivername,5)==0) return substr($drivername,5); 
+               case 'ado'  :   if (strncmp('ado_',$drivername,4)==0) return substr($drivername,4);
+               case 'native':  break;
+               default:
+                       return $provider;
+               }
+               
+               switch($drivername) {
+               case 'mysqlt':
+               case 'mysqli': 
+                               $drivername='mysql'; 
+                               break;
+               case 'postgres7':
+               case 'postgres8':
+                               $drivername = 'postgres'; 
+                               break;  
+               case 'firebird15': $drivername = 'firebird'; break;
+               case 'oracle': $drivername = 'oci8'; break;
+               case 'access': if ($perf) $drivername = ''; break;
+               case 'db2'   : break;
+               case 'sapdb' : break;
+               default:
+                       $drivername = 'generic';
+                       break;
+               }
+               return $drivername;
+       }
+       
+       function &NewPerfMonitor(&$conn)
+       {
+               $false = false;
+               $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType,true);
+               if (!$drivername || $drivername == 'generic') return $false;
+               include_once(ADODB_DIR.'/adodb-perf.inc.php');
+               @include_once(ADODB_DIR."/perf/perf-$drivername.inc.php");
+               $class = "Perf_$drivername";
+               if (!class_exists($class)) return $false;
+               $perf = new $class($conn);
+               
+               return $perf;
+       }
+       
+       function &NewDataDictionary(&$conn,$drivername=false)
+       {
+               $false = false;
+               if (!$drivername) $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType);
+
+               include_once(ADODB_DIR.'/adodb-lib.inc.php');
+               include_once(ADODB_DIR.'/adodb-datadict.inc.php');
+               $path = ADODB_DIR."/datadict/datadict-$drivername.inc.php";
+
+               if (!file_exists($path)) {
+                       ADOConnection::outp("Dictionary driver '$path' not available");
+                       return $false;
+               }
+               include_once($path);
+               $class = "ADODB2_$drivername";
+               $dict = new $class();
+               $dict->dataProvider = $conn->dataProvider;
+               $dict->connection = &$conn;
+               $dict->upperName = strtoupper($drivername);
+               $dict->quote = $conn->nameQuote;
+               if (!empty($conn->_connectionID))
+                       $dict->serverInfo = $conn->ServerInfo();
+               
+               return $dict;
+       }
+
+
+       
+       /*
+               Perform a print_r, with pre tags for better formatting.
+       */
+       function adodb_pr($var,$as_string=false)
+       {
+               if ($as_string) ob_start();
+               
+               if (isset($_SERVER['HTTP_USER_AGENT'])) { 
+                       echo " <pre>\n";print_r($var);echo "</pre>\n";
+               } else
+                       print_r($var);
+                       
+               if ($as_string) {
+                       $s = ob_get_contents();
+                       ob_end_clean();
+                       return $s;
+               }
+       }
+       
+       /*
+               Perform a stack-crawl and pretty print it.
+               
+               @param printOrArr  Pass in a boolean to indicate print, or an $exception->trace array (assumes that print is true then).
+               @param levels Number of levels to display
+       */
+       function adodb_backtrace($printOrArr=true,$levels=9999)
+       {
+               global $ADODB_INCLUDED_LIB;
+               if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
+               return _adodb_backtrace($printOrArr,$levels);
+       }
+
+
+}
+?>