]> git.mjollnir.org Git - moodle.git/commitdiff
Upgraded ADOdb to version 3.40
authormoodler <moodler>
Sun, 4 May 2003 11:59:49 +0000 (11:59 +0000)
committermoodler <moodler>
Sun, 4 May 2003 11:59:49 +0000 (11:59 +0000)
Works OK for me in tests under MySQL on my server

78 files changed:
lib/adodb/adodb-connection.inc.php [new file with mode: 0644]
lib/adodb/adodb-cryptsession.php
lib/adodb/adodb-csvlib.inc.php
lib/adodb/adodb-datadict.inc.php [new file with mode: 0644]
lib/adodb/adodb-error.inc.php [new file with mode: 0644]
lib/adodb/adodb-errorhandler.inc.php
lib/adodb/adodb-errorpear.inc.php
lib/adodb/adodb-lib.inc.php
lib/adodb/adodb-pager.inc.php
lib/adodb/adodb-pear.inc.php
lib/adodb/adodb-recordset.inc.php [new file with mode: 0644]
lib/adodb/adodb-session.php
lib/adodb/adodb-time.inc.php [new file with mode: 0644]
lib/adodb/adodb.inc.php
lib/adodb/crypt.inc.php
lib/adodb/datadict/datadict-mssql.inc.php [new file with mode: 0644]
lib/adodb/datadict/datadict-mysql.inc.php [new file with mode: 0644]
lib/adodb/datadict/datadict-oci8.inc.php [new file with mode: 0644]
lib/adodb/datadict/datadict-postgres.inc.php [new file with mode: 0644]
lib/adodb/drivers/adodb-access.inc.php
lib/adodb/drivers/adodb-ado.inc.php
lib/adodb/drivers/adodb-ado_access.inc.php
lib/adodb/drivers/adodb-ado_mssql.inc.php
lib/adodb/drivers/adodb-borland_ibase.inc.php
lib/adodb/drivers/adodb-csv.inc.php
lib/adodb/drivers/adodb-db2.inc.php
lib/adodb/drivers/adodb-fbsql.inc.php
lib/adodb/drivers/adodb-firebird.inc.php
lib/adodb/drivers/adodb-ibase.inc.php
lib/adodb/drivers/adodb-informix.inc.php
lib/adodb/drivers/adodb-informix72.inc.php
lib/adodb/drivers/adodb-mssql.inc.php
lib/adodb/drivers/adodb-mssqlpo.inc.php
lib/adodb/drivers/adodb-mysql.inc.php
lib/adodb/drivers/adodb-mysqlt.inc.php
lib/adodb/drivers/adodb-oci8.inc.php
lib/adodb/drivers/adodb-oci805.inc.php
lib/adodb/drivers/adodb-oci8po.inc.php
lib/adodb/drivers/adodb-odbc.inc.php
lib/adodb/drivers/adodb-odbc_mssql.inc.php
lib/adodb/drivers/adodb-odbc_oracle.inc.php
lib/adodb/drivers/adodb-oracle.inc.php
lib/adodb/drivers/adodb-postgres.inc.php
lib/adodb/drivers/adodb-postgres64.inc.php
lib/adodb/drivers/adodb-postgres7.inc.php
lib/adodb/drivers/adodb-proxy.inc.php
lib/adodb/drivers/adodb-sqlanywhere.inc.php
lib/adodb/drivers/adodb-sybase.inc.php
lib/adodb/drivers/adodb-vfp.inc.php
lib/adodb/license.txt
lib/adodb/pivottable.inc.php
lib/adodb/readme.htm
lib/adodb/readme.txt
lib/adodb/rsfilter.inc.php
lib/adodb/server.php
lib/adodb/tests/benchmark.php
lib/adodb/tests/client.php
lib/adodb/tests/test-datadict.php [new file with mode: 0644]
lib/adodb/tests/test.php
lib/adodb/tests/test2.php
lib/adodb/tests/test3.php
lib/adodb/tests/test4.php
lib/adodb/tests/test5.php
lib/adodb/tests/testcache.php
lib/adodb/tests/testdatabases.inc.php
lib/adodb/tests/testgenid.php
lib/adodb/tests/testmssql.php
lib/adodb/tests/testoci8.php
lib/adodb/tests/testoci8cursor.php
lib/adodb/tests/testpaging.php
lib/adodb/tests/testpear.php
lib/adodb/tests/testsessions.php
lib/adodb/tests/time.php [new file with mode: 0644]
lib/adodb/tests/tmssql.php [new file with mode: 0644]
lib/adodb/tips_portable_sql.htm
lib/adodb/toexport.inc.php
lib/adodb/tohtml.inc.php
lib/adodb/tute.htm

diff --git a/lib/adodb/adodb-connection.inc.php b/lib/adodb/adodb-connection.inc.php
new file mode 100644 (file)
index 0000000..321aada
--- /dev/null
@@ -0,0 +1,1787 @@
+<?php\r
+/** \r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Set tabs to 4 for best viewing.\r
+ * \r
+ * Latest version is available at http://php.weblogs.com\r
+ *\r
+ */\r
+\r
+       \r
+       function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)\r
+       {\r
+               //print "Errorno ($fn errno=$errno m=$errmsg) ";\r
+               \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
+    /**\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 = 256000;      /// maximum size of blobs or large text fields -- some databases die otherwise like foxpro\r
+       var $concat_operator = '+'; /// default concat operator -- change to || for Oracle/Interbase    \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 $charSet=false;             /// character set to use - only for interbase\r
+       var $metaTablesSQL = '';\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 $upperCase = false;         /// uppercase function to call for searching/where\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 $dbxDriver = false;\r
+       \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 = '';            /// A variable which was used to keep the returned last error message.  The value will\r
+                                                               /// then returned by the errorMsg() function    \r
+                                               \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 $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
+       /**\r
+        * Constructor\r
+        */\r
+       function ADOConnection()                        \r
+       {\r
+               die('Virtual Class -- cannot instantiate');\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 _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 $HTTP_SERVER_VARS;\r
+       \r
+               if (defined('ADODB_OUTP')) {\r
+                       $fn = ADODB_OUTP;\r
+                       $fn($msg,$newline);\r
+                       return;\r
+               }\r
+               \r
+               if ($newline) $msg .= "<br>\n";\r
+               \r
+               if (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) echo $msg;\r
+               else echo strip_tags($msg);\r
+               flush();\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 ($fn = $this->raiseErrorFn) {\r
+                       if ($forceNew) {\r
+                               if ($this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
+                       } else {\r
+                                if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true;\r
+                       }\r
+                       $err = $this->ErrorMsg();\r
+                       if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";\r
+                       $fn($this->databaseType,'CONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);\r
+               } else {\r
+                       if ($forceNew) {\r
+                               if ($this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
+                       } else {\r
+                               if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true;\r
+                       }\r
+               }\r
+               if ($this->debug) ADOConnection::outp( $this->host.': '.$this->ErrorMsg());\r
+               \r
+               return false;\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
+               \r
+               if ($fn = $this->raiseErrorFn) {\r
+                       if ($this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
+                       $err = $this->ErrorMsg();\r
+                       if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";\r
+                       $fn($this->databaseType,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);\r
+               } else \r
+                       if ($this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
+\r
+               if ($this->debug) ADOConnection::outp( $this->host.': '.$this->ErrorMsg());\r
+               \r
+               return false;\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)\r
+       {\r
+               return $this->Prepare($sql);\r
+       }\r
+       \r
+       /**\r
+       * PEAR DB Compat\r
+       */\r
+       function Quote($s)\r
+       {\r
+               return $this->qstr($s,false);\r
+       }\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)\r
+       {\r
+               $rs = &$this->SelectLimit($sql, $count, $offset); // swap \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
+       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
+               \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
+               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) $this->CommitTrans();\r
+               else $this->RollbackTrans();\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 && $this->transOff == 0) {\r
+                       ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans");\r
+               }\r
+               $this->_transOK = false;\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
+        * @param [arg3]        reserved for john lim for future use\r
+        * @return              RecordSet or false\r
+        */\r
+       function &Execute($sql,$inputarr=false,$arg3=false) \r
+       {\r
+               if ($this->fnExecute) {\r
+                       $fn = $this->fnExecute;\r
+                       $fn($this,$sql,$inputarr);\r
+               }\r
+               if (!$this->_bindInputArray && $inputarr) {\r
+                       $sqlarr = explode('?',$sql);\r
+                       $sql = '';\r
+                       $i = 0;\r
+                       foreach($inputarr as $v) {\r
+\r
+                               $sql .= $sqlarr[$i];\r
+                               // from Ron Baldwin <ron.baldwin@sourceprose.com>\r
+                               // Only quote string types      \r
+                               if (gettype($v) == 'string')\r
+                                       $sql .= $this->qstr($v);\r
+                               else if ($v === null)\r
+                                       $sql .= 'NULL';\r
+                               else\r
+                                       $sql .= $v;\r
+                               $i += 1;\r
+       \r
+                       }\r
+                       $sql .= $sqlarr[$i];\r
+                       if ($i+1 != sizeof($sqlarr))    \r
+                               ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql));\r
+                       $inputarr = false;\r
+               }\r
+               // debug version of query\r
+               if ($this->debug) {\r
+               global $HTTP_SERVER_VARS;\r
+               \r
+                       $ss = '';\r
+                       if ($inputarr) {\r
+                               foreach ($inputarr as $kk => $vv)  {\r
+                                       if (is_string($vv) && strlen($vv)>64) $vv = substr($vv,0,64).'...';\r
+                                       $ss .= "($kk=>'$vv') ";\r
+                               }\r
+                               $ss = "[ $ss ]";\r
+                       }\r
+                       if (is_array($sql)) $sqlTxt = $sql[0];\r
+                       else $sqlTxt = $sql;\r
+                       \r
+                       // check if running from browser or command-line\r
+                       $inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']);\r
+                       \r
+                       if ($inBrowser)\r
+                               ADOConnection::outp( "<hr />\n($this->databaseType): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<hr />\n",false);\r
+                       else\r
+                               ADOConnection::outp(  "=----\n($this->databaseType): ".($sqlTxt)." \n-----\n",false);\r
+                       flush();\r
+                       \r
+                       $this->_queryID = $this->_query($sql,$inputarr,$arg3);\r
+\r
+                       /* \r
+                               Alexios Fakios notes that ErrorMsg() must be called before ErrorNo() for mssql\r
+                               because ErrorNo() calls Execute('SELECT @ERROR'), causing recure\r
+                       */\r
+                       if ($this->databaseType == 'mssql') { \r
+                       // ErrorNo is a slow function call in mssql, and not reliable\r
+                       // in PHP 4.0.6\r
+                               if($emsg = $this->ErrorMsg()) {\r
+                                       $err = $this->ErrorNo();\r
+                                       if ($err) {\r
+                                               ADOConnection::outp($err.': '.$emsg);\r
+                                               flush();\r
+                                       }\r
+                               }\r
+                       } else \r
+                               if (!$this->_queryID) {\r
+                                       $e = $this->ErrorNo();\r
+                                       $m = $this->ErrorMsg();\r
+                                       ADOConnection::outp($e .': '. $m );\r
+                                       flush();\r
+                               }\r
+               } else {\r
+                       // non-debug version of query\r
+                       \r
+                       $this->_queryID =@$this->_query($sql,$inputarr,$arg3);\r
+                       \r
+               }\r
+               // error handling if query fails\r
+               if ($this->_queryID === false) {\r
+                       $fn = $this->raiseErrorFn;\r
+                       if ($fn) {\r
+                               $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr,$this);\r
+                       }\r
+                       return false;\r
+               } else if ($this->_queryID === true) {\r
+               // return simplified empty 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 = "ADORecordSet_".$this->databaseType;\r
+               $rs = new $rsclass($this->_queryID,$this->fetchMode); // &new not supported by older PHP versions\r
+               $rs->connection = &$this; // Pablo suggestion\r
+               $rs->Init();\r
+               if (is_array($sql)) $rs->sql = $sql[0];\r
+               else $rs->sql = $sql;\r
+               \r
+               if ($rs->_numOfRows <= 0) {\r
+               global $ADODB_COUNTRECS;\r
+               \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)\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
+\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
+               $rs = @$this->Execute($getnext);\r
+               if (!$rs) {\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
+        * @return  the last inserted ID. Not all databases support this.\r
+        */ \r
+               function Insert_ID()\r
+               {\r
+                               if ($this->hasInsertID) return $this->_insertid();\r
+                               if ($this->debug) ADOConnection::outp( '<p>Insert_ID error</p>');\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();\r
+                  } else {\r
+                          return $this->GetOne("SELECT MAX($id) FROM $table");\r
+                  }\r
+               }       \r
+       \r
+               \r
+        /**\r
+        * @return  # rows affected by UPDATE/DELETE\r
+        */ \r
+        function Affected_Rows()\r
+        {\r
+                 if ($this->hasAffectedRows) {\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
+               return '!! '.strtoupper($this->dataProvider.' '.$this->databaseType).': '.$this->_errorMsg;\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
+               return false;\r
+       }\r
+       \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 [arg3]         is a private parameter only used by jlim\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,$arg3=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) return $this->CacheExecute($secs2cache, $sql,$inputarr,$arg3);\r
+                                               else return $this->Execute($sql,$inputarr,$arg3);\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,$arg3);\r
+                       else $rs = &$this->Execute($sql,$inputarr,$arg3);\r
+               } else {\r
+                       if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr,$arg3);\r
+                       else $rs = &$this->Execute($sql,$inputarr,$arg3);\r
+               }\r
+               $ADODB_COUNTRECS = $savec;\r
+               if ($rs && !$rs->EOF) {\r
+                       return $this->_rs2rs($rs,$nrows,$offset);\r
+               }\r
+               //print_r($rs);\r
+               return $rs;\r
+       }\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) 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
+               \r
+               for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {\r
+                       $flds[] = $rs->FetchField($i);\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
+               return $rs2;\r
+       }\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
+                       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, $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
+       * Return all rows. Compat with PEAR DB\r
+       *\r
+       * @param sql                    SQL statement\r
+       * @param [inputarr]             input bind array\r
+       */\r
+       function GetAll($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
+               \r
+               if (!$rs) \r
+                       if (defined('ADODB_PEAR')) return ADODB_PEAR_Error();\r
+                       else return false;\r
+               $arr = $rs->GetArray();\r
+               $rs->Close();\r
+               return $arr;\r
+       }\r
+       \r
+       function CacheGetAll($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 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
+                       $arr = false;\r
+                       if (!$rs->EOF) $arr = $rs->fields;\r
+                       $rs->Close();\r
+                       return $arr;\r
+               }\r
+               \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
+               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
+       *\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
+               if (count($fieldArray) == 0) return 0;\r
+               $first = true;\r
+               $uSet = '';\r
+               \r
+               if (!is_array($keyCol)) {\r
+                       $keyCol = array($keyCol);\r
+               }\r
+               foreach($fieldArray as $k => $v) {\r
+                       if ($autoQuote && !is_numeric($v) and $v[0] != "'" and strcasecmp($v,'null')!=0) {\r
+                               $v = $this->qstr($v);\r
+                               $fieldArray[$k] = $v;\r
+                       }\r
+                       if (in_array($k,$keyCol)) continue; // skip UPDATE if is key\r
+                       \r
+                       if ($first) {\r
+                               $first = false;                 \r
+                               $uSet = "$k=$v";\r
+                       } else\r
+                               $uSet .= ",$k=$v";\r
+               }\r
+                \r
+               $first = true;\r
+               foreach ($keyCol as $v) {\r
+                       if ($first) {\r
+                               $first = false;\r
+                               $where = "$v=$fieldArray[$v]";\r
+                       } else {\r
+                               $where .= " and $v=$fieldArray[$v]";\r
+                       }\r
+               }\r
+               \r
+               if ($uSet) {\r
+                       $update = "UPDATE $table SET $uSet WHERE $where";\r
+               \r
+                       $rs = $this->Execute($update);\r
+                       if ($rs) {\r
+                               if ($this->poorAffectedRows) {\r
+                               /*\r
+                                The Select count(*) wipes out any errors that the update would have returned. \r
+                               http://phplens.com/lens/lensforum/msgs.php?id=5696\r
+                               */\r
+                                       if ($this->ErrorNo()<>0) return 0;\r
+                                       \r
+                               # affected_rows == 0 if update field values identical to old values\r
+                               # for mysql - which is silly. \r
+                       \r
+                                       $cnt = $this->GetOne("select count(*) from $table where $where");\r
+                                       if ($cnt > 0) return 1; // record already exists\r
+                               } else\r
+                                        if (($this->Affected_Rows()>0)) return 1;\r
+                       }\r
+                               \r
+               }\r
+       //      print "<p>Error=".$this->ErrorNo().'<p>';\r
+               $first = true;\r
+               foreach($fieldArray as $k => $v) {\r
+                       if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col\r
+                       \r
+                       if ($first) {\r
+                               $first = false;                 \r
+                               $iCols = "$k";\r
+                               $iVals = "$v";\r
+                       } else {\r
+                               $iCols .= ",$k";\r
+                               $iVals .= ",$v";\r
+                       }                               \r
+               }\r
+               $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)"; \r
+               $rs = $this->Execute($insert);\r
+               return ($rs) ? 2 : 0;\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
+       * @param [arg3]         is a private parameter only used by jlim\r
+       * @return               the recordset ($rs->databaseType == 'array')\r
+       */\r
+       function &CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false, $arg3=false)\r
+       {       \r
+               if (!is_numeric($secs2cache)) {\r
+                       if ($sql === false) $sql = -1;\r
+                       if ($offset == -1) $offset = false;\r
+                                                                         // sql,       nrows, offset,inputarr,arg3\r
+                       return $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$inputarr,$this->cacheSecs);\r
+               } else {\r
+                       if ($sql === false) ADOConnection::outp( "Warning: \$sql missing from CacheSelectLimit()");\r
+                       return $this->SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);\r
+               }\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 (strpos(strtoupper(PHP_OS),'WIN') !== false) {\r
+                               $cmd = 'del /s '.str_replace('/','\\',$ADODB_CACHE_DIR).'\adodb_*.cache';\r
+                       } else {\r
+                               $cmd = 'rm -rf '.$ADODB_CACHE_DIR.'/??/adodb_*.cache'; \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
+               $f = $this->_gencachename($sql.serialize($inputarr),false);\r
+               adodb_write_file($f,''); // is adodb_write_file needed?\r
+               @unlink($f);\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
+       *\r
+       * 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
+               \r
+               $m = md5($sql.$this->databaseType.$this->database.$this->user);\r
+               $dir = $ADODB_CACHE_DIR.'/'.substr($m,0,2);\r
+               if ($createdir && !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
+        * @param [arg3]        reserved for john lim for future use\r
+        * @return              RecordSet or false\r
+        */\r
+       function &CacheExecute($secs2cache,$sql=false,$inputarr=false,$arg3=false)\r
+       {\r
+               if (!is_numeric($secs2cache)) {\r
+                       $arg3 = $inputarr;\r
+                       $inputarr = $sql;\r
+                       $sql = $secs2cache;\r
+                       $secs2cache = $this->cacheSecs;\r
+               }\r
+               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);\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
+                               ADOConnection::outp( " $md5file cache failure: $err (see sql below)");\r
+                       }\r
+                       $rs = &$this->Execute($sql,$inputarr,$arg3);\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
+                       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
+                       global $HTTP_SERVER_VARS;\r
+                               \r
+                               $inBrowser = isset($HTTP_SERVER_VARS['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
+        * 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)\r
+       {\r
+               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
+               return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq);\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)\r
+       {       \r
+               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
+               return _adodb_getinsertsql($this,$rs,$arrFields,$magicq);\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
+       /**\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
+       \r
+       /**\r
+        *  $meta       contains the desired type, which could be...\r
+        *      C for character. You will have to define the precision yourself.\r
+        *      X for teXt. For unlimited character lengths.\r
+        *      B for Binary\r
+        *  F for floating point, with no need to define scale and precision\r
+        *      N for decimal numbers, you will have to define the (scale, precision) yourself\r
+        *      D for date\r
+        *      T for timestamp\r
+        *      L for logical/Boolean\r
+        *      I for integer\r
+        *      R for autoincrement counter/integer\r
+        *  and if you want to use double-byte, add a 2 to the end, like C2 or X2.\r
+        * \r
+        *\r
+        * @return the actual type of the data or false if no such type available\r
+       */\r
+       function ActualType($meta)\r
+       {\r
+               switch($meta) {\r
+               case 'C':\r
+               case 'X':\r
+                       return 'VARCHAR';\r
+               case 'B':\r
+                       \r
+               case 'D':\r
+               case 'T':\r
+               case 'L':\r
+               \r
+               case 'R':\r
+                       \r
+               case 'I':\r
+               case 'N':\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       /*\r
+       * Maximum size of C field\r
+       */\r
+       function CharMax()\r
+       {\r
+               return 255; // make it conservative if not defined\r
+       }\r
+       \r
+       \r
+       /*\r
+       * Maximum size of X field\r
+       */\r
+       function TextMax()\r
+       {\r
+               return 4000; // make it conservative if not defined\r
+       }\r
+       \r
+       /**\r
+        * Close Connection\r
+        */\r
+       function Close() \r
+       {\r
+               return $this->_close();\r
+               \r
+               // "Simon Lee" <simon@mediaroad.com> reports that persistent connections need \r
+               // to be closed too!\r
+               //if ($this->_isPersistentConnection != true) return $this->_close();\r
+               //else return true;     \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
+               {return false;}\r
+               \r
+       /**\r
+        * @return  array of tables for current database.\r
+        */ \r
+       function MetaTables() \r
+       {\r
+       global $ADODB_FETCH_MODE;\r
+       \r
+               if ($this->metaTablesSQL) {\r
+                       // complicated state saving by the need for backward compat\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
+                       for ($i=0; $i < sizeof($arr); $i++) {\r
+                               $arr2[] = $arr[$i][0];\r
+                       }\r
+                       $rs->Close();\r
+                       return $arr2;\r
+               }\r
+               return false;\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
+        *\r
+        * @return  array of ADOFieldObjects for current table.\r
+        */ \r
+       function MetaColumns($table,$upper=true) \r
+       {\r
+       global $ADODB_FETCH_MODE;\r
+       \r
+               if (!empty($this->metaColumnsSQL)) {\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) 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
+                               $fld->max_length = $rs->fields[2];\r
+                               $retarr[strtoupper($fld->name)] = $fld; \r
+                               \r
+                               $rs->MoveNext();\r
+                       }\r
+                       $rs->Close();\r
+                       return $retarr; \r
+               }\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) \r
+       {\r
+               $objarr = $this->MetaColumns($table);\r
+               if (!is_array($objarr)) return false;\r
+               \r
+               $arr = array();\r
+               foreach($objarr as $v) {\r
+                       $arr[] = $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
+       \r
+               if (empty($d) && $d !== 0) return 'null';\r
+\r
+               if (is_string($d) && !is_numeric($d)) \r
+                       if ($this->isoDates) return "'$d'";\r
+                       else $d = ADOConnection::UnixDate($d);\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
+               if (is_string($ts) && !is_numeric($ts)) \r
+                       if ($this->isoDates) return "'$ts'";\r
+                       else $ts = ADOConnection::UnixTimeStamp($ts);\r
+                       \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 (!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 (!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
+               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')\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
+               \r
+               return adodb_date($fmt,$tt);\r
+       \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 [arg3]         is a private parameter only used by jlim\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, $arg3=false, $secs2cache=0) \r
+       {\r
+               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
+               if ($this->pageExecuteCountRows) return _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $arg3, $secs2cache);\r
+               return _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $arg3, $secs2cache);\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
+       * @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
+       * @param [arg3]         is a private parameter only used by jlim\r
+       * @return               the recordset ($rs->databaseType == 'array')\r
+       */\r
+       function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false, $arg3=false) \r
+       {\r
+               /*switch($this->dataProvider) {\r
+               case 'postgres':\r
+               case 'mysql': \r
+                       break;\r
+               default: $secs2cache = 0; break;\r
+               }*/\r
+               return $this->PageExecute($sql,$nrows,$page,$inputarr,$arg3,$secs2cache);\r
+       }\r
+\r
+} // end class ADOConnection\r
+\r
+?>
\ No newline at end of file
index 15814f7c675c9d0403652863df14c43319e41040..099957abc830b7afb9b3574c457512ed0404bae0 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -76,22 +76,27 @@ GLOBAL      $ADODB_SESSION_CONNECT,
        $ADODB_SESS_CONN,\r
        $ADODB_SESS_LIFE,\r
        $ADODB_SESS_DEBUG,\r
-       $ADODB_SESS_INSERT; \r
+       $ADODB_SESS_INSERT,\r
+       $ADODB_SESSION_EXPIRE_NOTIFY; \r
 \r
        //$ADODB_SESS_DEBUG = true;\r
        \r
        /* SET THE FOLLOWING PARAMETERS */\r
 if (empty($ADODB_SESSION_DRIVER)) {\r
        $ADODB_SESSION_DRIVER='mysql';\r
-       $ADODB_SESSION_CONNECT='serverName';\r
-       $ADODB_SESSION_USER ='PhpSessions';\r
-       $ADODB_SESSION_PWD ='sessions';\r
-       $ADODB_SESSION_DB ='sessions';\r
+       $ADODB_SESSION_CONNECT='localhost';\r
+       $ADODB_SESSION_USER ='root';\r
+       $ADODB_SESSION_PWD ='';\r
+       $ADODB_SESSION_DB ='xphplens_2';\r
 }\r
+\r
 if (empty($ADODB_SESSION_TBL)){\r
        $ADODB_SESSION_TBL = 'sessions';\r
 }\r
 \r
+if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {\r
+       $ADODB_SESSION_EXPIRE_NOTIFY = false;\r
+}\r
 \r
 function ADODB_Session_Key() \r
 {\r
@@ -102,7 +107,7 @@ $ADODB_CRYPT_KEY = 'CRYPTED ADODB SESSIONS ROCK!';
        return crypt($ADODB_CRYPT_KEY, session_ID());\r
 }\r
 \r
-$ADODB_SESS_LIFE = get_cfg_var('session.gc_maxlifetime');\r
+$ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime');\r
 if ($ADODB_SESS_LIFE <= 1) {\r
        // bug in PHP 4.0.3 pl 1  -- how about other versions?\r
        //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";\r
@@ -165,46 +170,87 @@ global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL;
 function adodb_sess_write($key, $val) \r
 {\r
 $Crypt = new MD5Crypt;\r
-       global $ADODB_SESS_INSERT,$ADODB_SESS_CONN, $ADODB_SESS_LIFE, $ADODB_SESSION_TBL;\r
+       global $ADODB_SESS_INSERT,$ADODB_SESS_CONN, $ADODB_SESS_LIFE, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
 \r
        $expiry = time() + $ADODB_SESS_LIFE;\r
 \r
        // encrypt session data..       \r
        $val = $Crypt->Encrypt(rawurlencode($val), ADODB_Session_Key());\r
-       $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry,data='$val' WHERE sesskey='$key'";\r
-       $rs = $ADODB_SESS_CONN->Execute($qry);\r
-       if ($rs) $rs->Close();\r
-       else print '<p>Session Update: '.$ADODB_SESS_CONN->ErrorMsg().'</p>';\r
        \r
-       if ($ADODB_SESS_INSERT || $rs === false) {\r
-               $qry = "INSERT INTO $ADODB_SESSION_TBL(sesskey,expiry,data) VALUES ('$key',$expiry,'$val')";\r
-               $rs = $ADODB_SESS_CONN->Execute($qry);\r
-               if ($rs) $rs->Close();\r
-               else print '<p>Session Insert: '.$ADODB_SESS_CONN->ErrorMsg().'</p>';\r
+       $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val);\r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               $var = reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               global $$var;\r
+               $arr['expireref'] = $$var;\r
        }\r
-       // bug in access driver (could be odbc?) means that info is not commited\r
-       // properly unless select statement executed in Win2000\r
-       if ($ADODB_SESS_CONN->databaseType == 'access') $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+       $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,\r
+           $arr,\r
+       'sesskey',$autoQuote = true);\r
 \r
+       if (!$rs) {\r
+               ADOConnection::outp( '<p>Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'</p>',false);\r
+       } else {\r
+               // bug in access driver (could be odbc?) means that info is not commited\r
+               // properly unless select statement executed in Win2000\r
+       \r
+       if ($ADODB_SESS_CONN->databaseType == 'access') $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+       }\r
        return isset($rs);\r
 }\r
 \r
 function adodb_sess_destroy($key) \r
 {\r
-       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL;\r
-\r
-       $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";\r
-       $rs = $ADODB_SESS_CONN->Execute($qry);\r
-       if ($rs) $rs->Close();\r
-       return $rs;\r
+       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+       \r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+               $ADODB_SESS_CONN->SetFetchMode($savem);\r
+               if ($rs) {\r
+                       $ADODB_SESS_CONN->BeginTrans();\r
+                       while (!$rs->EOF) {\r
+                               $ref = $rs->fields[0];\r
+                               $key = $rs->fields[1];\r
+                               $fn($ref,$key);\r
+                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+                               $rs->MoveNext();\r
+                       }\r
+                       $ADODB_SESS_CONN->CommitTrans();\r
+               }\r
+       } else {\r
+               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";\r
+               $rs = $ADODB_SESS_CONN->Execute($qry);\r
+       }\r
+       return $rs ? true : false;\r
 }\r
 \r
+\r
 function adodb_sess_gc($maxlifetime) {\r
-       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL;\r
+       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
 \r
-       $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();\r
-       $rs = $ADODB_SESS_CONN->Execute($qry);\r
-       if ($rs) $rs->Close();\r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < " . time());\r
+               $ADODB_SESS_CONN->SetFetchMode($savem);\r
+               if ($rs) {\r
+                       $ADODB_SESS_CONN->BeginTrans();\r
+                       while (!$rs->EOF) {\r
+                               $ref = $rs->fields[0];\r
+                               $key = $rs->fields[1];\r
+                               $fn($ref,$key);\r
+                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+                               $rs->MoveNext();\r
+                       }\r
+                       $ADODB_SESS_CONN->CommitTrans();\r
+               }\r
+       } else {\r
+               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();\r
+               $ADODB_SESS_CONN->Execute($qry);\r
+       }\r
        \r
        // suggested by Cameron, "GaM3R" <gamr@outworld.cx>\r
        if (defined('ADODB_SESSION_OPTIMIZE'))\r
index eb1fc77ed5c749816175f740675c88ef7e420fc6..19adaa4dbe6c9e8aec2c645b1c57bf870a650b11 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. See License.txt. \r
@@ -17,6 +17,8 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
   ==============\r
 */\r
 \r
+\r
+\r
        /**\r
         * convert a recordset into special format\r
         *\r
@@ -81,19 +83,20 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
 */\r
        function &csv2rs($url,&$err,$timeout=0)\r
        {\r
+               $ishttp = strpos(substr($url,3,10),':') !== false;\r
                $fp = @fopen($url,'r');\r
                $err = false;\r
                if (!$fp) {\r
                        $err = $url.'file/URL not found';\r
                        return false;\r
                }\r
-               flock($fp, LOCK_SH);\r
+               if (!$ishttp) flock($fp, LOCK_SH);\r
                $arr = array();\r
                $ttl = 0;\r
                \r
-               if ($meta = fgetcsv ($fp, 32000, ",")) {\r
+               if ($meta = fgetcsv($fp, 32000, ",")) { // first read is larger because contains sql\r
                        // check if error message\r
-                       if (substr($meta[0],0,4) === '****') {\r
+                       if (strncmp($meta[0],'****',4) === 0) {\r
                                $err = trim(substr($meta[0],4,1024));\r
                                fclose($fp);\r
                                return false;\r
@@ -102,7 +105,7 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
                        // $meta[0] is -1 means return an empty recordset\r
                        // $meta[1] contains a time \r
        \r
-                       if (substr($meta[0],0,4) ===  '====') {\r
+                       if (strncmp($meta[0],'====',4) === 0) {\r
                        \r
                                if ($meta[0] == "====-1") {\r
                                        if (sizeof($meta) < 5) {\r
@@ -126,9 +129,13 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
                                        $rs->insertid = $meta[4];       \r
                                        return $rs;\r
                                }\r
+                       \r
+                       # If detect timeout here return false, forcing a fresh query and new cache values\r
+                       #\r
                        # Under high volume loads, we want only 1 thread/process to _write_file\r
                        # so that we don't have 50 processes queueing to write the same data.\r
-                       # Would require probabilistic blocking write \r
+                       #\r
+                       # We implement a probabilistic blocking write:\r
                        #\r
                        # -2 sec before timeout, give processes 1/16 chance of writing to file with blocking io\r
                        # -1 sec after timeout give processes 1/4 chance of writing with blocking\r
@@ -139,14 +146,14 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
                                                if ($tdiff <= 2) {\r
                                                        switch($tdiff) {\r
                                                        case 2: \r
-                                                               if ((rand() & 15) == 0) {\r
+                                                               if ((rand() & 0xf) == 0) {\r
                                                                        fclose($fp);\r
                                                                        $err = "Timeout 2";\r
                                                                        return false;\r
                                                                }\r
                                                                break;\r
                                                        case 1:\r
-                                                               if ((rand() & 3) == 0) {\r
+                                                               if ((rand() & 0x3) == 0) {\r
                                                                        fclose($fp);\r
                                                                        $err = "Timeout 1";\r
                                                                        return false;\r
@@ -202,9 +209,12 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
                }\r
                        \r
                fclose($fp);\r
-               $arr = @unserialize($text);\r
-               \r
-               //var_dump($arr);\r
+               //print "<hr>";\r
+               //print_r($text);\r
+               //if (strlen($text) == 0) $arr = array();\r
+               //else \r
+               $arr = unserialize($text);\r
+               //print_r($arr);\r
                if (!is_array($arr)) {\r
                        $err = "Recordset had unexpected EOF (in serialized recordset)";\r
                        if (get_magic_quotes_runtime()) $err .= ". Magic Quotes Runtime should be disabled!";\r
@@ -216,58 +226,4 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
                return $rs;\r
        }\r
        \r
-       /*\r
-       # The following code was an alternative method of saving \r
-       # recordsets and  is experimental and was never used.\r
-       # It is faster, but provides very little error checking.\r
-       \r
-       //High speed rs2csv 10% faster \r
-       function & xrs2csv(&$rs)\r
-       {\r
-               return time()."\n".serialize($rs);\r
-       }\r
-       function & xcsv2rs($url,&$err,$timeout)\r
-       {\r
-               $t = filemtime($url);// this is cached - should we clearstatcache() ?\r
-               if ($t === false) {\r
-                       $err = 'File not found 1';\r
-                       return false;\r
-               }\r
-               \r
-               if (time() > $t + $timeout){\r
-                       $err = " Timeout 1";\r
-                       return false;\r
-               }\r
-               \r
-               $fp = @fopen($url,'r');\r
-               if (!$fp) {\r
-                       $err = ' file not found ';\r
-                       return false;\r
-               }\r
-               \r
-               flock($fp,LOCK_SH);\r
-               $t = fgets($fp,100);\r
-               if ($t === false){\r
-                       fclose($fp);\r
-                       $err =  " EOF 1 ";\r
-                       return false;\r
-               }\r
-               /*\r
-               if (time() > ((integer)$t) + $timeout){\r
-                       fclose($fp);\r
-                       $err = " Timeout 2";\r
-                       return false;\r
-               }*   /\r
-               \r
-               $txt = &fread($fp,1999999); // Increase if EOF 2 error returned\r
-               fclose($fp);\r
-               $o = @unserialize($txt);\r
-               if (!is_object($o)) {\r
-                       $err = " EOF 2";\r
-                       return false;\r
-               }\r
-               $o->timeCreated = $t;\r
-               return $o;\r
-       }\r
-       */\r
 ?>
\ No newline at end of file
diff --git a/lib/adodb/adodb-datadict.inc.php b/lib/adodb/adodb-datadict.inc.php
new file mode 100644 (file)
index 0000000..2ddf79d
--- /dev/null
@@ -0,0 +1,332 @@
+<?php\r
+\r
+/**\r
+  V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+       \r
+  Set tabs to 4 for best viewing.\r
\r
+       DOCUMENTATION:\r
+       \r
+               See adodb/tests/test-datadict.php for docs and examples.\r
+*/\r
+\r
+class ADODB_DataDict {\r
+       var $connection;\r
+       var $debug = false;\r
+       var $dropTable = "DROP TABLE %s";\r
+       var $addCol = ' ADD';\r
+       var $alterCol = ' ALTER COLUMN';\r
+       var $dropCol = ' DROP COLUMN';\r
+       var $schema = false;\r
+       var $serverInfo = array();\r
+       \r
+       function MetaTables()\r
+       {\r
+               return $this->connection->MetaTables();\r
+       }\r
+       \r
+       function MetaColumns($tab)\r
+       {\r
+               return $this->connection->MetaColumns($tab);\r
+       }\r
+       \r
+       function MetaPrimaryKeys($tab,$owner=false,$intkey=false)\r
+       {\r
+               return $this->connection->MetaPrimaryKeys($tab.$owner,$intkey);\r
+       }\r
+       \r
+       function MetaType($t,$len=-1,$fieldobj=false)\r
+       {\r
+               return ADORecordSet::MetaType($t,$len,$fieldobj);\r
+       }\r
+       \r
+       // Executes the sql array returned by GetTableSQL and GetIndexSQL\r
+       function ExecuteSQLArray($sql, $continueOnError = true)\r
+       {\r
+               $rez = 2;\r
+               $conn = &$this->connection;\r
+               foreach($sql as $line) {\r
+                       $ok = $conn->Execute($line);\r
+                       if (!$ok) {\r
+                               if ($this->debug) ADOConnection::outp($conn->ErrorMsg());\r
+                               if (!$continueOnError) return 0;\r
+                               $rez = 1;\r
+                       }\r
+               }\r
+               return 2;\r
+       }\r
+       \r
+       /*\r
+               Returns the actual type given a character code.\r
+               \r
+               C:  varchar\r
+               X:  CLOB (character large object) or largest varchar size if CLOB is not supported\r
+               C2: Multibyte varchar\r
+               X2: Multibyte CLOB\r
+               \r
+               B:  BLOB (binary large object)\r
+               \r
+               D:  Date\r
+               T:  Date-time \r
+               L:  Integer field suitable for storing booleans (0 or 1)\r
+               I:  Integer\r
+               F:  Floating point number\r
+               N:  Numeric or decimal number\r
+       */\r
+       \r
+       function ActualType($meta)\r
+       {\r
+               return $meta;\r
+       }\r
+       \r
+       function CreateDatabase($dbname,$options=false)\r
+       {\r
+               $options = $this->_Options($options);\r
+               $s = 'CREATE DATABASE '.$dbname;\r
+               if (isset($options[$this->upperName])) $s .= ' '.$options[$this->upperName];\r
+               $sql[] = $s;\r
+               return $sql;\r
+       }\r
+       \r
+       /*\r
+        Generates the SQL to create index. Returns an array of sql strings.\r
+       */\r
+       function CreateIndexSQL($idxname, $tabname, $flds, $idxoptions = false)\r
+       {\r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               return $this->_IndexSQL($idxname, $tabname, $flds, $this->_Options($idxoptions));\r
+       }\r
+       \r
+       function SetSchema($schema)\r
+       {\r
+               $this->schema = $schema;\r
+       }\r
+       \r
+       function AddColumnSQL($tabname, $flds)\r
+       {       \r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               $sql = array();\r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+               foreach($lines as $v) {\r
+                       $sql[] = "ALTER TABLE $tabname $this->addCol $v";\r
+               }\r
+               return $sql;\r
+       }\r
+       \r
+       function AlterColumnSQL($tabname, $flds)\r
+       {\r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               $sql = array();\r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+\r
+               foreach($lines as $v) {\r
+                       $sql[] = "ALTER TABLE $tabname $this->alterCol $v";\r
+               }\r
+               return $sql;\r
+       }\r
+       \r
+       function DropColumnSQL($tabname, $flds)\r
+       {\r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               if (!is_array($flds)) $flds = explode(',',$flds);\r
+               $sql = array();\r
+               foreach($flds as $v) {\r
+                       $sql[] = "ALTER TABLE $tabname $this->dropCol $v";\r
+               }\r
+               return $sql;\r
+       }\r
+       \r
+       function DropTableSQL($tabname)\r
+       {\r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               $sql[] = sprintf($this->dropTable,$tabname);\r
+               return $sql;\r
+       }\r
+       \r
+       /*\r
+        Generate the SQL to create table. Returns an array of sql strings.\r
+       */\r
+       function CreateTableSQL($tabname, $flds, $tableoptions=false)\r
+       {\r
+               if (!$tableoptions) $tableoptions = array();\r
+       \r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+               \r
+               $taboptions = $this->_Options($tableoptions);\r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);\r
+               \r
+               $tsql = $this->_Triggers($tabname,$taboptions);\r
+               foreach($tsql as $s) $sql[] = $s;\r
+               \r
+               return $sql;\r
+       }\r
+       \r
+       function _GenFields($flds)\r
+       {\r
+               $lines = array();\r
+               $pkey = array();\r
+               foreach($flds as $fld) {\r
+                       $fld = _array_change_key_case($fld);\r
+               \r
+                       $fname = false;\r
+                       $fdefault = false;\r
+                       $fautoinc = false;\r
+                       $ftype = false;\r
+                       $fsize = false;\r
+                       $fprec = false;\r
+                       $fprimary = false;\r
+                       $fnoquote = false;\r
+                       $fdefts = false;\r
+                       $fdefdate = false;\r
+                       $fconstraint = false;\r
+                       $fnotnull = false;\r
+                       //-----------------\r
+                       // Parse attributes\r
+                       foreach($fld as $attr => $v) {\r
+                               if ($attr == 2 && is_numeric($v)) $attr = 'SIZE';\r
+                               else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v);\r
+                               \r
+                               switch($attr) {\r
+                               case '0':\r
+                               case 'NAME':    $fname = $v; break;\r
+                               case '1':\r
+                               case 'TYPE':    $ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;\r
+                               case 'SIZE':    $dotat = strpos($v,'.');\r
+                                                               if ($dotat === false) $fsize = $v;\r
+                                                               else {\r
+                                                                       $fsize = substr($v,0,$dotat);\r
+                                                                       $fprec = substr($v,$dotat+1);\r
+                                                               }\r
+                                                               break;\r
+                               case 'AUTOINCREMENT':\r
+                               case 'AUTO':    $fautoinc = true; $fnotnull = true; break;\r
+                               case 'KEY':\r
+                               case 'PRIMARY': $fprimary = $v; $fnotnull = true; break;\r
+                               case 'DEFAULT': $fdefault = $v; break;\r
+                               case 'NOTNULL': $fnotnull = $v; break;\r
+                               case 'NOQUOTE': $fnoquote = $v; break;\r
+                               case 'DEFDATE': $fdefdate = $v; break;\r
+                               case 'DEFTIMESTAMP': $fdefts = $v; break;\r
+                               case 'CONSTRAINT': $fconstraint = $v; break;\r
+                               } //switch\r
+                       } // foreach $fld\r
+                       \r
+                       //--------------------\r
+                       // VALIDATE FIELD INFO\r
+                       if (!strlen($fname)) {\r
+                               if ($this->debug) ADOConnection::outp("Undefined NAME");\r
+                               return false;\r
+                       }\r
+                       \r
+                       if (!strlen($ftype)) {\r
+                               if ($this->debug) ADOConnection::outp("Undefined TYPE for field '$fname'");\r
+                               return false;\r
+                       } else\r
+                               $ftype = strtoupper($ftype);\r
+                       \r
+                       $ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);\r
+                       \r
+                       if ($fprimary) $pkey[] = $fname;\r
+                       \r
+                       // some databases do not allow blobs to have defaults\r
+                       if ($ty == 'X') $fdefault = false;\r
+                       \r
+                       //--------------------\r
+                       // CONSTRUCT FIELD SQL\r
+                       if ($fdefts) {\r
+                               if (substr($this->connection->databaseType,0,5) == 'mysql') {\r
+                                       $ftype = 'TIMESTAMP';\r
+                               } else {\r
+                                       $fdefault = $this->connection->sysTimeStamp;\r
+                               }\r
+                       } else if ($fdefdate) {\r
+                               if (substr($this->connection->databaseType,0,5) == 'mysql') {\r
+                                       $ftype = 'TIMESTAMP';\r
+                               } else {\r
+                                       $fdefault = $this->connection->sysDate;\r
+                               }\r
+                       } else if (strlen($fdefault) && !$fnoquote)\r
+                               if ($ty == 'C' or $ty == 'X' or \r
+                                       ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault)))\r
+                                       if (substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ') \r
+                                               $fdefault = trim($fdefault);\r
+                                       else\r
+                                               $fdefault = $this->connection->qstr($fdefault);\r
+                       $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint);\r
+                       \r
+                       $fname = str_pad($fname,16);\r
+                       $lines[] = "$fname $ftype$suffix";\r
+                       \r
+               } // foreach $flds\r
+               \r
+               \r
+               return array($lines,$pkey);\r
+       }\r
+       /*\r
+                GENERATE THE SIZE PART OF THE DATATYPE\r
+                       $ftype is the actual type\r
+                       $ty is the type defined originally in the DDL\r
+       */\r
+       function _GetSize($ftype, $ty, $fsize, $fprec)\r
+       {\r
+               if (strlen($fsize) && $ty != 'X' && $ty != 'B') {\r
+                       $ftype .= "(".$fsize;\r
+                       if ($fprec) $ftype .= ",".$fprec;                               \r
+                       $ftype .= ')';\r
+               }\r
+               return $ftype;\r
+       }\r
+       \r
+       \r
+       function _TableSQL($tabname,$lines,$pkey,$tableoptions)\r
+       {\r
+               $sql = array();\r
+               \r
+               if (isset($tableoptions['REPLACE'])) $sql[] = sprintf($this->dropTable,$tabname);\r
+               $s = "CREATE TABLE $tabname (\n";\r
+               $s .= implode(",\n", $lines);\r
+               if (sizeof($pkey)>0) {\r
+                       $s .= ",\n                 PRIMARY KEY (";\r
+                       $s .= implode(", ",$pkey).")";\r
+               }\r
+               if (isset($tableoptions['CONSTRAINTS'])) \r
+                       $s .= "\n".$tableoptions['CONSTRAINTS'];\r
+               \r
+               if (isset($tableoptions[$this->upperName.'_CONSTRAINTS'])) \r
+                       $s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];\r
+               \r
+               $s .= "\n)";\r
+               if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];\r
+               $sql[] = $s;\r
+               \r
+               return $sql;\r
+       }\r
+       \r
+       /*\r
+               GENERATE TRIGGERS IF NEEDED\r
+               used when table has auto-incrementing field that is emulated using triggers\r
+       */\r
+       function _Triggers($tabname,$taboptions)\r
+       {\r
+               return array();\r
+       }\r
+       \r
+       /*\r
+               Sanitize options, so that array elements with no keys are promoted to keys\r
+       */\r
+       function _Options($opts)\r
+       {\r
+               if (!is_array($opts)) return array();\r
+               $newopts = array();\r
+               foreach($opts as $k => $v) {\r
+                       if (is_numeric($k)) $newopts[strtoupper($v)] = $v;\r
+                       else $newopts[strtoupper($k)] = $v;\r
+               }\r
+               return $newopts;\r
+       }\r
+}\r
+?>
\ No newline at end of file
diff --git a/lib/adodb/adodb-error.inc.php b/lib/adodb/adodb-error.inc.php
new file mode 100644 (file)
index 0000000..1390eda
--- /dev/null
@@ -0,0 +1,264 @@
+<?php\r
+/** \r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Set tabs to 4 for best viewing.\r
+ * \r
+ * The following code is adapted from the PEAR DB error handling code.\r
+ * Portions (c)1997-2002 The PHP Group.\r
+ */\r
+\r
+if (!defined("DB_ERROR")) define("DB_ERROR",-1);\r
+\r
+if (!defined("DB_ERROR_SYNTAX")) {\r
+       define("DB_ERROR_SYNTAX",              -2);\r
+       define("DB_ERROR_CONSTRAINT",          -3);\r
+       define("DB_ERROR_NOT_FOUND",           -4);\r
+       define("DB_ERROR_ALREADY_EXISTS",      -5);\r
+       define("DB_ERROR_UNSUPPORTED",         -6);\r
+       define("DB_ERROR_MISMATCH",            -7);\r
+       define("DB_ERROR_INVALID",             -8);\r
+       define("DB_ERROR_NOT_CAPABLE",         -9);\r
+       define("DB_ERROR_TRUNCATED",          -10);\r
+       define("DB_ERROR_INVALID_NUMBER",     -11);\r
+       define("DB_ERROR_INVALID_DATE",       -12);\r
+       define("DB_ERROR_DIVZERO",            -13);\r
+       define("DB_ERROR_NODBSELECTED",       -14);\r
+       define("DB_ERROR_CANNOT_CREATE",      -15);\r
+       define("DB_ERROR_CANNOT_DELETE",      -16);\r
+       define("DB_ERROR_CANNOT_DROP",        -17);\r
+       define("DB_ERROR_NOSUCHTABLE",        -18);\r
+       define("DB_ERROR_NOSUCHFIELD",        -19);\r
+       define("DB_ERROR_NEED_MORE_DATA",     -20);\r
+       define("DB_ERROR_NOT_LOCKED",         -21);\r
+       define("DB_ERROR_VALUE_COUNT_ON_ROW", -22);\r
+       define("DB_ERROR_INVALID_DSN",        -23);\r
+       define("DB_ERROR_CONNECT_FAILED",     -24);\r
+       define("DB_ERROR_EXTENSION_NOT_FOUND",-25);\r
+       define("DB_ERROR_NOSUCHDB",           -25);\r
+       define("DB_ERROR_ACCESS_VIOLATION",   -26);\r
+}\r
+\r
+function adodb_errormsg($value)\r
+{\r
+    static $ERRMSG;\r
+    if (!isset($ERRMSG)) {\r
+        $ERRMSG = array(\r
+            DB_ERROR                    => 'unknown error',\r
+            DB_ERROR_ALREADY_EXISTS     => 'already exists',\r
+            DB_ERROR_CANNOT_CREATE      => 'can not create',\r
+            DB_ERROR_CANNOT_DELETE      => 'can not delete',\r
+            DB_ERROR_CANNOT_DROP        => 'can not drop',\r
+            DB_ERROR_CONSTRAINT         => 'constraint violation',\r
+            DB_ERROR_DIVZERO            => 'division by zero',\r
+            DB_ERROR_INVALID            => 'invalid',\r
+            DB_ERROR_INVALID_DATE       => 'invalid date or time',\r
+            DB_ERROR_INVALID_NUMBER     => 'invalid number',\r
+            DB_ERROR_MISMATCH           => 'mismatch',\r
+            DB_ERROR_NODBSELECTED       => 'no database selected',\r
+            DB_ERROR_NOSUCHFIELD        => 'no such field',\r
+            DB_ERROR_NOSUCHTABLE        => 'no such table',\r
+            DB_ERROR_NOT_CAPABLE        => 'DB backend not capable',\r
+            DB_ERROR_NOT_FOUND          => 'not found',\r
+            DB_ERROR_NOT_LOCKED         => 'not locked',\r
+            DB_ERROR_SYNTAX             => 'syntax error',\r
+            DB_ERROR_UNSUPPORTED        => 'not supported',\r
+            DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',\r
+            DB_ERROR_INVALID_DSN        => 'invalid DSN',\r
+            DB_ERROR_CONNECT_FAILED     => 'connect failed',\r
+            0                         => 'no error', // DB_OK\r
+            DB_ERROR_NEED_MORE_DATA     => 'insufficient data supplied',\r
+            DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',\r
+            DB_ERROR_NOSUCHDB           => 'no such database',\r
+            DB_ERROR_ACCESS_VIOLATION   => 'insufficient permissions'\r
+        );\r
+    }\r
+\r
+    return isset($ERRMSG[$value]) ? $ERRMSG[$value] : $ERRMSG[DB_ERROR];\r
+}\r
+\r
+function adodb_error($provider,$dbType,$errno)\r
+{\r
+       var_dump($errno);\r
+       if (is_numeric($errno) && $errno == 0) return 0;\r
+       switch($provider) { \r
+       case 'mysql': $map = adodb_error_mysql(); break;\r
+       \r
+       case 'oracle':\r
+       case 'oci8': $map = adodb_error_oci8(); break;\r
+       \r
+       case 'ibase': $map = adodb_error_ibase(); break;\r
+       \r
+       case 'odbc': $map = adodb_error_odbc(); break;\r
+       \r
+       case 'mssql':\r
+       case 'sybase': $map = adodb_error_mssql(); break;\r
+       \r
+       case 'informix': $map = adodb_error_ifx(); break;\r
+       \r
+       case 'postgres': return adodb_error_pg($errno); break;\r
+       default:\r
+               return DB_ERROR;\r
+       }       \r
+       print_r($map);\r
+       var_dump($errno);\r
+       if (isset($map[$errno])) return $map[$errno];\r
+       return DB_ERROR;\r
+}\r
+\r
+//**************************************************************************************\r
+\r
+function adodb_error_pg($errormsg)\r
+{\r
+    static $error_regexps = array(\r
+            '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,\r
+            '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/'      => DB_ERROR_ALREADY_EXISTS,\r
+            '/divide by zero$/'                     => DB_ERROR_DIVZERO,\r
+            '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,\r
+            '/ttribute [\"\'].*[\"\'] not found$|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,\r
+            '/parser: parse error at or near \"/'   => DB_ERROR_SYNTAX,\r
+            '/referential integrity violation/'     => DB_ERROR_CONSTRAINT\r
+        );\r
+   \r
+    foreach ($error_regexps as $regexp => $code) {\r
+        if (preg_match($regexp, $errormsg)) {\r
+            return $code;\r
+        }\r
+    }\r
+    // Fall back to DB_ERROR if there was no mapping.\r
+    return DB_ERROR;\r
+}\r
+       \r
+function adodb_error_odbc()\r
+{\r
+static $MAP = array(\r
+            '01004' => DB_ERROR_TRUNCATED,\r
+            '07001' => DB_ERROR_MISMATCH,\r
+            '21S01' => DB_ERROR_MISMATCH,\r
+            '21S02' => DB_ERROR_MISMATCH,\r
+            '22003' => DB_ERROR_INVALID_NUMBER,\r
+            '22008' => DB_ERROR_INVALID_DATE,\r
+            '22012' => DB_ERROR_DIVZERO,\r
+            '23000' => DB_ERROR_CONSTRAINT,\r
+            '24000' => DB_ERROR_INVALID,\r
+            '34000' => DB_ERROR_INVALID,\r
+            '37000' => DB_ERROR_SYNTAX,\r
+            '42000' => DB_ERROR_SYNTAX,\r
+            'IM001' => DB_ERROR_UNSUPPORTED,\r
+            'S0000' => DB_ERROR_NOSUCHTABLE,\r
+            'S0001' => DB_ERROR_NOT_FOUND,\r
+            'S0002' => DB_ERROR_NOSUCHTABLE,\r
+            'S0011' => DB_ERROR_ALREADY_EXISTS,\r
+            'S0012' => DB_ERROR_NOT_FOUND,\r
+            'S0021' => DB_ERROR_ALREADY_EXISTS,\r
+            'S0022' => DB_ERROR_NOT_FOUND,\r
+                       'S1000' => DB_ERROR_NOSUCHTABLE,\r
+            'S1009' => DB_ERROR_INVALID,\r
+            'S1090' => DB_ERROR_INVALID,\r
+            'S1C00' => DB_ERROR_NOT_CAPABLE\r
+        );\r
+               return $MAP;\r
+}\r
+\r
+function adodb_error_ibase()\r
+{\r
+static $MAP = array(\r
+            -104 => DB_ERROR_SYNTAX,\r
+            -150 => DB_ERROR_ACCESS_VIOLATION,\r
+            -151 => DB_ERROR_ACCESS_VIOLATION,\r
+            -155 => DB_ERROR_NOSUCHTABLE,\r
+            -157 => DB_ERROR_NOSUCHFIELD,\r
+            -158 => DB_ERROR_VALUE_COUNT_ON_ROW,\r
+            -170 => DB_ERROR_MISMATCH,\r
+            -171 => DB_ERROR_MISMATCH,\r
+            -172 => DB_ERROR_INVALID,\r
+            -204 => DB_ERROR_INVALID,\r
+            -205 => DB_ERROR_NOSUCHFIELD,\r
+            -206 => DB_ERROR_NOSUCHFIELD,\r
+            -208 => DB_ERROR_INVALID,\r
+            -219 => DB_ERROR_NOSUCHTABLE,\r
+            -297 => DB_ERROR_CONSTRAINT,\r
+            -530 => DB_ERROR_CONSTRAINT,\r
+            -803 => DB_ERROR_CONSTRAINT,\r
+            -551 => DB_ERROR_ACCESS_VIOLATION,\r
+            -552 => DB_ERROR_ACCESS_VIOLATION,\r
+            -922 => DB_ERROR_NOSUCHDB,\r
+            -923 => DB_ERROR_CONNECT_FAILED,\r
+            -924 => DB_ERROR_CONNECT_FAILED\r
+        );\r
+               \r
+               return $MAP;\r
+}\r
+\r
+function adodb_error_ifx()\r
+{\r
+static $MAP = array(\r
+            '-201'    => DB_ERROR_SYNTAX,\r
+            '-206'    => DB_ERROR_NOSUCHTABLE,\r
+            '-217'    => DB_ERROR_NOSUCHFIELD,\r
+            '-329'    => DB_ERROR_NODBSELECTED,\r
+            '-1204'   => DB_ERROR_INVALID_DATE,\r
+            '-1205'   => DB_ERROR_INVALID_DATE,\r
+            '-1206'   => DB_ERROR_INVALID_DATE,\r
+            '-1209'   => DB_ERROR_INVALID_DATE,\r
+            '-1210'   => DB_ERROR_INVALID_DATE,\r
+            '-1212'   => DB_ERROR_INVALID_DATE\r
+       );\r
+          \r
+          return $MAP;\r
+}\r
+\r
+function adodb_error_oci8()\r
+{\r
+static $MAP = array(\r
+            900 => DB_ERROR_SYNTAX,\r
+            904 => DB_ERROR_NOSUCHFIELD,\r
+            923 => DB_ERROR_SYNTAX,\r
+            942 => DB_ERROR_NOSUCHTABLE,\r
+            955 => DB_ERROR_ALREADY_EXISTS,\r
+            1476 => DB_ERROR_DIVZERO,\r
+            1722 => DB_ERROR_INVALID_NUMBER,\r
+            2289 => DB_ERROR_NOSUCHTABLE,\r
+            2291 => DB_ERROR_CONSTRAINT,\r
+            2449 => DB_ERROR_CONSTRAINT,\r
+        );\r
+          \r
+       return $MAP;\r
+}\r
+\r
+function adodb_error_mssql()\r
+{\r
+static $MAP = array(\r
+                 208 => DB_ERROR_NOSUCHTABLE,\r
+          2601 => DB_ERROR_ALREADY_EXISTS\r
+       );\r
+          \r
+       return $MAP;\r
+}\r
+\r
+function adodb_error_mysql()\r
+{\r
+static $MAP = array(\r
+           1004 => DB_ERROR_CANNOT_CREATE,\r
+           1005 => DB_ERROR_CANNOT_CREATE,\r
+           1006 => DB_ERROR_CANNOT_CREATE,\r
+           1007 => DB_ERROR_ALREADY_EXISTS,\r
+           1008 => DB_ERROR_CANNOT_DROP,\r
+           1046 => DB_ERROR_NODBSELECTED,\r
+           1050 => DB_ERROR_ALREADY_EXISTS,\r
+           1051 => DB_ERROR_NOSUCHTABLE,\r
+           1054 => DB_ERROR_NOSUCHFIELD,\r
+           1062 => DB_ERROR_ALREADY_EXISTS,\r
+           1064 => DB_ERROR_SYNTAX,\r
+           1100 => DB_ERROR_NOT_LOCKED,\r
+           1136 => DB_ERROR_VALUE_COUNT_ON_ROW,\r
+           1146 => DB_ERROR_NOSUCHTABLE,\r
+           1048 => DB_ERROR_CONSTRAINT,\r
+       );\r
+          \r
+       return $MAP;\r
+}\r
+?>
\ No newline at end of file
index ea9c1dc4d03b08b98aafb172b760eca9c69ca85a..8b0e2f5f0d1f63c521bd37dd09365abd1ce701b3 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /**\r
- * @version V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license.\r
   Whenever there is any discrepancy between the two licenses,\r
   the BSD license will take precedence.\r
@@ -26,7 +26,7 @@ define('ADODB_ERROR_HANDLER','ADODB_Error_Handler');
 * @param $p1           $fn specific parameter - see below\r
 * @param $P2           $fn specific parameter - see below\r
        */\r
-function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)\r
+function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)\r
 {\r
        if (error_reporting() == 0) return; // obey @ protocol\r
        switch($fn) {\r
index 09571081a9d5536febb658c757cb7b8618dfdd64..04e607778724356bdc0dd7d51ebc8fc6be08d3be 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
index 498ec491aa6552587823f6cce1003cd5ab577c7d..78d26ec1592318336f1ff0832245645cade1a748 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. See License.txt. \r
@@ -10,6 +10,20 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
 */ \r
 \r
 \r
+// Force key to upper. \r
+// See also http://www.php.net/manual/en/function.array-change-key-case.php\r
+function _array_change_key_case($an_array)\r
+{\r
+       if (is_array($an_array)) {\r
+       foreach($an_array as $key => $value)\r
+               $new_array[strtoupper($key)] = $value;\r
+\r
+               return $new_array;\r
+   }\r
+\r
+       return $an_array;\r
+}\r
+\r
 // Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM\r
 function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false,\r
                        $size=0, $selectAttr='',$compareFields0=true)\r
@@ -24,7 +38,12 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
        else $attr ='';\r
 \r
        $s = "<select name=\"$name\"$attr $selectAttr>";\r
-       if ($blank1stItem) $s .= "\n<option></option>";\r
+       if ($blank1stItem) \r
+               if (is_string($blank1stItem))  {\r
+                       $barr = explode(':',$blank1stItem);\r
+                       if (sizeof($barr) == 1) $barr[] = '';\r
+                       $s .= "\n<option value=\"".$barr[0]."\">".$barr[1]."</option>";\r
+               } else $s .= "\n<option></option>";\r
 \r
        if ($zthis->FieldCount() > 1) $hasvalue=true;\r
        else $compareFields0 = true;\r
@@ -57,7 +76,7 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
                else {\r
                        if (strcasecmp($selected,$defstr)==0) \r
                                $s .= "<option selected$value>".htmlspecialchars($zval).'</option>';\r
-                       else \r
+                       else\r
                                $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';\r
                }\r
                $zthis->MoveNext();\r
@@ -66,6 +85,79 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
        return $s ."\n</select>\n";\r
 }\r
 \r
+/*\r
+       Count the number of records this sql statement will return by using\r
+       query rewriting techniques...\r
+       \r
+       Does not work with UNIONs.\r
+*/\r
+function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0) \r
+{\r
+        if (preg_match("/^\s*SELECT\s+DISTINCT/i", $sql) || preg_match('/\s+GROUP\s+BY\s+/is',$sql)) {\r
+               // ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias\r
+               // but this is only supported by oracle and postgresql...\r
+               if ($zthis->dataProvider == 'oci8') {\r
+                       \r
+                       $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);\r
+                       $rewritesql = "SELECT COUNT(*) FROM ($rewritesql)"; \r
+                       \r
+               } else if ( $zthis->databaseType == 'postgres' || $zthis->databaseType == 'postgres7')  {\r
+                       \r
+                       $info = $zthis->ServerInfo();\r
+                       if (substr($info['version'],0,3) >= 7.1) { // good till version 999\r
+                               $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);\r
+                               $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";\r
+                       }\r
+               }\r
+       } else { \r
+               // now replace SELECT ... FROM with SELECT COUNT(*) FROM\r
+               \r
+               $rewritesql = preg_replace(\r
+                                       '/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);\r
+               \r
+               // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails \r
+               // with mssql, access and postgresql. Also a good speedup optimization - skips sorting!\r
+               $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql); \r
+       }\r
+       \r
+       if (isset($rewritesql) && $rewritesql != $sql) {\r
+               if ($secs2cache) {\r
+                       // we only use half the time of secs2cache because the count can quickly\r
+                       // become inaccurate if new records are added\r
+                       $qryRecs = $zthis->CacheGetOne($secs2cache/2,$rewritesql,$inputarr);\r
+                       \r
+               } else {\r
+                       $qryRecs = $zthis->GetOne($rewritesql,$inputarr);\r
+               }\r
+               if ($qryRecs !== false) return $qryRecs;\r
+       }\r
+       \r
+       // query rewrite failed - so try slower way...\r
+       $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); \r
+       $rstest = &$zthis->Execute($rewritesql);\r
+       if ($rstest) {\r
+               $qryRecs = $rstest->RecordCount();\r
+               if ($qryRecs == -1) { \r
+               global $ADODB_EXTENSION;\r
+               // some databases will return -1 on MoveLast() - change to MoveNext()\r
+                       if ($ADODB_EXTENSION) {\r
+                               while(!$rstest->EOF) {\r
+                                       adodb_movenext($rstest);\r
+                               }\r
+                       } else {\r
+                               while(!$rstest->EOF) {\r
+                                       $rstest->MoveNext();\r
+                               }\r
+                       }\r
+                       $qryRecs = $rstest->_currentRow;\r
+               }\r
+               $rstest->Close();\r
+               if ($qryRecs == -1) return 0;\r
+       }\r
+\r
+       return $qryRecs;\r
+}\r
+\r
 /*\r
        Code originally from "Cornel G" <conyg@fx.ro>\r
 \r
@@ -88,49 +180,8 @@ function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
 \r
        $qryRecs = false; //count records for no offset\r
        \r
-       // jlim - attempt query rewrite first if no GROUP BY nor SELECT DISTINCT\r
-       if (!preg_match('/\s+GROUP\s+BY\s+/is',$sql) && !preg_match("/\s*SELECT\s*DISTINCT/i", $sql))\r
-               $rewritesql = preg_replace(\r
-                       '/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);\r
-               \r
-       if (isset($rewritesql) && $rewritesql != $sql){\r
-               \r
-               // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails \r
-               // with mssql, access and postgresql\r
-               $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql); \r
-               \r
-               if ($secs2cache) {\r
-                       // we only use half the time of secs2cache because the count can quickly\r
-                       // become inaccurate if new records are added\r
-                       $rs = $zthis->CacheExecute($secs2cache/2,$rewritesql);\r
-                       if ($rs) {\r
-                               if (!$rs->EOF) $qryRecs = reset($rs->fields);\r
-                               $rs->Close();\r
-                       }\r
-               } else $qryRecs = $zthis->GetOne($rewritesql,$inputarr);\r
-               if ($qryRecs !== false)\r
-                       $lastpageno = (int) ceil($qryRecs / $nrows);\r
-       }\r
-       \r
-       // query rewrite failed - so try slower way...\r
-       if ($qryRecs === false) {\r
-               $rstest = &$zthis->Execute($sql);\r
-               if ($rstest) {\r
-                       $qryRecs = $rstest->RecordCount();\r
-                       if ($qryRecs == -1) { \r
-                       // some databases will return -1 on MoveLast() - change to MoveNext()\r
-                               while(!$rstest->EOF) {\r
-                                       $rstest->MoveNext();\r
-                               }\r
-                               $qryRecs = $rstest->_currentRow;\r
-                       }\r
-                       if ($qryRecs == -1) $qryRecs = 0;\r
-                                       \r
-                       $lastpageno = (int) ceil($qryRecs / $nrows);\r
-               }\r
-               if ($rstest) $rstest->Close();\r
-       }\r
-       \r
+       $qryRecs = _adodb_getcount($zthis,$sql,$inputarr,$secs2cache);\r
+       $lastpageno = (int) ceil($qryRecs / $nrows);\r
        $zthis->_maxRecordCount = $qryRecs;\r
        \r
        // If page number <= 1, then we are at the first page\r
@@ -157,6 +208,7 @@ function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
        \r
        // Before returning the RecordSet, we set the pagination properties we need\r
        if ($rsreturn) {\r
+               $rsreturn->_maxRecordCount = $qryRecs;\r
                $rsreturn->rowsPerPage = $nrows;\r
                $rsreturn->AbsolutePage($page);\r
                $rsreturn->AtFirstPage($atfirstpage);\r
@@ -225,9 +277,10 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
                }\r
        \r
                $fieldUpdatedCount = 0;\r
-               \r
+               $arrFields = _array_change_key_case($arrFields);\r
+\r
                // Get the table name from the existing query.\r
-               preg_match("/FROM\s".ADODB_TABLE_REGEX."/i", $rs->sql, $tableName);\r
+               preg_match("/FROM\s+".ADODB_TABLE_REGEX."/i", $rs->sql, $tableName);\r
 \r
                // Get the full where clause excluding the word "WHERE" from\r
                // the existing query.\r
@@ -245,7 +298,7 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
                // processing has completed.\r
                $updateSQL = "UPDATE " . $tableName[1] . " SET ";\r
 \r
-               $hasnumeric = (isset($rs->fields[0]));\r
+               $hasnumeric = isset($rs->fields[0]);\r
                \r
                // Loop through all of the fields in the recordset\r
                for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {\r
@@ -255,15 +308,19 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
 \r
                        // If the recordset field is one\r
                        // of the fields passed in then process.\r
-                       if (isset($arrFields[$field->name])) {\r
+                       $upperfname = strtoupper($field->name);\r
+                       if (isset($arrFields[$upperfname])) {\r
 \r
                                // If the existing field value in the recordset\r
                                // is different from the value passed in then\r
                                // go ahead and append the field name and new value to\r
                                // the update query.\r
                                \r
-                               $val = ($hasnumeric) ? $rs->fields[$i] : $rs->fields[$field->name];\r
-                               if ($forceUpdate || strcmp($val, $arrFields[$field->name])) {\r
+                               if ($hasnumeric) $val = $rs->fields[$i];\r
+                               else if (isset($rs->fields[$upperfname])) $val = $rs->fields[$upperfname];\r
+                               else $val = '';\r
+                               \r
+                               if ($forceUpdate || strcmp($val, $arrFields[$upperfname])) {\r
                                        // Set the counter for the number of fields that will be updated.\r
                                        $fieldUpdatedCount++;\r
 \r
@@ -273,24 +330,26 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq
                                        \r
                                        // "mike" <mike@partner2partner.com> patch and "Ryan Bailey" <rebel@windriders.com> \r
                                        //PostgreSQL uses a 't' or 'f' and therefore needs to be processed as a string ('C') type field.\r
-                                       if ((substr($zthis->databaseType,0,8) == "postgres") && ($mt == "L")) $mt = "C";\r
-                                       if ($arrFields[$field->name] === 'null') \r
+                                       if ((strncmp($zthis->databaseType,"postgres",8) === 0) && ($mt == "L")) $mt = "C";\r
+                                       // is_null requires php 4.0.4\r
+                                       if (/*is_null($arrFields[$fieldname]) ||*/ $arrFields[$upperfname] === 'null') \r
                                                $updateSQL .= $field->name . " = null, ";\r
                                        else            \r
                                        switch($mt) {\r
                                                case 'null':\r
                                                case "C":\r
                                                case "X":\r
-                                                       $updateSQL .= $field->name . " = " . $zthis->qstr($arrFields[$field->name],$magicq) . ", ";\r
+                                               case 'B':\r
+                                                       $updateSQL .= $field->name . " = " . $zthis->qstr($arrFields[$upperfname],$magicq) . ", ";\r
                                                        break;\r
                                                case "D":\r
-                                                       $updateSQL .= $field->name . " = " . $zthis->DBDate($arrFields[$field->name]) . ", ";\r
+                                                       $updateSQL .= $field->name . " = " . $zthis->DBDate($arrFields[$upperfname]) . ", ";\r
                                                        break;\r
                                                case "T":\r
-                                                       $updateSQL .= $field->name . " = " . $zthis->DBTimeStamp($arrFields[$field->name]) . ", ";\r
+                                                       $updateSQL .= $field->name . " = " . $zthis->DBTimeStamp($arrFields[$upperfname]) . ", ";\r
                                                        break;\r
                                                default:\r
-                                                       $updateSQL .= $field->name . " = " . (float) $arrFields[$field->name] . ", ";\r
+                                                       $updateSQL .= $field->name . " = " . (float) $arrFields[$upperfname] . ", ";\r
                                                        break;\r
                                        };\r
                                };\r
@@ -316,7 +375,7 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false)
 {\r
        $values = '';\r
        $fields = '';\r
-       \r
+       $arrFields = _array_change_key_case($arrFields);\r
        if (!$rs) {\r
                        printf(ADODB_BAD_RS,'GetInsertSQL');\r
                        return false;\r
@@ -325,7 +384,7 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false)
                $fieldInsertedCount = 0;\r
        \r
                // Get the table name from the existing query.\r
-               preg_match("/FROM\s".ADODB_TABLE_REGEX."/i", $rs->sql, $tableName);\r
+               preg_match("/FROM\s+".ADODB_TABLE_REGEX."/i", $rs->sql, $tableName);\r
 \r
                // Loop through all of the fields in the recordset\r
                for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {\r
@@ -334,7 +393,8 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false)
                        $field = $rs->FetchField($i);\r
                        // If the recordset field is one\r
                        // of the fields passed in then process.\r
-                       if (isset($arrFields[$field->name])) {\r
+                       $upperfname = strtoupper($field->name);\r
+                       if (isset($arrFields[$upperfname])) {\r
        \r
                                // Set the counter for the number of fields that will be inserted.\r
                                $fieldInsertedCount++;\r
@@ -346,26 +406,27 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false)
                                \r
                                // "mike" <mike@partner2partner.com> patch and "Ryan Bailey" <rebel@windriders.com> \r
                                //PostgreSQL uses a 't' or 'f' and therefore needs to be processed as a string ('C') type field.\r
-                               if ((substr($zthis->databaseType,0,8) == "postgres") && ($mt == "L")) $mt = "C";\r
+                               if ((strncmp($zthis->databaseType,"postgres",8) === 0) && ($mt == "L")) $mt = "C";\r
 \r
                                // Based on the datatype of the field\r
                                // Format the value properly for the database\r
-                               if ($arrFields[$field->name] === 'null') \r
+                               if (/*is_null($arrFields[$fieldname]) ||*/ $arrFields[$upperfname] === 'null') \r
                                                $values .= "null, ";\r
                                else            \r
                                switch($mt) {\r
                                        case "C":\r
                                        case "X":\r
-                                               $values .= $zthis->qstr($arrFields[$field->name],$magicq) . ", ";\r
+                                       case 'B':\r
+                                               $values .= $zthis->qstr($arrFields[$upperfname],$magicq) . ", ";\r
                                                break;\r
                                        case "D":\r
-                                               $values .= $zthis->DBDate($arrFields[$field->name]) . ", ";\r
+                                               $values .= $zthis->DBDate($arrFields[$upperfname]) . ", ";\r
                                                break;\r
                                        case "T":\r
-                                               $values .= $zthis->DBTimeStamp($arrFields[$field->name]) . ", ";\r
+                                               $values .= $zthis->DBTimeStamp($arrFields[$upperfname]) . ", ";\r
                                                break;\r
                                        default:\r
-                                               $values .= (float) $arrFields[$field->name] . ", ";\r
+                                               $values .= (float) $arrFields[$upperfname] . ", ";\r
                                                break;\r
                                };\r
                        };\r
index 9d660c05e7bcb40f709d2cd9a3f887ed875fc667..e5a2d7d4b086757b58b3f0ffae4eb809a8125ec2 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-       V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+       V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
          Released under both BSD license and Lesser GPL library license. \r
          Whenever there is any discrepancy between the two licenses, \r
          the BSD license will take precedence. \r
@@ -273,9 +273,9 @@ class ADODB_Pager {
        \r
        //------------------------------------------------------\r
        // override this to control overall layout and formating\r
-       function RenderLayout($header,$grid,$footer)\r
+       function RenderLayout($header,$grid,$footer,$attributes='border=1 bgcolor=beige')\r
        {\r
-               echo "<table border=1 bgcolor=beige><tr><td>",\r
+               echo "<table ".$attributes."><tr><td>",\r
                                $header,\r
                        "</td></tr><tr><td>",\r
                                $grid,\r
index 03515b5749b8ebe349ad891c19312aa450d44199..83f14209a79e6b80f7b4878a38971506574a879f 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
  * Whenever there is any discrepancy between the two licenses, \r
  * the BSD license will take precedence. \r
@@ -10,7 +10,7 @@
  * PEAR DB Emulation Layer for ADODB.\r
  *\r
  * The following code is modelled on PEAR DB code by Stig Bakken <ssb@fast.no>                                                            |\r
- * and Tomas V.V.Cox <cox@idecnet.com> \r
+ * and Tomas V.V.Cox <cox@idecnet.com>.        Portions (c)1997-2002 The PHP Group.\r
  */\r
 \r
  /*\r
@@ -150,11 +150,26 @@ class DB
                if (!is_object($obj)) return new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);\r
 \r
                if (is_array($options)) {\r
-                       $persist = !empty($options['persistent']);\r
+                       foreach($options as $k => $v) {\r
+                               switch(strtolower($k)) {\r
+                               case 'persistent':      $persist = $v; break;\r
+                               #ibase\r
+                               case 'dialect':         $obj->dialect = $v; break;\r
+                               case 'charset':         $obj->charset = $v; break;\r
+                               case 'buffers':         $obj->buffers = $v; break;\r
+                               #ado\r
+                               case 'charpage':        $obj->charPage = $v; break;\r
+                               #mysql\r
+                               case 'clientflags': $obj->clientFlags = $v; break;\r
+                               }\r
+                       }\r
                } else {\r
-                       $persist = true;\r
+                       $persist = false;\r
                }\r
 \r
+               if (isset($dsninfo['socket'])) $dsninfo['hostspec'] .= ':'.$dsninfo['socket'];\r
+               else if (isset($dsninfo['port'])) $dsninfo['hostspec'] .= ':'.$dsninfo['port'];\r
+               \r
                if($persist) $ok = $obj->PConnect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);\r
                else  $ok = $obj->Connect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);\r
                \r
diff --git a/lib/adodb/adodb-recordset.inc.php b/lib/adodb/adodb-recordset.inc.php
new file mode 100644 (file)
index 0000000..e245e05
--- /dev/null
@@ -0,0 +1,919 @@
+<?php\r
+/** \r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Set tabs to 4 for best viewing.\r
+ * \r
+ * Latest version is available at http://php.weblogs.com\r
+ *\r
+ */\r
+\r
\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 {\r
+       /*\r
+        * public variables     \r
+        */\r
+       var $dataProvider = "native";\r
+       var $fields = false;    /// holds the current row data\r
+       var $blobSize = 64;     /// any varchar/char field this size or greater is treated as a blob\r
+                                                       /// in other words, we use a text area for editting.\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 $dateHasTime = 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
+       }\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
+                       $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
+               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
+        * 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
+               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
+               return _adodb_getmenu($this,$name,$defstr,$blank1stItem,$multiple,\r
+                       $size, $selectAttr,false);\r
+       }\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
+       /*\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
+                       return $this->GetArray($nrows);\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
+               return $this->GetArray($nRows);\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
+               $cols = $this->_numOfFields;\r
+               if ($cols < 2) {\r
+                       return false;\r
+               }\r
+               $numIndex = isset($this->fields[0]);\r
+               $results = array();\r
+               \r
+               if (!$first2cols && ($cols > 2 || $force_array)) {\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
+               } else {\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
+                                       $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
+               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
+               $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
+       /**\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
+               \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] <= 1903) 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
+        * @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
+               \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
+               if ($rr[1] <= 1903 && $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
+       /**\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) return false;\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
+        * 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
+        \r
+               if (!$this->bind) {\r
+                       $this->GetAssocKeys($upper);\r
+               }\r
+               \r
+               $record = array();\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
+               return FetchObject(false);\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
+               $o = &$this->_obj;\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
+               return $this->FetchNextObject(false);\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 < 200 chars\r
+        *      X for teXt (>= 200 chars)\r
+        *      B for Binary\r
+        *      N for numeric 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
+               'M' => 'X',\r
+               'X' => 'X',\r
+               'CLOB' => 'X',\r
+               'NCLOB' => 'X',\r
+               'LVARCHAR' => 'X',\r
+               ##\r
+               'BLOB' => 'B',\r
+               'NTEXT' => '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
+               'BOOLEAN' => 'L', \r
+               'BIT' => 'L',\r
+               'L' => 'L',\r
+               ##\r
+               'COUNTER' => 'R',\r
+               'R' => 'R',\r
+               'SERIAL' => 'R', // ifx\r
+               ##\r
+               'INT' => 'I',\r
+               'INTEGER' => '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
+               \r
+               $tmap = false;\r
+               $t = strtoupper($t);\r
+               $tmap = @$typeMap[$t];\r
+               switch ($tmap) {\r
+               case 'C':\r
+               \r
+                       // is the char field is too long, return as text field... \r
+                       if (!empty($this)) {\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 ($this->dateHasTime) 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
+} // end class ADORecordSet\r
+\r
+?>
\ No newline at end of file
index 5179b97e123494706d8413fbb84428b4f4602c6c..67b61e7583e4b65d4aad038a8f867a3c17482b52 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -42,6 +42,7 @@ To force non-persistent connections, call adodb_session_open first before sessio
   create table sessions (\r
           SESSKEY char(32) not null,\r
           EXPIRY int(11) unsigned not null,\r
+          EXPIREREF varchar(64),\r
           DATA text not null,\r
          primary key (sesskey)\r
   );\r
@@ -58,6 +59,26 @@ To force non-persistent connections, call adodb_session_open first before sessio
   3. Recommended is PHP 4.0.6 or later. There are documented\r
         session bugs in earlier versions of PHP.\r
 \r
+  4. If you want to receive notifications when a session expires, then\r
+        you can tag a session with an EXPIREREF, and before the session\r
+        record is deleted, we can call a function that will pass the EXPIREREF\r
+        as the first parameter, and the session key as the second parameter.\r
+        \r
+        To do this, define a notification function, say NotifyFn:\r
+        \r
+               function NotifyFn($expireref, $sesskey)\r
+               {\r
+               }\r
+        \r
+        Then define a global variable, with the first parameter being the\r
+        global variable you would like to store in the EXPIREREF field, and\r
+        the second is the function name.\r
+        \r
+        In this example, we want to be notified when a user's session \r
+        has expired, so we store the user id in $USERID, and make this\r
+        the value stored in the EXPIREREF field:\r
+        \r
+               $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn');\r
 */\r
 \r
 if (!defined('_ADODB_LAYER')) {\r
@@ -67,6 +88,9 @@ if (!defined('_ADODB_LAYER')) {
 if (!defined('ADODB_SESSION')) {\r
 \r
  define('ADODB_SESSION',1);\r
\r
+ /* if database time and system time is difference is greater than this, then give warning */\r
+ define('ADODB_SESSION_SYNCH_SECS',60); \r
 \r
 /****************************************************************************************\\r
        Global definitions\r
@@ -79,9 +103,10 @@ GLOBAL      $ADODB_SESSION_CONNECT,
        $ADODB_SESS_CONN,\r
        $ADODB_SESS_LIFE,\r
        $ADODB_SESS_DEBUG,\r
-       $ADODB_SESS_INSERT, \r
+       $ADODB_SESSION_EXPIRE_NOTIFY,\r
        $ADODB_SESSION_CRC;\r
        \r
+       \r
        $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime');\r
        if ($ADODB_SESS_LIFE <= 1) {\r
         // bug in PHP 4.0.3 pl 1  -- how about other versions?\r
@@ -103,11 +128,27 @@ GLOBAL    $ADODB_SESSION_CONNECT,
                $ADODB_SESSION_DB ='xphplens_2';\r
        }\r
        \r
+       if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {\r
+               $ADODB_SESSION_EXPIRE_NOTIFY = false;\r
+       }\r
        //  Made table name configurable - by David Johnson djohnson@inpro.net\r
        if (empty($ADODB_SESSION_TBL)){\r
                $ADODB_SESSION_TBL = 'sessions';\r
        }\r
-\r
+       \r
+       /*\r
+       $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER;\r
+       $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT;\r
+       $ADODB_SESS['user'] = $ADODB_SESSION_USER;\r
+       $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD;\r
+       $ADODB_SESS['db'] = $ADODB_SESSION_DB;\r
+       $ADODB_SESS['life'] = $ADODB_SESS_LIFE;\r
+       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+       \r
+       $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+       $ADODB_SESS['table'] = $ADODB_SESS_TBL;\r
+       */\r
+       \r
 /****************************************************************************************\\r
        Create the connection to the database. \r
        \r
@@ -155,13 +196,11 @@ global $ADODB_SESS_CONN;
 \****************************************************************************************/\r
 function adodb_sess_read($key) \r
 {\r
-global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;\r
+global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;\r
 \r
-       $ADODB_SESS_INSERT = false;     \r
        $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());\r
        if ($rs) {\r
                if ($rs->EOF) {\r
-                       $ADODB_SESS_INSERT = true;\r
                        $v = '';\r
                } else \r
                        $v = rawurldecode(reset($rs->fields));\r
@@ -173,7 +212,6 @@ global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC
                \r
                return $v;\r
        }\r
-       else $ADODB_SESS_INSERT = true;\r
        \r
        return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com\r
 }\r
@@ -185,12 +223,13 @@ global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC
 \****************************************************************************************/\r
 function adodb_sess_write($key, $val) \r
 {\r
-       global $ADODB_SESS_INSERT,\r
+       global\r
                $ADODB_SESS_CONN, \r
                $ADODB_SESS_LIFE, \r
                $ADODB_SESSION_TBL,\r
                $ADODB_SESS_DEBUG, \r
-               $ADODB_SESSION_CRC;\r
+               $ADODB_SESSION_CRC,\r
+               $ADODB_SESSION_EXPIRE_NOTIFY;\r
 \r
        $expiry = time() + $ADODB_SESS_LIFE;\r
        \r
@@ -198,48 +237,91 @@ function adodb_sess_write($key, $val)
        // now we only update expiry date, thx to sebastian thom in adodb 2.32\r
        if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) {\r
                if ($ADODB_SESS_DEBUG) echo "<p>Session: Only updating date - crc32 not changed</p>";\r
-               $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key'";\r
+               $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time();\r
                $rs = $ADODB_SESS_CONN->Execute($qry);  \r
                return true;\r
        }\r
        $val = rawurlencode($val);\r
        \r
-       $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,\r
-           array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val),\r
+       $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val);\r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               $var = reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               global $$var;\r
+               $arr['expireref'] = $$var;\r
+       }\r
+       $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr,\r
        'sesskey',$autoQuote = true);\r
        \r
        if (!$rs) {\r
                ADOConnection::outp( '<p>Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'</p>',false);\r
+       }  else {\r
+               // bug in access driver (could be odbc?) means that info is not commited\r
+               // properly unless select statement executed in Win2000\r
+               if ($ADODB_SESS_CONN->databaseType == 'access') \r
+                       $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
        }\r
-       \r
-       // bug in access driver (could be odbc?) means that info is not commited\r
-       // properly unless select statement executed in Win2000\r
-       if ($rs && $ADODB_SESS_CONN->databaseType == 'access') \r
-               $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
-\r
        return !empty($rs);\r
 }\r
 \r
 function adodb_sess_destroy($key) \r
 {\r
-       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL;\r
-\r
-       $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";\r
-       $rs = $ADODB_SESS_CONN->Execute($qry);\r
+       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+       \r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+               $ADODB_SESS_CONN->SetFetchMode($savem);\r
+               if ($rs) {\r
+                       $ADODB_SESS_CONN->BeginTrans();\r
+                       while (!$rs->EOF) {\r
+                               $ref = $rs->fields[0];\r
+                               $key = $rs->fields[1];\r
+                               $fn($ref,$key);\r
+                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+                               $rs->MoveNext();\r
+                       }\r
+                       $ADODB_SESS_CONN->CommitTrans();\r
+               }\r
+       } else {\r
+               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";\r
+               $rs = $ADODB_SESS_CONN->Execute($qry);\r
+       }\r
        return $rs ? true : false;\r
 }\r
 \r
 function adodb_sess_gc($maxlifetime) \r
 {\r
-       global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_DRIVER;\r
-\r
-       $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();\r
-       $rs = $ADODB_SESS_CONN->Execute($qry);\r
-       if ($rs) $rs->Close();\r
+       global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+       \r
+       if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+               reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+               $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+               $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < " . time());\r
+               $ADODB_SESS_CONN->SetFetchMode($savem);\r
+               if ($rs) {\r
+                       $ADODB_SESS_CONN->BeginTrans();\r
+                       while (!$rs->EOF) {\r
+                               $ref = $rs->fields[0];\r
+                               $key = $rs->fields[1];\r
+                               $fn($ref,$key);\r
+                               $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+                               $rs->MoveNext();\r
+                       }\r
+                       $ADODB_SESS_CONN->CommitTrans();\r
+               }\r
+       } else {\r
+               $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();\r
+               $ADODB_SESS_CONN->Execute($qry);\r
        \r
+               if ($ADODB_SESS_DEBUG) ADOConnection::outp("<p><b>Garbage Collection</b>: $qry</p>");\r
+       }\r
        // suggested by Cameron, "GaM3R" <gamr@outworld.cx>\r
-       if (defined('ADODB_SESSION_OPTIMIZE'))\r
-       {\r
+       if (defined('ADODB_SESSION_OPTIMIZE')) {\r
+       global $ADODB_SESSION_DRIVER;\r
+       \r
                switch( $ADODB_SESSION_DRIVER ) {\r
                        case 'mysql':\r
                        case 'mysqlt':\r
@@ -250,6 +332,24 @@ function adodb_sess_gc($maxlifetime)
                                $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL;        \r
                                break;\r
                }\r
+               if (!empty($opt_qry)) {\r
+                       $ADODB_SESS_CONN->Execute($opt_qry);\r
+               }\r
+       }\r
+       \r
+       $rs = $ADODB_SESS_CONN->SelectLimit('select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL,1);\r
+       if ($rs && !$rs->EOF) {\r
+       \r
+               $dbt = reset($rs->fields);\r
+               $rs->Close();\r
+               $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbt);\r
+               $t = time();\r
+               if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) {\r
+               global $HTTP_SERVER_VARS;\r
+                       $msg = "adodb-session.php: Server time for webserver {$HTTP_SERVER_VARS['HTTP_HOST']} not in synch: database=$dbt, webserver=".$t;\r
+                       error_log($msg);\r
+                       if ($ADODB_SESS_DEBUG) ADOConnection::outp("<p>$msg</p>");\r
+               }\r
        }\r
        \r
        return true;\r
diff --git a/lib/adodb/adodb-time.inc.php b/lib/adodb/adodb-time.inc.php
new file mode 100644 (file)
index 0000000..a53f02b
--- /dev/null
@@ -0,0 +1,868 @@
+<?php\r
+/**\r
+ADOdb Date Library, part of the ADOdb abstraction library\r
+Download: http://php.weblogs.com/adodb_date_time_library\r
+\r
+PHP native date functions use integer timestamps for computations.\r
+Because of this, dates are restricted to the years 1901-2038 on Unix \r
+and 1970-2038 on Windows due to integer overflow for dates beyond \r
+those years. This library overcomes these limitations by replacing the \r
+native function's signed integers (normally 32-bits) with PHP floating \r
+point numbers (normally 64-bits).\r
+\r
+Dates from 100 A.D. to 3000 A.D. and later\r
+have been tested. The minimum is 100 A.D. as <100 will invoke the\r
+2 => 4 digit year conversion. The maximum is billions of years in the \r
+future, but this is a theoretical limit as the computation of that year \r
+would take too long with the current implementation of adodb_mktime().\r
+\r
+This library replaces native functions as follows:\r
+\r
+<pre>  \r
+       getdate()  with  adodb_getdate()\r
+       date()     with  adodb_date() \r
+       gmdate()   with  adodb_gmdate()\r
+       mktime()   with  adodb_mktime()\r
+       gmmktime() with  adodb_gmmktime()45\r
+</pre>\r
+       \r
+The parameters are identical, except that adodb_date() accepts a subset\r
+of date()'s field formats. Mktime() will convert from local time to GMT, \r
+and date() will convert from GMT to local time, but daylight savings is \r
+not handled currently.\r
+\r
+This library is independant of the rest of ADOdb, and can be used\r
+as standalone code.\r
+\r
+PERFORMANCE\r
+\r
+For high speed, this library uses the native date functions where\r
+possible, and only switches to PHP code when the dates fall outside \r
+the 32-bit signed integer range.\r
+\r
+GREGORIAN CORRECTION\r
+\r
+Pope Gregory shortened October of A.D. 1582 by ten days. Thursday, \r
+October 4, 1582 (Julian) was followed immediately by Friday, October 15, \r
+1582 (Gregorian). \r
+\r
+Since 0.06, we handle this correctly, so:\r
+\r
+adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582) \r
+       == 24 * 3600 (1 day)\r
+\r
+=============================================================================\r
+\r
+COPYRIGHT\r
+\r
+(c) 2003 John Lim and released under BSD-style license except for code by jackbbs,\r
+which includes adodb_mktime, adodb_get_gmt_different, adodb_is_leap_year\r
+and originally found at http://www.php.net/manual/en/function.mktime.php\r
+\r
+=============================================================================\r
+\r
+BUG REPORTS\r
+\r
+These should be posted to the ADOdb forums at\r
+\r
+       http://phplens.com/lens/lensforum/topics.php?id=4\r
+\r
+=============================================================================\r
+\r
+FUNCTION DESCRIPTIONS\r
+\r
+\r
+FUNCTION adodb_getdate($date=false)\r
+\r
+Returns an array containing date information, as getdate(), but supports\r
+dates greater than 1901 to 2038.\r
+\r
+\r
+FUNCTION adodb_date($fmt, $timestamp = false)\r
+\r
+Convert a timestamp to a formatted local date. If $timestamp is not defined, the\r
+current timestamp is used. Unlike the function date(), it supports dates\r
+outside the 1901 to 2038 range.\r
+\r
+The format fields that adodb_date supports:\r
+\r
+<pre>\r
+a - "am" or "pm" \r
+A - "AM" or "PM" \r
+d - day of the month, 2 digits with leading zeros; i.e. "01" to "31" \r
+D - day of the week, textual, 3 letters; e.g. "Fri" \r
+F - month, textual, long; e.g. "January" \r
+g - hour, 12-hour format without leading zeros; i.e. "1" to "12" \r
+G - hour, 24-hour format without leading zeros; i.e. "0" to "23" \r
+h - hour, 12-hour format; i.e. "01" to "12" \r
+H - hour, 24-hour format; i.e. "00" to "23" \r
+i - minutes; i.e. "00" to "59" \r
+j - day of the month without leading zeros; i.e. "1" to "31" \r
+l (lowercase 'L') - day of the week, textual, long; e.g. "Friday"  \r
+L - boolean for whether it is a leap year; i.e. "0" or "1" \r
+m - month; i.e. "01" to "12" \r
+M - month, textual, 3 letters; e.g. "Jan" \r
+n - month without leading zeros; i.e. "1" to "12" \r
+O - Difference to Greenwich time in hours; e.g. "+0200" \r
+r - RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" \r
+s - seconds; i.e. "00" to "59" \r
+S - English ordinal suffix for the day of the month, 2 characters; \r
+                       i.e. "st", "nd", "rd" or "th" \r
+t - number of days in the given month; i.e. "28" to "31"\r
+T - Timezone setting of this machine; e.g. "EST" or "MDT" \r
+U - seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)  \r
+w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) \r
+Y - year, 4 digits; e.g. "1999" \r
+y - year, 2 digits; e.g. "99" \r
+z - day of the year; i.e. "0" to "365" \r
+Z - timezone offset in seconds (i.e. "-43200" to "43200"). \r
+                       The offset for timezones west of UTC is always negative, \r
+                       and for those east of UTC is always positive. \r
+</pre>\r
+\r
+Unsupported:\r
+<pre>\r
+B - Swatch Internet time \r
+I (capital i) - "1" if Daylight Savings Time, "0" otherwise.\r
+W - ISO-8601 week number of year, weeks starting on Monday \r
+\r
+</pre>\r
+\r
+\r
+FUNCTION adodb_gmdate($fmt, $timestamp = false)\r
+\r
+Convert a timestamp to a formatted GMT date. If $timestamp is not defined, the\r
+current timestamp is used. Unlike the function date(), it supports dates\r
+outside the 1901 to 2038 range.\r
+\r
+\r
+FUNCTION adodb_mktime($hr, $min, $sec, $month, $day, $year)\r
+\r
+Converts a local date to a unix timestamp.  Unlike the function mktime(), it supports\r
+dates outside the 1901 to 2038 range. Differs from mktime() in that all parameters\r
+are currently compulsory.\r
+\r
+FUNCTION adodb_gmmktime($hr, $min, $sec, $month, $day, $year)\r
+\r
+Converts a gmt date to a unix timestamp.  Unlike the function gmmktime(), it supports\r
+dates outside the 1901 to 2038 range. Differs from gmmktime() in that all parameters\r
+are currently compulsory.\r
+\r
+=============================================================================\r
+\r
+NOTES\r
+\r
+Useful url for generating test timestamps:\r
+       http://www.4webhelp.net/us/timestamp.php\r
+\r
+Possible future optimizations include \r
+\r
+a. Using an algorithm similar to Plauger's in "The Standard C Library" \r
+(page 428, xttotm.c _Ttotm() function). Plauger's algorithm will not \r
+work outside 32-bit signed range, so i decided not to implement it.\r
+\r
+b. Iterate over a block of years (say 12) when searching for the \r
+correct year.\r
+\r
+c. Implement daylight savings, which looks awfully complicated, see\r
+       http://webexhibits.org/daylightsaving/\r
+\r
+\r
+CHANGELOG\r
+- 3 March 2003 0.08\r
+Added support for 'S' adodb_date() format char. Added constant ADODB_ALLOW_NEGATIVE_TS\r
+if you want PHP to handle negative timestamps between 1901 to 1969.\r
+\r
+- 27 Feb 2003 0.07\r
+All negative numbers handled by adodb now because of RH 7.3+ problems.\r
+See http://bugs.php.net/bug.php?id=20048&edit=2\r
+\r
+- 4 Feb 2003 0.06\r
+Fixed a typo, 1852 changed to 1582! This means that pre-1852 dates\r
+are now correctly handled.\r
+\r
+- 29 Jan 2003 0.05\r
+\r
+Leap year checking differs under Julian calendar (pre 1582). Also\r
+leap year code optimized by checking for most common case first.\r
+\r
+We also handle month overflow correctly in mktime (eg month set to 13).\r
+\r
+Day overflow for less than one month's days is supported.\r
+\r
+- 28 Jan 2003 0.04\r
+\r
+Gregorian correction handled. In PHP5, we might throw an error if \r
+mktime uses invalid dates around 5-14 Oct 1582. Released with ADOdb 3.10.\r
+Added limbo 5-14 Oct 1582 check, when we set to 15 Oct 1582.\r
+\r
+- 27 Jan 2003 0.03\r
+\r
+Fixed some more month problems due to gmt issues. Added constant ADODB_DATE_VERSION.\r
+Fixed calculation of days since start of year for <1970. \r
+\r
+- 27 Jan 2003 0.02\r
+\r
+Changed _adodb_getdate() to inline leap year checking for better performance.\r
+Fixed problem with time-zones west of GMT +0000.\r
+\r
+- 24 Jan 2003 0.01\r
+\r
+First implementation.\r
+*/\r
+\r
+\r
+/* Initialization */\r
+\r
+/*\r
+       Version Number\r
+*/\r
+define('ADODB_DATE_VERSION',0.08);\r
+\r
+/*\r
+       We check for Windows as only +ve ints are accepted as dates on Windows.\r
+       \r
+       Apparently this problem happens also with Linux, RH 7.3 and later!\r
+       \r
+       glibc-2.2.5-34 and greater has been changed to return -1 for dates <\r
+       1970.  This used to work.  The problem exists with RedHat 7.3 and 8.0\r
+       echo (mktime(0, 0, 0, 1, 1, 1960));  // prints -1\r
+       \r
+       References:\r
+        http://bugs.php.net/bug.php?id=20048&edit=2\r
+        http://lists.debian.org/debian-glibc/2002/debian-glibc-200205/msg00010.html\r
+*/\r
+\r
+if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1);\r
+\r
+function adodb_date_test_date($y1,$m)\r
+{\r
+       //print " $y1/$m ";\r
+       $t = adodb_mktime(0,0,0,$m,13,$y1);\r
+       if ("$y1-$m-13 00:00:00" != adodb_date('Y-n-d H:i:s',$t)) {\r
+               print "<b>$y1 error</b><br>";\r
+               return false;\r
+       }\r
+       return true;\r
+}\r
+/**\r
+        Test Suite\r
+*/\r
+function adodb_date_test()\r
+{\r
+       \r
+       error_reporting(E_ALL);\r
+       print "<h4>Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION. "</h4>";\r
+       set_time_limit(0);\r
+       $fail = false;\r
+       \r
+       // This flag disables calling of PHP native functions, so we can properly test the code\r
+       if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1);\r
+       \r
+       print "<p>Testing gregorian <=> julian conversion<p>";\r
+       $t = adodb_mktime(0,0,0,10,11,1492);\r
+       //http://www.holidayorigins.com/html/columbus_day.html - Friday check\r
+       if (!(adodb_date('D Y-m-d',$t) == 'Fri 1492-10-11')) print 'Error in Columbus landing<br>';\r
+       \r
+       $t = adodb_mktime(0,0,0,2,29,1500);\r
+       if (!(adodb_date('Y-m-d',$t) == '1500-02-29')) print 'Error in julian leap years<br>';\r
+       \r
+       $t = adodb_mktime(0,0,0,2,29,1700);\r
+       if (!(adodb_date('Y-m-d',$t) == '1700-03-01')) print 'Error in gregorian leap years<br>';\r
+       \r
+       print  adodb_mktime(0,0,0,10,4,1582).' ';\r
+       print adodb_mktime(0,0,0,10,15,1582);\r
+       $diff = (adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582));\r
+       if ($diff != 3600*24) print " <b>Error in gregorian correction = ".($diff/3600/24)." days </b><br>";\r
+               \r
+       print " 15 Oct 1582, Fri=".(adodb_dow(1582,10,15) == 5 ? 'Fri' : '<b>Error</b>')."<br>";\r
+       print " 4 Oct 1582, Thu=".(adodb_dow(1582,10,4) == 4 ? 'Thu' : '<b>Error</b>')."<br>";\r
+       \r
+       print "<p>Testing overflow<p>";\r
+       \r
+       $t = adodb_mktime(0,0,0,3,33,1965);\r
+       if (!(adodb_date('Y-m-d',$t) == '1965-04-02')) print 'Error in day overflow 1 <br>';\r
+       $t = adodb_mktime(0,0,0,4,33,1971);\r
+       if (!(adodb_date('Y-m-d',$t) == '1971-05-03')) print 'Error in day overflow 2 <br>';\r
+       $t = adodb_mktime(0,0,0,1,60,1965);\r
+       if (!(adodb_date('Y-m-d',$t) == '1965-03-01')) print 'Error in day overflow 3 '.adodb_date('Y-m-d',$t).' <br>';\r
+       $t = adodb_mktime(0,0,0,12,32,1965);\r
+       if (!(adodb_date('Y-m-d',$t) == '1966-01-01')) print 'Error in day overflow 4 '.adodb_date('Y-m-d',$t).' <br>';\r
+       $t = adodb_mktime(0,0,0,12,63,1965);\r
+       if (!(adodb_date('Y-m-d',$t) == '1966-02-01')) print 'Error in day overflow 5 '.adodb_date('Y-m-d',$t).' <br>';\r
+       $t = adodb_mktime(0,0,0,13,3,1965);\r
+       if (!(adodb_date('Y-m-d',$t) == '1966-01-03')) print 'Error in mth overflow 1 <br>';\r
+       \r
+       print "Testing 2-digit => 4-digit year conversion<p>";\r
+       if (adodb_year_digit_check(00) != 2000) print "Err 2-digit 2000<br>";\r
+       if (adodb_year_digit_check(10) != 2010) print "Err 2-digit 2010<br>";\r
+       if (adodb_year_digit_check(20) != 2020) print "Err 2-digit 2020<br>";\r
+       if (adodb_year_digit_check(30) != 2030) print "Err 2-digit 2030<br>";\r
+       if (adodb_year_digit_check(40) != 1940) print "Err 2-digit 1940<br>";\r
+       if (adodb_year_digit_check(50) != 1950) print "Err 2-digit 1950<br>";\r
+       if (adodb_year_digit_check(90) != 1990) print "Err 2-digit 1990<br>";\r
+       \r
+       // Test string formating\r
+       print "<p>Testing date formating</p>";\r
+       $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C822 r s t U w y Y z Z 2003';\r
+       $s1 = date($fmt,0);\r
+       $s2 = adodb_date($fmt,0);\r
+       if ($s1 != $s2) {\r
+               print " date() 0 failed<br>$s1<br>$s2<br>";\r
+       }\r
+       flush();\r
+       for ($i=100; --$i > 0; ) {\r
+\r
+               $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000);\r
+               $s1 = date($fmt,$ts);\r
+               $s2 = adodb_date($fmt,$ts);\r
+               //print "$s1 <br>$s2 <p>";\r
+               $pos = strcmp($s1,$s2);\r
+\r
+               if (($s1) != ($s2)) {\r
+                       for ($j=0,$k=strlen($s1); $j < $k; $j++) {\r
+                               if ($s1[$j] != $s2[$j]) {\r
+                                       print substr($s1,$j).' ';\r
+                                       break;\r
+                               }\r
+                       }\r
+                       print "<b>Error date(): $ts<br><pre> \r
+&nbsp; \"$s1\" (date len=".strlen($s1).")\r
+&nbsp; \"$s2\" (adodb_date len=".strlen($s2).")</b></pre><br>";\r
+                       $fail = true;\r
+               }\r
+               \r
+               $a1 = getdate($ts);\r
+               $a2 = adodb_getdate($ts);\r
+               $rez = array_diff($a1,$a2);\r
+               if (sizeof($rez)>0) {\r
+                       print "<b>Error getdate() $ts</b><br>";\r
+                               print_r($a1);\r
+                       print "<br>";\r
+                               print_r($a2);\r
+                       print "<p>";\r
+                       $fail = true;\r
+               }\r
+       }\r
+       \r
+       // Test generation of dates outside 1901-2038\r
+       print "<p>Testing random dates between 100 and 4000</p>";\r
+       adodb_date_test_date(100,1);\r
+       for ($i=100; --$i >= 0;) {\r
+               $y1 = 100+rand(0,1970-100);\r
+               $m = rand(1,12);\r
+               adodb_date_test_date($y1,$m);\r
+               \r
+               $y1 = 3000-rand(0,3000-1970);\r
+               adodb_date_test_date($y1,$m);\r
+       }\r
+       print '<p>';\r
+       $start = 1960+rand(0,10);\r
+       $yrs = 12;\r
+       $i = 365.25*86400*($start-1970);\r
+       $offset = 36000+rand(10000,60000);\r
+       $max = 365*$yrs*86400;\r
+       $lastyear = 0;\r
+       \r
+       // we generate a timestamp, convert it to a date, and convert it back to a timestamp\r
+       // and check if the roundtrip broke the original timestamp value.\r
+       print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: ";\r
+       \r
+       for ($max += $i; $i < $max; $i += $offset) {\r
+               $ret = adodb_date('m,d,Y,H,i,s',$i);\r
+               $arr = explode(',',$ret);\r
+               if ($lastyear != $arr[2]) {\r
+                       $lastyear = $arr[2];\r
+                       print " $lastyear ";\r
+                       flush();\r
+               }\r
+               $newi = adodb_mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]);\r
+               if ($i != $newi) {\r
+                       print "Error at $i, adodb_mktime returned $newi ($ret)";\r
+                       $fail = true;\r
+                       break;\r
+               }\r
+       }\r
+       \r
+       if (!$fail) print "<p>Passed !</p>";\r
+       else print "<p><b>Failed</b> :-(</p>";\r
+}\r
+\r
+/**\r
+       Returns day of week, 0 = Sunday,... 6=Saturday. \r
+       Algorithm from PEAR::Date_Calc\r
+*/\r
+function adodb_dow($year, $month, $day)\r
+{\r
+/*\r
+Pope Gregory removed 10 days - October 5 to October 14 - from the year 1582 and \r
+proclaimed that from that time onwards 3 days would be dropped from the calendar \r
+every 400 years.\r
+\r
+Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 15, 1582 (Gregorian). \r
+*/\r
+       if ($year <= 1582) {\r
+               if ($year < 1582 || \r
+                       ($year == 1582 && ($month < 10 || ($month == 10 && $day < 15)))) $greg_correction = 3;\r
+                else\r
+                       $greg_correction = 0;\r
+       } else\r
+               $greg_correction = 0;\r
+       \r
+       if($month > 2)\r
+           $month -= 2;\r
+       else {\r
+           $month += 10;\r
+           $year--;\r
+       }\r
+       \r
+       $day =  ( floor((13 * $month - 1) / 5) +\r
+               $day + ($year % 100) +\r
+               floor(($year % 100) / 4) +\r
+               floor(($year / 100) / 4) - 2 *\r
+               floor($year / 100) + 77);\r
+       \r
+       return (($day - 7 * floor($day / 7))) + $greg_correction;\r
+}\r
+\r
+\r
+/**\r
+ Checks for leap year, returns true if it is. No 2-digit year check. Also \r
+ handles julian calendar correctly.\r
+*/\r
+function _adodb_is_leap_year($year) \r
+{\r
+       if ($year % 4 != 0) return false;\r
+       \r
+       if ($year % 400 == 0) {\r
+               return true;\r
+       // if gregorian calendar (>1582), century not-divisible by 400 is not leap\r
+       } else if ($year > 1582 && $year % 100 == 0 ) {\r
+               return false;\r
+       } \r
+       \r
+       return true;\r
+}\r
+\r
+/**\r
+ checks for leap year, returns true if it is. Has 2-digit year check\r
+*/\r
+function adodb_is_leap_year($year) \r
+{\r
+       return  _adodb_is_leap_year(adodb_year_digit_check($year));\r
+}\r
+\r
+/**\r
+       Fix 2-digit years. Works for any century.\r
+       Assumes that if 2-digit is more than 30 years in future, then previous century.\r
+*/\r
+function adodb_year_digit_check($y) \r
+{\r
+       if ($y < 100) {\r
+       \r
+               $yr = (integer) date("Y");\r
+               $century = (integer) ($yr /100);\r
+               \r
+               if ($yr%100 > 50) {\r
+                       $c1 = $century + 1;\r
+                       $c0 = $century;\r
+               } else {\r
+                       $c1 = $century;\r
+                       $c0 = $century - 1;\r
+               }\r
+               $c1 *= 100;\r
+               // if 2-digit year is less than 30 years in future, set it to this century\r
+               // otherwise if more than 30 years in future, then we set 2-digit year to the prev century.\r
+               if (($y + $c1) < $yr+30) $y = $y + $c1;\r
+               else $y = $y + $c0*100;\r
+       }\r
+       return $y;\r
+}\r
+\r
+/**\r
+ get local time zone offset from GMT\r
+*/\r
+function adodb_get_gmt_different() \r
+{\r
+static $DIFF;\r
+       if (isset($DIFF)) return $DIFF;\r
+       \r
+       $DIFF = mktime(0,0,0,1,2,1970) - gmmktime(0,0,0,1,2,1970);\r
+       return $DIFF;\r
+}\r
+\r
+/**\r
+       Returns an array with date info.\r
+*/\r
+function adodb_getdate($d=false,$fast=false)\r
+{\r
+       if ($d === false) return getdate();\r
+       if (!defined('ADODB_TEST_DATES')) {\r
+               if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range\r
+                       if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer\r
+                               return @getdate($d);\r
+               }\r
+       }\r
+       return _adodb_getdate($d);\r
+}\r
+\r
+/**\r
+       Low-level function that returns the getdate() array. We have a special\r
+       $fast flag, which if set to true, will return fewer array values,\r
+       and is much faster as it does not calculate dow, etc.\r
+*/\r
+function _adodb_getdate($origd=false,$fast=false,$is_gmt=false)\r
+{\r
+       $d =  $origd - ($is_gmt ? 0 : adodb_get_gmt_different());\r
+       \r
+       $_day_power = 86400;\r
+       $_hour_power = 3600;\r
+       $_min_power = 60;\r
+       \r
+       if ($d < -12219321600) $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction \r
+       \r
+       $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31);\r
+       $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31);\r
+       \r
+       if ($d < 0) {\r
+               $origd = $d;\r
+               // The valid range of a 32bit signed timestamp is typically from \r
+               // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT\r
+               for ($a = 1970 ; --$a >= 0;) {\r
+                       $lastd = $d;\r
+                       \r
+                       if ($leaf = _adodb_is_leap_year($a)) {\r
+                               $d += $_day_power * 366;\r
+                       } else\r
+                               $d += $_day_power * 365;\r
+                       if ($d >= 0) {\r
+                               $year = $a;\r
+                               break;\r
+                       }\r
+               }\r
+               \r
+               $secsInYear = 86400 * ($leaf ? 366 : 365) + $lastd;\r
+               \r
+               $d = $lastd;\r
+               $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal;\r
+               for ($a = 13 ; --$a > 0;) {\r
+                       $lastd = $d;\r
+                       $d += $mtab[$a] * $_day_power;\r
+                       if ($d >= 0) {\r
+                               $month = $a;\r
+                               $ndays = $mtab[$a];\r
+                               break;\r
+                       }\r
+               }\r
+               \r
+               $d = $lastd;\r
+               $day = $ndays + ceil(($d+1) / ($_day_power));\r
+\r
+               $d += ($ndays - $day+1)* $_day_power;\r
+               $hour = floor($d/$_hour_power);\r
+       \r
+       } else {\r
+       \r
+               for ($a = 1970 ;; $a++) {\r
+                       $lastd = $d;\r
+                       \r
+                       if ($leaf = _adodb_is_leap_year($a)) {\r
+                               $d -= $_day_power * 366;\r
+                       } else\r
+                               $d -= $_day_power * 365;\r
+                       if ($d <= 0) {\r
+                               $year = $a;\r
+                               break;\r
+                       }\r
+               }\r
+               $secsInYear = $lastd;\r
+               $d = $lastd;\r
+               $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal;\r
+               for ($a = 1 ; $a <= 12; $a++) {\r
+                       $lastd = $d;\r
+                       $d -= $mtab[$a] * $_day_power;\r
+                       if ($d <= 0) {\r
+                               $month = $a;\r
+                               $ndays = $mtab[$a];\r
+                               break;\r
+                       }\r
+               }\r
+               $d = $lastd;\r
+               $day = ceil(($d+1) / $_day_power);\r
+               $d = $d - ($day-1) * $_day_power;\r
+               $hour = floor($d /$_hour_power);\r
+       }\r
+       \r
+       $d -= $hour * $_hour_power;\r
+       $min = floor($d/$_min_power);\r
+       $secs = $d - $min * $_min_power;\r
+       if ($fast) {\r
+               return array(\r
+               'seconds' => $secs,\r
+               'minutes' => $min,\r
+               'hours' => $hour,\r
+               'mday' => $day,\r
+               'mon' => $month,\r
+               'year' => $year,\r
+               'yday' => floor($secsInYear/$_day_power),\r
+               'leap' => $leaf,\r
+               'ndays' => $ndays\r
+               );\r
+       }\r
+       \r
+       \r
+       $dow = adodb_dow($year,$month,$day);\r
+\r
+       return array(\r
+               'seconds' => $secs,\r
+               'minutes' => $min,\r
+               'hours' => $hour,\r
+               'mday' => $day,\r
+               'wday' => $dow,\r
+               'mon' => $month,\r
+               'year' => $year,\r
+               'yday' => floor($secsInYear/$_day_power),\r
+               'weekday' => gmdate('l',$_day_power*(3+$dow)),\r
+               'month' => gmdate('F',mktime(0,0,0,$month,2,1971)),\r
+               0 => $origd\r
+       );\r
+}\r
+\r
+function adodb_gmdate($fmt,$d=false)\r
+{\r
+       return adodb_date($fmt,$d,true);\r
+}\r
+\r
+\r
+/**\r
+       Return formatted date based on timestamp $d\r
+*/\r
+function adodb_date($fmt,$d=false,$is_gmt=false)\r
+{\r
+       if ($d === false) return date($fmt);\r
+       if (!defined('ADODB_TEST_DATES')) {\r
+               if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range\r
+                       if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer\r
+                               return @date($fmt,$d);\r
+               }\r
+       }\r
+       $_day_power = 86400;\r
+       \r
+       $arr = _adodb_getdate($d,true,$is_gmt);\r
+       $year = $arr['year'];\r
+       $month = $arr['mon'];\r
+       $day = $arr['mday'];\r
+       $hour = $arr['hours'];\r
+       $min = $arr['minutes'];\r
+       $secs = $arr['seconds'];\r
+       \r
+       $max = strlen($fmt);\r
+       $dates = '';\r
+       \r
+       /*\r
+               at this point, we have the following integer vars to manipulate:\r
+               $year, $month, $day, $hour, $min, $secs\r
+       */\r
+       for ($i=0; $i < $max; $i++) {\r
+               switch($fmt[$i]) {\r
+               case 'T': $dates .= date('T',100000);break;\r
+               // YEAR\r
+               case 'L': $dates .= $arr['leap'] ? '1' : '0'; break;\r
+               case 'r': // Thu, 21 Dec 2000 16:01:07 +0200\r
+               \r
+                       $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', '         \r
+                               . ($day<10?' '.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' ';\r
+                       \r
+                       if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; \r
+                       \r
+                       if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min;\r
+                       \r
+                       if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs;\r
+                       \r
+                       $gmt = adodb_get_gmt_different();\r
+                       $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break;\r
+                               \r
+               case 'Y': $dates .= $year; break;\r
+               case 'y': $dates .= substr($year,strlen($year)-2,2); break;\r
+               // MONTH\r
+               case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break;\r
+               case 'n': $dates .= $month; break;\r
+               case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break;\r
+               case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break;\r
+               // DAY\r
+               case 't': $dates .= $arr['ndays']; break;\r
+               case 'z': $dates .= $arr['yday']; break;\r
+               case 'w': $dates .= adodb_dow($year,$month,$day); break;\r
+               case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break;\r
+               case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break;\r
+               case 'j': $dates .= $day; break;\r
+               case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break;\r
+               case 'S': \r
+                       $d10 = $day % 10;\r
+                       if ($d10 == 1) $dates .= 'st';\r
+                       else if ($d10 == 2) $dates .= 'nd';\r
+                       else if ($d10 == 3) $dates .= 'rd';\r
+                       else $dates .= 'th';\r
+                       break;\r
+                       \r
+               // HOUR\r
+               case 'Z':\r
+                       $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_different(); break;\r
+               case 'O': \r
+                       $gmt = ($is_gmt) ? 0 : adodb_get_gmt_different();\r
+                       $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break;\r
+                       \r
+               case 'H': \r
+                       if ($hour < 10) $dates .= '0'.$hour; \r
+                       else $dates .= $hour; \r
+                       break;\r
+               case 'h': \r
+                       if ($hour > 12) $hh = $hour - 12; \r
+                       else {\r
+                               if ($hour == 0) $hh = '12'; \r
+                               else $hh = $hour;\r
+                       }\r
+                       \r
+                       if ($hh < 10) $dates .= '0'.$hh;\r
+                       else $dates .= $hh;\r
+                       break;\r
+                       \r
+               case 'G': \r
+                       $dates .= $hour;\r
+                       break;\r
+                       \r
+               case 'g':\r
+                       if ($hour > 12) $hh = $hour - 12; \r
+                       else {\r
+                               if ($hour == 0) $hh = '12'; \r
+                               else $hh = $hour; \r
+                       }\r
+                       $dates .= $hh;\r
+                       break;\r
+               // MINUTES\r
+               case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break;\r
+               // SECONDS\r
+               case 'U': $dates .= $d; break;\r
+               case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break;\r
+               // AM/PM\r
+               // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM\r
+               case 'a':\r
+                       if ($hour>=12) $dates .= 'pm';\r
+                       else $dates .= 'am';\r
+                       break;\r
+               case 'A':\r
+                       if ($hour>=12) $dates .= 'PM';\r
+                       else $dates .= 'AM';\r
+                       break;\r
+               default:\r
+                       $dates .= $fmt[$i]; break;\r
+               // ESCAPE\r
+               case "\\": \r
+                       $i++;\r
+                       if ($i < $max) $dates .= $fmt[$i];\r
+                       break;\r
+               }\r
+       }\r
+       return $dates;\r
+}\r
+\r
+/**\r
+       Returns a timestamp given a GMT/UTC time. \r
+       Note that $is_dst is not implemented and is ignored.\r
+*/\r
+function adodb_gmmktime($hr,$min,$sec,$mon,$day,$year,$is_dst=false)\r
+{\r
+       return adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst,true);\r
+}\r
+\r
+/**\r
+       Return a timestamp given a local time. Originally by jackbbs.\r
+       Note that $is_dst is not implemented and is ignored.\r
+*/\r
+function adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst=false,$is_gmt=false) \r
+{\r
+       if (!defined('ADODB_TEST_DATES')) {\r
+               // for windows, we don't check 1970 because with timezone differences, \r
+               // 1 Jan 1970 could generate negative timestamp, which is illegal\r
+               if (!defined('ADODB_NO_NEGATIVE_TS') || ($year >= 1971)) \r
+                       if (1901 < $year && $year < 2038)\r
+                               return @mktime($hr,$min,$sec,$mon,$day,$year);\r
+       }\r
+       \r
+       $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_different();\r
+       \r
+       $hr = intval($hr);\r
+       $min = intval($min);\r
+       $sec = intval($sec);\r
+       $mon = intval($mon);\r
+       $day = intval($day);\r
+       $year = intval($year);\r
+       \r
+       \r
+       $year = adodb_year_digit_check($year);\r
+       \r
+       if ($mon > 12) {\r
+               $y = floor($mon / 12);\r
+               $year += $y;\r
+               $mon -= $y*12;\r
+       }\r
+       \r
+       $_day_power = 86400;\r
+       $_hour_power = 3600;\r
+       $_min_power = 60;\r
+       \r
+       $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31);\r
+       $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31);\r
+       \r
+       $_total_date = 0;\r
+       if ($year >= 1970) {\r
+               for ($a = 1970 ; $a <= $year; $a++) {\r
+                       $leaf = _adodb_is_leap_year($a);\r
+                       if ($leaf == true) {\r
+                               $loop_table = $_month_table_leaf;\r
+                               $_add_date = 366;\r
+                       } else {\r
+                               $loop_table = $_month_table_normal;\r
+                               $_add_date = 365;\r
+                       }\r
+                       if ($a < $year) { \r
+                               $_total_date += $_add_date;\r
+                       } else {\r
+                               for($b=1;$b<$mon;$b++) {\r
+                                       $_total_date += $loop_table[$b];\r
+                               }\r
+                       }\r
+               }\r
+               $_total_date +=$day-1;\r
+               $ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different;\r
+       \r
+       } else {\r
+               for ($a = 1969 ; $a >= $year; $a--) {\r
+                       $leaf = _adodb_is_leap_year($a);\r
+                       if ($leaf == true) {\r
+                               $loop_table = $_month_table_leaf;\r
+                               $_add_date = 366;\r
+                       } else {\r
+                               $loop_table = $_month_table_normal;\r
+                               $_add_date = 365;\r
+                       }\r
+                       if ($a > $year) { $_total_date += $_add_date;\r
+                       } else {\r
+                               for($b=12;$b>$mon;$b--) {\r
+                                       $_total_date += $loop_table[$b];\r
+                               }\r
+                       }\r
+               }\r
+               $_total_date += $loop_table[$mon] - $day;\r
+               \r
+               $_day_time = $hr * $_hour_power + $min * $_min_power + $sec;\r
+               $_day_time = $_day_power - $_day_time;\r
+               $ret = -( $_total_date * $_day_power + $_day_time - $gmt_different);\r
+               if ($ret < -12220185600) $ret += 10*86400; // if earlier than 5 Oct 1582 - gregorian correction\r
+               else if ($ret < -12219321600) $ret = -12219321600; // if in limbo, reset to 15 Oct 1582.\r
+       } \r
+       //print " dmy=$day/$mon/$year $hr:$min:$sec => " .$ret;\r
+       return $ret;\r
+}\r
+\r
+?>\r
index dd54caa226140c236eb612fdaa7885b1386c3a0f..bf1dc5bb911327879fe7efeb3eaba2d446a35f84 100644 (file)
 <?php \r
 \r
-/** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
- * Released under both BSD license and Lesser GPL library license. \r
- * Whenever there is any discrepancy between the two licenses, \r
- * the BSD license will take precedence. \r
- *\r
- * Set tabs to 4 for best viewing.\r
- * \r
- * Latest version is available at http://php.weblogs.com\r
- * \r
- * This is the main include file for ADODB.\r
- * It has all the generic functionality of ADODB. \r
- * Database specific drivers are stored in the adodb-*.inc.php files.\r
- *\r
- * Requires PHP4.01pl2 or later because it uses include_once\r
-*/\r
-\r
- if (!defined('_ADODB_LAYER')) {\r
-       define('_ADODB_LAYER',1);\r
-       \r
-       //==============================================================================================        \r
-       // CONSTANT DEFINITIONS\r
-       //==============================================================================================        \r
-\r
-       define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>');\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
-       /*\r
-       Controls ADODB_FETCH_ASSOC field-name case. Default is 0, use lowercase names.\r
-       For maximum compatibility with other drivers, set to 2.\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
-       if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',0); \r
-       \r
-       // allow [ ] @ and . in table names\r
-       define('ADODB_TABLE_REGEX','([]0-9a-z_\.\@\[-]*)');\r
-       \r
-       if (!defined('MAX_BLOB_SIZE')) define('MAX_BLOB_SIZE',999999); // 900K\r
-       \r
-       if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);\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
-       if (strpos(strtoupper(PHP_OS),'WIN') !== false) {\r
-       // on windows, negative timestamps are illegal as of php 4.2.0\r
-               define('TIMESTAMP_FIRST_YEAR',1970);\r
-       } else\r
-               define('TIMESTAMP_FIRST_YEAR',1904);\r
-       \r
-       //==============================================================================================        \r
-       // GLOBAL VARIABLES\r
-       //==============================================================================================        \r
-\r
-       GLOBAL \r
-               $ADODB_vers,            // database version\r
-               $ADODB_Database,        // last database driver used\r
-               $ADODB_COUNTRECS,       // count number of records returned - slows down query\r
-               $ADODB_CACHE_DIR,       // directory to cache recordsets\r
-               $ADODB_FETCH_MODE;      // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...\r
-       \r
-       //==============================================================================================        \r
-       // GLOBAL SETUP\r
-       //==============================================================================================        \r
-       \r
-       $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;\r
-       \r
-       if (!isset($ADODB_CACHE_DIR)) {\r
-               $ADODB_CACHE_DIR = '/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
-       // CHANGE NOTHING BELOW UNLESS YOU ARE CODING\r
-       //==============================================================================================        \r
-\r
-       \r
-       // Initialize random number generator for randomizing cache flushes\r
-       srand(((double)microtime())*1000000);\r
-       \r
-       /**\r
-        * Name of last database driver loaded into memory. Set by ADOLoadCode().\r
-        */\r
-       $ADODB_Database = '';\r
-       \r
-       /**\r
-        * ADODB version as a string.\r
-        */\r
-       $ADODB_vers = 'V2.50 14 Nov 2002 (c) 2000-2002 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
-       $ADODB_COUNTRECS = true; \r
-\r
-       //==============================================================================================        \r
-       // CLASS ADOFieldObject\r
-       //==============================================================================================        \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
-       // 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\r
-       var $debug = false;             // if set to true will output sql statements\r
-       var $maxblobsize = 64000;       // maximum size of blobs or large text fields -- some databases die otherwise like foxpro\r
-       var $concat_operator = '+'; // default concat operator -- change to || for Oracle/Interbase     \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 $hasInsertID = false;       // supports autoincrement ID?\r
-       var $hasAffectedRows = false;   // supports affected rows for update/delete?\r
-       var $charSet=false;             // character set to use - only for interbase\r
-       var $metaTablesSQL = '';\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 $genID = 0;                         // sequence id used by GenID();\r
-       var $raiseErrorFn = false;      // error function to call\r
-       var $upperCase = false;         // uppercase function to call for searching/where\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';\r
-       \r
-       var $noNullStrings = false; // oracle specific stuff\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;\r
-       var $autoRollback = false; // autoRollback on PConnect().\r
-       \r
-       /*\r
-        * PRIVATE VARS\r
-        */\r
-       var $_connectionID      = false;        // The returned link identifier whenever a successful database connection is made.      */\r
-               \r
-       var $_errorMsg = '';            // A variable which was used to keep the returned last error message.  The value will\r
-                                       //then returned by the errorMsg() function      \r
-                                               \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
-       \r
-       var $_bindInputArray = false; // set to true if ADOConnection.Execute() permits binding of array parameters.\r
-       \r
-       var $autoCommit = true;         // do not modify this yourself - actually private\r
-       \r
-       var $transOff = false; // temporarily disable transactions\r
-       \r
-       var $transCnt = 0;      // count of nested transactions\r
-       /**\r
-        * Constructor\r
-        */\r
-       function ADOConnection()                        \r
-       {\r
-               die('Virtual Class -- cannot instantiate');\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
-       function outp($msg,$newline=true)\r
-       {\r
-       global $HTTP_SERVER_VARS;\r
-       \r
-               if (defined('ADODB_OUTP')) {\r
-                       $fn = ADODB_OUTP;\r
-                       $fn($msg,$newline);\r
-                       return;\r
-               }\r
-               \r
-               if ($newline) $msg .= "<br>\n";\r
-               \r
-               if (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) echo $msg;\r
-               else echo strip_tags($msg);\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
-        *\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 ($fn = $this->raiseErrorFn) {\r
-                       if ($forceNew) {\r
-                               if ($this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
-                       } else {\r
-                                if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true;\r
-                       }\r
-                       $err = $this->ErrorMsg();\r
-                       if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";\r
-                       $fn($this->databaseType,'CONNECT',$this->ErrorNo(),$err,$this->host,$this->database);\r
-               } else {\r
-                       if ($forceNew) {\r
-                               if ($this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
-                       } else {\r
-                               if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true;\r
-                       }\r
-               }\r
-               if ($this->debug) ADOConnection::outp( $this->host.': '.$this->ErrorMsg());\r
-               \r
-               return false;\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 ($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
-               \r
-               if ($fn = $this->raiseErrorFn) {\r
-                       if ($this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
-                       $err = $this->ErrorMsg();\r
-                       if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";\r
-                       $fn($this->databaseType,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database);\r
-               } else \r
-                       if ($this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
-\r
-               if ($this->debug) ADOConnection::outp( $this->host.': '.$this->ErrorMsg());\r
-               \r
-               return false;\r
-       }\r
-/*\r
-       function UnixDate($d)\r
-       {\r
-               return ADORecordSet::UnixDate($d);\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)\r
-       {\r
-               return $this->Prepare($sql);\r
-       }\r
-       \r
-       /**\r
-       * PEAR DB Compat - Quote with auto-checking of magic-quotes-gpc.\r
-       */\r
-       function Quote($s)\r
-       {\r
-               return $this->qstr($s,get_magic_quotes_gpc());\r
-       }\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
-       function SetFetchMode($mode)\r
-       {\r
-       global $ADODB_FETCH_MODE;\r
-               $ADODB_FETCH_MODE = $mode;\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)\r
-       {\r
-               $rs = &$this->SelectLimit($sql, $count, $offset); // swap \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
-       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
-        * 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
-        * @param [arg3]        reserved for john lim for future use\r
-        * @return              RecordSet or false\r
-        */\r
-       function &Execute($sql,$inputarr=false,$arg3=false) \r
-       {\r
-               if (!$this->_bindInputArray && $inputarr) {\r
-                       $sqlarr = explode('?',$sql);\r
-                       $sql = '';\r
-                       $i = 0;\r
-                       foreach($inputarr as $v) {\r
-\r
-                               $sql .= $sqlarr[$i];\r
-                               // from Ron Baldwin <ron.baldwin@sourceprose.com>\r
-                               // Only quote string types      \r
-                               if (gettype($v) == 'string')\r
-                                       $sql .= $this->qstr($v);\r
-                               else if ($v === null)\r
-                                       $sql .= 'NULL';\r
-                               else\r
-                                       $sql .= $v;\r
-                               $i += 1;\r
-       \r
-                       }\r
-                       $sql .= $sqlarr[$i];\r
-                       if ($i+1 != sizeof($sqlarr))    \r
-                               ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql));\r
-                       $inputarr = false;\r
-               }\r
-               \r
-               // debug version of query\r
-               if ($this->debug) {\r
-               global $HTTP_SERVER_VARS;\r
-               \r
-                       $ss = '';\r
-                       if ($inputarr) {\r
-                               foreach ($inputarr as $kk => $vv)  {\r
-                                       if (is_string($vv) && strlen($vv)>64) $vv = substr($vv,0,64).'...';\r
-                                       $ss .= "($kk=>'$vv') ";\r
-                               }\r
-                               $ss = "[ $ss ]";\r
-                       }\r
-                       if (is_array($sql)) $sqlTxt = $sql[0];\r
-                       else $sqlTxt = $sql;\r
-                       \r
-                       // check if running from browser or command-line\r
-                       $inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']);\r
-                       \r
-                       if ($inBrowser)\r
-                               ADOConnection::outp( "<hr />\n($this->databaseType): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<hr />\n",false);\r
-                       else\r
-                               ADOConnection::outp(  "=----\n($this->databaseType): ".($sqlTxt)." \n-----\n",false);\r
-                       flush();\r
-                       \r
-                       $this->_queryID = $this->_query($sql,$inputarr,$arg3);\r
-\r
-                       /* \r
-                               Alexios Fakios notes that ErrorMsg() must be called before ErrorNo() for mssql\r
-                               because ErrorNo() calls Execute('SELECT @ERROR'), causing recure\r
-                       */\r
-                       if ($this->databaseType == 'mssql') { \r
-                       // ErrorNo is a slow function call in mssql, and not reliable\r
-                       // in PHP 4.0.6\r
-                               if($emsg = $this->ErrorMsg()) {\r
-                                       $err = $this->ErrorNo();\r
-                                       if ($err) {\r
-                                               ADOConnection::outp($err.': '.$emsg);\r
-                                               flush();\r
-                                       }\r
-                               }\r
-                       } else \r
-                               if (!$this->_queryID) {\r
-                                       ADOConnection::outp( $this->ErrorNo().': '.$this->ErrorMsg() );\r
-                                       flush();\r
-                               }\r
-               } else \r
-                       // non-debug version of query\r
-                       $this->_queryID =@$this->_query($sql,$inputarr,$arg3);\r
-               \r
-               // error handling if query fails\r
-               if ($this->_queryID === false) {\r
-                       $fn = $this->raiseErrorFn;\r
-                       if ($fn) {\r
-                               $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr);\r
-                       }\r
-                       return false;\r
-               } else if ($this->_queryID === true){\r
-               // return simplified empty 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 = "ADORecordSet_".$this->databaseType;\r
-               $rs = new $rsclass($this->_queryID); // &new not supported by older PHP versions\r
-               $rs->connection = &$this; // Pablo suggestion\r
-               $rs->Init();\r
-\r
-               if (is_array($sql)) $rs->sql = $sql[0];\r
-               else $rs->sql = $sql;\r
-               \r
-               global $ADODB_COUNTRECS;\r
-               if ($rs->_numOfRows <= 0 && $ADODB_COUNTRECS) {\r
-                       if (!$rs->EOF){ \r
-                               $rs = &$this->_rs2rs($rs);\r
-                               $rs->_queryID = $this->_queryID;\r
-                       } else\r
-                               $rs->_numOfRows = 0;\r
-               }\r
-               return $rs;\r
-       }\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
-        * @seqname             name of sequence to use\r
-        * @startID             if sequence does not exist, start at this ID\r
-        * @return              0 if not supported, otherwise a sequence id\r
-        */\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
-               $rs = @$this->Execute($getnext);\r
-               if (!$rs) {\r
-                       $u = strtoupper($seqname);\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
-        * @return  the last inserted ID. Not all databases support this.\r
-        */ \r
-               function Insert_ID()\r
-               {\r
-                               if ($this->hasInsertID) return $this->_insertid();\r
-                               if ($this->debug) ADOConnection::outp( '<p>Insert_ID error</p>');\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();\r
-                  } else {\r
-                          return $this->GetOne("SELECT MAX($id) FROM $table");\r
-                  }\r
-               }       \r
-       \r
-               \r
-        /**\r
-        * @return  # rows affected by UPDATE/DELETE\r
-        */ \r
-        function Affected_Rows()\r
-        {\r
-                 if ($this->hasAffectedRows) {\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
-               return '!! '.strtoupper($this->dataProvider.' '.$this->databaseType).': '.$this->_errorMsg;\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
-       \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
-               return false;\r
-       }\r
-       \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 [rows]         is the number of rows to get\r
-       * @param [inputarr]     array of bind variables\r
-       * @param [arg3]         is a private parameter only used by jlim\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,$arg3=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) return $this->CacheExecute($secs2cache, $sql,$inputarr,$arg3);\r
-                                               else return $this->Execute($sql,$inputarr,$arg3);\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,$arg3);\r
-                       else $rs = &$this->Execute($sql,$inputarr,$arg3);\r
-               } else {\r
-                       if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr,$arg3);\r
-                       else $rs = &$this->Execute($sql,$inputarr,$arg3);\r
-               }\r
-               $ADODB_COUNTRECS = $savec;\r
-               \r
-               if ($rs && !$rs->EOF) {\r
-                       return $this->_rs2rs($rs,$nrows,$offset);\r
-               }\r
-               //print_r($rs);\r
-               return $rs;\r
-       }\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)\r
-       {\r
-               if (! $rs) return false;\r
-               if ($rs->databaseType == 'array' && $nrows == -1 && $offset == -1) {\r
-                       $rs->MoveFirst();\r
-                       $rs = &$rs; // required to prevent crashing in 4.2.1-- why ?\r
-                       return $rs;\r
-               }\r
-               $arr = &$rs->GetArrayLimit($nrows,$offset);\r
-               $flds = array();\r
-               for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)\r
-                       $flds[] = &$rs->FetchField($i);\r
-               $rs->Close();\r
-               \r
-               $arrayClass = $this->arrayClass;\r
-               \r
-               $rs2 = new $arrayClass();\r
-               $rs2->connection = &$this;\r
-               $rs2->sql = $rs->sql;\r
-               $rs2->InitArrayFields($arr,$flds);\r
-               return $rs2;\r
-       }\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
-               $ret = false;\r
-               $rs = &$this->Execute($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 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)\r
-       {\r
-               $rv = false;\r
-               $rs = &$this->Execute($sql, $inputarr);\r
-               if ($rs) {\r
-                       while (!$rs->EOF) {\r
-                               $rv[] = reset($rs->fields);\r
-                               $rs->MoveNext();\r
-                       }\r
-                       $rs->Close();\r
-               }\r
-               return $rv;\r
-       }\r
-       \r
-       function CacheGetCol($secs, $sql, $inputarr = false)\r
-       {\r
-               $rv = false;\r
-               $rs = &$this->CacheExecute($secs, $sql, $inputarr);\r
-               if ($rs) {\r
-                       while (!$rs->EOF) {\r
-                               $rv[] = reset($rs->fields);\r
-                               $rs->MoveNext();\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
-       * Return all rows. Compat with PEAR DB\r
-       *\r
-       * @param sql                    SQL statement\r
-       * @param [inputarr]             input bind array\r
-       */\r
-       function GetAll($sql,$inputarr=false)\r
-       {\r
-               $rs = $this->Execute($sql,$inputarr);\r
-               if (!$rs) \r
-                       if (defined('ADODB_PEAR')) return ADODB_PEAR_Error();\r
-                       else return false;\r
-               $arr = $rs->GetArray();\r
-               $rs->Close();\r
-               return $arr;\r
-       }\r
-       \r
-       function CacheGetAll($secs2cache,$sql=false,$inputarr=false)\r
-       {\r
-               $rs = $this->CacheExecute($secs2cache,$sql,$inputarr);\r
-               if (!$rs) \r
-                       if (defined('ADODB_PEAR')) return ADODB_PEAR_Error();\r
-                       else return false;\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
-               $rs = $this->Execute($sql,$inputarr);\r
-               if ($rs) {\r
-                       $arr = false;\r
-                       if (!$rs->EOF) $arr = $rs->fields;\r
-                       $rs->Close();\r
-                       return $arr;\r
-               }\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
-               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
-       *\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
-               if (count($fieldArray) == 0) return 0;\r
-               $first = true;\r
-               $uSet = '';\r
-               \r
-               if (!is_array($keyCol)) {\r
-                       $keyCol = array($keyCol);\r
-               }\r
-               foreach($fieldArray as $k => $v) {\r
-                       if ($autoQuote && !is_numeric($v) and $v[0] != "'" and strcasecmp($v,'null')!=0) {\r
-                               $v = $this->qstr($v);\r
-                               $fieldArray[$k] = $v;\r
-                       }\r
-                       if (in_array($k,$keyCol)) continue; // skip UPDATE if is key\r
-                       \r
-                       if ($first) {\r
-                               $first = false;                 \r
-                               $uSet = "$k=$v";\r
-                       } else\r
-                               $uSet .= ",$k=$v";\r
-               }\r
-                \r
-               $first = true;\r
-               foreach ($keyCol as $v) {\r
-                       if ($first) {\r
-                               $first = false;\r
-                               $where = "$v=$fieldArray[$v]";\r
-                       } else {\r
-                               $where .= " and $v=$fieldArray[$v]";\r
-                       }\r
-               }\r
-               \r
-               if ($uSet) {\r
-                       $update = "UPDATE $table SET $uSet WHERE $where";\r
-               \r
-                       $rs = $this->Execute($update);\r
-                       if ($rs && ($this->Affected_Rows()>0)) return 1;\r
-                       \r
-                       if ($this->dataProvider == 'mysql') {\r
-                       # affected_rows == 0 if update field values identical to old values\r
-                       # for mysql - which is silly.\r
-                               $cnt = $this->GetOne("select count(*) from $table where $where");\r
-                               if ($cnt > 0) return 1; // record already exists\r
-                       }\r
-               }\r
-       //      print "<p>Error=".$this->ErrorNo().'<p>';\r
-               $first = true;\r
-               foreach($fieldArray as $k => $v) {\r
-                       if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col\r
-                       \r
-                       if ($first) {\r
-                               $first = false;                 \r
-                               $iCols = "$k";\r
-                               $iVals = "$v";\r
-                       } else {\r
-                               $iCols .= ",$k";\r
-                               $iVals .= ",$v";\r
-                       }                               \r
-               }\r
-               $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)"; \r
-               $rs = $this->Execute($insert);\r
-               return ($rs) ? 2 : 0;\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
-       * @param [arg3]         is a private parameter only used by jlim\r
-       * @return               the recordset ($rs->databaseType == 'array')\r
-       */\r
-       function &CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false, $arg3=false)\r
-       {       \r
-               if (!is_numeric($secs2cache)) {\r
-                       if ($sql === false) $sql = -1;\r
-                       if ($offset == -1) $offset = false;\r
-                                                                         // sql,       nrows, offset,inputarr,arg3\r
-                       return $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$inputarr,$this->cacheSecs);\r
-               } else {\r
-                       if ($sql === false) ADOConnection::outp( "Warning: \$sql missing from CacheSelectLimit()");\r
-                       return $this->SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);\r
-               }\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)\r
-       {\r
-       global $ADODB_CACHE_DIR;\r
-       \r
-               if (!$sql) {\r
-                       if (strpos(strtoupper(PHP_OS),'WIN') !== false) {\r
-                               $cmd = 'del /s '.str_replace('/','\\',$ADODB_CACHE_DIR).'\adodb_*.cache';\r
-                       } else {\r
-                               $cmd = '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
-               $f = $this->_gencachename($sql,false);\r
-               adodb_write_file($f,''); // is adodb_write_file needed?\r
-               @unlink($f);\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
-       *\r
-       * 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
-               \r
-               $m = md5($sql.$this->databaseType.$this->database.$this->user);\r
-               $dir = $ADODB_CACHE_DIR.'/'.substr($m,0,2);\r
-               if ($createdir)\r
-                       if(!file_exists($dir) && !mkdir($dir,0771)) \r
-                               if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql");\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
-        * @param [arg3]        reserved for john lim for future use\r
-        * @return              RecordSet or false\r
-        */\r
-       function &CacheExecute($secs2cache,$sql=false,$inputarr=false,$arg3=false)\r
-       {\r
-               if (!is_numeric($secs2cache)) {\r
-                       $arg3 = $inputarr;\r
-                       $inputarr = $sql;\r
-                       $sql = $secs2cache;\r
-                       $secs2cache = $this->cacheSecs;\r
-               }\r
-               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);\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
-                               ADOConnection::outp( " $md5file cache failure: $err (see sql below)");\r
-                       }\r
-                       $rs = &$this->Execute($sql,$inputarr,$arg3);\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);\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
-               // ok, set cached object found\r
-                       $rs->connection = &$this; // Pablo suggestion\r
-                       if ($this->debug){ \r
-                       global $HTTP_SERVER_VARS;\r
-                               \r
-                               $inBrowser = isset($HTTP_SERVER_VARS['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
-        * 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)\r
-       {\r
-               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq);\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)\r
-       {       \r
-               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_getinsertsql($this,$rs,$arrFields,$magicq);\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
-       /**\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
-       \r
-       /**\r
-        *  @meta       contains the desired type, which could be...\r
-        *      C for character. You will have to define the precision yourself.\r
-        *      X for teXt. For unlimited character lengths.\r
-        *      B for Binary\r
-        *  F for floating point, with no need to define scale and precision\r
-        *      N for decimal numbers, you will have to define the (scale, precision) yourself\r
-        *      D for date\r
-        *      T for timestamp\r
-        *      L for logical/Boolean\r
-        *      I for integer\r
-        *      R for autoincrement counter/integer\r
-        *  and if you want to use double-byte, add a 2 to the end, like C2 or X2.\r
-        * \r
-        *\r
-        * @return the actual type of the data or false if no such type available\r
-       */\r
-       function ActualType($meta)\r
-       {\r
-               switch($meta) {\r
-               case 'C':\r
-               case 'X':\r
-                       return 'VARCHAR';\r
-               case 'B':\r
-                       \r
-               case 'D':\r
-               case 'T':\r
-               case 'L':\r
-               \r
-               case 'R':\r
-                       \r
-               case 'I':\r
-               case 'N':\r
-                       return false;\r
-               }\r
-       }\r
-\r
-       /*\r
-       * Maximum size of C field\r
-       */\r
-       function CharMax()\r
-       {\r
-               return 255; // make it conservative if not defined\r
-       }\r
-       \r
-       \r
-       /*\r
-       * Maximum size of X field\r
-       */\r
-       function TextMax()\r
-       {\r
-               return 4000; // make it conservative if not defined\r
-       }\r
-       \r
-       /**\r
-        * Close Connection\r
-        */\r
-       function Close() \r
-       {\r
-               return $this->_close();\r
-               \r
-               // "Simon Lee" <simon@mediaroad.com> reports that persistent connections need \r
-               // to be closed too!\r
-               //if ($this->_isPersistentConnection != true) return $this->_close();\r
-               //else return true;     \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
-               {return false;}\r
-               \r
-       /**\r
-        * @return  array of tables for current database.\r
-        */ \r
-       function MetaTables() \r
-       {\r
-       global $ADODB_FETCH_MODE;\r
-       \r
-               if ($this->metaTablesSQL) {\r
-                       $save = $ADODB_FETCH_MODE; \r
-                       $ADODB_FETCH_MODE = ADODB_FETCH_NUM; \r
-                       $rs = $this->Execute($this->metaTablesSQL);\r
-                       $ADODB_FETCH_MODE = $save; \r
-                       \r
-                       if ($rs === false) return false;\r
-                       $arr = $rs->GetArray();\r
-                       $arr2 = array();\r
-                       for ($i=0; $i < sizeof($arr); $i++) {\r
-                               $arr2[] = $arr[$i][0];\r
-                       }\r
-                       $rs->Close();\r
-                       return $arr2;\r
-               }\r
-               return false;\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
-        * @params table        table name to query\r
-        * @params upper        uppercase table name (required by some 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
-               if (!empty($this->metaColumnsSQL)) {\r
-                       $save = $ADODB_FETCH_MODE;\r
-                       $ADODB_FETCH_MODE = ADODB_FETCH_NUM;\r
-                       $rs = $this->Execute(sprintf($this->metaColumnsSQL,($upper)?strtoupper($table):$table));\r
-                       $ADODB_FETCH_MODE = $save;\r
-                       if ($rs === false) 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
-                               $fld->max_length = $rs->fields[2];\r
-                               $retarr[strtoupper($fld->name)] = $fld; \r
-                               \r
-                               $rs->MoveNext();\r
-                       }\r
-                       $rs->Close();\r
-                       return $retarr; \r
-               }\r
-               return false;\r
-       }\r
-       \r
-       /**\r
-        * List columns names in a table as an array. \r
-        * @params table        table name to query\r
-        *\r
-        * @return  array of column names for current table.\r
-        */ \r
-       function MetaColumnNames($table) \r
-       {\r
-               $objarr = $this->MetaColumns($table);\r
-               if (!is_array($objarr)) return false;\r
-               \r
-               $arr = array();\r
-               foreach($objarr as $v) {\r
-                       $arr[] = $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
-       \r
-               if (empty($d) && $d !== 0) return 'null';\r
-\r
-               if (is_string($d) && !is_numeric($d)) \r
-                       if ($this->isoDates) return "'$d'";\r
-                       else $d = ADOConnection::UnixDate($d);\r
-               \r
-               return 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
-               if (is_string($ts) && !is_numeric($ts)) \r
-                       if ($this->isoDates) return "'$ts'";\r
-                       else $ts = ADOConnection::UnixTimeStamp($ts);\r
-               return 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 (!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 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 (!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
-               if ($rr[1] <= TIMESTAMP_FIRST_YEAR && $rr[2]<= 1) return 0;\r
-       \r
-               // h-m-s-MM-DD-YY\r
-               return  @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')\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 date($fmt,$tt);\r
-       \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
-       $nofixquotes=false;\r
-               if (!$magic_quotes) {\r
-               \r
-                       if ($this->replaceQuote[0] == '\\'){\r
-                               $s = 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 [arg3]         is a private parameter only used by jlim\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, $arg3=false, $secs2cache=0) \r
-       {\r
-               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               if ($this->pageExecuteCountRows) return _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $arg3, $secs2cache);\r
-               return _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $arg3, $secs2cache);\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
-       * @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
-       * @param [arg3]         is a private parameter only used by jlim\r
-       * @return               the recordset ($rs->databaseType == 'array')\r
-       */\r
-       function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false, $arg3=false) \r
-       {\r
-               return $this->PageExecute($sql,$nrows,$page,$inputarr,$arg3,$secs2cache);\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 $EOF = true;\r
-               var $_numOfRows = 0;\r
-               var $fields = 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
-       }\r
-       \r
-       //==============================================================================================        \r
-       // CLASS ADORecordSet\r
-       //==============================================================================================        \r
-       \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 {\r
-       /*\r
-        * public variables     \r
-        */\r
-       var $dataProvider = "native";\r
-       var $fields = false;    // holds the current row data\r
-       var $blobSize = 64;     // any varchar/char field this size or greater is treated as a blob\r
-                                                       // in other words, we use a text area for editting.\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
-       /**\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
-       }\r
-       \r
-       \r
-       \r
-       function Init()\r
-       {\r
-               if ($this->_inited) return;\r
-               $this->_inited = true;\r
-               \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
-                       $this->_currentRow = 0;\r
-                       $this->EOF = ($this->_fetch() === false);\r
-               } else  \r
-                       $this->EOF = true;\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Generate a <SELECT> 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>\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>.\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
-               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
-        * Generate a <SELECT> 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
-               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_getmenu($this,$name,$defstr,$blank1stItem,$multiple,\r
-                       $size, $selectAttr,false);\r
-       }\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
-               $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
-       * 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) return $this->GetArray($nrows);\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
-               return $this->GetArray($nRows);\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
-               $cols = $this->_numOfFields;\r
-               if ($cols < 2) {\r
-                       return false;\r
-               }\r
-               $numIndex = isset($this->fields[0]);\r
-               $results = array();\r
-               \r
-               if (!$first2cols && ($cols > 2 || $force_array)) {\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
-               } else {\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
-                                       $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
-               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
-               $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
-               \r
-               return 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 date($fmt,$tt);\r
-       \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
-               if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|", \r
-                       ($v), $rr)) return false;\r
-                       \r
-               if ($rr[1] <= 1903) return 0;\r
-               // h-m-s-MM-DD-YY\r
-               return mktime(0,0,0,$rr[2],$rr[3],$rr[1]);\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
-               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
-               if ($rr[1] <= 1903 && $rr[2]<= 1) return 0;\r
-       \r
-               // h-m-s-MM-DD-YY\r
-               return  @mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]);\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) return false;\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
-                               while (!$this->EOF) $this->MoveNext();\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
-        * 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
-               if ($rowNumber == $this->_currentRow) return true;\r
-               if ($rowNumber > $this->_numOfRows)\r
-                       if ($this->_numOfRows != -1) $rowNumber = $this->_numOfRows-1;\r
-   \r
-               if ($this->canSeek) {\r
-                       if ($this->_seek($rowNumber)) {\r
-                               $this->_currentRow = $rowNumber;\r
-                               if ($this->_fetch()) {\r
-                                       $this->EOF = false;     \r
-                                                                  //  $this->_currentRow += 1;                 \r
-                                       return true;\r
-                               }\r
-                       } else \r
-                               return false;\r
-               } else {\r
-                       if ($rowNumber < $this->_currentRow) return false;\r
-                       while (! $this->EOF && $this->_currentRow < $rowNumber) {\r
-                               $this->_currentRow++;\r
-                               if (!$this->_fetch()) $this->EOF = true;\r
-                       }\r
-                       return !($this->EOF);\r
-               }\r
-               \r
-               $this->fields = null;   \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
-       \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
-        \r
-               if (!$this->bind) {\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
-               $record = array();\r
-               foreach($this->bind as $k => $v) {\r
-                       $record[$k] = $this->fields[$v];\r
-               }\r
+/*\r
+ * Set tabs to 4 for best viewing.\r
+ * \r
+ * Latest version is available at http://php.weblogs.com\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
-               return $record;\r
-       }\r
+/**\r
+       \mainpage       \r
        \r
+        @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim\@natsoft.com.my). All rights reserved.\r
+\r
+       Released under both BSD license and Lesser GPL library license. \r
+       Whenever there is any discrepancy between the two licenses, \r
+       the BSD license will take precedence. \r
        \r
-       /**\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
+       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,\r
+       Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access,\r
+        ADO and ODBC. We have had successful reports of connecting to Progress and DB2 via ODBC. \r
+        We hope more people will contribute drivers to support other databases.\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
-        * 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
+       // CONSTANT DEFINITIONS\r
+       //==============================================================================================        \r
+\r
+       define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>');\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
        /*\r
-       * If we are using PageExecute(), this will return the maximum possible rows\r
-       * that can be returned when paging a recordset.\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
-       function MaxRecordCount()\r
-       {\r
-               return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount();\r
-       }\r
+       if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);\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
+       // allow [ ] @ ` and . in table names\r
+       define('ADODB_TABLE_REGEX','([]0-9a-z_\`\.\@\[-]*)');\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
+       if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);\r
+\r
+       /** \r
+        * Set ADODB_DIR to the directory where this file resides...\r
+        * This constant was formerly called $ADODB_RootPath\r
         */\r
-       function CurrentRow() {return $this->_currentRow;}\r
+       if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));\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
+       define('TIMESTAMP_FIRST_YEAR',100);\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
+       // GLOBAL VARIABLES\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
+       GLOBAL \r
+               $ADODB_vers,            // database version\r
+               $ADODB_Database,        // last database driver used\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_PATCH, // 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
-        * 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
+       // GLOBAL SETUP\r
+       //==============================================================================================        \r
        \r
-       /**\r
-       * Return the fields array of the current row as an object for convenience.\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
-               $o = &$this->_obj;\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
+       if (strnatcmp(PHP_VERSION,'4.3.0')>=0) {\r
+               define('ADODB_PHPVER',0x4300);\r
+       } else if (strnatcmp(PHP_VERSION,'4.2.0')>=0) {\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
+       $ADODB_EXTENSION = defined('ADODB_EXTENSION');\r
+       //if (extension_loaded('dbx')) define('ADODB_DBX',1);\r
+       \r
        /**\r
-       * Return the fields array of the current row as an object for convenience.\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
+               Accepts $src and $dest arrays, replacing string $data\r
        */\r
-       function &FetchNextObject($isupper=true)\r
+       function ADODB_str_replace($src, $dest, $data)\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
+               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
-               $this->EOF = true;\r
-               return $o;\r
+               return $data;\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 < 200 chars\r
-        *      X for teXt (>= 200 chars)\r
-        *      B for Binary\r
-        *      N for numeric 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
+       function ADODB_Setup()\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
-               ##\r
-               'LONGCHAR' => 'X',\r
-               'TEXT' => 'X',\r
-               'M' => 'X',\r
-               'X' => 'X',\r
-               'CLOB' => 'X',\r
-               'NCLOB' => 'X',\r
-               'LONG' => 'X',\r
-               'LVARCHAR' => 'X',\r
-               ##\r
-               'BLOB' => 'B',\r
-               'NTEXT' => 'B',\r
-               'BINARY' => 'B',\r
-               'VARBINARY' => 'B',\r
-               'LONGBINARY' => 'B',\r
-               'B' => 'B',\r
-               ##\r
-               'DATE' => 'D',\r
-               'D' => 'D',\r
-               ##\r
-               'TIME' => 'T',\r
-               'TIMESTAMP' => 'T',\r
-               'DATETIME' => 'T',\r
-               'TIMESTAMPTZ' => 'T',\r
-               'T' => 'T',\r
-               ##\r
-               'BOOLEAN' => 'L', \r
-               'BIT' => 'L',\r
-               'L' => 'L',\r
-               ##\r
-               'COUNTER' => 'R',\r
-               'R' => 'R',\r
-               'SERIAL' => 'R', // ifx\r
-               ##\r
-               'INT' => 'I',\r
-               'INTEGER' => 'I',\r
-               'SHORT' => 'I',\r
-               'TINYINT' => 'I',\r
-               'SMALLINT' => 'I',\r
-               'I' => 'I',\r
-               ##\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
-               \r
+       GLOBAL \r
+               $ADODB_vers,            // database version\r
+               $ADODB_Database,        // last database driver used\r
+               $ADODB_COUNTRECS,       // count number of records returned - slows down query\r
+               $ADODB_CACHE_DIR,       // directory to cache recordsets\r
+               $ADODB_FETCH_MODE;\r
                \r
-               $tmap = false;\r
-               $tmap = @$typeMap[strtoupper($t)];\r
-               switch ($tmap) {\r
-               case 'C':\r
-                       if (!empty($this)) {\r
-                               if ($len <= $this->blobSize) return 'C';\r
-                       } else if ($len <= 250) {\r
-                               return 'C';\r
-                       }\r
-                       // ok, the char field is too long, return as text field... \r
-                       return 'X';\r
-                       \r
-               case 'I':\r
-                       if (!empty($fieldobj->primary_key)) return 'R';\r
-                       return 'I';\r
+               $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;\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
-               default: return $tmap;\r
+               if (!isset($ADODB_CACHE_DIR)) {\r
+                       $ADODB_CACHE_DIR = '/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
-       function oldMetaType($t,$len=-1,$fieldobj=false)\r
-       {\r
-               switch (strtoupper($t)) {\r
-               case 'VARCHAR':\r
-               case 'VARCHAR2':\r
-               case 'CHAR':\r
-               case 'STRING':\r
-               case 'C':\r
-               case 'NCHAR':\r
-               case 'NVARCHAR':\r
-               case 'VARYING':\r
-               case 'BPCHAR':\r
-               case 'CHARACTER':\r
-                       if (!empty($this)) if ($len <= $this->blobSize) return 'C';\r
-                       else if ($len <= 250) return 'C';\r
-               \r
-               case 'LONGCHAR':\r
-               case 'TEXT':\r
-               case 'M':\r
-               case 'X':\r
-               case 'CLOB':\r
-               case 'NCLOB':\r
-               case 'LONG':\r
-                       return 'X';\r
                \r
-               case 'BLOB':\r
-               case 'NTEXT':\r
-               case 'BINARY':\r
-               case 'VARBINARY':\r
-               case 'LONGBINARY':\r
-               case 'B':\r
-                       return 'B';\r
                        \r
-               case 'DATE':\r
-               case 'D':\r
-                       return 'D';\r
+               // Initialize random number generator for randomizing cache flushes\r
+               srand(((double)microtime())*1000000);\r
                \r
+               /**\r
+                * Name of last database driver loaded into memory. Set by ADOLoadCode().\r
+                */\r
+               $ADODB_Database = '';\r
                \r
-               case 'TIME':\r
-               case 'TIMESTAMP':\r
-               case 'DATETIME':\r
-               case 'TIMESTAMPTZ':\r
-               case 'T':\r
-                       return 'T';\r
-               \r
-               case 'BOOLEAN': \r
-               case 'BIT':\r
-               case 'L':\r
-                       return 'L';\r
-                       \r
-               case 'COUNTER':\r
-               case 'R':\r
-               case 'SERIAL': // ifx \r
-                       return 'R';\r
-                       \r
-               case 'INT':\r
-               case 'INTEGER':\r
-               case 'SHORT':\r
-               case 'TINYINT':\r
-               case 'SMALLINT':\r
-               case 'I':\r
-                       if (!empty($fieldobj->primary_key)) return 'R';\r
-                       return 'I';\r
-                       \r
-               default: return 'N';\r
-               }\r
-       }*/\r
+               /**\r
+                * ADODB version as a string.\r
+                */\r
+               $ADODB_vers = 'V3.40 7 April 2003 (c) 2000-2003 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
+               $ADODB_COUNTRECS = true; \r
+       }\r
+       \r
        \r
-       function _close() {}\r
+       //==============================================================================================        \r
+       // CHANGE NOTHING BELOW UNLESS YOU ARE CODING\r
+       //==============================================================================================        \r
        \r
+       ADODB_Setup();\r
+\r
+       //==============================================================================================        \r
+       // CLASS ADOFieldObject\r
+       //==============================================================================================        \r
        /**\r
-        * set/returns the current recordset page when paginating\r
+        * Helper class for FetchFields -- holds info on a column\r
         */\r
-       function AbsolutePage($page=-1)\r
-       {\r
-               if ($page != -1) $this->_currentPage = $page;\r
-               return $this->_currentPage;\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
+       // CLASS ADOConnection\r
+       //==============================================================================================        \r
+       \r
+       include_once(ADODB_DIR.'/adodb-connection.inc.php');\r
+       \r
+       \r
+       \r
+       //==============================================================================================        \r
+       // CLASS ADOFetchObj\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
+       * Internal placeholder for record objects. Used by ADORecordSet->FetchObj().\r
+       */\r
+       class ADOFetchObj {\r
+       };\r
        \r
-       function LastPageNo($page = false)\r
-       {\r
-               if ($page != false) $this->_lastPageNo = $page;\r
-               return $this->_lastPageNo;\r
-       }\r
+       //==============================================================================================        \r
+       // CLASS ADORecordSet_empty\r
+       //==============================================================================================        \r
        \r
        /**\r
-        * set/returns the status of the atLastPage flag when paginating\r
-        */\r
-       function AtLastPage($status=false)\r
+       * Lightweight recordset when there are no records to be returned\r
+       */\r
+       class ADORecordSet_empty\r
        {\r
-               if ($status != false) $this->_atLastPage = $status;\r
-               return $this->_atLastPage;\r
+               var $dataProvider = 'empty';\r
+               var $databaseType = false;\r
+               var $EOF = true;\r
+               var $_numOfRows = 0;\r
+               var $fields = 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
        }\r
-} // end class ADORecordSet\r
+       \r
+       //==============================================================================================        \r
+       // DATE AND TIME FUNCTIONS\r
+       //==============================================================================================        \r
+       include_once(ADODB_DIR.'/adodb-time.inc.php');\r
+       \r
+       //==============================================================================================        \r
+       // CLASS ADORecordSet\r
+       //==============================================================================================        \r
+       include_once(ADODB_DIR.'/adodb-recordset.inc.php');\r
        \r
        //==============================================================================================        \r
        // CLASS ADORecordSet_array\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;\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
                 *                      unless paramter $colnames is used.\r
                 * @param fieldarr      holds an array of ADOFieldObject's.\r
                 */\r
-               function InitArrayFields(&$array,&$fieldarr)\r
+               function InitArrayFields($array,$fieldarr)\r
                {\r
-                       $this->_array = &$array;\r
+                       $this->_array = $array;\r
                        $this->_skiprow1= false;\r
                        if ($fieldarr) {\r
-                               $this->_fieldobjects = &$fieldarr;\r
+                               $this->_fieldobjects = $fieldarr;\r
                        } \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
+                               return ADORecordSet::GetArray($nRows);\r
+                       }\r
+               }\r
+               \r
                function _initrs()\r
                {\r
                        $this->_numOfRows =  sizeof($this->_array);\r
                        return false;\r
                }\r
                \r
+               function MoveNext() \r
+               {\r
+                       if (!$this->EOF) {              \r
+                               $this->_currentRow++;\r
+                               \r
+                               $pos = $this->_currentRow;\r
+                               if ($this->_skiprow1) $pos += 1;\r
+                               \r
+                               if ($this->_numOfRows <= $pos) {\r
+                                       if (!$this->compat) $this->fields = false;\r
+                               } else {\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
+                       if ($this->_skiprow1) $pos += 1;\r
                        \r
-                       if ($this->_skiprow1) {\r
-                               if ($this->_numOfRows <= $pos-1) return false;\r
-                               $pos += 1;\r
-                       } else {\r
-                               if ($this->_numOfRows <= $pos) return false;\r
+                       if ($this->_numOfRows <= $pos) {\r
+                               if (!$this->compat) $this->fields = false;\r
+                               return false;\r
                        }\r
-                       \r
+\r
                        $this->fields = $this->_array[$pos];\r
                        return true;\r
                }\r
                $ADODB_Database = strtolower($dbType);\r
                switch ($ADODB_Database) {\r
                        case 'maxsql': $ADODB_Database = 'mysqlt'; break;\r
+                       case 'postgres':\r
                        case 'pgsql': $ADODB_Database = 'postgres7'; break;\r
                }\r
                // Karsten Kraus <Karsten.Kraus@web.de> \r
-               return @include_once(ADODB_DIR."/drivers/adodb-$ADODB_Database.inc.php");               \r
+               return @include_once(ADODB_DIR."/drivers/adodb-".$ADODB_Database.".inc.php");           \r
        }\r
 \r
        /**\r
                return $obj;\r
        }\r
        \r
+       function &NewDataDictionary(&$conn)\r
+       {\r
+               $provider = $conn->dataProvider;\r
+               if ($provider !== 'native' && $provider != 'odbc' && $provider != 'ado') \r
+                       $drivername = $conn->dataProvider;\r
+               else {\r
+                       $drivername = $conn->databaseType;\r
+                       if (substr($drivername,0,5) == 'odbc_') $drivername = substr($drivername,5);\r
+                       else if (substr($drivername,0,4) == 'ado_') $drivername = substr($drivername,4);\r
+                       else if ($drivername == 'oracle') $drivername = 'oci8';\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->connection = &$conn;\r
+               $dict->upperName = strtoupper($drivername);\r
+               if (is_resource($conn->_connectionID))\r
+                       $dict->serverInfo = $conn->ServerInfo();\r
+               \r
+               return $dict;\r
+       }\r
+\r
+\r
        /**\r
        * Save a file $filename and its $contents (normally for caching) with file locking\r
        */\r
                return $ok;\r
        }\r
 \r
+       \r
+       function adodb_backtrace($print=true)\r
+       {\r
+               $s = '';\r
+               if (PHPVERSION() >= 4.3) {\r
+               \r
+                       $MAXSTRLEN = 64;\r
+               \r
+                       $s = '<pre align=left>';\r
+                       $traceArr = debug_backtrace();\r
+                       array_shift($traceArr);\r
+                       $tabs = sizeof($traceArr)-1;\r
+                       foreach ($traceArr as $arr) {\r
+                               for ($i=0; $i < $tabs; $i++) $s .= ' &nbsp; ';\r
+                               $tabs -= 1;\r
+                               $s .= '<font face="Courier New,Courier">';\r
+                               if (isset($arr['class'])) $s .= $arr['class'].'.';\r
+                               foreach($arr['args'] as $v) {\r
+                                       if (is_null($v)) $args[] = 'null';\r
+                                       else if (is_array($v)) $args[] = 'Array['.sizeof($v).']';\r
+                                       else if (is_object($v)) $args[] = 'Object:'.get_class($v);\r
+                                       else if (is_bool($v)) $args[] = $v ? 'true' : 'false';\r
+                                       else { \r
+                                               $v = (string) @$v;\r
+                                               $str = htmlspecialchars(substr($v,0,$MAXSTRLEN));\r
+                                               if (strlen($v) > $MAXSTRLEN) $str .= '...';\r
+                                               $args[] = $str;\r
+                                       }\r
+                               }\r
+                               \r
+                               $s .= $arr['function'].'('.implode(', ',$args).')';\r
+                               $s .= sprintf("</font><font color=#808080 size=-1> # line %4d, file: <a href=\"file:/%s\">%s</a></font>",\r
+                                       $arr['line'],$arr['file'],$arr['file']);\r
+                               $s .= "\n";\r
+                       }       \r
+                       $s .= '</pre>';\r
+                       if ($print) print $s;\r
+               }\r
+               return $s;\r
+       }\r
+       \r
 } // defined\r
 ?>
\ No newline at end of file
index 4b623b36671c6680d55049225ecdd99966c38c28..7266ab619df1ed4702419bbf476d74ff843139e8 100644 (file)
@@ -1,7 +1,8 @@
 <?php\r
 //      Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com>\r
 class MD5Crypt{\r
-               function keyED($txt,$encrypt_key){\r
+               function keyED($txt,$encrypt_key)\r
+               {\r
                                $encrypt_key = md5($encrypt_key);\r
                                $ctr=0;\r
                                $tmp = "";\r
@@ -13,7 +14,8 @@ class MD5Crypt{
                                return $tmp;\r
                }\r
 \r
-               function Encrypt($txt,$key){\r
+               function Encrypt($txt,$key)\r
+               {\r
                                srand((double)microtime()*1000000);\r
                                $encrypt_key = md5(rand(0,32000));\r
                                $ctr=0;\r
@@ -28,7 +30,8 @@ class MD5Crypt{
                                return base64_encode($this->keyED($tmp,$key));\r
                }\r
 \r
-               function Decrypt($txt,$key){\r
+               function Decrypt($txt,$key)\r
+               {\r
                                $txt = $this->keyED(base64_decode($txt),$key);\r
                                $tmp = "";\r
                                for ($i=0;$i<strlen($txt);$i++){\r
diff --git a/lib/adodb/datadict/datadict-mssql.inc.php b/lib/adodb/datadict/datadict-mssql.inc.php
new file mode 100644 (file)
index 0000000..bd5c25b
--- /dev/null
@@ -0,0 +1,183 @@
+<?php\r
+\r
+/**\r
+  V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+       \r
+  Set tabs to 4 for best viewing.\r
\r
+*/\r
+\r
+class ADODB2_mssql extends ADODB_DataDict {\r
+       \r
+       function ActualType($meta)\r
+       {\r
+               switch(strtoupper($meta)) {\r
+               case 'C': return 'VARCHAR';\r
+               case 'X': return 'TEXT';\r
+               \r
+               case 'C2': return 'NVARCHAR';\r
+               case 'X2': return 'NTEXT';\r
+               \r
+               case 'B': return 'IMAGE';\r
+                       \r
+               case 'D': return 'DATETIME';\r
+               case 'T': return 'DATETIME';\r
+               case 'L': return 'BIT';\r
+               \r
+               case 'I': return 'INT'; \r
+               case 'I1': return 'TINYINT';\r
+               case 'I2': return 'SMALLINT';\r
+               case 'I4': return 'INT';\r
+               case 'I8': return 'BIGINT';\r
+               \r
+               case 'F': return 'REAL';\r
+               case 'N': return 'NUMERIC';\r
+               default:\r
+                       return $meta;\r
+               }\r
+       }\r
+       \r
+       \r
+       function AddColumnSQL($tabname, $flds)\r
+       {       \r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               $f = array();\r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+               $s = "ALTER TABLE $tabname $this->addCol";\r
+               foreach($lines as $v) {\r
+                       $f[] = "\n $v";\r
+               }\r
+               $s .= implode(',',$f);\r
+               $sql[] = $s;\r
+               return $sql;\r
+       }\r
+       \r
+       function AlterColumnSQL($tabname, $flds)\r
+       {\r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               $sql = array();\r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+               foreach($lines as $v) {\r
+                       $sql[] = "ALTER TABLE $tabname $this->alterCol $v";\r
+               }\r
+\r
+               return $sql;\r
+       }\r
+       \r
+       function DropColumnSQL($tabname, $flds)\r
+       {\r
+               if ($this->schema) $tabname = $this->schema.'.'.$tabname;\r
+               if (!is_array($flds)) $flds = explode(',',$flds);\r
+               $f = array();\r
+               $s = "ALTER TABLE $tabname";\r
+               foreach($flds as $v) {\r
+                       $f[] = "\n$this->dropCol $v";\r
+               }\r
+               $s .= implode(',',$f);\r
+               $sql[] = $s;\r
+               return $sql;\r
+       }\r
+       \r
+       // return string must begin with space\r
+       function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)\r
+       {       \r
+               $suffix = '';\r
+               if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";\r
+               if ($fautoinc) $suffix .= ' IDENTITY(1,1)';\r
+               if ($fnotnull) $suffix .= ' NOT NULL';\r
+               if ($fconstraint) $suffix .= ' '.$fconstraint;\r
+               return $suffix;\r
+       }\r
+       \r
+       /*\r
+CREATE TABLE \r
+    [ database_name.[ owner ] . | owner. ] table_name \r
+    ( { < column_definition > \r
+        | column_name AS computed_column_expression \r
+        | < table_constraint > ::= [ CONSTRAINT constraint_name ] }\r
+\r
+            | [ { PRIMARY KEY | UNIQUE } [ ,...n ] \r
+    ) \r
+\r
+[ ON { filegroup | DEFAULT } ] \r
+[ TEXTIMAGE_ON { filegroup | DEFAULT } ] \r
+\r
+< column_definition > ::= { column_name data_type } \r
+    [ COLLATE < collation_name > ] \r
+    [ [ DEFAULT constant_expression ] \r
+        | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]\r
+    ] \r
+    [ ROWGUIDCOL] \r
+    [ < column_constraint > ] [ ...n ] \r
+\r
+< column_constraint > ::= [ CONSTRAINT constraint_name ] \r
+    { [ NULL | NOT NULL ] \r
+        | [ { PRIMARY KEY | UNIQUE } \r
+            [ CLUSTERED | NONCLUSTERED ] \r
+            [ WITH FILLFACTOR = fillfactor ] \r
+            [ON {filegroup | DEFAULT} ] ] \r
+        ] \r
+        | [ [ FOREIGN KEY ] \r
+            REFERENCES ref_table [ ( ref_column ) ] \r
+            [ ON DELETE { CASCADE | NO ACTION } ] \r
+            [ ON UPDATE { CASCADE | NO ACTION } ] \r
+            [ NOT FOR REPLICATION ] \r
+        ] \r
+        | CHECK [ NOT FOR REPLICATION ] \r
+        ( logical_expression ) \r
+    } \r
+\r
+< table_constraint > ::= [ CONSTRAINT constraint_name ] \r
+    { [ { PRIMARY KEY | UNIQUE } \r
+        [ CLUSTERED | NONCLUSTERED ] \r
+        { ( column [ ASC | DESC ] [ ,...n ] ) } \r
+        [ WITH FILLFACTOR = fillfactor ] \r
+        [ ON { filegroup | DEFAULT } ] \r
+    ] \r
+    | FOREIGN KEY \r
+        [ ( column [ ,...n ] ) ] \r
+        REFERENCES ref_table [ ( ref_column [ ,...n ] ) ] \r
+        [ ON DELETE { CASCADE | NO ACTION } ] \r
+        [ ON UPDATE { CASCADE | NO ACTION } ] \r
+        [ NOT FOR REPLICATION ] \r
+    | CHECK [ NOT FOR REPLICATION ] \r
+        ( search_conditions ) \r
+    } \r
+\r
+\r
+       */\r
+       \r
+       /*\r
+       CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name \r
+    ON { table | view } ( column [ ASC | DESC ] [ ,...n ] ) \r
+               [ WITH < index_option > [ ,...n] ] \r
+               [ ON filegroup ]\r
+               < index_option > :: = \r
+                   { PAD_INDEX | \r
+                       FILLFACTOR = fillfactor | \r
+                       IGNORE_DUP_KEY | \r
+                       DROP_EXISTING | \r
+                   STATISTICS_NORECOMPUTE | \r
+                   SORT_IN_TEMPDB  \r
+               }\r
+*/\r
+       function _IndexSQL($idxname, $tabname, $flds, $idxoptions)\r
+       {\r
+               if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $idxname";\r
+               if (isset($idxoptions['UNIQUE'])) $unique = ' UNIQUE';\r
+               else $unique = '';\r
+               if (is_array($flds)) $flds = implode(', ',$flds);\r
+               if (isset($idxoptions['CLUSTERED'])) $clustered = ' CLUSTERED';\r
+               else $clustered = '';\r
+               \r
+               $s = "CREATE$unique$clustered INDEX $idxname ON $tabname ($flds)";\r
+               if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];\r
+               $sql[] = $s;\r
+               \r
+               return $sql;\r
+       }\r
+}\r
+?>
\ No newline at end of file
diff --git a/lib/adodb/datadict/datadict-mysql.inc.php b/lib/adodb/datadict/datadict-mysql.inc.php
new file mode 100644 (file)
index 0000000..a409d99
--- /dev/null
@@ -0,0 +1,92 @@
+<?php\r
+\r
+/**\r
+  V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+       \r
+  Set tabs to 4 for best viewing.\r
\r
+*/\r
+\r
+class ADODB2_mysql extends ADODB_DataDict {\r
+       \r
+       var $alterCol = ' MODIFY COLUMN';\r
+       \r
+       function ActualType($meta)\r
+       {\r
+               switch(strtoupper($meta)) {\r
+               case 'C': return 'VARCHAR';\r
+               case 'X': return 'LONGTEXT';\r
+               \r
+               case 'C2': return 'VARCHAR';\r
+               case 'X2': return 'LONGTEXT';\r
+               \r
+               case 'B': return 'LONGBLOB';\r
+                       \r
+               case 'D': return 'DATE';\r
+               case 'T': return 'DATETIME';\r
+               case 'L': return 'TINYINT';\r
+               \r
+               case 'I': return 'INTEGER';\r
+               case 'I1': return 'TINYINT';\r
+               case 'I2': return 'SMALLINT';\r
+               case 'I4': return 'MEDIUMINT';\r
+               case 'I8': return 'BIGINT';\r
+               \r
+               case 'F': return 'DOUBLE';\r
+               case 'N': return 'NUMERIC';\r
+               default:\r
+                       return $meta;\r
+               }\r
+       }\r
+       \r
+       // return string must begin with space\r
+       function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)\r
+       {       \r
+               $suffix = '';\r
+               if ($fnotnull) $suffix .= ' NOT NULL';\r
+               if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";\r
+               if ($fautoinc) $suffix .= ' AUTO_INCREMENT';\r
+               if ($fconstraint) $suffix .= ' '.$fconstraint;\r
+               return $suffix;\r
+       }\r
+       \r
+       /*\r
+       CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]\r
+               [table_options] [select_statement]\r
+               create_definition:\r
+               col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]\r
+               [PRIMARY KEY] [reference_definition]\r
+               or PRIMARY KEY (index_col_name,...)\r
+               or KEY [index_name] (index_col_name,...)\r
+               or INDEX [index_name] (index_col_name,...)\r
+               or UNIQUE [INDEX] [index_name] (index_col_name,...)\r
+               or FULLTEXT [INDEX] [index_name] (index_col_name,...)\r
+               or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)\r
+               [reference_definition]\r
+               or CHECK (expr)\r
+       */\r
+       \r
+       /*\r
+       CREATE [UNIQUE|FULLTEXT] INDEX index_name\r
+               ON tbl_name (col_name[(length)],... )\r
+       */\r
+       \r
+       function _IndexSQL($idxname, $tabname, $flds, $idxoptions)\r
+       {\r
+               //if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX IF EXISTS $idxname";\r
+               if (isset($idxoptions['FULLTEXT'])) $unique = ' FULLTEXT';\r
+               else if (isset($idxoptions['UNIQUE'])) $unique = ' UNIQUE';\r
+               else $unique = '';\r
+               \r
+               if (is_array($flds)) $flds = implode(', ',$flds);\r
+               $s = "CREATE$unique INDEX $idxname ON $tabname ($flds)";\r
+               if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];\r
+               $sql[] = $s;\r
+               \r
+               return $sql;\r
+       }\r
+}\r
+?>
\ No newline at end of file
diff --git a/lib/adodb/datadict/datadict-oci8.inc.php b/lib/adodb/datadict/datadict-oci8.inc.php
new file mode 100644 (file)
index 0000000..8e7e248
--- /dev/null
@@ -0,0 +1,180 @@
+<?php\r
+\r
+/**\r
+  V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+       \r
+  Set tabs to 4 for best viewing.\r
\r
+*/\r
+\r
+class ADODB2_oci8 extends ADODB_DataDict {\r
+       \r
+       var $seqField = false;\r
+       var $seqPrefix = 'SEQ_';\r
+       var $dropTable = "DROP TABLE %s CASCADE CONSTRAINTS";\r
+       \r
+       function ActualType($meta)\r
+       {\r
+               switch($meta) {\r
+               case 'C': return 'VARCHAR';\r
+               case 'X': return 'CLOB';\r
+               \r
+               case 'C2': return 'NVARCHAR';\r
+               case 'X2': return 'NCLOB';\r
+               \r
+               case 'B': return 'BLOB';\r
+                       \r
+               case 'D': \r
+               case 'T': return 'DATE';\r
+               case 'L': return 'NUMBER(1)';\r
+               case 'I1': return 'NUMBER(3)';\r
+               case 'I2': return 'NUMBER(5)';\r
+               case 'I':\r
+               case 'I4': return 'NUMBER(10)';\r
+               \r
+               case 'I8': return 'NUMBER(20)';\r
+               case 'F': return 'NUMBER';\r
+               case 'N': return 'NUMBER';\r
+               default:\r
+                       return $meta;\r
+               }       \r
+       }\r
+       \r
+       function CreateDatabase($dbname, $options=false)\r
+       {\r
+               $options = $this->_Options($options);\r
+               $password = isset($options['PASSWORD']) ? $options['PASSWORD'] : 'tiger';\r
+               $tablespace = isset($options["TABLESPACE"]) ? " DEFAULT TABLESPACE ".$options["TABLESPACE"] : '';\r
+               $sql[] = "CREATE USER ".$dbname." IDENTIFIED BY ".$password.$tablespace;\r
+               $sql[] = "GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO $dbname";\r
+               \r
+               return $sql;\r
+       }\r
+       \r
+       function AddColumnSQL($tabname, $flds)\r
+       {\r
+               $f = array();\r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+               $s = "ALTER TABLE $tabname ADD (";\r
+               foreach($lines as $v) {\r
+                       $f[] = "\n $v";\r
+               }\r
+               \r
+               $s .= implode(',',$f).')';\r
+               $sql[] = $s;\r
+               return $sql;\r
+       }\r
+       \r
+       function AlterColumnSQL($tabname, $flds)\r
+       {\r
+               $f = array();\r
+               list($lines,$pkey) = $this->_GenFields($flds);\r
+               $s = "ALTER TABLE $tabname MODIFY(";\r
+               foreach($lines as $v) {\r
+                       $f[] = "\n $v";\r
+               }\r
+               $s .= implode(',',$f).')';\r
+               $sql[] = $s;\r
+               return $sql;\r
+       }\r
+       \r
+       function DropColumnSQL($tabname, $flds)\r
+       {\r
+               if ($this->debug) ADOConnection::outp("DropColumnSQL not supported for Oracle");\r
+               return array();\r
+       }\r
+       \r
+       // return string must begin with space\r
+       function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)\r
+       {\r
+               $suffix = '';\r
+               \r
+               if ($fdefault == "''" && $fnotnull) {// this is null in oracle\r
+                       $fnotnull = false;\r
+                       if ($this->debug) ADOConnection::outp("NOT NULL and DEFAULT='' illegal in Oracle");\r
+               }\r
+                               \r
+               if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";\r
+               if ($fnotnull) {\r
+                       $suffix .= ' NOT NULL';\r
+               }\r
+               if ($fautoinc) $this->seqField = $fname;\r
+               if ($fconstraint) $suffix .= ' '.$fconstraint;\r
+               \r
+               return $suffix;\r
+       }\r
+       \r
+/*\r
+CREATE or replace TRIGGER jaddress_insert\r
+before insert on jaddress\r
+for each row\r
+begin\r
+select seqaddress.nextval into :new.A_ID from dual;\r
+end;\r
+*/\r
+       function _Triggers($tabname,$tableoptions)\r
+       {\r
+               if (!$this->seqField) return array();\r
+               \r
+               if ($this->schema) {\r
+                       $t = strpos($tabname,'.');\r
+                       if ($t !== false) $tab = substr($tabname,$t+1);\r
+                       else $tab = $tabname;\r
+                       $seqname = $this->schema.'.'.$this->seqPrefix.$tab;\r
+                       $trigname = $this->schema.'.TRIG_'.$this->seqPrefix.$tab;\r
+               } else {\r
+                       $seqname = $this->seqPrefix.$tabname;\r
+                       $trigname = "TRIG_$seqname";\r
+               }\r
+               if (isset($tableoptions['REPLACE'])) $sql[] = "DROP SEQUENCE $seqname";\r
+               $sql[] = "CREATE SEQUENCE $seqname";\r
+               $sql[] = "CREATE OR REPLACE TRIGGER $trigname BEFORE insert ON $tabname \r
+               FOR EACH ROW\r
+               BEGIN\r
+                 select $seqname.nextval into :new.$this->seqField from dual;\r
+               END";\r
+               \r
+               $this->seqField = false;\r
+               return $sql;\r
+       }\r
+       \r
+       /*\r
+       CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]\r
+               [table_options] [select_statement]\r
+               create_definition:\r
+               col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]\r
+               [PRIMARY KEY] [reference_definition]\r
+               or PRIMARY KEY (index_col_name,...)\r
+               or KEY [index_name] (index_col_name,...)\r
+               or INDEX [index_name] (index_col_name,...)\r
+               or UNIQUE [INDEX] [index_name] (index_col_name,...)\r
+               or FULLTEXT [INDEX] [index_name] (index_col_name,...)\r
+               or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)\r
+               [reference_definition]\r
+               or CHECK (expr)\r
+       */\r
+       \r
+\r
+       \r
+       function _IndexSQL($idxname, $tabname, $flds,$idxoptions)\r
+       {\r
+               if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $idxname";\r
+               if (isset($idxoptions['BITMAP'])) {\r
+                       $unique = ' BITMAP'; \r
+               } else if (isset($idxoptions['UNIQUE'])) \r
+                       $unique = ' UNIQUE';\r
+               else \r
+                       $unique = '';\r
+               \r
+               if (is_array($flds)) $flds = implode(', ',$flds);\r
+               $s = "CREATE$unique INDEX $idxname ON $tabname ($flds)";\r
+               if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];\r
+               $sql[] = $s;\r
+               \r
+               return $sql;\r
+       }\r
+}\r
+?>
\ No newline at end of file
diff --git a/lib/adodb/datadict/datadict-postgres.inc.php b/lib/adodb/datadict/datadict-postgres.inc.php
new file mode 100644 (file)
index 0000000..649f804
--- /dev/null
@@ -0,0 +1,123 @@
+<?php\r
+\r
+/**\r
+  V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+       \r
+  Set tabs to 4 for best viewing.\r
\r
+*/\r
+\r
+class ADODB2_postgres extends ADODB_DataDict {\r
+       \r
+       var $seqField = false;\r
+       var $seqPrefix = 'SEQ_';\r
+       \r
+       \r
+       function ActualType($meta)\r
+       {\r
+               switch($meta) {\r
+               case 'C': return 'VARCHAR';\r
+               case 'X': return 'TEXT';\r
+               \r
+               case 'C2': return 'VARCHAR';\r
+               case 'X2': return 'TEXT';\r
+               \r
+               case 'B': return 'BYTEA';\r
+                       \r
+               case 'D': return 'DATE';\r
+               case 'T': return 'TIMESTAMP';\r
+               \r
+               case 'L': return 'SMALLINT';\r
+               case 'I': return 'INTEGER';\r
+               case 'I1': return 'SMALLINT';\r
+               case 'I2': return 'INT2';\r
+               case 'I4': return 'INT4';\r
+               case 'I8': return 'INT8';\r
+               \r
+               case 'F': return 'FLOAT8';\r
+               case 'N': return 'NUMERIC';\r
+               default:\r
+                       return $meta;\r
+               }\r
+       }\r
+\r
+       function AlterColumnSQL($tabname, $flds)\r
+       {\r
+               if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported for PostgreSQL");\r
+               return array();\r
+       }\r
+       \r
+       \r
+       function DropColumnSQL($tabname, $flds)\r
+       {\r
+               if ($this->debug) ADOConnection::outp("DropColumnSQL not supported for PostgreSQL");\r
+               return array();\r
+       }\r
+       \r
+       // return string must begin with space\r
+       function _CreateSuffix($fname, &$ftype, $fnotnull,$fdefault,$fautoinc,$fconstraint)\r
+       {\r
+               if ($fautoinc) {\r
+                       $ftype = 'SERIAL';\r
+                       return '';\r
+               }\r
+               $suffix = '';\r
+               if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";\r
+               if ($fnotnull) $suffix .= ' NOT NULL';\r
+               if ($fconstraint) $suffix .= ' '.$fconstraint;\r
+               return $suffix;\r
+       }\r
+       \r
+       /*\r
+       CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name (\r
+       { column_name data_type [ DEFAULT default_expr ] [ column_constraint [, ... ] ]\r
+       | table_constraint } [, ... ]\r
+       )\r
+       [ INHERITS ( parent_table [, ... ] ) ]\r
+       [ WITH OIDS | WITHOUT OIDS ]\r
+       where column_constraint is:\r
+       [ CONSTRAINT constraint_name ]\r
+       { NOT NULL | NULL | UNIQUE | PRIMARY KEY |\r
+       CHECK (expression) |\r
+       REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL ]\r
+       [ ON DELETE action ] [ ON UPDATE action ] }\r
+       [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]\r
+       and table_constraint is:\r
+       [ CONSTRAINT constraint_name ]\r
+       { UNIQUE ( column_name [, ... ] ) |\r
+       PRIMARY KEY ( column_name [, ... ] ) |\r
+       CHECK ( expression ) |\r
+       FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ]\r
+       [ MATCH FULL | MATCH PARTIAL ] [ ON DELETE action ] [ ON UPDATE action ] }\r
+       [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]\r
+       */\r
+       \r
+       \r
+       /*\r
+       CREATE [ UNIQUE ] INDEX index_name ON table\r
+[ USING acc_method ] ( column [ ops_name ] [, ...] )\r
+[ WHERE predicate ]\r
+CREATE [ UNIQUE ] INDEX index_name ON table\r
+[ USING acc_method ] ( func_name( column [, ... ]) [ ops_name ] )\r
+[ WHERE predicate ]\r
+       */\r
+       function _IndexSQL($idxname, $tabname, $flds, $idxoptions)\r
+       {\r
+               if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $idxname";\r
+               if (isset($idxoptions['UNIQUE'])) $unique = ' UNIQUE';\r
+               else $unique = '';\r
+               \r
+               if (is_array($flds)) $flds = implode(', ',$flds);\r
+               $s = "CREATE$unique INDEX $idxname ON $tabname ";\r
+               if (isset($idxoptions['HASH'])) $s .= 'USING HASH ';\r
+               if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];\r
+               $s .= "($flds)";\r
+               $sql[] = $s;\r
+               \r
+               return $sql;\r
+       }\r
+}\r
+?>
\ No newline at end of file
index be998258a1438439581564d0a4774c64eeac0e72..fa4aa4ae0766dabf1f4a6c74d3f0f92eab92abe2 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. See License.txt. \r
@@ -24,9 +24,13 @@ class  ADODB_access extends ADODB_odbc {
        var $_bindInputArray = false; // strangely enough, setting to true does not work reliably\r
        var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";\r
        var $sysTimeStamp = 'NOW';\r
+       var $hasTransactions = false;\r
        \r
        function ADODB_access()\r
        {\r
+       global $ADODB_EXTENSION;\r
+       \r
+               $ADODB_EXTENSION = false;\r
                $this->ADODB_odbc();\r
        }\r
        \r
@@ -39,17 +43,17 @@ class  ADODB_access extends ADODB_odbc {
                $savem = $ADODB_FETCH_MODE;\r
                $ADODB_FETCH_MODE = ADODB_FETCH_NUM;\r
                $qid = odbc_tables($this->_connectionID);\r
-               $ADODB_FETCH_MODE = $savem;\r
                $rs = new ADORecordSet_odbc($qid);\r
+               $ADODB_FETCH_MODE = $savem;\r
                if (!$rs) return false;\r
                \r
                $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;\r
                \r
                $arr = &$rs->GetArray();\r
-               \r
+               //print_pre($arr);\r
                $arr2 = array();\r
                for ($i=0; $i < sizeof($arr); $i++) {\r
-                       if ($arr[$i][2] && substr($arr[$i][2],0,4) != 'MSys')\r
+                       if ($arr[$i][2] && $arr[$i][3] != 'SYSTEM TABLE')\r
                                $arr2[] = $arr[$i][2];\r
                }\r
                return $arr2;\r
@@ -61,10 +65,10 @@ class  ADORecordSet_access extends ADORecordSet_odbc {
        \r
        var $databaseType = "access";           \r
        \r
-       function ADORecordSet_access($id)\r
+       function ADORecordSet_access($id,$mode=false)\r
        {\r
-               return $this->ADORecordSet_odbc($id);\r
+               return $this->ADORecordSet_odbc($id,$mode);\r
        }\r
-}\r
-} // class\r
+}// class\r
+} \r
 ?>
\ No newline at end of file
index f7831dae7f93cc67ad6399f1f626bb9c3ef95d1e..9d195d3170231d278eedce6b936c4af903895218 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -29,16 +29,23 @@ class ADODB_ado extends ADOConnection {
        var $_cursor_location = 3; // 2=adUseServer, 3 = adUseClient;\r
        var $_lock_type = -1;\r
        var $_execute_option = -1;\r
-                                         \r
-       \r
+       var $poorAffectedRows = true; \r
+       var $charPage;\r
+               \r
        function ADODB_ado() \r
        {       \r
+               $this->_affectedRows = new VARIANT;\r
        }\r
 \r
+       function ServerInfo()\r
+       {\r
+               if (!empty($this->_connectionID)) $desc = $this->_connectionID->provider;\r
+               return array('description' => $desc, 'version' => '');\r
+       }\r
        \r
        function _affectedrows()\r
        {\r
-                       return $this->_affectedRows;\r
+                       return $this->_affectedRows->value;\r
        }\r
        \r
        // you can also pass a connection string like this:\r
@@ -49,7 +56,11 @@ class ADODB_ado extends ADOConnection {
                $u = 'UID';\r
                $p = 'PWD';\r
        \r
-               $dbc = new COM('ADODB.Connection');\r
+               if (!empty($this->charPage))\r
+                       $dbc = new COM('ADODB.Connection',null,$this->charPage);\r
+               else\r
+                       $dbc = new COM('ADODB.Connection');\r
+                       \r
                if (! $dbc) return false;\r
 \r
                /* special support if provider is mssql or access */\r
@@ -190,7 +201,11 @@ class ADODB_ado extends ADOConnection {
                \r
        //      return rs       \r
                if ($inputarr) {\r
-                       $oCmd = new COM('ADODB.Command');\r
+                       \r
+                       if (!empty($this->charPage))\r
+                               $oCmd = new COM('ADODB.Command',null,$this->charPage);\r
+                       else\r
+                               $oCmd = new COM('ADODB.Command');\r
                        $oCmd->ActiveConnection = $dbc;\r
                        $oCmd->CommandText = $sql;\r
                        $oCmd->CommandType = 1;\r
@@ -298,12 +313,14 @@ class ADORecordSet_ado extends ADORecordSet {
        var $canSeek = true;\r
        var $hideErrors = true;\r
                  \r
-       function ADORecordSet_ado(&$id)\r
+       function ADORecordSet_ado($id,$mode=false)\r
        {\r
-       global $ADODB_FETCH_MODE;\r
-       \r
-               $this->fetchMode = $ADODB_FETCH_MODE;\r
-               return $this->ADORecordSet($id);\r
+               if ($mode === false) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               $this->fetchMode = $mode;\r
+               return $this->ADORecordSet($id,$mode);\r
        }\r
 \r
 \r
@@ -445,8 +462,14 @@ class ADORecordSet_ado extends ADORecordSet {
        adPropVariant   = 138,\r
        adVarNumeric    = 139\r
 */\r
-       function MetaType($t,$len=-1)\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
+               \r
                if (!is_numeric($t)) return $t;\r
                \r
                switch ($t) {\r
@@ -494,7 +517,10 @@ class ADORecordSet_ado extends ADORecordSet {
        function _fetch()\r
        {       \r
                $rs = $this->_queryID;\r
-               if (!$rs or $rs->EOF) return false;\r
+               if (!$rs or $rs->EOF) {\r
+                       $this->fields = false;\r
+                       return false;\r
+               }\r
                $this->fields = array();\r
        \r
                if (!$this->_tarr) {\r
@@ -545,7 +571,7 @@ class ADORecordSet_ado extends ADORecordSet {
                if ($this->hideErrors) error_reporting($olde);\r
                @$rs->MoveNext(); // @ needed for some versions of PHP!\r
                \r
-               if ($this->fetchMode == ADODB_FETCH_ASSOC) {\r
+               if ($this->fetchMode & ADODB_FETCH_ASSOC) {\r
                        $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);\r
                }\r
                return true;\r
index 342c42d515272c67a28df1574b5770f634b6fb3b..c3748e5e9998dd9a58f23e517aa0bbc4391ce7d0 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
 Released under both BSD license and Lesser GPL library license. \r
 Whenever there is any discrepancy between the two licenses, \r
 the BSD license will take precedence. See License.txt. \r
@@ -22,9 +22,11 @@ class  ADODB_ado_access extends ADODB_ado {
        var $fmtTimeStamp = "#Y-m-d h:i:sA#";// note no comma\r
        var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";\r
        var $sysTimeStamp = 'NOW';\r
+       var $hasTransactions = false;\r
        \r
        function ADODB_ado_access()\r
        {\r
+               $this->ADODB_ado();\r
        }\r
        \r
        function BeginTrans() { return false;}\r
@@ -36,9 +38,9 @@ class  ADORecordSet_ado_access extends ADORecordSet_ado {
        \r
        var $databaseType = "ado_access";               \r
        \r
-       function ADORecordSet_ado_access(&$id)\r
+       function ADORecordSet_ado_access($id,$mode=false)\r
        {\r
-               return $this->ADORecordSet_ado($id);\r
+               return $this->ADORecordSet_ado($id,$mode);\r
        }\r
 }\r
 ?>
\ No newline at end of file
index 7b5402f2af09dd8f5dd49f547bdb9d9bc57a5b24..bf295892ee5074e2d317f665ec393a80ead9cb76 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -32,6 +32,7 @@ class  ADODB_ado_mssql extends ADODB_ado {
        \r
        function ADODB_ado_mssql()\r
        {\r
+               $this->ADODB_ado();\r
        }\r
        \r
        function _insertid()\r
@@ -50,9 +51,9 @@ class  ADORecordSet_ado_mssql extends ADORecordSet_ado {
        \r
        var $databaseType = 'ado_mssql';\r
        \r
-       function ADORecordSet_ado_mssql(&$id)\r
+       function ADORecordSet_ado_mssql($id,$mode=false)\r
        {\r
-               return $this->ADORecordSet_ado($id);\r
+               return $this->ADORecordSet_ado($id,$mode);\r
        }\r
 }\r
 ?>
\ No newline at end of file
index fb0b8dd20655dc252f48136f9bd8dc1c8d28ca58..05a491587364d3e575ed3900ec80f3b1b665b6bd 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -22,12 +22,27 @@ class ADODB_borland_ibase extends ADODB_ibase {
                $this->ADODB_ibase();\r
        }\r
        \r
+       function ServerInfo()\r
+       {\r
+               $arr['dialect'] = $this->dialect;\r
+               switch($arr['dialect']) {\r
+               case '': \r
+               case '1': $s = 'Interbase 6.5, Dialect 1'; break;\r
+               case '2': $s = 'Interbase 6.5, Dialect 2'; break;\r
+               default:\r
+               case '3': $s = 'Interbase 6.5, Dialect 3'; break;\r
+               }\r
+               $arr['version'] = '6.5';\r
+               $arr['description'] = $s;\r
+               return $arr;\r
+       }\r
+       \r
        // Note that Interbase 6.5 uses ROWS instead - don't you love forking wars!\r
        //              SELECT col1, col2 FROM table ROWS 5 -- get 5 rows \r
        //              SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2\r
        // Firebird uses\r
        //              SELECT FIRST 5 SKIP 2 col1, col2 FROM TABLE\r
-       function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $arg3=false,$secs=0)\r
+       function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $arg3=false,$secs2cache=0)\r
        {\r
                if ($nrows > 0) {\r
                        if ($offset <= 0) $str = " ROWS $nrows "; \r
@@ -43,8 +58,8 @@ class ADODB_borland_ibase extends ADODB_ibase {
                }\r
                $sql .= $str;\r
                \r
-               return ($secs) ? \r
-                               $this->CacheExecute($secs,$sql,$inputarr,$arg3)\r
+               return ($secs2cache) ? \r
+                               $this->CacheExecute($secs2cache,$sql,$inputarr,$arg3)\r
                        :\r
                                $this->Execute($sql,$inputarr,$arg3);\r
        }\r
@@ -56,9 +71,9 @@ class  ADORecordSet_borland_ibase extends ADORecordSet_ibase {
        \r
        var $databaseType = "borland_ibase";            \r
        \r
-       function ADORecordSet_borland_ibase($id)\r
+       function ADORecordSet_borland_ibase($id,$mode=false)\r
        {\r
-               $this->ADORecordSet_ibase($id);\r
+               $this->ADORecordSet_ibase($id,$mode);\r
        }\r
 }\r
 ?>
\ No newline at end of file
index e04482151566f0634cfaec220a78453914bfd0e8..792408452709445e3f00a88e9795e19ddc28829b 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -18,6 +18,7 @@ include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
  \r
 class ADODB_csv extends ADOConnection {\r
        var $databaseType = 'csv';\r
+       var $databaseProvider = 'csv';\r
        var $hasInsertID = true;\r
        var $hasAffectedRows = true;    \r
        var $fmtTimeStamp = "'Y-m-d H:i:s'";\r
@@ -25,6 +26,8 @@ class ADODB_csv extends ADOConnection {
        var $_insertid=0;\r
        var $_url;\r
        var $replaceQuote = "''"; // string to use to replace quotes\r
+       var $hasTransactions = false;\r
+       var $_errorNo = false;\r
        \r
        function ADODB_csv() \r
        {                       \r
@@ -73,7 +76,9 @@ class ADODB_csv extends ADOConnection {
        {\r
        global $ADODB_FETCH_MODE;\r
        \r
-               $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=$ADODB_FETCH_MODE&offset=$offset&arg3=".urlencode($arg3);\r
+               $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=".\r
+                       (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE).\r
+                       "&offset=$offset&arg3=".urlencode($arg3);\r
                $err = false;\r
                $rs = csv2rs($url,$err,false);\r
                \r
@@ -92,9 +97,10 @@ class ADODB_csv extends ADOConnection {
                                $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,'');\r
                        }\r
                        \r
-               if (is_object($rs)) {\r
+               if (is_object($rs)) {   \r
+               \r
                        $rs->databaseType='csv';                \r
-                       $rs->fetchMode = $ADODB_FETCH_MODE;\r
+                       $rs->fetchMode = ($this->fetchMode !== false) ?  $this->fetchMode : $ADODB_FETCH_MODE;\r
                        $rs->connection = &$this;\r
                }\r
                return $rs;\r
@@ -129,7 +135,8 @@ class ADODB_csv extends ADOConnection {
                        $inputarr = false;\r
                }\r
                \r
-               $url =  $this->_url.'?sql='.urlencode($sql)."&fetch=$ADODB_FETCH_MODE";\r
+               $url =  $this->_url.'?sql='.urlencode($sql)."&fetch=".\r
+                       (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE);\r
                if ($arg3) $url .= "&arg3=".urlencode($arg3);\r
                $err = false;\r
                \r
@@ -149,7 +156,8 @@ class ADODB_csv extends ADOConnection {
                                $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr);\r
                        }\r
                if (is_object($rs)) {\r
-                       $rs->fetchMode = $ADODB_FETCH_MODE;\r
+                       $rs->fetchMode = ($this->fetchMode !== false) ?  $this->fetchMode : $ADODB_FETCH_MODE;\r
+                       \r
                        $this->_affectedrows = $rs->affectedrows;\r
                        $this->_insertid = $rs->insertid;\r
                        $rs->databaseType='csv';\r
@@ -178,9 +186,9 @@ class ADODB_csv extends ADOConnection {
 } // class\r
 \r
 class ADORecordset_csv extends ADORecordset {\r
-       function ADORecordset_csv($id)\r
+       function ADORecordset_csv($id,$mode=false)\r
        {\r
-               $this->ADORecordset($id);\r
+               $this->ADORecordset($id,$mode);\r
        }\r
        \r
        function _close()\r
index af322cabcd8516c9851d86d952844d94e0b09995..2ba16955afaf6f3618ecf6bffe639e25a70a9e1f 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -56,6 +56,14 @@ library.
 So I guess this means the message [above] was related to using a 3rd party\r
 odbc driver.\r
 \r
+Setting SQL_CUR_USE_ODBC\r
+========================\r
+To set SQL_CUR_USE_ODBC for drivers that require it, do this:\r
+\r
+$db = NewADOConnection('db2');\r
+$db->curMode = SQL_CUR_USE_ODBC;\r
+$db->Connect($dsn, $userid, $pwd);\r
+\r
 */\r
 \r
 if (!defined('_ADODB_ODBC_LAYER')) {\r
@@ -76,32 +84,6 @@ class ADODB_DB2 extends ADODB_odbc {
        {\r
                $this->ADODB_odbc();\r
        }\r
-\r
-       // returns true or false\r
-       // curmode is not properly supported by DB2 odbc driver according to Mark Newnham\r
-       function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)\r
-       {\r
-       global $php_errormsg;\r
-       \r
-               $php_errormsg = '';\r
-               $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);\r
-               $this->_errorMsg = $php_errormsg;\r
-\r
-               //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);\r
-               return $this->_connectionID != false;\r
-       }\r
-       \r
-       // returns true or false\r
-       function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)\r
-       {\r
-       global $php_errormsg;\r
-               $php_errormsg = '';\r
-               $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword);\r
-               $this->_errorMsg = $php_errormsg;\r
-               \r
-               //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);\r
-               return $this->_connectionID != false;\r
-       }\r
        \r
        function RowLock($tables,$where)\r
        {\r
@@ -161,9 +143,9 @@ class  ADORecordSet_db2 extends ADORecordSet_odbc {
        \r
        var $databaseType = "db2";              \r
        \r
-       function ADORecordSet_db2($id)\r
+       function ADORecordSet_db2($id,$mode=false)\r
        {\r
-               $this->ADORecordSet_odbc($id);\r
+               $this->ADORecordSet_odbc($id,$mode);\r
        }\r
 \r
        function MetaType($t,$len=-1,$fieldobj=false)\r
index 484666d8b30f437cd8059bff6bc482b5f7540117..9affce5671cd31f6539776eb4772ebfd9c720fd4 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
- @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -159,10 +159,13 @@ class ADORecordSet_fbsql extends ADORecordSet{
        var $databaseType = "fbsql";\r
        var $canSeek = true;\r
        \r
-       function ADORecordSet_fbsql($queryID) {\r
-       global $ADODB_FETCH_MODE;\r
-       \r
-               switch($ADODB_FETCH_MODE) {\r
+       function ADORecordSet_fbsql($queryID,$mode=false) \r
+       {\r
+               if (!$mode) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               switch ($mode) {\r
                case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break;\r
                default:\r
                case ADODB_FETCH_BOTH: $this->fetchMode = FBSQL_BOTH; break;\r
@@ -212,6 +215,11 @@ class ADORecordSet_fbsql extends ADORecordSet{
        \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
                $len = -1; // fbsql max_length is not accurate\r
                switch (strtoupper($t)) {\r
                case 'CHARACTER':\r
index b58dd59dea04a99c36a201d088923cec1be421e6..5789618601d923056f645ce40c9d2899b5a71fe4 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -21,6 +21,21 @@ class ADODB_firebird extends ADODB_ibase {
                $this->ADODB_ibase();\r
        }\r
        \r
+       function ServerInfo()\r
+       {\r
+               $arr['dialect'] = $this->dialect;\r
+               switch($arr['dialect']) {\r
+               case '': \r
+               case '1': $s = 'Firebird Dialect 1'; break;\r
+               case '2': $s = 'Firebird Dialect 2'; break;\r
+               default:\r
+               case '3': $s = 'Firebird Dialect 3'; break;\r
+               }\r
+               $arr['version'] = ADOConnection::_findvers($s);\r
+               $arr['description'] = $s;\r
+               return $arr;\r
+       }\r
+       \r
        // Note that Interbase 6.5 uses this ROWS instead - don't you love forking wars!\r
        //              SELECT col1, col2 FROM table ROWS 5 -- get 5 rows \r
        //              SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2\r
@@ -37,6 +52,7 @@ class ADODB_firebird extends ADODB_ibase {
                                $this->Execute($sql,$inputarr,$arg3);\r
        }\r
        \r
+       \r
 };\r
  \r
 \r
@@ -44,9 +60,9 @@ class  ADORecordSet_firebird extends ADORecordSet_ibase {
        \r
        var $databaseType = "firebird";         \r
        \r
-       function ADORecordSet_firebird($id)\r
+       function ADORecordSet_firebird($id,$mode=false)\r
        {\r
-               $this->ADORecordSet_ibase($id);\r
+               $this->ADORecordSet_ibase($id,$mode);\r
        }\r
 }\r
 ?>
\ No newline at end of file
index fefb2b18a1f9926d712fca4529ffcb54ed860e9e..5a1870c215cf25e494066f05bcd8df1158623754 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.  \r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.  \r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -27,7 +27,8 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
 class ADODB_ibase extends ADOConnection {\r
        var $databaseType = "ibase";\r
        var $dataProvider = "ibase";\r
-       var $replaceQuote = "\'"; // string to use to replace quotes\r
+       var $replaceQuote = "''"; // string to use to replace quotes\r
+       var $ibase_timefmt = '%Y-%m-%d';\r
        var $fmtDate = "'Y-m-d'";\r
        var $fmtTimeStamp = "'Y-m-d, H:i:s'";\r
        var $concat_operator='||';\r
@@ -42,12 +43,44 @@ class ADODB_ibase extends ADOConnection {
        var $sysDate = "cast('TODAY' as date)";\r
        var $sysTimeStamp = "cast('NOW' as timestamp)";\r
        var $ansiOuter = true;\r
+       var $hasAffectedRows = false;\r
+       var $poorAffectedRows = true;\r
+       var $blobEncodeType = 'C';\r
        \r
        function ADODB_ibase() \r
        {\r
-               ibase_timefmt('%Y-%m-%d');\r
-       \r
        }\r
+       \r
+       function MetaPrimaryKeys($table,$owner_notused=false,$internalKey=false)\r
+       {       \r
+               if ($internalKey) return array('RDB$DB_KEY');\r
+               \r
+               $table = strtoupper($table);\r
+               \r
+               $sql = 'SELECT S.RDB$FIELD_NAME AFIELDNAME\r
+       FROM RDB$INDICES I JOIN RDB$INDEX_SEGMENTS S ON I.RDB$INDEX_NAME=S.RDB$INDEX_NAME  \r
+       WHERE I.RDB$RELATION_NAME=\''.$table.'\' and I.RDB$INDEX_NAME like \'RDB$PRIMARY%\'\r
+       ORDER BY I.RDB$INDEX_NAME,S.RDB$FIELD_POSITION';\r
+\r
+               $a = $this->GetCol($sql,false,true);\r
+               if ($a && sizeof($a)>0) return $a;\r
+               return false;     \r
+       }\r
+       \r
+       function ServerInfo()\r
+       {\r
+               $arr['dialect'] = $this->dialect;\r
+               switch($arr['dialect']) {\r
+               case '': \r
+               case '1': $s = 'Interbase 5.5 or earlier'; break;\r
+               case '2': $s = 'Interbase 5.6'; break;\r
+               default:\r
+               case '3': $s = 'Interbase 6.0'; break;\r
+               }\r
+               $arr['version'] = ADOConnection::_findvers($s);\r
+               $arr['description'] = $s;\r
+               return $arr;\r
+       }\r
 \r
        function BeginTrans()\r
        {        \r
@@ -94,7 +127,7 @@ class ADODB_ibase extends ADOConnection {
                return 1;\r
        }\r
        \r
-       // use delete and insert instead\r
+       /*// use delete and insert instead\r
        function Replace($table, $fieldArray, $keyCol,$autoQuote=false)\r
        {\r
                if (count($fieldArray) == 0) return 0;\r
@@ -139,13 +172,25 @@ class ADODB_ibase extends ADOConnection {
                \r
                return ($ok) ? 2 : 0;\r
        }\r
+       */\r
+       function CreateSequence($seqname,$startID=1)\r
+       {\r
+               $ok = $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" ));\r
+               if (!$ok) return false;\r
+               return $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';');\r
+       }\r
+       \r
+       function DropSequence($seqname)\r
+       {\r
+               $seqname = strtoupper($seqname);\r
+               $this->Execute("delete from RDB\$GENERATORS where RDB\$GENERATOR_NAME='$seqname'");\r
+       }\r
        \r
        function GenID($seqname='adodbseq',$startID=1)\r
        {\r
                $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE");\r
                $rs = @$this->Execute($getnext);\r
                if (!$rs) {\r
-                       $u = strtoupper($seqname);\r
                        $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" ));\r
                        $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';');\r
                        $rs = $this->Execute($getnext);\r
@@ -158,7 +203,8 @@ class ADODB_ibase extends ADOConnection {
                return $this->genID;\r
        }\r
 \r
-       function SelectDB($dbName) {\r
+       function SelectDB($dbName) \r
+       {\r
                   return false;\r
        }\r
 \r
@@ -167,19 +213,21 @@ class ADODB_ibase extends ADOConnection {
                $this->_errorMsg = ibase_errmsg();\r
        }\r
 \r
-       function ErrorNo() {\r
-       if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1];\r
-       else return 0;\r
+       function ErrorNo() \r
+       {\r
+               if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1];\r
+               else return 0;\r
        }\r
 \r
-       function ErrorMsg() {\r
+       function ErrorMsg() \r
+       {\r
                        return $this->_errorMsg;\r
        }\r
 \r
           // returns true or false\r
        function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
        {  \r
-\r
+               if ($argDatabasename) $argHostname .= ':'.$argDatabasename;\r
                $this->_connectionID = ibase_connect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect);\r
                if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html\r
                        $this->replaceQuote = "''";\r
@@ -188,12 +236,14 @@ class ADODB_ibase extends ADOConnection {
                        $this->_handleerror();\r
                        return false;\r
                }\r
-       \r
+               \r
+               ibase_timefmt($this->ibase_timefmt);    \r
                return true;\r
        }\r
           // returns true or false\r
        function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
        {\r
+               if ($argDatabasename) $argHostname .= ':'.$argDatabasename;\r
                $this->_connectionID = ibase_pconnect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect);\r
                if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html\r
                        $this->replaceQuote = "''";\r
@@ -203,12 +253,13 @@ class ADODB_ibase extends ADOConnection {
                        return false;\r
                }\r
                \r
+               ibase_timefmt($this->ibase_timefmt);\r
                return true;\r
        }       \r
        \r
        function Prepare($sql)\r
        {\r
-               return $sql;\r
+       //      return $sql;\r
                $stmt = ibase_prepare($sql);\r
                if (!$stmt) return false;\r
                return array($sql,$stmt);\r
@@ -218,12 +269,7 @@ class ADODB_ibase extends ADOConnection {
           // there have been reports of problems with nested queries - the code is probably not re-entrant?\r
        function _query($sql,$iarr=false)\r
        { \r
-               if (is_array($sql)) {\r
-                       $fn = 'ibase_execute';\r
-                       $sql = $sql[1];\r
-               } else\r
-                       $fn = 'ibase_query';\r
-               \r
+\r
                if (!$this->autoCommit && $this->_transactionID) {\r
                        $conn = $this->_transactionID;\r
                        $docommit = false;\r
@@ -231,20 +277,50 @@ class ADODB_ibase extends ADOConnection {
                        $conn = $this->_connectionID;\r
                        $docommit = true;\r
                }\r
-               if (is_array($iarr)) {  \r
-                       switch(sizeof($iarr)) {\r
-                       case 1: $ret = $fn($conn,$sql,$iarr[0]); break;\r
-                       case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break;\r
-                       case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break;\r
-                       case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break;\r
-                       case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break;\r
-                       case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break;\r
-                       case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break;\r
-                       default: ADOConnection::outp( "Too many parameters to ibase query $sql");\r
-                       case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break;\r
-                       }\r
-               } else $ret = $fn($conn,$sql); \r
-                  \r
+               if (is_array($sql)) {\r
+                       $fn = 'ibase_execute';\r
+                       $sql = $sql[1];\r
+                       \r
+                       if (is_array($iarr)) {  \r
+                               if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4\r
+                                       $fnarr = array_merge( array($sql) , $iarr);\r
+                                       $ret = call_user_func_array($fn,$fnarr);\r
+                               } else {\r
+                                       switch(sizeof($iarr)) {\r
+                                       case 1: $ret = $fn($sql,$iarr[0]); break;\r
+                                       case 2: $ret = $fn($sql,$iarr[0],$iarr[1]); break;\r
+                                       case 3: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2]); break;\r
+                                       case 4: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break;\r
+                                       case 5: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break;\r
+                                       case 6: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break;\r
+                                       case 7: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break;\r
+                                       default: ADOConnection::outp( "Too many parameters to ibase query $sql");\r
+                                       case 8: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break;\r
+                                       }\r
+                               }\r
+                       } else $ret = $fn($sql); \r
+               } else {\r
+                       $fn = 'ibase_query';\r
+               \r
+                       if (is_array($iarr)) {  \r
+                               if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4\r
+                                       $fnarr = array_merge( array($conn,$sql) , $iarr);\r
+                                       $ret = call_user_func_array($fn,$fnarr);\r
+                               } else {\r
+                                       switch(sizeof($iarr)) {\r
+                                       case 1: $ret = $fn($conn,$sql,$iarr[0]); break;\r
+                                       case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break;\r
+                                       case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break;\r
+                                       case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break;\r
+                                       case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break;\r
+                                       case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break;\r
+                                       case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break;\r
+                                       default: ADOConnection::outp( "Too many parameters to ibase query $sql");\r
+                                       case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break;\r
+                                       }\r
+                               }\r
+                       } else $ret = $fn($conn,$sql); \r
+               }\r
                if ($docommit && $ret === true) ibase_commit($this->_connectionID);\r
 \r
                $this->_handleerror();\r
@@ -276,7 +352,7 @@ class ADODB_ibase extends ADOConnection {
                        $retarr = array();\r
                        while (!$rs->EOF) { //print_r($rs->fields);\r
                                $fld = new ADOFieldObject();\r
-                               $fld->name = $rs->fields[0];\r
+                               $fld->name = trim($rs->fields[0]);\r
                                $tt = $rs->fields[1];\r
                                switch($tt)\r
                                {\r
@@ -292,6 +368,7 @@ class ADODB_ibase extends ADOConnection {
                                case 35:$tt = 'DATE'; break;\r
                                case 37:$tt = 'VARCHAR'; break;\r
                                case 261:$tt = 'BLOB'; break;\r
+                               case 14: $tt = 'TEXT'; break;\r
                                case 13:\r
                                case 35:$tt = 'TIMESTAMP'; break;\r
                                }\r
@@ -326,12 +403,34 @@ class ADODB_ibase extends ADOConnection {
        function _BlobDecode( $blob ) \r
        {\r
                $blobid = ibase_blob_open( $blob );\r
-               $realblob = ibase_blob_get( $blobid,MAX_BLOB_SIZE); // 2nd param is max size of blob -- Kevin Boillet <kevinboillet@yahoo.fr>\r
+               $realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <kevinboillet@yahoo.fr>\r
+               while($string = ibase_blob_get($blobid, 8192)){ \r
+                       $realblob .= $string; \r
+               }\r
                ibase_blob_close( $blobid );\r
 \r
                return( $realblob );\r
        } \r
        \r
+       function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') \r
+       { \r
+               $fd = fopen($path,'rb'); \r
+               if ($fd === false) return false; \r
+               $blob_id = ibase_blob_create($this->_connectionID); \r
+               \r
+               /* fill with data */ \r
+               \r
+               while ($val = fread($fd,32768)){ \r
+                       ibase_blob_add($blob_id, $val); \r
+               } \r
+               \r
+               /* close and get $blob_id_str for inserting into table */ \r
+               $blob_id_str = ibase_blob_close($blob_id); \r
+               \r
+               fclose($fd); \r
+               return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; \r
+       } \r
+       \r
        /*\r
                Insert a null into the blob field of the table first.\r
                Then use UpdateBlob to store the blob.\r
@@ -341,13 +440,88 @@ class ADODB_ibase extends ADOConnection {
                $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');\r
                $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');\r
        */\r
-       function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')\r
+       function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') \r
+       { \r
+       $blob_id = ibase_blob_create($this->_connectionID); \r
+       \r
+       // ibase_blob_add($blob_id, $val); \r
+       \r
+       // replacement that solves the problem by which only the first modulus 64K / \r
+       // of $val are stored at the blob field //////////////////////////////////// \r
+       // Thx Abel Berenstein  aberenstein#afip.gov.ar\r
+       $len = strlen($val); \r
+       $chunk_size = 32768; \r
+       $tail_size = $len % $chunk_size; \r
+       $n_chunks = ($len - $tail_size) / $chunk_size; \r
+       \r
+       for ($n = 0; $n < $n_chunks; $n++) { \r
+               $start = $n * $chunk_size; \r
+               $data = substr($val, $start, $chunk_size); \r
+               ibase_blob_add($blob_id, $data); \r
+       } \r
+       \r
+       if ($tail_size) {\r
+               $start = $n_chunks * $chunk_size; \r
+               $data = substr($val, $start, $tail_size); \r
+               ibase_blob_add($blob_id, $data); \r
+       }\r
+       // end replacement ///////////////////////////////////////////////////////// \r
+       \r
+       $blob_id_str = ibase_blob_close($blob_id); \r
+       \r
+       return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; \r
+       \r
+       } \r
+       \r
+       \r
+       function OldUpdateBlob($table,$column,$val,$where,$blobtype='BLOB')\r
        {\r
                $blob_id = ibase_blob_create($this->_connectionID);\r
                ibase_blob_add($blob_id, $val);\r
                $blob_id_str = ibase_blob_close($blob_id);\r
                return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false;\r
        }\r
+       \r
+       // Format date column in sql string given an input format that understands Y M D\r
+       // Only since Interbase 6.0 - uses EXTRACT\r
+       // problem - does not zero-fill the day and month yet\r
+       function SQLDate($fmt, $col=false)\r
+       {       \r
+               if (!$col) $col = $this->sysDate;\r
+               $s = '';\r
+               \r
+               $len = strlen($fmt);\r
+               for ($i=0; $i < $len; $i++) {\r
+                       if ($s) $s .= '||';\r
+                       $ch = $fmt[$i];\r
+                       switch($ch) {\r
+                       case 'Y':\r
+                       case 'y':\r
+                               $s .= "extract(year from $col)";\r
+                               break;\r
+                       case 'M':\r
+                       case 'm':\r
+                               $s .= "extract(month from $col)";\r
+                               break;\r
+                       case 'Q':\r
+                       case 'q':\r
+                               $s .= "cast(((extract(month from $col)+2) / 3) as integer)";\r
+                               break;\r
+                       case 'D':\r
+                       case 'd':\r
+                               $s .= "(extract(day from $col))";\r
+                               break;\r
+                       default:\r
+                               if ($ch == '\\') {\r
+                                       $i++;\r
+                                       $ch = substr($fmt,$i,1);\r
+                               }\r
+                               $s .= $this->qstr($ch);\r
+                               break;\r
+                       }\r
+               }\r
+               return $s;\r
+       }\r
 }\r
 \r
 /*--------------------------------------------------------------------------------------\r
@@ -361,11 +535,11 @@ class ADORecordset_ibase extends ADORecordSet
        var $bind=false;\r
        var $_cacheType;\r
        \r
-       function ADORecordset_ibase($id)\r
+       function ADORecordset_ibase($id,$mode=false)\r
        {\r
        global $ADODB_FETCH_MODE;\r
        \r
-                       $this->fetchMode = $ADODB_FETCH_MODE;\r
+                       $this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode;\r
                        return $this->ADORecordSet($id);\r
        }\r
 \r
@@ -378,7 +552,6 @@ class ADORecordset_ibase extends ADORecordSet
        {\r
                         $fld = new ADOFieldObject;\r
                         $ibf = ibase_field_info($this->_queryID,$fieldOffset);\r
-               \r
                         $fld->name = strtolower($ibf['alias']);\r
                         if (empty($fld->name)) $fld->name = strtolower($ibf['name']);\r
                         $fld->type = $ibf['type'];\r
@@ -405,12 +578,13 @@ class ADORecordset_ibase extends ADORecordSet
 \r
        function _fetch() \r
        {\r
-               $f = ibase_fetch_row($this->_queryID); \r
-               if ($f === false) return false;\r
-               \r
+               $f = @ibase_fetch_row($this->_queryID); \r
+               if ($f === false) {\r
+                       $this->fields = false;\r
+                       return false;\r
+               }\r
                // OPN stuff start - optimized\r
-               // fix missing nulls and decode blobs automatically \r
-               // WARNING - this could break bc.\r
+               // fix missing nulls and decode blobs automatically\r
                for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { \r
                        if ($this->_cacheType[$i]=="BLOB") { \r
                                if (isset($f[$i])) { \r
@@ -455,8 +629,13 @@ class ADORecordset_ibase extends ADORecordSet
                        return @ibase_free_result($this->_queryID);\r
        }\r
 \r
-       function MetaType($t,$len=-1)\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
                switch (strtoupper($t)) {\r
                case 'CHAR':\r
                        return 'C';\r
index 8b30f5f1695b25f650d3be04ebba75449fc47188..cd6c1fbc0ab742f6668a81e6472fb24270cd0337 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /**\r
-* @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+* @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
 * Released under both BSD license and Lesser GPL library license.\r
 * Whenever there is any discrepancy between the two licenses,\r
 * the BSD license will take precedence.\r
@@ -22,9 +22,9 @@ class ADODB_informix extends ADODB_informix72 {
 \r
 class ADORecordset_informix extends ADORecordset_informix72 {\r
        var $databaseType = "informix";\r
-       function ADORecordset_informix($id)\r
+       function ADORecordset_informix($id,$mode=false)\r
        {\r
-               $this->ADORecordset_informix72($id);\r
+               $this->ADORecordset_informix72($id,$mode);\r
        }\r
 }\r
 ?>
\ No newline at end of file
index b48ff94699872d3a7e823b7938a0a74dcb0e4e4e..2b1804160d8d011dfd7b480700629daf5a44927b 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim. All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim. All rights reserved.\r
   Released under both BSD license and Lesser GPL library license.\r
   Whenever there is any discrepancy between the two licenses,\r
   the BSD license will take precedence.\r
@@ -100,7 +100,8 @@ class ADODB_informix72 extends ADOConnection {
                return $this->_errorMsg;\r
        }\r
 \r
-   function ErrorNo() {\r
+   function ErrorNo() \r
+   {\r
          return ifx_error();\r
    }\r
 \r
@@ -109,7 +110,17 @@ class ADODB_informix72 extends ADOConnection {
                return ADOConnection::MetaColumns($table,false);\r
    }\r
 \r
+   function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB')\r
+   {\r
+               $type = ($blobtype == 'TEXT') ? 1 : 0;\r
+               $blobid = ifx_create_blob($type,0,$val);\r
+               return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blobid));\r
+   }\r
 \r
+   function BlobDecode($blobid)\r
+   {\r
+               return @ifx_get_blob($blobid);\r
+   }\r
        // returns true or false\r
    function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
        {\r
@@ -201,11 +212,13 @@ class ADORecordset_informix72 extends ADORecordSet {
        var $canSeek = true;\r
        var $_fieldprops = false;\r
 \r
-       function ADORecordset_informix72($id)\r
+       function ADORecordset_informix72($id,$mode=false)\r
        {\r
-       global $ADODB_FETCH_MODE;\r
-\r
-               $this->fetchMode = $ADODB_FETCH_MODE;\r
+               if ($mode === false) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               $this->fetchMode = $mode;\r
                return $this->ADORecordSet($id);\r
        }\r
 \r
index c0eda0f423f7bc08ae73cbcb537c391f33fca6ba..d713cc9a8ddbea8b54dc94994b1cd308c96afbe9 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -32,34 +32,34 @@ Set tabs to 4 for best viewing.
 //        CONVERT(char(12),datecol,120)\r
 //----------------------------------------------------------------\r
 \r
-global $ADODB_mssql_date_order; // 'dmy' and 'mdy' supported\r
 \r
-$ADODB_mssql_has_datetimeconvert = (strnatcmp(PHP_VERSION,'4.2.0')>=0);\r
-if ($ADODB_mssql_has_datetimeconvert) {\r
+// has datetime converstion to YYYY-MM-DD format, and also mssql_fetch_assoc\r
+if (ADODB_PHPVER >= 0x4300) {\r
+// docs say 4.2.0, but testing shows only since 4.3.0 does it work!\r
        ini_set('mssql.datetimeconvert',0); \r
 } else {\r
 global $ADODB_mssql_mths;              // array, months must be upper-case\r
-global $ADODB_mssql_has_datetimeconvert;\r
+\r
 \r
        $ADODB_mssql_date_order = 'mdy'; \r
        $ADODB_mssql_mths = array(\r
                'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,\r
                'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12);\r
 }\r
+\r
 //---------------------------------------------------------------------------\r
 // Call this to autoset $ADODB_mssql_date_order at the beginning of your code,\r
-// just after you connect to the database. Supports mdy and dmy only\r
+// just after you connect to the database. Supports mdy and dmy only.\r
+// Not required for PHP 4.2.0 and above.\r
 function AutoDetect_MSSQL_Date_Order($conn)\r
 {\r
 global $ADODB_mssql_date_order;\r
-\r
        $adate = $conn->GetOne('select getdate()');\r
-       \r
        if ($adate) {\r
                $anum = (int) $adate;\r
                if ($anum > 0) {\r
                        if ($anum > 31) {\r
-                               ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently");\r
+                               //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently");\r
                        } else\r
                                $ADODB_mssql_date_order = 'dmy';\r
                } else\r
@@ -79,7 +79,7 @@ class ADODB_mssql extends ADOConnection {
        var $metaColumnsSQL = "select c.name,t.name,c.length from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'";\r
        var $hasTop = 'top';            // support mssql SELECT TOP 10 * FROM TABLE\r
        var $hasGenID = true;\r
-       var $sysDate = 'convert(datetime,convert(char,getdate(),102),102)';\r
+       var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';\r
        var $sysTimeStamp = 'GetDate()';\r
        var $_has_mssql_init;\r
        var $maxParameterLen = 4000;\r
@@ -88,23 +88,73 @@ class ADODB_mssql extends ADOConnection {
        var $leftOuter = '*=';\r
        var $rightOuter = '=*';\r
        var $ansiOuter = true; // for mssql7 or later\r
+       var $poorAffectedRows = true;\r
+       var $identitySQL = 'select @@IDENTITY'; // 'select SCOPE_IDENTITY'; # for mssql 2000\r
+       \r
        \r
        function ADODB_mssql() \r
-       {                       \r
+       {               \r
                $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0);   \r
        }\r
 \r
-       // might require begintrans -- committrans\r
+       function ServerInfo()\r
+       {\r
+       global $ADODB_FETCH_MODE;\r
+       \r
+               $stmt = $this->PrepareSP('sp_server_info');\r
+               $val = 2;\r
+               if ($this->fetchMode === false) {\r
+                       $savem = $ADODB_FETCH_MODE;\r
+                       $ADODB_FETCH_MODE = ADODB_FETCH_NUM;\r
+               } else \r
+                       $savem = $this->SetFetchMode(ADODB_FETCH_NUM);\r
+               \r
+               \r
+               $this->Parameter($stmt,$val,'attribute_id');\r
+               $row = $this->GetRow($stmt);\r
+               \r
+               //$row = $this->GetRow("execute sp_server_info 2");\r
+               \r
+               if ($this->fetchMode === false) {\r
+                       $ADODB_FETCH_MODE = $savem;\r
+               } else\r
+                       $this->SetFetchMode($savem);\r
+               \r
+               $arr['description'] = $row[2];\r
+               $arr['version'] = ADOConnection::_findvers($arr['description']);\r
+               return $arr;\r
+       }\r
+       \r
        function _insertid()\r
        {\r
-                       return $this->GetOne('select @@identity');\r
+       // SCOPE_IDENTITY()\r
+       // Returns the last IDENTITY value inserted into an IDENTITY column in \r
+       // the same scope. A scope is a module -- a stored procedure, trigger, \r
+       // function, or batch. Thus, two statements are in the same scope if \r
+       // they are in the same stored procedure, function, or batch.\r
+                       return $this->GetOne($this->identitySQL);\r
        }\r
-         // might require begintrans -- committrans\r
+       \r
        function _affectedrows()\r
        {\r
                return $this->GetOne('select @@rowcount');\r
        }\r
        \r
+       var $_dropSeqSQL = "drop table %s";\r
+       \r
+       function CreateSequence($seq='adodbseq',$start=1)\r
+       {\r
+               $start -= 1;\r
+               $this->Execute("create table $seq (id float(53))");\r
+               $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");\r
+               if (!$ok) {\r
+                               $this->Execute('ROLLBACK TRANSACTION adodbseq');\r
+                               return false;\r
+               }\r
+               $this->Execute('COMMIT TRANSACTION adodbseq'); \r
+               return true;\r
+       }\r
+       \r
        function GenID($seq='adodbseq',$start=1)\r
        {       \r
                //$this->debug=1;\r
@@ -232,6 +282,22 @@ class ADODB_mssql extends ADOConnection {
                 return(false); \r
        } \r
 \r
+       // "Stein-Aksel Basma" <basma@accelero.no>\r
+       // tested with MSSQL 2000\r
+       function MetaPrimaryKeys($table)\r
+       {\r
+               $sql = "select k.column_name from information_schema.key_column_usage k,\r
+               information_schema.table_constraints tc \r
+               where tc.constraint_name = k.constraint_name and tc.constraint_type =\r
+               'PRIMARY KEY' and k.table_name = '$table'";\r
+               \r
+               $a = $this->GetCol($sql);\r
+               if ($a && sizeof($a)>0) return $a;\r
+               return false;     \r
+       }\r
+\r
+\r
\r
        function SelectDB($dbName) \r
        {\r
                $this->databaseName = $dbName;\r
@@ -240,8 +306,7 @@ class ADODB_mssql extends ADOConnection {
                }\r
                else return false;      \r
        }\r
-       /*      Returns: the last error message from previous database operation\r
-               Note: This function is NOT available for Microsoft SQL Server.  */\r
+       \r
        function ErrorMsg() \r
        {\r
                if (empty($this->_errorMsg)){\r
@@ -367,9 +432,10 @@ class ADODB_mssql extends ADOConnection {
        // returns query ID if successful, otherwise false\r
        function _query($sql,$inputarr)\r
        {\r
-               $this->_errorMsg = false;\r
-               if (is_array($sql)) return mssql_execute($sql[1]);\r
-               return mssql_query($sql,$this->_connectionID);\r
+               $this->_errorMsg = false; \r
+               if (is_array($sql)) $rez = mssql_execute($sql[1]);\r
+               else $rez = mssql_query($sql,$this->_connectionID);\r
+               return $rez;\r
        }\r
        \r
        // returns true or false\r
@@ -403,13 +469,24 @@ class ADORecordset_mssql extends ADORecordSet {
        var $canSeek = true;\r
        // _mths works only in non-localised system\r
                \r
-       function ADORecordset_mssql($id)\r
+       function ADORecordset_mssql($id,$mode=false)\r
        {\r
-       GLOBAL $ADODB_FETCH_MODE;\r
+               if ($mode === false) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               $this->fetchMode = $mode;\r
+               return $this->ADORecordSet($id,$mode);\r
+       }\r
+       \r
        \r
-               $this->fetchMode = $ADODB_FETCH_MODE;\r
-               return $this->ADORecordSet($id);\r
+       function _initrs()\r
+       {\r
+       GLOBAL $ADODB_COUNTRECS;        \r
+               $this->_numOfRows = ($ADODB_COUNTRECS)? @mssql_num_rows($this->_queryID):-1;\r
+               $this->_numOfFields = @mssql_num_fields($this->_queryID);\r
        }\r
+       \r
 \r
        //Contributed by "Sven Axelsson" <sven.axelsson@bokochwebb.se>\r
        // get next resultset - requires PHP 4.0.5 or later\r
@@ -454,13 +531,6 @@ class ADORecordset_mssql extends ADORecordSet {
                return null;\r
        }\r
        \r
-       function _initrs()\r
-       {\r
-       GLOBAL $ADODB_COUNTRECS;\r
-               $this->_numOfRows = ($ADODB_COUNTRECS)? @mssql_num_rows($this->_queryID):-1;\r
-               $this->_numOfFields = @mssql_num_fields($this->_queryID);\r
-       }\r
-       \r
        function _seek($row) \r
        {\r
                return @mssql_data_seek($this->_queryID, $row);\r
@@ -469,13 +539,19 @@ class ADORecordset_mssql extends ADORecordSet {
        // speedup\r
        function MoveNext() \r
        {\r
-               if (!$this->EOF) {              \r
-                       $this->_currentRow++;\r
-                       if ($this->fetchMode & ADODB_FETCH_ASSOC) {\r
-                       global $ADODB_mssql_has_datetimeconvert;\r
-                               if ($ADODB_mssql_has_datetimeconvert) // only for PHP 4.2.0 or later\r
-                                       $this->fields = @mssql_fetch_assoc($this->_queryID);\r
-                               else {\r
+               if ($this->EOF) return false;\r
+               \r
+               $this->_currentRow++;\r
+               \r
+               if ($this->fetchMode & ADODB_FETCH_ASSOC) {\r
+                       if ($this->fetchMode & ADODB_FETCH_NUM) {\r
+                               //ADODB_FETCH_BOTH mode\r
+                               $this->fields = @mssql_fetch_array($this->_queryID);\r
+                       }\r
+                       else {\r
+                               if (ADODB_PHPVER >= 0x4200) {// only for PHP 4.2.0 or later\r
+                                        $this->fields = @mssql_fetch_assoc($this->_queryID);\r
+                               } else {\r
                                        $flds = @mssql_fetch_array($this->_queryID);\r
                                        if (is_array($flds)) {\r
                                                $fassoc = array();\r
@@ -484,15 +560,27 @@ class ADORecordset_mssql extends ADORecordSet {
                                                        $fassoc[$k] = $v;\r
                                                }\r
                                                $this->fields = $fassoc;\r
-                                       } else \r
-                                               $this->fields = $flds;\r
+                                       }\r
+                               }\r
+                       }\r
+                       \r
+                       if (is_array($this->fields)) {\r
+                               if (ADODB_ASSOC_CASE == 0) {\r
+                                       foreach($this->fields as $k=>$v) {\r
+                                               $this->fields[strtolower($k)] = $v;\r
+                                       }\r
+                               } else if (ADODB_ASSOC_CASE == 1) {\r
+                                       foreach($this->fields as $k=>$v) {\r
+                                               $this->fields[strtoupper($k)] = $v;\r
+                                       }\r
                                }\r
-                       } else {\r
-                               $this->fields = @mssql_fetch_row($this->_queryID);\r
                        }\r
-                       if (is_array($this->fields)) return true;\r
-                       $this->EOF = true;\r
+               } else {\r
+                       $this->fields = @mssql_fetch_row($this->_queryID);\r
                }\r
+               if ($this->fields) return true;\r
+               $this->EOF = true;\r
+               \r
                return false;\r
        }\r
 \r
@@ -502,33 +590,48 @@ class ADORecordset_mssql extends ADORecordSet {
        function _fetch($ignore_fields=false) \r
        {\r
                if ($this->fetchMode & ADODB_FETCH_ASSOC) {\r
-               global $ADODB_mssql_has_datetimeconvert;\r
-                       if ($ADODB_mssql_has_datetimeconvert) // only for PHP 4.2.0 or later\r
-                               $this->fields = @mssql_fetch_assoc($this->_queryID);\r
-                       else {\r
-                               $flds = @mssql_fetch_array($this->_queryID);\r
-                               if (is_array($flds)) {\r
-                                       $fassoc = array();\r
-                                       foreach($flds as $k => $v) {\r
-                                               if (is_integer($k)) continue;\r
-                                               $fassoc[$k] = $v;\r
+                       if ($this->fetchMode & ADODB_FETCH_NUM) {\r
+                               //ADODB_FETCH_BOTH mode\r
+                               $this->fields = @mssql_fetch_array($this->_queryID);\r
+                       } else {\r
+                               if (ADODB_PHPVER >= 0x4200) // only for PHP 4.2.0 or later\r
+                                       $this->fields = @mssql_fetch_assoc($this->_queryID);\r
+                               else {\r
+                                       $this->fields = @mssql_fetch_array($this->_queryID);\r
+                                       if (is_array($$this->fields)) {\r
+                                               $fassoc = array();\r
+                                               foreach($$this->fields as $k => $v) {\r
+                                                       if (is_integer($k)) continue;\r
+                                                       $fassoc[$k] = $v;\r
+                                               }\r
+                                               $this->fields = $fassoc;\r
                                        }\r
-                                       $this->fields = $fassoc;\r
-                               } else\r
-                                       $this->fields = $flds;\r
+                               }\r
+                       }\r
+                       \r
+                       if (!$this->fields) {\r
+                       } else if (ADODB_ASSOC_CASE == 0) {\r
+                               foreach($this->fields as $k=>$v) {\r
+                                       $this->fields[strtolower($k)] = $v;\r
+                               }\r
+                       } else if (ADODB_ASSOC_CASE == 1) {\r
+                               foreach($this->fields as $k=>$v) {\r
+                                       $this->fields[strtoupper($k)] = $v;\r
+                               }\r
                        }\r
                } else {\r
                        $this->fields = @mssql_fetch_row($this->_queryID);\r
                }\r
-               return (!empty($this->fields));\r
+               return $this->fields;\r
        }\r
        \r
        /*      close() only needs to be called if you are worried about using too much memory while your script\r
                is running. All associated result memory for the specified result identifier will automatically be freed.       */\r
 \r
-       function _close() {\r
-               $rez = @mssql_free_result($this->_queryID);     \r
-               $this->_queryID = false;        \r
+       function _close() \r
+       {\r
+               $rez = mssql_free_result($this->_queryID);      \r
+               $this->_queryID = false;\r
                return $rez;\r
        }\r
        // mssql uses a default date like Dec 30 2000 12:00AM\r
@@ -546,16 +649,16 @@ class ADORecordset_mssql extends ADORecordSet {
 \r
 \r
 class ADORecordSet_array_mssql extends ADORecordSet_array {\r
-       function ADORecordSet_array_mssql($id=-1) \r
+       function ADORecordSet_array_mssql($id=-1,$mode=false\r
        {\r
-               $this->ADORecordSet_array($id);\r
+               $this->ADORecordSet_array($id,$mode);\r
        }\r
        \r
                // mssql uses a default date like Dec 30 2000 12:00AM\r
        function UnixDate($v)\r
        {\r
-       global $ADODB_mssql_has_datetimeconvert;\r
-               if ($ADODB_mssql_has_datetimeconvert) return parent::UnixDate($v);\r
+       \r
+               if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v);\r
                \r
        global $ADODB_mssql_mths,$ADODB_mssql_date_order;\r
        \r
@@ -585,8 +688,8 @@ class ADORecordSet_array_mssql extends ADORecordSet_array {
        \r
        function UnixTimeStamp($v)\r
        {\r
-       global $ADODB_mssql_has_datetimeconvert;\r
-               if ($ADODB_mssql_has_datetimeconvert) return parent::UnixTimeStamp($v);\r
+       \r
+               if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v);\r
                \r
        global $ADODB_mssql_mths,$ADODB_mssql_date_order;\r
        \r
index 628668f1f25637134b112adc68abff17839c0d2c..6784bba5e7214dbefacc88fd727fd470ef634b29 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /**\r
-* @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+* @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
 * Released under both BSD license and Lesser GPL library license.\r
 * Whenever there is any discrepancy between the two licenses,\r
 * the BSD license will take precedence.\r
 *  Portable MSSQL Driver that supports || instead of +\r
 *\r
 */\r
+\r
+\r
+/*\r
+       The big difference between mssqlpo and it's parent mssql is that mssqlpo supports\r
+       the more standard || string concatenation operator.\r
+*/\r
+       \r
 include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php');\r
 \r
 class ADODB_mssqlpo extends ADODB_mssql {\r
        var $databaseType = "mssqlpo";\r
+       var $concat_operator = '||'; \r
+       \r
+       function ADODB_mssqlpo()\r
+       {\r
+               ADODB_mssql::ADODB_mssql();\r
+       }\r
+\r
+       function PrepareSP($sql)\r
+       {\r
+               if (!$this->_has_mssql_init) {\r
+                       ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0");\r
+                       return $sql;\r
+               }\r
+               if (is_string($sql)) $sql = str_replace('||','+',$sql);\r
+               $stmt = mssql_init($sql,$this->_connectionID);\r
+               if (!$stmt)  return $sql;\r
+               return array($sql,$stmt);\r
+       }\r
        \r
-       /*\r
-               The big difference between mssqlpo and it's parent mssql is that mssqlpo supports\r
-               the more standard || string concatenation operator.\r
-       */\r
        function _query($sql,$inputarr)\r
        {\r
-               return ADODB_mssql::_query(str_replace('||','+',$sql),$inputarr);\r
+               if (is_string($sql)) $sql = str_replace('||','+',$sql);\r
+               return ADODB_mssql::_query($sql,$inputarr);\r
        }\r
 }\r
 \r
 class ADORecordset_mssqlpo extends ADORecordset_mssql {\r
        var $databaseType = "mssqlpo";\r
-       function ADORecordset_mssqlpo($id)\r
+       function ADORecordset_mssqlpo($id,$mode=false)\r
        {\r
-               $this->ADORecordset_mssql($id);\r
-       }\r
-       \r
-       function MoveNext() \r
-       {\r
-               if (!$this->EOF) {              \r
-                       $this->_currentRow++;\r
-                       if ($this->fetchMode & ADODB_FETCH_ASSOC) {\r
-                       global $ADODB_mssql_has_datetimeconvert;\r
-                               if ($ADODB_mssql_has_datetimeconvert) // only for PHP 4.2.0 or later\r
-                                       $this->fields = @mssql_fetch_assoc($this->_queryID);\r
-                               else {\r
-                                       $flds = @mssql_fetch_array($this->_queryID);\r
-                                       if (is_array($flds)) {\r
-                                               $fassoc = array();\r
-                                               foreach($flds as $k => $v) {\r
-                                                       if (is_numeric($k)) continue;\r
-                                                       $fassoc[$k] = $v;\r
-                                               }\r
-                                               $this->fields = $fassoc;\r
-                                       } else \r
-                                               $this->fields = $flds;\r
-                               }\r
-                       } else {\r
-                               $this->fields = @mssql_fetch_row($this->_queryID);\r
-                       }\r
-                       if (is_array($this->fields)) return true;\r
-                       $this->EOF = true;\r
-               }\r
-               return false;\r
+               $this->ADORecordset_mssql($id,$mode);\r
        }\r
 }\r
 ?>
\ No newline at end of file
index 876b9e72a5fa9e833659befe769f95f9f08a37d2..4582fb7864f4de2e1fadc27feaafb57d151de02c 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -30,12 +30,45 @@ class ADODB_mysql extends ADOConnection {
        var $isoDates = true; // accepts dates in ISO format\r
        var $sysDate = 'CURDATE()';\r
        var $sysTimeStamp = 'NOW()';\r
+       var $hasTransactions = false;\r
        var $forceNewConnect = false;\r
+       var $poorAffectedRows = true;\r
+       var $clientFlags = 0;\r
+       var $dbxDriver = 1;\r
        \r
        function ADODB_mysql() \r
        {                       \r
        }\r
        \r
+       function ServerInfo()\r
+       {\r
+               $arr['description'] = $this->GetOne("select version()");\r
+               $arr['version'] = ADOConnection::_findvers($arr['description']);\r
+               return $arr;\r
+       }\r
+       \r
+       // if magic quotes disabled, use mysql_real_escape_string()\r
+       function qstr($s,$magic_quotes=false)\r
+       {\r
+               if (!$magic_quotes) {\r
+               \r
+                       if (ADODB_PHPVER >= 0x4300) {\r
+                               if (is_resource($this->_connectionID))\r
+                                       return "'".mysql_real_escape_string($s,$this->_connectionID)."'";\r
+                               else\r
+                                       return "'".mysql_real_escape_string($s)."'";\r
+                       }\r
+                       if ($this->replaceQuote[0] == '\\'){\r
+                               $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);\r
+                       }\r
+                       return  "'".str_replace("'",$this->replaceQuote,$s)."'"; \r
+               }\r
+               \r
+               // undo magic quotes for "\r
+               $s = str_replace('\\"','"',$s);\r
+               return "'$s'";\r
+       }\r
+       \r
        function _insertid()\r
        {\r
                        return mysql_insert_id($this->_connectionID);\r
@@ -51,10 +84,23 @@ class ADODB_mysql extends ADOConnection {
        var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";\r
        var $_genSeqSQL = "create table %s (id int not null)";\r
        var $_genSeq2SQL = "insert into %s values (%s)";\r
+       var $_dropSeqSQL = "drop table %s";\r
+       \r
+       function CreateSequence($seqname='adodbseq',$startID=1)\r
+       {\r
+               if (empty($this->_genSeqSQL)) return false;\r
+               $u = strtoupper($seqname);\r
+               \r
+               $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));\r
+               if (!$ok) return false;\r
+               return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));\r
+       }\r
        \r
        function GenID($seqname='adodbseq',$startID=1)\r
        {\r
-               //if (!$this->hasGenID) return false;\r
+               // post-nuke sets hasGenID to false\r
+               if (!$this->hasGenID) return false;\r
+               \r
                $getnext = sprintf($this->_genIDSQL,$seqname);\r
                $rs = @$this->Execute($getnext);\r
                if (!$rs) {\r
@@ -160,10 +206,15 @@ class ADODB_mysql extends ADOConnection {
        // returns true or false\r
        function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
        {\r
-               if ($this->forceNewConnect && (strnatcmp(PHP_VERSION,'4.2.0')>=0))\r
-                       $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,true);\r
+               if (ADODB_PHPVER >= 0x4300)\r
+                       $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,\r
+                                                                                               $this->forceNewConnect,$this->clientFlags);\r
+               else if (ADODB_PHPVER >= 0x4200)\r
+                       $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,\r
+                                                                                               $this->forceNewConnect);\r
                else\r
                        $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);\r
+       \r
                if ($this->_connectionID === false) return false;\r
                if ($argDatabasename) return $this->SelectDB($argDatabasename);\r
                return true;    \r
@@ -172,13 +223,22 @@ class ADODB_mysql extends ADOConnection {
        // returns true or false\r
        function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
        {\r
-               $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);\r
+               if (ADODB_PHPVER >= 0x4300)\r
+                       $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);\r
+               else\r
+                       $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);\r
                if ($this->_connectionID === false) return false;\r
                if ($this->autoRollback) $this->RollbackTrans();\r
                if ($argDatabasename) return $this->SelectDB($argDatabasename);\r
                return true;    \r
        }\r
        \r
+       function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
+       {\r
+               $this->forceNewConnect = true;\r
+               $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);\r
+       }\r
+       \r
        function &MetaColumns($table) \r
        {\r
        \r
@@ -254,9 +314,10 @@ class ADODB_mysql extends ADOConnection {
        // returns queryID or false\r
        function _query($sql,$inputarr)\r
        {\r
-       global $ADODB_COUNTRECS;\r
-               if($ADODB_COUNTRECS) return mysql_query($sql,$this->_connectionID);\r
-               else return mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6\r
+       //global $ADODB_COUNTRECS;\r
+               //if($ADODB_COUNTRECS) \r
+               return mysql_query($sql,$this->_connectionID);\r
+               //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6\r
        }\r
 \r
        /*      Returns: the last error message from previous database operation        */      \r
@@ -283,29 +344,6 @@ class ADODB_mysql extends ADOConnection {
                $this->_connectionID = false;\r
        }\r
 \r
-        function ActualType($meta)\r
-       {\r
-               switch($meta) {\r
-               case 'C': return 'VARCHAR';\r
-               case 'X': return 'LONGTEXT';\r
-               \r
-               case 'C2': return 'VARCHAR';\r
-               case 'X2': return 'LONGTEXT';\r
-               \r
-               case 'B': return 'LONGBLOB';\r
-                       \r
-               case 'D': return 'DATE';\r
-               case 'T': return 'DATETIME';\r
-               case 'L': return 'TINYINT';\r
-               case 'R': return 'INTEGER NOT NULL AUTO_INCREMENT';\r
-               case 'I': return 'INTEGER';  // enough for 9 petabytes!\r
-               \r
-               case 'F': return 'DOUBLE';\r
-               case 'N': return 'NUMERIC';\r
-               default:\r
-                       return false;\r
-               }\r
-       }\r
        \r
        /*\r
        * Maximum size of C field\r
@@ -334,10 +372,13 @@ class ADORecordSet_mysql extends ADORecordSet{
        var $databaseType = "mysql";\r
        var $canSeek = true;\r
        \r
-       function ADORecordSet_mysql($queryID) {\r
-       GLOBAL $ADODB_FETCH_MODE;\r
-       \r
-               switch ($ADODB_FETCH_MODE)\r
+       function ADORecordSet_mysql($queryID,$mode=false) \r
+       {\r
+               if ($mode === false) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               switch ($mode)\r
                {\r
                case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;\r
                case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;\r
@@ -351,8 +392,9 @@ class ADORecordSet_mysql extends ADORecordSet{
        \r
        function _initrs()\r
        {\r
-       GLOBAL $ADODB_COUNTRECS;\r
-               $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;\r
+       //GLOBAL $ADODB_COUNTRECS;\r
+       //      $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;\r
+               $this->_numOfRows = @mysql_num_rows($this->_queryID);\r
                $this->_numOfFields = @mysql_num_fields($this->_queryID);\r
        }\r
        \r
@@ -377,7 +419,7 @@ class ADORecordSet_mysql extends ADORecordSet{
 \r
        function &GetRowAssoc($upper=true)\r
        {\r
-               if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $rs->fields;\r
+               if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $this->fields;\r
                return ADORecordSet::GetRowAssoc($upper);\r
        }\r
        \r
@@ -399,34 +441,24 @@ class ADORecordSet_mysql extends ADORecordSet{
        \r
        function _seek($row)\r
        {\r
+               if ($this->_numOfRows == 0) return false;\r
                return @mysql_data_seek($this->_queryID,$row);\r
        }\r
        \r
-       /*function &FetchRow()\r
+       \r
+       // 10% speedup to move MoveNext to child class\r
+       function MoveNext() \r
        {\r
+       //global $ADODB_EXTENSION;if ($ADODB_EXTENSION) return adodb_movenext($this);\r
+       \r
                if ($this->EOF) return false;\r
-               \r
-               $arr = $this->fields;\r
+                               \r
                $this->_currentRow++;\r
-                       // using & below slows things down by 20%!\r
                $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);\r
-                       \r
-               if (is_array($this->fields)) return $arr;\r
+               if (is_array($this->fields)) return true;\r
+               \r
                $this->EOF = true;\r
-               return false;\r
-       } */\r
-       \r
-       // 10% speedup to move MoveNext to child class\r
-       function MoveNext() \r
-       {\r
-               if (!$this->EOF) {              \r
-                       $this->_currentRow++;\r
-                       // using & below slows things down by 20%!\r
-                       $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);\r
-                       \r
-                       if (is_array($this->fields)) return true;\r
-                       $this->EOF = true;\r
-               }\r
+               \r
                /* -- tested raising an error -- appears pointless\r
                $conn = $this->connection;\r
                if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) {\r
@@ -439,8 +471,8 @@ class ADORecordSet_mysql extends ADORecordSet{
        \r
        function _fetch()\r
        {\r
-               $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);\r
-               return (is_array($this->fields));\r
+               $this->fields =  @mysql_fetch_array($this->_queryID,$this->fetchMode);\r
+               return is_array($this->fields);\r
        }\r
        \r
        function _close() {\r
@@ -450,6 +482,12 @@ class ADORecordSet_mysql extends ADORecordSet{
        \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
+               \r
                $len = -1; // mysql max_length is not accurate\r
                switch (strtoupper($t)) {\r
                case 'STRING': \r
@@ -473,7 +511,7 @@ class ADORecordSet_mysql extends ADORecordSet{
                case 'BLOB':\r
                case 'MEDIUMBLOB':\r
                        return !empty($fieldobj->binary) ? 'B' : 'X';\r
-                       \r
+               case 'YEAR':\r
                case 'DATE': return 'D';\r
                \r
                case 'TIME':\r
index 56c30056ef78be06733a67bca1647433b9378ddd..5b8e8ffa0d65ec383bb551c7ea537b9cf5c8c6f2 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -20,6 +20,7 @@ include_once(ADODB_DIR."/drivers/adodb-mysql.inc.php");
 class ADODB_mysqlt extends ADODB_mysql {\r
        var $databaseType = 'mysqlt';\r
        var $ansiOuter = true; // for Version 3.23.17 or later\r
+       var $hasTransactions = true;\r
        \r
        function BeginTrans()\r
        {         \r
@@ -55,20 +56,20 @@ class ADODB_mysqlt extends ADODB_mysql {
 class ADORecordSet_mysqlt extends ADORecordSet_mysql{  \r
        var $databaseType = "mysqlt";\r
        \r
-       function ADORecordSet_mysqlt($queryID) {\r
-               return $this->ADORecordSet_mysql($queryID);\r
+       function ADORecordSet_mysqlt($queryID,$mode=false) {\r
+               return $this->ADORecordSet_mysql($queryID,$mode);\r
        }\r
        \r
        function MoveNext() \r
-       {\r
-               if (!$this->EOF) {              \r
-                       $this->_currentRow++;\r
-                       // using & below slows things down by 20%!\r
-                       $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);\r
-                       \r
-                       if (is_array($this->fields)) return true;\r
-                       $this->EOF = true;\r
-               }\r
+       {       \r
+               if ($this->EOF) return false;\r
+\r
+               $this->_currentRow++;\r
+               // using & below slows things down by 20%!\r
+               $this->fields =  @mysql_fetch_array($this->_queryID,$this->fetchMode);\r
+               if ($this->fields) return true;\r
+               $this->EOF = true;\r
+               \r
                return false;\r
        }       \r
 }\r
index 7ed7ea71221d35d95a9611569df9dd85c5486a6b..85d2c98c8f421aa541e7b911d3731831b37ff183 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 /*\r
 \r
-  version V2.50 14 Nov 2002 (c) 2000-2002 John Lim. All rights reserved.\r
+  version V3.40 7 April 2003 (c) 2000-2003 John Lim. All rights reserved.\r
 \r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
@@ -51,6 +51,7 @@ class ADODB_oci8 extends ADOConnection {
        var $hasGenID = true;\r
        var $_genIDSQL = "SELECT (%s.nextval) FROM DUAL";\r
        var $_genSeqSQL = "CREATE SEQUENCE %s START WITH %s";\r
+       var $_dropSeqSQL = "DROP SEQUENCE %s";\r
        var $hasAffectedRows = true;\r
        var $upperCase = 'upper';\r
        var $noNullStrings = false;\r
@@ -69,22 +70,28 @@ class ADODB_oci8 extends ADOConnection {
     \r
        function ADODB_oci8() \r
        {\r
-               $this->_hasOCIFetchStatement = (strnatcmp(PHP_VERSION,'4.2.0')>=0);;\r
+       \r
+               $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200;\r
        }\r
        \r
        \r
 /*\r
 \r
-  4 modes of connection are supported:\r
+  Multiple modes of connection are supported:\r
   \r
-  a. $conn->Connect(false,'scott','tiger'); // local database\r
+  a. Local Database\r
+    $conn->Connect(false,'scott','tiger');\r
   \r
-  b. $conn->Connect(false,'scott','tiger',$tnsname); // from tnsnames.ora\r
+  b. From tnsnames.ora\r
+    $conn->Connect(false,'scott','tiger',$tnsname); \r
+    $conn->Connect($tnsname,'scott','tiger'); \r
   \r
-  c. $conn->Connect($serveraddress,'scott,'tiger',$service_name); \r
+  c. Server + service name\r
+    $conn->Connect($serveraddress,'scott,'tiger',$service_name);\r
   \r
-  d. $conn->connectSID = true;\r
-        $conn->Connect($serveraddress,'scott,'tiger',$SID);\r
+  d. Server + SID\r
+       $conn->connectSID = true;\r
+       $conn->Connect($serveraddress,'scott,'tiger',$SID);\r
 \r
 \r
 Example TNSName:\r
@@ -98,32 +105,37 @@ NATSOFT.DOMAIN =
          (SERVICE_NAME = natsoft.domain)\r
        )\r
   )\r
+  \r
+  There are 3 connection modes, 0 = non-persistent, 1 = persistent, 2 = force new connection\r
        \r
 */\r
-       // returns true or false\r
-       function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$persist=false, $new=false)\r
+       function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$mode=0)\r
        {\r
                if($argHostname) { // added by Jorma Tuomainen <jorma.tuomainen@ppoy.fi>\r
-                       if(strpos($argHostname,":")) {\r
-                               $argHostinfo=explode(":",$argHostname);\r
-                               $argHostname=$argHostinfo[0];\r
-                               $argHostport=$argHostinfo[1];\r
-                       } else {\r
-                               $argHostport="1521";\r
-                       }\r
-                       \r
-                       if ($this->connectSID) {\r
-                               $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname\r
-                               .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";\r
-                       } else\r
-                               $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname\r
-                               .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";\r
+                       if (empty($argDatabasename)) $argDatabasename = $argHostname;\r
+                       else {\r
+                               if(strpos($argHostname,":")) {\r
+                                       $argHostinfo=explode(":",$argHostname);\r
+                                       $argHostname=$argHostinfo[0];\r
+                                       $argHostport=$argHostinfo[1];\r
+                               } else {\r
+                                       $argHostport="1521";\r
+                               }\r
+                               \r
+                               if ($this->connectSID) {\r
+                                       $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname\r
+                                       .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";\r
+                               } else\r
+                                       $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname\r
+                                       .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";\r
+                       }\r
                }\r
                                \r
                //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";\r
-               if ($persist) {\r
+               if ($mode==1) {\r
                        $this->_connectionID = OCIPLogon($argUsername,$argPassword, $argDatabasename);\r
-               } else if ($new) {\r
+                       if ($this->_connectionID && $this->autoRollback)  OCIrollback($this->_connectionID);\r
+               } else if ($mode==2) {\r
                        $this->_connectionID = OCINLogon($argUsername,$argPassword, $argDatabasename);\r
                } else {\r
                        $this->_connectionID = OCILogon($argUsername,$argPassword, $argDatabasename);\r
@@ -133,24 +145,30 @@ NATSOFT.DOMAIN =
                        $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'");\r
                }\r
                \r
-               if ($persist && $this->autoRollback)  OCIrollback($this->_connectionID);\r
-               \r
                // looks like: \r
                // Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production With the Partitioning option JServer Release 8.1.7.0.0 - Production\r
                // $vers = OCIServerVersion($this->_connectionID);\r
                // if (strpos($vers,'8i') !== false) $this->ansiOuter = true;\r
                return true;\r
        }\r
+       \r
+       function ServerInfo()\r
+       {\r
+               $arr['compat'] = $this->GetOne('select value from sys.database_compatible_level');\r
+               $arr['description'] = @OCIServerVersion($this->_connectionID);\r
+               $arr['version'] = ADOConnection::_findvers($arr['description']);\r
+               return $arr;\r
+       }\r
                // returns true or false\r
        function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
        {\r
-               return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,true);\r
+               return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,1);\r
        }\r
        \r
        // returns true or false\r
        function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
        {\r
-               return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,false, true);\r
+               return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,2);\r
        }\r
        \r
        function Affected_Rows()\r
@@ -164,7 +182,7 @@ NATSOFT.DOMAIN =
                if (empty($d) && $d !== 0) return 'null';\r
                \r
                if (is_string($d)) $d = ADORecordSet::UnixDate($d);\r
-               return "TO_DATE(".date($this->fmtDate,$d).",'".$this->NLS_DATE_FORMAT."')";\r
+               return "TO_DATE(".adodb_date($this->fmtDate,$d).",'".$this->NLS_DATE_FORMAT."')";\r
        }\r
 \r
        \r
@@ -173,7 +191,7 @@ NATSOFT.DOMAIN =
        {\r
                if (empty($ts) && $ts !== 0) return 'null';\r
                if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);\r
-               return 'TO_DATE('.date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";\r
+               return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";\r
        }\r
        \r
        function RowLock($tables,$where) \r
@@ -223,6 +241,7 @@ NATSOFT.DOMAIN =
        function ErrorMsg() \r
        {\r
                $arr = @OCIerror($this->_stmt);\r
+               \r
                if ($arr === false) {\r
                        $arr = @OCIerror($this->_connectionID);\r
                        if ($arr === false) $arr = @OCIError();\r
@@ -496,15 +515,26 @@ NATSOFT.DOMAIN =
                \r
                Example:\r
                        Note: we return a cursor variable in :RS2\r
-                       $rs = $db->RunCursor("BEGIN adodb.open_tab(:RS2); END;",'RS2');\r
+                       $rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:RS2); END;",'RS2');\r
+                       \r
+                       $rs = $db->ExecuteCursor(\r
+                               "BEGIN :RS2 = adodb.getdata(:VAR1); END;", \r
+                               'RS2',\r
+                               array('VAR1' => 'Mr Bean'));\r
                        \r
        */\r
-       function &ExecuteCursor($sql,$cursorName='rs')\r
+       function &ExecuteCursor($sql,$cursorName='rs',$params=false)\r
        {\r
                $stmt = ADODB_oci8::Prepare($sql);\r
                        \r
                if (is_array($stmt) && sizeof($stmt) >= 5) {\r
                        $this->Parameter($stmt, $ignoreCur, $cursorName, false, -1, OCI_B_CURSOR);\r
+                       if ($params) {\r
+                               reset($params);\r
+                               while (list($k,$v) = each($params)) {\r
+                                       $this->Parameter($stmt,$params[$k], $k);\r
+                               }\r
+                       }\r
                }\r
                return $this->Execute($stmt);\r
        }\r
@@ -685,21 +715,25 @@ NATSOFT.DOMAIN =
                $this->_connectionID = false;\r
        }\r
        \r
-       function MetaPrimaryKeys($table, $owner=false)\r
+       function MetaPrimaryKeys($table, $owner=false,$internalKey=false)\r
        {\r
+               if ($internalKey) return array('ROWID');\r
+               \r
        // tested with oracle 8.1.7\r
                $table = strtoupper($table);\r
                if ($owner) {\r
                        $owner_clause = "AND ((a.OWNER = b.OWNER) AND (a.OWNER = UPPER('$owner')))";\r
                } else $owner_clause = '';\r
                \r
-               $sql = "SELECT /*+ RULE */ distinct b.column_name\r
+               $sql = "\r
+SELECT /*+ RULE */ distinct b.column_name\r
    FROM ALL_CONSTRAINTS a\r
          , ALL_CONS_COLUMNS b\r
   WHERE ( UPPER(b.table_name) = ('$table'))\r
        AND (UPPER(a.table_name) = ('$table') and a.constraint_type = 'P')\r
        $owner_clause\r
        AND (a.constraint_name = b.constraint_name)";\r
+\r
                $rs = $this->Execute($sql);\r
                if ($rs && !$rs->EOF) {\r
                        $arr = $rs->GetArray();\r
@@ -713,29 +747,6 @@ NATSOFT.DOMAIN =
        }\r
        \r
 \r
-       function ActualType($meta)\r
-       {\r
-               switch($meta) {\r
-               case 'C': return 'VARCHAR';\r
-               case 'X': return 'VARCHAR(4000)';\r
-               \r
-               case 'C2': return 'NVARCHAR';\r
-               case 'X2': return 'NVARCHAR(4000)';\r
-               \r
-               case 'B': return 'BLOB';\r
-                       \r
-               case 'D': \r
-               case 'T': return 'DATE';\r
-               case 'L': return 'NUMBER(1)';\r
-               case 'R': return false;\r
-               case 'I': return 'NUMBER(16)';  // enough for 9 petabytes!\r
-               \r
-               case 'F': return 'NUMBER';\r
-               case 'N': return 'NUMBER';\r
-               default:\r
-                       return false;\r
-               }\r
-       }\r
        \r
        function CharMax()\r
        {\r
@@ -794,11 +805,13 @@ class ADORecordset_oci8 extends ADORecordSet {
        var $_fieldobjs;\r
        //var $_arr = false;\r
                \r
-       function ADORecordset_oci8($queryID)\r
+       function ADORecordset_oci8($queryID,$mode=false)\r
        {\r
-       global $ADODB_FETCH_MODE;\r
-\r
-               switch ($ADODB_FETCH_MODE)\r
+               if ($mode === false) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               switch ($mode)\r
                {\r
                default:\r
                case ADODB_FETCH_NUM: $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break;\r
@@ -815,17 +828,18 @@ class ADORecordset_oci8 extends ADORecordSet {
                if ($this->_inited) return;\r
                \r
                $this->_inited = true;\r
-               $this->fields = array();\r
                \r
                if ($this->_queryID) {\r
                                                \r
                        $this->_currentRow = 0;\r
-                       \r
                        @$this->_initrs();\r
-                       \r
                        $this->EOF = !$this->_fetch();  \r
-               \r
+                       if (!is_array($this->fields)) {\r
+                               $this->_numOfRows = 0;\r
+                               $this->fields = array();\r
+                       }\r
                } else {\r
+                       $this->fields = array();\r
                        $this->_numOfRows = 0;\r
                        $this->_numOfFields = 0;\r
                        $this->EOF = true;\r
@@ -869,35 +883,19 @@ class ADORecordset_oci8 extends ADORecordSet {
                return $this->_fieldobjs[$fieldOffset];\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
-       //      if ($this->_arr) return $this->_arr;\r
-               $results = array();\r
-               $cnt = 0;\r
-               while (!$this->EOF && $nRows != $cnt) {\r
-                       $results[$cnt++] = $this->fields;\r
-                       $this->MoveNext();\r
-               }\r
-               return $results;\r
-       }\r
        \r
        // 10% speedup to move MoveNext to child class\r
        function MoveNext() \r
        {\r
-               if (!$this->EOF) {              \r
-                       $this->_currentRow++;\r
-                       if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode))\r
-                               return true;\r
-                       \r
-                       $this->EOF = true;\r
-               }\r
+       //global $ADODB_EXTENSION;if ($ADODB_EXTENSION) return @adodb_movenext($this);\r
+               \r
+               if ($this->EOF) return false;\r
+               \r
+               $this->_currentRow++;\r
+               if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode))\r
+                       return true;\r
+               $this->EOF = true;\r
+               \r
                return false;\r
        }       \r
        \r
@@ -957,6 +955,11 @@ class ADORecordset_oci8 extends ADORecordSet {
 \r
        function MetaType($t,$len=-1)\r
        {\r
+               if (is_object($t)) {\r
+                       $fieldobj = $t;\r
+                       $t = $fieldobj->type;\r
+                       $len = $fieldobj->max_length;\r
+               }\r
                switch (strtoupper($t)) {\r
                case 'VARCHAR':\r
                case 'VARCHAR2':\r
@@ -965,10 +968,10 @@ class ADORecordset_oci8 extends ADORecordSet {
                case 'BINARY':\r
                case 'NCHAR':\r
                case 'NVARCHAR':\r
-                                if ($len <= $this->blobSize) return 'C';\r
+                                if (isset($this) && $len <= $this->blobSize) return 'C';\r
                \r
                case 'NCLOB':\r
-                        case 'LONG':\r
+               case 'LONG':\r
                case 'LONG VARCHAR':\r
                case 'CLOB';\r
                return 'X';\r
index c9b76affba8402b4fbccc738f283233c4ee8b3d1..17b2f0740b8515577dffe476600c4f2250c91376 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
  * Whenever there is any discrepancy between the two licenses, \r
  * the BSD license will take precedence. \r
@@ -48,9 +48,9 @@ class ADODB_oci805 extends ADODB_oci8 {
 \r
 class ADORecordset_oci805 extends ADORecordset_oci8 {  \r
        var $databaseType = "oci805";\r
-       function ADORecordset_oci805($id)\r
+       function ADORecordset_oci805($id,$mode=false)\r
        {\r
-               $this->ADORecordset_oci8($id);\r
+               $this->ADORecordset_oci8($id,$mode);\r
        }\r
 }\r
 ?>
\ No newline at end of file
index 5e0ab42c11ccd18aaefa6fc611caec8dcaabdd23..c11e8c9d67d3b0c91a96f439212ad25858e10b0e 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim. All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim. All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -22,6 +22,8 @@ include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
 class ADODB_oci8po extends ADODB_oci8 {\r
        var $databaseType = 'oci8po';\r
        var $dataProvider = 'oci8';\r
+       var $metaColumnsSQL = "select lower(cname),coltype,width from col where tname='%s' order by colno";\r
+       var $metaTablesSQL = "select lower(table_name) from cat where table_type in ('TABLE','VIEW')";\r
        \r
        function Prepare($sql)\r
        {\r
@@ -52,6 +54,7 @@ class ADODB_oci8po extends ADODB_oci8 {
                }\r
                return ADODB_oci8::_query($sql,$inputarr);\r
        }\r
+       \r
 \r
 }\r
 \r
@@ -63,9 +66,9 @@ class ADORecordset_oci8po extends ADORecordset_oci8 {
 \r
        var $databaseType = 'oci8po';\r
        \r
-               function ADORecordset_oci8po($queryID)\r
+               function ADORecordset_oci8po($queryID,$mode=false)\r
                {\r
-                       $this->ADORecordset_oci8($queryID);\r
+                       $this->ADORecordset_oci8($queryID,$mode);\r
                }\r
 \r
                function Fields($colname)\r
@@ -107,7 +110,6 @@ class ADORecordset_oci8po extends ADORecordset_oci8 {
                                if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();\r
                                return true;\r
                        }\r
-                       \r
                        $this->EOF = true;\r
                }\r
                return false;\r
@@ -132,13 +134,21 @@ class ADORecordset_oci8po extends ADORecordset_oci8 {
                return $results;\r
        }\r
 \r
-       // Uggh - a useless slowdown\r
+       // Create associative array\r
        function _updatefields()\r
        {\r
+               if (ADODB_ASSOC_CASE == 2) return; // native\r
+               \r
                $arr = array();\r
+               $lowercase = ADODB_ASSOC_CASE == 0;\r
                foreach ($this->fields as $k => $v) {\r
                        if (is_integer($k)) $arr[$k] = $v;\r
-                       else $arr[strtolower($k)] = $v;\r
+                       else {\r
+                               if ($lowercase)\r
+                                       $arr[strtolower($k)] = $v;\r
+                               else\r
+                                       $arr[strtoupper($k)] = $v;\r
+                       }\r
                }\r
                $this->fields = $arr;\r
        }\r
@@ -146,7 +156,9 @@ class ADORecordset_oci8po extends ADORecordset_oci8 {
        function _fetch() \r
        {\r
                $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);\r
-               if ($ret && $this->fetchMode & OCI_ASSOC) $this->_updatefields();\r
+               if ($ret) {\r
+                       if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();\r
+               }\r
                return $ret;\r
        }\r
        \r
index b9e5a6daa6d0e1ce0b0d4a49bd4b6831eb4f730a..e1280dd6a2f9e112783a4a9383cb362dc6f21eaf 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -33,11 +33,37 @@ class ADODB_odbc extends ADOConnection {
        var $_autocommit = true;\r
        var $_haserrorfunctions = true;\r
        var $_has_stupid_odbc_fetch_api_change = true;\r
+       var $_lastAffectedRows = 0;\r
        \r
        function ADODB_odbc() \r
        {       \r
-               $this->_haserrorfunctions = (strnatcmp(PHP_VERSION,'4.0.5')>=0);\r
-               $this->_has_stupid_odbc_fetch_api_change = (strnatcmp(PHP_VERSION,'4.2.0')>=0);\r
+               $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050;\r
+               $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;\r
+       }\r
+       \r
+       function ServerInfo()\r
+       {\r
+       \r
+               if (!empty($this->host) && ADODB_PHPVER >= 0x4300) {\r
+                       $dsn = strtoupper($this->host);\r
+                       $first = true;\r
+                       $found = false;\r
+                       while(true) {\r
+                               $rez = odbc_data_source($this->_connectionID,\r
+                                       $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT);\r
+                               $first = false;\r
+                               if (!is_array($rez)) break;\r
+                               if (strtoupper($rez['server']) == $dsn) {\r
+                                       $found = true;\r
+                                       break;\r
+                               }\r
+                       } \r
+                       if (!$found) return ADOConnection::ServerInfo();\r
+                       if (!isset($rez['version'])) $rez['version'] = '';\r
+                       return $rez;\r
+               } else {\r
+                       return ADOConnection::ServerInfo();\r
+               }\r
        }\r
 \r
        function ErrorMsg()\r
@@ -48,6 +74,22 @@ class ADODB_odbc extends ADOConnection {
                } else return ADOConnection::ErrorMsg();\r
        }\r
        \r
+       function CreateSequence($seqname='adodbseq',$start=1)\r
+       {\r
+               if (empty($this->_genSeqSQL)) return false;\r
+               $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));\r
+               if (!$ok) return false;\r
+               $start -= 1;\r
+               return $this->Execute("insert into $seqname values($start)");\r
+       }\r
+       \r
+       var $_dropSeqSQL = 'drop table %s';\r
+       function DropSequence($seqname)\r
+       {\r
+               if (empty($this->_dropSeqSQL)) return false;\r
+               return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));\r
+       }\r
+       \r
        /*\r
                This algorithm is not very efficient, but works even if table locking\r
                is not available.\r
@@ -59,7 +101,7 @@ class ADODB_odbc extends ADOConnection {
                // if you have to modify the parameter below, your database is overloaded,\r
                // or you need to implement generation of id's yourself!\r
                $MAXLOOPS = 100;\r
-               \r
+               //$this->debug=1;\r
                while (--$MAXLOOPS>=0) {\r
                        $num = $this->GetOne("select id from $seq");\r
                        if ($num === false) {\r
@@ -71,14 +113,14 @@ class ADODB_odbc extends ADOConnection {
                        } \r
                        $this->Execute("update $seq set id=id+1 where id=$num");\r
                        \r
-                       if ($this->affected_rows() == 1) {\r
+                       if ($this->affected_rows() > 0) {\r
                                $num += 1;\r
                                $this->genID = $num;\r
                                return $num;\r
                        }\r
                }\r
                if ($fn = $this->raiseErrorFn) {\r
-                       $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOP attempts",$seq,$num);\r
+                       $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);\r
                }\r
                return false;\r
        }\r
@@ -101,9 +143,12 @@ class ADODB_odbc extends ADOConnection {
        function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)\r
        {\r
        global $php_errormsg;\r
-               if ($this->debug && $argDatabasename) ADOConnection::outp("For odbc Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");\r
+               if ($this->debug && $argDatabasename) {\r
+                       ADOConnection::outp("For odbc Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");\r
+               }\r
                $php_errormsg = '';\r
-               $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);\r
+               if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);\r
+               else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);\r
                $this->_errorMsg = $php_errormsg;\r
 \r
                //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);\r
@@ -115,16 +160,21 @@ class ADODB_odbc extends ADOConnection {
        {\r
        global $php_errormsg;\r
                $php_errormsg = '';\r
-               if ($this->debug && $argDatabasename) ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");\r
-               $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);\r
-               $this->_errorMsg = $php_errormsg;\r
+               if ($this->debug && $argDatabasename) {\r
+                       ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");\r
+               }\r
+       //      print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();\r
+               if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);\r
+               else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);\r
                \r
+               $this->_errorMsg = $php_errormsg;\r
                if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID);\r
                return $this->_connectionID != false;\r
        }\r
 \r
        function BeginTrans()\r
        {        \r
+               if (!$this->hasTransactions) return false;\r
                if ($this->transOff) return true; \r
                $this->transCnt += 1;\r
                $this->_autocommit = false;\r
@@ -172,7 +222,7 @@ class ADODB_odbc extends ADOConnection {
                \r
                $arr = $rs->GetArray();\r
                $rs->Close();\r
-               print_r($arr);\r
+               //print_r($arr);\r
                $arr2 = array();\r
                for ($i=0; $i < sizeof($arr); $i++) {\r
                        if ($arr[$i][3]) $arr2[] = $arr[$i][3];\r
@@ -197,6 +247,7 @@ class ADODB_odbc extends ADOConnection {
                \r
                //print_r($rs);\r
                $arr = $rs->GetArray();\r
+               \r
                $rs->Close();\r
                $arr2 = array();\r
                for ($i=0; $i < sizeof($arr); $i++) {\r
@@ -226,6 +277,10 @@ class ADODB_odbc extends ADOConnection {
 #define SQL_TYPE_DATE    91\r
 #define SQL_TYPE_TIME    92\r
 #define SQL_TYPE_TIMESTAMP 93\r
+\r
+#define SQL_UNICODE                             (-95)\r
+#define SQL_UNICODE_VARCHAR                     (-96)\r
+#define SQL_UNICODE_LONGVARCHAR                 (-97)\r
 */\r
        function ODBCTypes($t)\r
        {\r
@@ -233,7 +288,10 @@ class ADODB_odbc extends ADOConnection {
                case 1: \r
                case 12:\r
                case 0:\r
+               case -95:\r
+               case -96:\r
                        return 'C';\r
+               case -97:\r
                case -1: //text\r
                        return 'X';\r
                case -4: //image\r
@@ -266,41 +324,79 @@ class ADODB_odbc extends ADOConnection {
        global $ADODB_FETCH_MODE;\r
        \r
                $table = strtoupper($table);\r
-               \r
-       /* // for some reason, cannot view only 1 table with odbc_columns -- bug?\r
-               $qid = odbc_tables($this->_connectionID);\r
-               $rs = new ADORecordSet_odbc($qid);\r
-               if (!$rs) return false;\r
-               while (!$rs->EOF) {\r
-                       if ($table == strtoupper($rs->fields[2])) {\r
-                               $q = $rs->fields[0];\r
-                               $o = $rs->fields[1];\r
-                               break;\r
+\r
+               $savem = $ADODB_FETCH_MODE;\r
+               $ADODB_FETCH_MODE = ADODB_FETCH_NUM;\r
+\r
+               if (false) { // after testing, confirmed that the following does not work becoz of a bug\r
+                       $qid2 = odbc_tables($this->_connectionID);\r
+                       $rs = new ADORecordSet_odbc($qid2);             \r
+                       $ADODB_FETCH_MODE = $savem;\r
+                       if (!$rs) return false;\r
+                       $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;\r
+                       $rs->_fetch();\r
+                       \r
+                       while (!$rs->EOF) {\r
+                               if ($table == strtoupper($rs->fields[2])) {\r
+                                       $q = $rs->fields[0];\r
+                                       $o = $rs->fields[1];\r
+                                       break;\r
+                               }\r
+                               $rs->MoveNext();\r
                        }\r
-                       $rs->MoveNext();\r
+                       $rs->Close();\r
+                       \r
+                       $qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%');\r
+               } else if ($this->databaseType == 'access') {\r
+                       $qid = odbc_columns($this->_connectionID);\r
+               } else {\r
+                       $qid = odbc_columns($this->_connectionID,'%','%',strtoupper($table),'%');\r
                }\r
-               $rs->Close();\r
                \r
-               $qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%');\r
-       */\r
-               $savem = $ADODB_FETCH_MODE;\r
-               $ADODB_FETCH_MODE = ADODB_FETCH_NUM;\r
-               $qid = odbc_columns($this->_connectionID);\r
                $rs = new ADORecordSet_odbc($qid);\r
                $ADODB_FETCH_MODE = $savem;\r
                \r
                if (!$rs) return false;\r
                \r
+               //print_r($rs);\r
                $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;\r
-               \r
+               $rs->_fetch();\r
                $retarr = array();\r
+               \r
+               /*\r
+               $rs->fields indices\r
+               0 TABLE_QUALIFIER\r
+               1 TABLE_SCHEM\r
+               2 TABLE_NAME\r
+               3 COLUMN_NAME\r
+               4 DATA_TYPE\r
+               5 TYPE_NAME\r
+               6 PRECISION\r
+               7 LENGTH\r
+               8 SCALE\r
+               9 RADIX\r
+               10 NULLABLE\r
+               11 REMARKS\r
+               */\r
                while (!$rs->EOF) {\r
                        //print_r($rs->fields);\r
                        if (strtoupper($rs->fields[2]) == $table) {\r
                                $fld = new ADOFieldObject();\r
                                $fld->name = $rs->fields[3];\r
                                $fld->type = $this->ODBCTypes($rs->fields[4]);\r
-                               $fld->max_length = $rs->fields[7];\r
+                               \r
+                               // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp\r
+                               // access uses precision to store length for char/varchar\r
+                               if ($fld->type == 'C' or $fld->type == 'X') {\r
+                                       if ($this->databaseType == 'access') \r
+                                               $fld->max_length = $rs->fields[6];\r
+                                       else if ($rs->fields[4] <= -95) // UNICODE\r
+                                               $fld->max_length = $rs->fields[7]/2;\r
+                                       else\r
+                                               $fld->max_length = $rs->fields[7];\r
+                               } else \r
+                                       $fld->max_length = $rs->fields[7];\r
+                               $fld->not_null = !empty($rs->fields[10]);\r
                                $retarr[strtoupper($fld->name)] = $fld; \r
                        } else if (sizeof($retarr)>0)\r
                                break;\r
@@ -330,30 +426,38 @@ class ADODB_odbc extends ADOConnection {
                $this->_error = '';\r
                \r
                if ($inputarr) {\r
-                       if (is_array($sql)) $stmtid = $sql[1];\r
-                       else $stmtid = odbc_prepare($this->_connectionID,$sql);\r
-               \r
-                       if ($stmtid == false) {\r
-                               $this->_errorMsg = $php_errormsg;\r
-                               return false;\r
+                       if (is_array($sql)) {\r
+                               $stmtid = $sql[1];\r
+                       } else {\r
+                               $stmtid = odbc_prepare($this->_connectionID,$sql);\r
+       \r
+                               if ($stmtid == false) {\r
+                                       $this->_errorMsg = $php_errormsg;\r
+                                       return false;\r
+                               }\r
                        }\r
                        if (! odbc_execute($stmtid,$inputarr)) {\r
-                               @odbc_free_result($stmtid);\r
+                               //@odbc_free_result($stmtid);\r
                                return false;\r
                        }\r
                        \r
                } else if (is_array($sql)) {\r
                        $stmtid = $sql[1];\r
                        if (!odbc_execute($stmtid)) {\r
-                               @odbc_free_result($stmtid);\r
+                               //@odbc_free_result($stmtid);\r
                                return false;\r
                        }\r
                } else\r
                        $stmtid = odbc_exec($this->_connectionID,$sql);\r
                \r
                if ($stmtid) {\r
-                       odbc_binmode($stmtid,$this->binmode);\r
-                       odbc_longreadlen($stmtid,$this->maxblobsize);\r
+                       if (@odbc_num_fields($stmtid) == 0) {\r
+                               $this->_lastAffectedRows = odbc_num_rows($stmtid);\r
+                               $stmtid = true;\r
+                       } else {\r
+                               odbc_binmode($stmtid,$this->binmode);\r
+                               odbc_longreadlen($stmtid,$this->maxblobsize);\r
+                       }\r
                }\r
                $this->_errorMsg = $php_errormsg;\r
                return $stmtid;\r
@@ -383,7 +487,7 @@ class ADODB_odbc extends ADOConnection {
 \r
        function _affectedrows()\r
        {\r
-                       return  odbc_num_rows($this->_queryID);\r
+               return $this->_lastAffectedRows;\r
        }\r
        \r
 }\r
@@ -400,17 +504,26 @@ class ADORecordSet_odbc extends ADORecordSet {
        var $useFetchArray;\r
        var $_has_stupid_odbc_fetch_api_change;\r
        \r
-       function ADORecordSet_odbc($id)\r
+       function ADORecordSet_odbc($id,$mode=false)\r
        {\r
-       global $ADODB_FETCH_MODE;\r
-\r
-               $this->fetchMode = $ADODB_FETCH_MODE;\r
-               return $this->ADORecordSet($id);\r
+               if ($mode === false) {  \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               $this->fetchMode = $mode;\r
+               \r
+               $this->_queryID = $id;\r
+               \r
+               // the following is required for mysql odbc driver in 4.3.1 -- why?\r
+               $this->EOF = false;\r
+               $this->_currentRow = -1;\r
+               //$this->ADORecordSet($id);\r
        }\r
 \r
 \r
        // returns the field object\r
-       function &FetchField($fieldOffset = -1) {\r
+       function &FetchField($fieldOffset = -1) \r
+       {\r
                \r
                $off=$fieldOffset+1; // offsets begin at 1\r
                \r
@@ -443,8 +556,10 @@ class ADORecordSet_odbc extends ADORecordSet {
        global $ADODB_COUNTRECS;\r
                $this->_numOfRows = ($ADODB_COUNTRECS) ? @odbc_num_rows($this->_queryID) : -1;\r
                $this->_numOfFields = @odbc_num_fields($this->_queryID);\r
+               // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0\r
+               if ($this->_numOfRows == 0) $this->_numOfRows = -1;\r
                //$this->useFetchArray = $this->connection->useFetchArray;\r
-               $this->_has_stupid_odbc_fetch_api_change = $this->connection->_has_stupid_odbc_fetch_api_change;\r
+               $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;\r
        }       \r
        \r
        function _seek($row)\r
@@ -482,9 +597,9 @@ class ADORecordSet_odbc extends ADORecordSet {
                        $this->_currentRow++;\r
                        $row = 0;\r
                        if ($this->_has_stupid_odbc_fetch_api_change)\r
-                               $rez = odbc_fetch_into($this->_queryID,$this->fields,$row);\r
+                               $rez = @odbc_fetch_into($this->_queryID,$this->fields);\r
                        else \r
-                               $rez = odbc_fetch_into($this->_queryID,$row,$this->fields);\r
+                               $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);\r
                        if ($rez) {\r
                                if ($this->fetchMode & ADODB_FETCH_ASSOC) {\r
                                        $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);\r
@@ -492,6 +607,7 @@ class ADORecordSet_odbc extends ADORecordSet {
                                return true;\r
                        }\r
                }\r
+               $this->fields = false;\r
                $this->EOF = true;\r
                return false;\r
        }       \r
@@ -499,25 +615,10 @@ class ADORecordSet_odbc extends ADORecordSet {
        function _fetch()\r
        {\r
                $row = 0;\r
-               \r
-               /* code doesn't work - odbc_fetch_array undefined - why ??\r
-               if ($this->useFetchArray) {\r
-                       if ($this->fetchMode & ADODB_FETCH_ASSOC) {\r
-                               $this->fields = odbc_fetch_array($this->_queryID);\r
-                               return is_array($this->fields);\r
-                       } else {\r
-                               \r
-                               if ($this->_has_stupid_odbc_fetch_api_change)\r
-                                       return odbc_fetch_into($this->_queryID,$this->fields,$row);\r
-                               else \r
-                                       return odbc_fetch_into($this->_queryID,$row,$this->fields);\r
-                       }\r
-               }\r
-               */\r
                if ($this->_has_stupid_odbc_fetch_api_change)\r
-                       $rez = odbc_fetch_into($this->_queryID,$this->fields,$row);\r
+                       $rez = @odbc_fetch_into($this->_queryID,$this->fields,$row);\r
                else \r
-                       $rez = odbc_fetch_into($this->_queryID,$row,$this->fields);\r
+                       $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);\r
                \r
                if ($rez) {\r
                        if ($this->fetchMode & ADODB_FETCH_ASSOC) {\r
@@ -525,14 +626,15 @@ class ADORecordSet_odbc extends ADORecordSet {
                        }\r
                        return true;\r
                }\r
+               $this->fields = false;\r
                return false;\r
        }\r
        \r
-       function _close() {\r
-               \r
+       function _close() \r
+       {\r
                return @odbc_free_result($this->_queryID);              \r
        }\r
 \r
 }\r
 \r
-?>
\ No newline at end of file
+?>\r
index acec44d840fff48dd3d755b7cf91f2de6da7fa7c..1f2bbf0570fa6f2b566bc7cba25cebf53f2cf848 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -22,17 +22,64 @@ class  ADODB_odbc_mssql extends ADODB_odbc {
        var $fmtDate = "'Y-m-d'";\r
        var $fmtTimeStamp = "'Y-m-d h:i:sA'";\r
        var $_bindInputArray = true;\r
+       var $metaTablesSQL="select name from sysobjects where type='U' or type='V' and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE'))";\r
+       var $metaColumnsSQL = "select c.name,t.name,c.length from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'";\r
        var $hasTop = 'top';            // support mssql/interbase SELECT TOP 10 * FROM TABLE\r
        var $sysDate = 'GetDate()';\r
        var $sysTimeStamp = 'GetDate()';\r
        var $leftOuter = '*=';\r
        var $rightOuter = '=*';\r
        var $ansiOuter = true; // for mssql7 or later\r
+       var $identitySQL = 'select @@IDENTITY'; // 'select SCOPE_IDENTITY'; # for mssql 2000\r
+       var $hasInsertID = true;\r
        \r
        function ADODB_odbc_mssql()\r
        {\r
                $this->ADODB_odbc();\r
        }\r
+\r
+       function xServerInfo()\r
+       {\r
+               $row = $this->GetRow("execute sp_server_info 2");\r
+               $arr['description'] = $row[2];\r
+               $arr['version'] = ADOConnection::_findvers($arr['description']);\r
+               return $arr;\r
+       }\r
+       \r
+       \r
+       function _insertid()\r
+       {\r
+       // SCOPE_IDENTITY()\r
+       // Returns the last IDENTITY value inserted into an IDENTITY column in \r
+       // the same scope. A scope is a module -- a stored procedure, trigger, \r
+       // function, or batch. Thus, two statements are in the same scope if \r
+       // they are in the same stored procedure, function, or batch.\r
+                       return $this->GetOne($this->identitySQL);\r
+       }\r
+       \r
+       function MetaTables()\r
+       {\r
+               return ADOConnection::MetaTables();\r
+       }\r
+       \r
+       function MetaColumns($table)\r
+       {\r
+               return ADOConnection::MetaColumns($table);\r
+       }\r
+       \r
+       // "Stein-Aksel Basma" <basma@accelero.no>\r
+       // tested with MSSQL 2000\r
+       function MetaPrimaryKeys($table)\r
+       {\r
+               $sql = "select k.column_name from information_schema.key_column_usage k,\r
+               information_schema.table_constraints tc \r
+               where tc.constraint_name = k.constraint_name and tc.constraint_type =\r
+               'PRIMARY KEY' and k.table_name = '$table'";\r
+               \r
+               $a = $this->GetCol($sql);\r
+               if ($a && sizeof($a)>0) return $a;\r
+               return false;     \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
@@ -80,10 +127,9 @@ class  ADORecordSet_odbc_mssql extends ADORecordSet_odbc {
        \r
        var $databaseType = 'odbc_mssql';\r
        \r
-       function ADORecordSet_odbc_mssql($id)\r
+       function ADORecordSet_odbc_mssql($id,$mode=false)\r
        {\r
-               return $this->ADORecordSet_odbc($id);\r
-       }\r
-       \r
+               return $this->ADORecordSet_odbc($id,$mode);\r
+       }       \r
 }\r
 ?>
\ No newline at end of file
index 696d5b61a35ba14cbb5c019abbaefb39d2d987bc..a628ea6f17cf6518548b2845ee558572b071befc 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -104,9 +104,9 @@ class  ADORecordSet_odbc_oracle extends ADORecordSet_odbc {
        \r
        var $databaseType = 'odbc_oracle';\r
        \r
-       function ADORecordSet_odbc_oracle($id)\r
+       function ADORecordSet_odbc_oracle($id,$mode=false)\r
        {\r
-               return $this->ADORecordSet_odbc($id);\r
+               return $this->ADORecordSet_odbc($id,$mode);\r
        }\r
 }\r
 ?>
\ No newline at end of file
index c70236ac0d4199ecfd7ca2f6df72b66ef5f5d4c4..c4868b421dcd577fb9ae4d8ce3fad8896436c9bb 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -34,14 +34,14 @@ class ADODB_oracle extends ADOConnection {
        function DBDate($d)\r
        {\r
                if (is_string($d)) $d = ADORecordSet::UnixDate($d);\r
-               return 'TO_DATE('.date($this->fmtDate,$d).",'YYYY-MM-DD')";\r
+               return 'TO_DATE('.adodb_date($this->fmtDate,$d).",'YYYY-MM-DD')";\r
        }\r
        \r
        // format and return date string in database timestamp format\r
        function DBTimeStamp($ts)\r
        {\r
                if (is_string($ts)) $d = ADORecordSet::UnixTimeStamp($ts);\r
-               return 'TO_DATE('.date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";\r
+               return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";\r
        }\r
        \r
        function BeginTrans()\r
@@ -145,11 +145,14 @@ class ADORecordset_oracle extends ADORecordSet {
        var $databaseType = "oracle";\r
        var $bind = false;\r
 \r
-       function ADORecordset_oracle($queryID)\r
+       function ADORecordset_oracle($queryID,$mode=false)\r
        {\r
-       global $ADODB_FETCH_MODE;\r
                \r
-               $this->fetchMode = $ADODB_FETCH_MODE;\r
+               if ($mode === false) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               $this->fetchMode = $mode;\r
                \r
                $this->_queryID = $queryID;\r
        \r
@@ -228,6 +231,12 @@ class ADORecordset_oracle extends ADORecordSet {
 \r
        function MetaType($t,$len=-1)\r
        {\r
+               if (is_object($t)) {\r
+                       $fieldobj = $t;\r
+                       $t = $fieldobj->type;\r
+                       $len = $fieldobj->max_length;\r
+               }\r
+               \r
                switch (strtoupper($t)) {\r
                case 'VARCHAR':\r
                case 'VARCHAR2':\r
index bb20864f8757e4389f5b5f4e917f878f72f99920..dbbc7286ac1e0f89c5cc51d0b4812923c0c3b342 100644 (file)
@@ -1,64 +1,14 @@
 <?php\r
 /*\r
- V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
   Set tabs to 4.\r
   \r
-  Postgres7 support.\r
-  28 Feb 2001: Currently indicate that we support LIMIT\r
-  01 Dec 2001: dannym added support for default values\r
+  NOTE: Since 3.31, this file is no longer used, and the "postgres" driver is\r
+  remapped to "postgres7". Maintaining multiple postgres drivers is no easy\r
+  job, so hopefully this will ensure greater consistency and fewer bugs.\r
 */\r
 \r
-include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");\r
-\r
-class ADODB_postgres extends ADODB_postgres64 {\r
-       var $databaseType = 'postgres'; \r
-       var $hasLimit = true;   // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10\r
-       var $ansiOuter = true;\r
-       function ADODB_postgres() \r
-       {\r
-               \r
-       }\r
-\r
-       // the following should be compat with postgresql 7.2, \r
-       // which makes obsolete the LIMIT limit,offset syntax\r
-        function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$arg3=false,$secs2cache=0) \r
-        {\r
-         $offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';\r
-         $limitStr  = ($nrows >= 0)  ? " LIMIT $nrows" : '';\r
-         return $secs2cache ?\r
-          $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr,$arg3)\r
-         :\r
-          $this->Execute($sql."$limitStr$offsetStr",$inputarr,$arg3);\r
-        }\r
\r
-       // 10% speedup to move MoveNext to child class\r
-       function MoveNext() \r
-       {\r
-               if (!$this->EOF) {              \r
-                       $this->_currentRow++;\r
-                       $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);\r
-                       if (is_array($this->fields)) return true;\r
-               }\r
-               $this->EOF = true;\r
-               return false;\r
-       }       \r
-}\r
-       \r
-/*--------------------------------------------------------------------------------------\r
-        Class Name: Recordset\r
---------------------------------------------------------------------------------------*/\r
-\r
-class ADORecordSet_postgres extends ADORecordSet_postgres64{\r
-\r
-       var $databaseType = "postgres";\r
-\r
-       function ADORecordSet_postgres($queryID) \r
-       {\r
-               $this->ADORecordSet_postgres64($queryID);\r
-       }\r
-\r
-}\r
-?>\r
+?>
\ No newline at end of file
index 16972a93f341652414f619cd86fc89e156bea1d5..94b42d437e5d2a1c7952cdfca254d649f95e9ccf 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
- V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
   01 Mar 2001 jlim - Freek Dijkstra changes, also support for text type\r
 */\r
 \r
+function adodb_addslashes($s)\r
+{\r
+       $len = strlen($s);\r
+       if ($len == 0) return "''";\r
+       if (substr($s,0,1) == "'" && substr(s,$len-1) == "'") return $s; // already quoted\r
+       \r
+       return "'".addslashes($s)."'";\r
+}\r
+\r
 class ADODB_postgres64 extends ADOConnection{\r
        var $databaseType = 'postgres64';\r
        var $dataProvider = 'postgres';\r
@@ -29,7 +38,7 @@ class ADODB_postgres64 extends ADOConnection{
        var $isoDates = true; // accepts dates in ISO format\r
        var $sysDate = "CURRENT_DATE";\r
        var $sysTimeStamp = "CURRENT_TIMESTAMP";\r
-       \r
+       var $blobEncodeType = 'C';\r
 /*\r
 # show tables and views suggestion\r
 "SELECT c.relname AS tablename FROM pg_class c \r
@@ -54,8 +63,10 @@ SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%' ORDER BY 1"
        var $hasGenID = true;\r
        var $_genIDSQL = "SELECT NEXTVAL('%s')";\r
        var $_genSeqSQL = "CREATE SEQUENCE %s START %s";\r
+       var $_dropSeqSQL = "DROP SEQUENCE %s";\r
        var $metaDefaultsSQL = "SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum";\r
-               \r
+       \r
+       \r
        // The last (fmtTimeStamp is not entirely correct: \r
        // PostgreSQL also has support for time zones, \r
        // and writes these time in this format: "2001-03-01 18:59:26+02". \r
@@ -67,7 +78,13 @@ SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%' ORDER BY 1"
        function ADODB_postgres64() \r
        {\r
        // changes the metaColumnsSQL, adds columns: attnum[6]\r
-                       \r
+       }\r
+       \r
+       function ServerInfo()\r
+       {\r
+               $arr['description'] = $this->GetOne("select version()");\r
+               $arr['version'] = ADOConnection::_findvers($arr['description']);\r
+               return $arr;\r
        }\r
        \r
        // get the last id - never tested\r
@@ -88,14 +105,16 @@ Unless you are very careful, you might end up with a tuple having
 a different OID if a database must be reloaded. */\r
        function _insertid()\r
        {\r
-               return pg_getlastoid($this->_resultid);\r
+               if (!is_resource($this->_resultid)) return false;\r
+          return pg_getlastoid($this->_resultid);\r
        }\r
 \r
 // I get this error with PHP before 4.0.6 - jlim\r
 // Warning: This compilation does not support pg_cmdtuples() in d:/inetpub/wwwroot/php/adodb/adodb-postgres.inc.php on line 44\r
    function _affectedrows()\r
    {\r
-          return pg_cmdtuples($this->_resultid);         \r
+               if (!is_resource($this->_resultid)) return false;\r
+               return pg_cmdtuples($this->_resultid);\r
    }\r
 \r
        \r
@@ -130,8 +149,27 @@ a different OID if a database must be reloaded. */
                $this->transCnt -= 1;\r
                return @pg_Exec($this->_connectionID, "rollback");\r
        }\r
+       /*\r
+       // if magic quotes disabled, use pg_escape_string()\r
+       function qstr($s,$magic_quotes=false)\r
+       {\r
+               if (!$magic_quotes) {\r
+                       if (ADODB_PHPVER >= 0x4200) {\r
+                               return  "'".pg_escape_string($s)."'";\r
+                       }\r
+                       if ($this->replaceQuote[0] == '\\'){\r
+                               $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);\r
+                       }\r
+                       return  "'".str_replace("'",$this->replaceQuote,$s)."'"; \r
+               }\r
+               \r
+               // undo magic quotes for "\r
+               $s = str_replace('\\"','"',$s);\r
+               return "'$s'";\r
+       }\r
+       */\r
        \r
-                       // Format date column in sql string given an input format that understands Y M D\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
@@ -177,11 +215,22 @@ a different OID if a database must be reloaded. */
        * postgres proprietary blob handling routines \r
        *\r
        * contributed by Mattia Rossi mattia@technologist.com\r
+       * modified for safe mode by juraj chlebec\r
        */ \r
-       function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB') \r
+       function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') \r
        { \r
                pg_exec ($this->_connectionID, "begin"); \r
-               $oid = pg_lo_import ($val); \r
+               \r
+               $fd = fopen($path,'r');\r
+               $contents = fread($fd,filesize($path));\r
+               fclose($fd);\r
+               \r
+               $oid = pg_lo_create($this->_connectionID);\r
+               $handle = pg_lo_open($this->_connectionID, $oid, 'w');\r
+               pg_lo_write($handle, $contents);\r
+               pg_lo_close($handle);\r
+               \r
+               // $oid = pg_lo_import ($path); \r
                pg_exec ($this->_connectionID, "commit"); \r
                $rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype); \r
                $rez = !empty($rs); \r
@@ -189,20 +238,50 @@ a different OID if a database must be reloaded. */
        } \r
        \r
        /* \r
-       * Reads the real blob from the db using the oid supplied as a parameter\r
+       * If an OID is detected, then we use pg_lo_* to open the oid file and read the\r
+       * real blob from the db using the oid supplied as a parameter. If you are storing\r
+       * blobs using bytea, we autodetect and process it so this function is not needed.\r
        *\r
        * contributed by Mattia Rossi mattia@technologist.com\r
+       *\r
+       * see http://www.postgresql.org/idocs/index.php?largeobjects.html\r
        */ \r
-       function BlobDecode( $blob \r
+       function BlobDecode( $blob) \r
        { \r
                @pg_exec("begin"); \r
-               $fd = @pg_lo_open($blob,"r"); \r
+               $fd = @pg_lo_open($blob,"r");\r
+               if ($fd === false) {\r
+                       @pg_exec("commit");\r
+                       return $blob;\r
+               }\r
                $realblob = @pg_loreadall($fd); \r
                @pg_loclose($fd); \r
                @pg_exec("commit"); \r
-               return( $realblob ); \r
+               return $realblob;\r
        } \r
        \r
+       /* \r
+               See http://www.postgresql.org/idocs/index.php?datatype-binary.html\r
+               \r
+               NOTE: SQL string literals (input strings) must be preceded with two backslashes \r
+               due to the fact that they must pass through two parsers in the PostgreSQL \r
+               backend.\r
+       */\r
+       function BlobEncode($blob)\r
+       { // requires php 4.0.5\r
+               $badch = array(chr(92),chr(0),chr(39)); # \  null  '\r
+               $fixch = array('\\\\134','\\\\000','\\\\047');\r
+               return adodb_str_replace($badch,$fixch,$blob);\r
+               \r
+               // note that there is a pg_escape_bytea function only for php 4.2.0 or later\r
+       }\r
+       \r
+       function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')\r
+       {\r
+               return $this->Execute("UPDATE $table SET $column=? WHERE $where",\r
+                       array($this->BlobEncode($val))) != false;\r
+       }\r
+       \r
        function OffsetDate($dayFraction,$date=false)\r
        {               \r
                if (!$date) $date = $this->sysDate;\r
@@ -215,13 +294,14 @@ a different OID if a database must be reloaded. */
        {\r
        global $ADODB_FETCH_MODE;\r
        \r
+               if (strncmp(PHP_OS,"WIN",3) === 0) $table = strtolower($table);\r
+       \r
                if (!empty($this->metaColumnsSQL)) { \r
-                       // the following is the only difference -- we lowercase it\r
                        $save = $ADODB_FETCH_MODE;\r
                        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;\r
-                       \r
+                       if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);\r
                        $rs = $this->Execute(sprintf($this->metaColumnsSQL,($table)));\r
-                       \r
+                       if (isset($savem)) $this->SetFetchMode($savem);\r
                        $ADODB_FETCH_MODE = $save;\r
                        \r
                        if ($rs === false) return false;\r
@@ -237,7 +317,7 @@ a different OID if a database must be reloaded. */
                                $rskey = $this->Execute(sprintf($this->metaKeySQL,($table)));\r
                                // fetch all result in once for performance.\r
                                $keys = $rskey->GetArray();\r
-                               \r
+                               if (isset($savem)) $this->SetFetchMode($savem);\r
                                $ADODB_FETCH_MODE = $save;\r
                                \r
                                $rskey->Close();\r
@@ -246,12 +326,16 @@ a different OID if a database must be reloaded. */
 \r
                        $rsdefa = array();\r
                        if (!empty($this->metaDefaultsSQL)) {\r
+                               $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;\r
                                $sql = sprintf($this->metaDefaultsSQL, ($table));\r
                                $rsdef = $this->Execute($sql);\r
+                               if (isset($savem)) $this->SetFetchMode($savem);\r
+                               $ADODB_FETCH_MODE = $save;\r
+                               \r
                                if ($rsdef) {\r
                                        while (!$rsdef->EOF) {\r
-                                               $num = $rsdef->Fields('num');\r
-                                               $s = $rsdef->Fields('def');\r
+                                               $num = $rsdef->fields['num'];\r
+                                               $s = $rsdef->fields['def'];\r
                                                if (substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */\r
                                                        $s = substr($s, 1);\r
                                                        $s = substr($s, 0, strlen($s) - 1);\r
@@ -328,9 +412,13 @@ a different OID if a database must be reloaded. */
        // examples:\r
        //      $db->Connect("host=host1 user=user1 password=secret port=4341");\r
        //      $db->Connect('host1','user1','secret');\r
-       function _connect($str,$user='',$pwd='',$db='')\r
+       function _connect($str,$user='',$pwd='',$db='',$persist=false)\r
        {                  \r
                if ($user || $pwd || $db) {\r
+                       $str = adodb_addslashes($str);\r
+                       $user = adodb_addslashes($user);\r
+                       $pwd = adodb_addslashes($pwd);\r
+                       $db = adodb_addslashes($db);\r
                        if ($str)  {\r
                                $host = split(":", $str);\r
                                if ($host[0]) $str = "host=$host[0]";\r
@@ -343,10 +431,11 @@ a different OID if a database must be reloaded. */
                }\r
                \r
                //if ($user) $linea = "user=$user host=$linea password=$pwd dbname=$db port=5432";\r
-               $this->_connectionID = pg_connect($str);\r
+               if ($persist) $this->_connectionID = pg_pconnect($str);\r
+               else $this->_connectionID = pg_connect($str);\r
                if ($this->_connectionID === false) return false;\r
                $this->Execute("set datestyle='ISO'");\r
-                               return true;\r
+               return true;\r
        }\r
        \r
        // returns true or false\r
@@ -356,77 +445,58 @@ a different OID if a database must be reloaded. */
        //      $db->PConnect('host1','user1','secret');\r
        function _pconnect($str,$user='',$pwd='',$db='')\r
        {\r
-               if ($user || $pwd || $db) {\r
-                               if ($str)  {\r
-                               $host = split(":", $str);\r
-                               if ($host[0]) $str = "host=$host[0]";\r
-                               else $str = 'localhost';\r
-                               if (isset($host[1])) $str .= " port=$host[1]";\r
-                       }\r
-                               if ($user) $str .= " user=".$user;\r
-                               if ($pwd)  $str .= " password=".$pwd;\r
-                       if ($db)   $str .= " dbname=".$db;\r
-               }//print $str;\r
-               $this->_connectionID = pg_pconnect($str);\r
-               if ($this->_connectionID === false) return false;\r
-               $this->Execute("set datestyle='ISO'");\r
-               return true;\r
+               return $this->_connect($str,$user,$pwd,$db,true);\r
        }\r
 \r
        // returns queryID or false\r
        function _query($sql,$inputarr)\r
        {\r
-                               $this->_resultid= pg_Exec($this->_connectionID,$sql);\r
-                               return $this->_resultid;\r
+               $rez = pg_Exec($this->_connectionID,$sql);\r
+               // check if no data returned, then no need to create real recordset\r
+               if ($rez && pg_numfields($rez) <= 0) {\r
+                       $this->_resultid = $rez;\r
+                       return true;\r
+               }\r
+               return $rez;\r
        }\r
        \r
 \r
        /*      Returns: the last error message from previous database operation        */      \r
        function ErrorMsg() \r
        {\r
-               if (empty($this->_connectionID)) $this->_errorMsg = @pg_errormessage();\r
-               else $this->_errorMsg = @pg_errormessage($this->_connectionID);\r
+               if (ADODB_PHPVER >= 0x4300) {\r
+                       if (!empty($this->_resultid)) {\r
+                               $this->_errorMsg = @pg_result_error($this->_resultid);\r
+                               if ($this->_errorMsg) return $this->_errorMsg;\r
+                       }\r
+                       \r
+                       if (!empty($this->_connectionID)) {\r
+                               $this->_errorMsg = @pg_last_error($this->_connectionID);\r
+                       } else $this->_errorMsg = @pg_last_error();\r
+               } else {\r
+                       if (empty($this->_connectionID)) $this->_errorMsg = @pg_errormessage();\r
+                       else $this->_errorMsg = @pg_errormessage($this->_connectionID);\r
+               }\r
                return $this->_errorMsg;\r
        }\r
        \r
        function ErrorNo()\r
        {\r
-               return (strlen($this->ErrorMsg())) ? -1 : 0;\r
+               $e = $this->ErrorMsg();\r
+               return (strlen($e)) ? $e : 0;\r
        }\r
 \r
        // returns true or false\r
        function _close()\r
        {\r
                if ($this->transCnt) $this->RollbackTrans();\r
-               @pg_close($this->_connectionID);\r
                $this->_resultid = false;\r
+               @pg_close($this->_connectionID);\r
                $this->_connectionID = false;\r
                return true;\r
        }\r
        \r
-       function ActualType($meta)\r
-       {\r
-               switch($meta) {\r
-               case 'C': return 'VARCHAR';\r
-               case 'X': return 'TEXT';\r
-               \r
-               case 'C2': return 'VARCHAR';\r
-               case 'X2': return 'TEXT';\r
-               \r
-               case 'B': return 'BYTEA';\r
-                       \r
-               case 'D': return 'DATE';\r
-               case 'T': return 'DATETIME';\r
-               case 'L': return 'SMALLINT';\r
-               case 'R': return 'SERIAL';\r
-               case 'I': return 'INTEGER'; \r
-               \r
-               case 'F': return 'FLOAT8';\r
-               case 'N': return 'NUMERIC';\r
-               default:\r
-                       return false;\r
-               }\r
-       }\r
+       \r
        /*\r
        * Maximum size of C field\r
        */\r
@@ -451,14 +521,16 @@ a different OID if a database must be reloaded. */
 --------------------------------------------------------------------------------------*/\r
 \r
 class ADORecordSet_postgres64 extends ADORecordSet{\r
-\r
+       var $_blobArr;\r
        var $databaseType = "postgres64";\r
        var $canSeek = true;\r
-       function ADORecordSet_postgres64($queryID) \r
+       function ADORecordSet_postgres64($queryID,$mode=false\r
        {\r
-       global $ADODB_FETCH_MODE;\r
-       \r
-               switch ($ADODB_FETCH_MODE)\r
+               if ($mode === false) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               switch ($mode)\r
                {\r
                case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break;\r
                case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break;\r
@@ -466,13 +538,12 @@ class ADORecordSet_postgres64 extends ADORecordSet{
                case ADODB_FETCH_DEFAULT:\r
                case ADODB_FETCH_BOTH:$this->fetchMode = PGSQL_BOTH; break;\r
                }\r
-       \r
                $this->ADORecordSet($queryID);\r
        }\r
        \r
        function &GetRowAssoc($upper=true)\r
        {\r
-               if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $rs->fields;\r
+               if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields;\r
                return ADORecordSet::GetRowAssoc($upper);\r
        }\r
 \r
@@ -481,6 +552,12 @@ class ADORecordSet_postgres64 extends ADORecordSet{
        global $ADODB_COUNTRECS;\r
                $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($this->_queryID):-1;\r
                $this->_numOfFields = @pg_numfields($this->_queryID);\r
+               \r
+               // cache types for blob decode check\r
+               for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { \r
+                       $f1 = $this->FetchField($i);\r
+                       if ($f1->type == 'bytea') $this->_blobArr[$i] = $f1->name;\r
+               }               \r
        }\r
 \r
                /* Use associative array to get fields array */\r
@@ -516,36 +593,71 @@ class ADORecordSet_postgres64 extends ADORecordSet{
                return @pg_fetch_row($this->_queryID,$row);\r
        }\r
        \r
+       function _decode($blob)\r
+       {\r
+               \r
+               eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";');\r
+               return $realblob;\r
+               \r
+       }\r
+       function _fixblobs()\r
+       {\r
+               if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) {\r
+                       foreach($this->_blobArr as $k => $v) {\r
+                               $this->fields[$k] = ADORecordSet_postgres64::_decode($this->fields[$k]);\r
+                       }\r
+               }\r
+               if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) {\r
+                       foreach($this->_blobArr as $k => $v) {\r
+                               $this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]);\r
+                       }\r
+               }\r
+       }\r
+       \r
        // 10% speedup to move MoveNext to child class\r
        function MoveNext() \r
        {\r
-               if (!$this->EOF) {              \r
+               if (!$this->EOF) {\r
                        $this->_currentRow++;\r
+                       if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {\r
+                               $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);\r
                        \r
-                       $f = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);\r
-                       \r
-                       if (is_array($f)) {\r
-                               $this->fields = $f;\r
-                               return true;\r
+                               if (is_array($this->fields)) {\r
+                                       if (isset($this->_blobArr)) $this->_fixblobs();\r
+                                       return true;\r
+                               }\r
                        }\r
+                       $this->fields = false;\r
+                       $this->EOF = true;\r
                }\r
-               $this->EOF = true;\r
                return false;\r
        }               \r
        \r
        function _fetch()\r
        {\r
+               if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0)\r
+               return false;\r
+\r
                $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);\r
+               if (isset($this->_blobArr)) $this->_fixblobs();\r
+                       \r
                return (is_array($this->fields));\r
        }\r
 \r
-       function _close() {\r
+       function _close() \r
+       {\r
                return @pg_freeresult($this->_queryID);\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
                switch (strtoupper($t)) {\r
+                               case 'INTERVAL':\r
                                case 'CHAR':\r
                                case 'CHARACTER':\r
                                case 'VARCHAR':\r
index a1b789db500702aa2a8b8b4da6e1e3888467a8bb..28e083597af50b96d1fd79aa6efd2fa333255de9 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
- V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -20,7 +20,7 @@ class ADODB_postgres7 extends ADODB_postgres64 {
        \r
        function ADODB_postgres7() \r
        {\r
-               \r
+               $this->ADODB_postgres64();\r
        }\r
 \r
        // the following should be compat with postgresql 7.2, \r
@@ -35,17 +35,7 @@ class ADODB_postgres7 extends ADODB_postgres64 {
           $this->Execute($sql."$limitStr$offsetStr",$inputarr,$arg3);\r
         }\r
  \r
-       // 10% speedup to move MoveNext to child class\r
-       function MoveNext() \r
-       {\r
-               if (!$this->EOF) {              \r
-                       $this->_currentRow++;\r
-                       $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);\r
-                       if (is_array($this->fields)) return true;\r
-               }\r
-               $this->EOF = true;\r
-               return false;\r
-       }       \r
+\r
 }\r
        \r
 /*--------------------------------------------------------------------------------------\r
@@ -56,10 +46,29 @@ class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
 \r
        var $databaseType = "postgres7";\r
 \r
-       function ADORecordSet_postgres7($queryID) \r
+       function ADORecordSet_postgres7($queryID,$mode=false\r
        {\r
-               $this->ADORecordSet_postgres64($queryID);\r
+               $this->ADORecordSet_postgres64($queryID,$mode);\r
        }\r
+       \r
+               // 10% speedup to move MoveNext to child class\r
+       function MoveNext() \r
+       {\r
+               if (!$this->EOF) {\r
+                       $this->_currentRow++;\r
+                       if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {\r
+                               $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);\r
+                       \r
+                               if (is_array($this->fields)) {\r
+                                       if (isset($this->_blobArr)) $this->_fixblobs();\r
+                                       return true;\r
+                               }\r
+                       }\r
+                       $this->fields = false;\r
+                       $this->EOF = true;\r
+               }\r
+               return false;\r
+       }               \r
 \r
 }\r
-?>\r
+?>
\ No newline at end of file
index 1fec2504b5930652dcb78c50285850e9e87bb69f..9b69ef338bd844dc00d841a4c31df991a079c0e1 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -15,14 +15,14 @@ if (! defined("_ADODB_PROXY_LAYER")) {
         \r
        class ADODB_proxy extends ADODB_csv {\r
                var $databaseType = 'proxy';\r
-               \r
+               var $databaseProvider = 'csv';\r
        }\r
        class ADORecordset_proxy extends ADORecordset_csv {\r
        var $databaseType = "proxy";            \r
        \r
-               function ADORecordset_proxy($id) \r
+               function ADORecordset_proxy($id,$mode=false\r
                {\r
-                       $this->ADORecordset($id);\r
+                       $this->ADORecordset($id,$mode);\r
                }\r
        };\r
 } // define\r
index 7892434de232770322cff6b46cbd8a8ceea6f068..af44f5f3301c537d9a3ebc412619b50147f023cc 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-version V2.50 14 Nov 2002 (c) 2000-2002  John Lim (jlim@natsoft.com.my). All rights\r
+version V3.40 7 April 2003 (c) 2000-2003  John Lim (jlim@natsoft.com.my). All rights\r
 reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
@@ -153,9 +153,9 @@ if (!defined('ADODB_SYBASE_SQLANYWHERE')){
 \r
   var $databaseType = "sqlanywhere";           \r
 \r
- function ADORecordSet_sqlanywhere($id)\r
+ function ADORecordSet_sqlanywhere($id,$mode=false)\r
  {\r
-  $this->ADORecordSet_odbc($id);\r
+  $this->ADORecordSet_odbc($id,$mode);\r
  }\r
 \r
 \r
index 7507dddd0f5fb05df7b82f0b5941693bdfc29b76..e76fd6e2422c137a459760f9d6f4be96274a4a91 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim. All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim. All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -17,13 +17,19 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim. All rights reserved.
  \r
 class ADODB_sybase extends ADOConnection {\r
        var $databaseType = "sybase";   \r
+       var $dataProvider = 'sybase';\r
        var $replaceQuote = "''"; // string to use to replace quotes\r
        var $fmtDate = "'Y-m-d'";\r
        var $fmtTimeStamp = "'Y-m-d H:i:s'";\r
        var $hasInsertID = true;\r
        var $hasAffectedRows = true;\r
        var $metaTablesSQL="select name from sysobjects where type='U' or type='V'";\r
-       var $metaColumnsSQL = "select c.name,t.name,c.length from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'";\r
+       var $metaColumnsSQL = "SELECT c.name,t.name,c.length FROM syscolumns c, systypes t, sysobjects o WHERE o.name='%s' and t.xusertype=c.xusertype and o.id=c.id";\r
+       /*\r
+       "select c.name,t.name,c.length from \r
+       syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id \r
+       where o.name='%s'";\r
+       */\r
        var $concat_operator = '+'; \r
        var $sysDate = 'GetDate()';\r
        var $arrayClass = 'ADORecordSet_array_sybase';\r
@@ -121,13 +127,20 @@ class ADODB_sybase extends ADOConnection {
        // returns query ID if successful, otherwise false\r
        function _query($sql,$inputarr)\r
        {\r
-               //@sybase_free_result($this->_queryID);\r
-               return sybase_query($sql,$this->_connectionID);\r
+       global $ADODB_COUNTRECS;\r
+       \r
+               if ($ADODB_COUNTRECS == false && ADODB_PHPVER >= 0x4300)\r
+                       return sybase_unbuffered_query($sql,$this->_connectionID);\r
+               else\r
+                       return sybase_query($sql,$this->_connectionID);\r
        }\r
        \r
        // See http://www.isug.com/Sybase_FAQ/ASE/section6.2.html#6.2.12\r
        function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$arg3=false,$secs2cache=0) \r
        {\r
+               if ($secs2cache > 0) // we do not cache rowcount, so we have to load entire recordset\r
+                       return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);\r
+               \r
                $cnt = ($nrows > 0) ? $nrows : 0;\r
                if ($offset > 0 && $cnt) $cnt += $offset;\r
                \r
@@ -170,13 +183,15 @@ class ADORecordset_sybase extends ADORecordSet {
        // _mths works only in non-localised system\r
        var  $_mths = array('JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12);    \r
 \r
-       function ADORecordset_sybase($id)\r
+       function ADORecordset_sybase($id,$mode=false)\r
        {\r
-       global $ADODB_FETCH_MODE;\r
-       \r
-               if (!$ADODB_FETCH_MODE) $this->fetchMode = ADODB_FETCH_ASSOC;\r
-               else $this->fetchMode = $ADODB_FETCH_MODE;\r
-               return $this->ADORecordSet($id);\r
+               if ($mode === false) { \r
+                       global $ADODB_FETCH_MODE;\r
+                       $mode = $ADODB_FETCH_MODE;\r
+               }\r
+               if (!$mode) $this->fetchMode = ADODB_FETCH_ASSOC;\r
+               else $this->fetchMode = $mode;\r
+               return $this->ADORecordSet($id,$mode);\r
        }\r
        \r
        /*      Returns: an object containing field information. \r
@@ -210,9 +225,23 @@ class ADORecordset_sybase extends ADORecordSet {
 \r
        function _fetch($ignore_fields=false) \r
        {\r
-               if ($this->fetchMode == ADODB_FETCH_NUM) $this->fields = @sybase_fetch_row($this->_queryID);\r
-               else $this->fields = @sybase_fetch_array($this->_queryID);\r
-               return is_array($this->fields);\r
+               if ($this->fetchMode == ADODB_FETCH_NUM) {\r
+                       $this->fields = @sybase_fetch_row($this->_queryID);\r
+               } else if ($this->fetchMode == ADODB_FETCH_ASSOC) {\r
+                       $this->fields = @sybase_fetch_row($this->_queryID);\r
+                       if (is_array($this->fields)) {\r
+                               $this->fields = $this->GetRowAssoc(ADODB_CASE_ASSOC);\r
+                               return true;\r
+                       }\r
+                       return false;\r
+               }  else {\r
+                       $this->fields = @sybase_fetch_array($this->_queryID);\r
+               }\r
+               if ( is_array($this->fields)) {\r
+                       return true;\r
+               }\r
+\r
+               return false;\r
        }\r
        \r
        /*      close() only needs to be called if you are worried about using too much memory while your script\r
index 604378edb76c88a8b7f0a8e255811bc5d97d1572..548a27f033a8613a50ad18461e097ec4ab2fac31 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -29,6 +29,8 @@ class ADODB_vfp extends ADODB_odbc {
        var $sysTimeStamp = 'datetime()';\r
        var $sysDate = 'date()';\r
        var $ansiOuter = true;\r
+       var $hasTransactions = false;\r
+       var $curmode = SQL_CUR_USE_ODBC ; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L\r
        \r
        function ADODB_vfp()\r
        {\r
@@ -36,7 +38,7 @@ class ADODB_vfp extends ADODB_odbc {
        }\r
        \r
        function BeginTrans() { return false;}\r
-\r
+       \r
        // quote string to be sent back to database\r
        function qstr($s,$nofixquotes=false)\r
        {\r
@@ -61,13 +63,18 @@ class  ADORecordSet_vfp extends ADORecordSet_odbc {
        var $databaseType = "vfp";              \r
 \r
        \r
-       function ADORecordSet_vfp($id)\r
+       function ADORecordSet_vfp($id,$mode=false)\r
        {\r
-               return $this->ADORecordSet_odbc($id);\r
+               return $this->ADORecordSet_odbc($id,$mode);\r
        }\r
 \r
        function MetaType($t,$len=-1)\r
        {\r
+               if (is_object($t)) {\r
+                       $fieldobj = $t;\r
+                       $t = $fieldobj->type;\r
+                       $len = $fieldobj->max_length;\r
+               }\r
                switch (strtoupper($t)) {\r
                case 'C':\r
                        if ($len <= $this->blobSize) return 'C';\r
index 654beb2213d9f2f7f24728c386fbb32c374e1737..71f6905b433a1a42a7447c1b2f05e01091083d3c 100644 (file)
-ADOdb is dual licensed using BSD-Style and LGPL. Where there is any discrepancy, the BSD-Style license will take precedence. In plain English, you do not need to distribute your application  in source code form, nor do you need to distribute ADOdb source code, provided you follow the rest of terms of the BSD-style license.\r
-\r
-Commercial use of ADOdb is encouraged. Make money and multiply!\r
-\r
-BSD Style-License\r
-=================\r
-\r
-Copyright (c) 2000, 2001, 2002 John Lim\r
-All rights reserved.\r
-\r
-Redistribution and use in source and binary forms, with or without modification, \r
-are permitted provided that the following conditions are met:\r
-\r
-Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. \r
-Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. \r
-Neither the name of the John Lim nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. \r
-\r
-DISCLAIMER:\r
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-==========================================================\r
-GNU LESSER GENERAL PUBLIC LICENSE\r
-Version 2.1, February 1999 \r
\r
-Copyright (C) 1991, 1999 Free Software Foundation, Inc.\r
-59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
-Everyone is permitted to copy and distribute verbatim copies\r
-of this license document, but changing it is not allowed.\r
-\r
-[This is the first released version of the Lesser GPL.  It also counts\r
- as the successor of the GNU Library Public License, version 2, hence\r
- the version number 2.1.]\r
\r
\r
-Preamble\r
-The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. \r
-\r
-This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. \r
-\r
-When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. \r
-\r
-To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. \r
-\r
-For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. \r
-\r
-We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. \r
-\r
-To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. \r
-\r
-Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. \r
-\r
-Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. \r
-\r
-When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. \r
-\r
-We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. \r
-\r
-For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. \r
-\r
-In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. \r
-\r
-Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. \r
-\r
-The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. \r
-\r
-\r
-TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\r
-0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". \r
-\r
-A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. \r
-\r
-The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) \r
-\r
-"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. \r
-\r
-Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. \r
-\r
-1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. \r
-\r
-You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. \r
-\r
-2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: \r
-\r
-\r
-a) The modified work must itself be a software library. \r
-b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. \r
-c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. \r
-d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. \r
-(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) \r
-\r
-These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. \r
-\r
-Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. \r
-\r
-In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. \r
-\r
-3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. \r
-\r
-Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. \r
-\r
-This option is useful when you wish to copy part of the code of the Library into a program that is not a library. \r
-\r
-4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. \r
-\r
-If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. \r
-\r
-5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. \r
-\r
-However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. \r
-\r
-When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. \r
-\r
-If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) \r
-\r
-Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. \r
-\r
-6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. \r
-\r
-You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: \r
-\r
-\r
-a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) \r
-b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. \r
-c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. \r
-d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. \r
-e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. \r
-For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. \r
-\r
-It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. \r
-\r
-7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: \r
-\r
-\r
-a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. \r
-b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. \r
-8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. \r
-\r
-9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. \r
-\r
-10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. \r
-\r
-11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. \r
-\r
-If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. \r
-\r
-It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. \r
-\r
-This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. \r
-\r
-12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. \r
-\r
-13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. \r
-\r
-Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. \r
-\r
-14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. \r
-\r
-NO WARRANTY \r
-\r
-15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. \r
-\r
-16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. \r
-\r
-\r
+ADOdb is dual licensed using BSD-Style and LGPL. Where there is any discrepancy, the BSD-Style license will take precedence. In plain English, you do not need to distribute your application  in source code form, nor do you need to distribute ADOdb source code, provided you follow the rest of terms of the BSD-style license.
+
+Commercial use of ADOdb is encouraged. Make money and multiply!
+
+BSD Style-License
+=================
+
+Copyright (c) 2000, 2001, 2002 John Lim
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, 
+are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
+Neither the name of the John Lim nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
+
+DISCLAIMER:
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+==========================================================
+GNU LESSER GENERAL PUBLIC LICENSE
+Version 2.1, February 1999 
+Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+Preamble
+The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. 
+
+This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. 
+
+When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. 
+
+To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. 
+
+For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. 
+
+We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. 
+
+To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. 
+
+Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. 
+
+Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. 
+
+When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. 
+
+We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. 
+
+For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. 
+
+In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. 
+
+Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. 
+
+The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. 
+
+
+TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". 
+
+A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. 
+
+The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) 
+
+"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. 
+
+Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 
+
+1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. 
+
+You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 
+
+2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: 
+
+
+a) The modified work must itself be a software library. 
+b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. 
+c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. 
+d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. 
+(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) 
+
+These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. 
+
+Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. 
+
+In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 
+
+3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. 
+
+Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. 
+
+This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 
+
+4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. 
+
+If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 
+
+5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. 
+
+However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. 
+
+When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. 
+
+If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) 
+
+Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 
+
+6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. 
+
+You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: 
+
+
+a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) 
+b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. 
+c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. 
+d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. 
+e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. 
+For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. 
+
+It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 
+
+7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: 
+
+
+a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. 
+b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 
+8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 
+
+9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 
+
+10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 
+
+11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. 
+
+If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. 
+
+It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. 
+
+This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 
+
+12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 
+
+13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 
+
+Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 
+
+14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. 
+
+NO WARRANTY 
+
+15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 
+
+16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
+
+
 END OF TERMS AND CONDITIONS
\ No newline at end of file
index a45d62d6fe89d30648f06448b5c66cd9cf8cb245..2b449ab3f062f54caa079a94006d6b4e62f02fdd 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
  * Whenever there is any discrepancy between the two licenses, \r
  * the BSD license will take precedence. \r
index 1dd22ca2d45880dd276fd2e25e180949972fee23..6e8ad23e1770a8c5c97b886ae8626953650a653f 100644 (file)
@@ -11,7 +11,7 @@
 <body bgcolor="#FFFFFF">\r
 \r
 <h2>ADOdb Library for PHP</h2>\r
-<p>V2.50 14 Nov 2002 (c) 2000-2002 John Lim (<a href="mailto:jlim@natsoft.com.my">jlim@natsoft.com.my</a>)</p>\r
+<p>V3.40 7 April 2003 (c) 2000-2003 John Lim (<a href="mailto:jlim#natsoft.com.my">jlim#natsoft.com.my</a>)</p>\r
 <p>This software is dual licensed using BSD-Style and LGPL. \r
 Where there is any discrepancy, the BSD-Style license will take precedence. \r
 This means you can use it in proprietary and commercial products.</p>\r
@@ -37,12 +37,15 @@ This means you can use it in proprietary and commercial products.</p>
   <b> <a href="#errorhandling">Using Custom Error Handlers and PEAR_Error</a><br>\r
   <a href="#DSN">Data Source Names</a><br>\r
   <a href="#caching">Caching</a><br>\r
-  <a href="#pivot">Pivot Tables</a></b><p></p>\r
-<p><a href="#ref"><b>REFERENCE</b></a><br>\r
-       <a href="#ADOConnection"><b><br>\r
-       ADOConnection</b></a><br>\r
-       <font size="2">Connections: <a href="#connect">Connect</a> <a href="#pconnect">PConnect</a> <a href="#nconnect">NConnect</a> \r
-       <br>\r
+  <a href="#pivot">Pivot Tables</a></b>\r
+<p><a href="#ref"><b>REFERENCE</b></a>\r
+<p> <font size="2">Variables: <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> \r
+       <a href="#adodb_cache_dir">$ADODB_CACHE_DIR</a> </font><font size="2"><a href=#adodb_fetch_mode>$ADODB_FETCH_MODE</a>&nbsp;<br>\r
+       Constants: </font><font size="2"><a href=#adodb_assoc_case>ADODB_ASSOC_CASE</a> \r
+       </font><br>\r
+       <a href="#ADOConnection"><b> ADOConnection</b></a><br>\r
+       <font size="2">Connections: <a href="#connect">Connect</a> <a href="#pconnect">PConnect</a> \r
+       <a href="#nconnect">NConnect</a> <br>\r
        Executing SQL: <a href="#execute">Execute</a> <a href="#cacheexecute"><i>CacheExecute</i></a> \r
        <a href="#SelectLimit">SelectLimit</a> <a href="#cacheSelectLimit"><i>CacheSelectLimit</i></a> \r
        <a href="#prepare">Prepare</a> <a href=#preparesp>PrepareSP</a> <a href="#parameter">Parameter</a><br>\r
@@ -52,51 +55,52 @@ This means you can use it in proprietary and commercial products.</p>
        <a href="#getall">GetAll</a> <a href="#cachegetall"><i>CacheGetAll</i></a> \r
        <a href="#getcol">GetCol</a> <a href="#cachegetcol"><i>CacheGetCol</i></a> \r
        <a href="#replace">Replace</a> <br>\r
-       &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \r
-       <a href="#executecursor">ExecuteCursor</a> (oci8 only)<br>\r
-       Generates SQL: <a href="#getupdatesql">GetUpdateSQL</a> <a href="#getinsertsql">GetInsertSQL</a></font><font size="2"><br>\r
+       &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#executecursor">ExecuteCursor</a> \r
+       (oci8 only)<br>\r
+       Generates SQL: <a href="#getupdatesql">GetUpdateSQL</a> <a href="#getinsertsql">GetInsertSQL</a><br>\r
        Blobs: <a href="#updateblob">UpdateBlob</a> <a href="#updateclob">UpdateClob</a> \r
-       <a href="#updateblobfile">UpdateBlobFile</a> <br>\r
+       <a href="#updateblobfile">UpdateBlobFile</a> <a href="#blobencode">BlobEncode</a> \r
+       <a href="#blobdecode">BlobDecode</a><br>\r
        Paging/Scrolling: <a href="#pageexecute">PageExecute</a> <a href="#cachepageexecute">CachePageExecute</a><br>\r
-       Cleanup: <a href="#CacheFlush">CacheFlush</a> <a href="#Close">Close</a><br>\r
+       Cleanup: <a href="#cacheflush">CacheFlush</a> <a href="#Close">Close</a><br>\r
        Transactions: <a href="#begintrans">BeginTrans</a> <a href="#committrans">CommitTrans</a> \r
-       <a href="#rollbacktrans">RollbackTrans</a> <br>\r
-       Fetching Data: <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a></font> <br>\r
-       Strings: <a href="#concat"><font size="2">concat</font></a> <font size="2"><a href="#qstr">qstr</a> \r
-       <a href="#quote">quote</a></font><br>\r
-       Dates: <a href="#dbdate"><font size="2">DBDate</font></a> <font size="2"><a href="#dbtimestamp">DBTimeStamp</a> \r
+       <a href="#rollbacktrans">RollbackTrans</a> <a href="#starttrans">StartTrans</a> <a href="#completetrans">CompleteTrans</a> <br>\r
+       Fetching Data: </font> <font size="2"><a href="#setfetchmode">SetFetchMode</a><br>\r
+       Strings: <a href="#concat">concat</a> <a href="#qstr">qstr</a> <a href="#quote">quote</a><br>\r
+       Dates: <a href="#dbdate">DBDate</a> <a href="#dbtimestamp">DBTimeStamp</a> \r
        <a href="#unixdate">UnixDate</a> <a href="#unixtimestamp">UnixTimeStamp</a> \r
-       <a href="#OffsetDate">OffsetDate</a> <a href="#SQLDate">SQLDate</a> </font><br>\r
-       Rows Management: <a href="#affected_rows"><font size="2">Affected_Rows</font></a> \r
-       <font size="2"><a href="#inserted_id">Insert_ID</a> <a href="#genid">GenID</a> \r
-       </font><font size="2"><br>\r
-       Error Handling: </font><font size="2"><a href="#errormsg">ErrorMsg</a> <a href="#errorno">ErrorNo</a><br>\r
+       <a href="#OffsetDate">OffsetDate</a> <a href="#SQLDate">SQLDate</a> <br>\r
+       Rows Management: <a href="#affected_rows">Affected_Rows</a> <a href="#inserted_id">Insert_ID</a> \r
+       <a href="#genid">GenID</a> <a href=#createseq>CreateSequence</a> <a href=#dropseq>DropSequence</a> \r
+       <br>\r
+       Error Handling: <a href="#errormsg">ErrorMsg</a> <a href="#errorno">ErrorNo</a>\r
+        <a href="#metaerror">MetaError</a> <a href="#metaerrormsg">MetaErrorMsg</a><br>\r
        Data Dictionary (metadata): <a href="#metadatabases">MetaDatabases</a> <a href="#metatables">MetaTables</a> \r
        <a href="#metacolumns">MetaColumns</a> <a href="#metacolumnames">MetaColumnNames</a> \r
-       </font><br>\r
-       <font size="2">Deprecated: <a href="#bind">Bind</a> <a href="#blankrecordset">BlankRecordSet</a></font> \r
+       <a href="#metaprimarykeys">MetaPrimaryKeys</a> <a href="#serverinfo">ServerInfo</a> \r
        <br>\r
-       <a href="#ADORecordSet"><b><br>\r
+       Statistics and Query-Rewriting: <a href="#fnexecute">fnExecute and fnCacheExecute</a><br>\r
+       </font><font size="2">Deprecated: <a href="#bind">Bind</a> <a href="#blankrecordset">BlankRecordSet</a></font><br>\r
+       <a href="#adorecordSet"><b><br>\r
        ADORecordSet</b></a><br>\r
-       <font size="2">Returns one row:</font><font size="2"><a href="#fetchrow">FetchRow</a> \r
-       <a href="#fetchinto">FetchInto</a> <a href="#fetchobject">FetchObject</a> \r
-       <a href="#fetchnextobject">FetchNextObject</a> </font><font size="2"><br>\r
-       Returns all rows:</font><font size="2"><a href="#getarray">GetArray</a> <a href="#getrows">GetRows</a> \r
-       </font><font size="2"><a href="#getassoc">GetAssoc</a><br>\r
-       Scrolling:</font><font size="2"><a href="#move">Move</a> <a href="#movenext">MoveNext</a> \r
-       <a href="#movefirst">MoveFirst</a> <a href="#movelast">MoveLast</a> <a href="#abspos">AbsolutePosition</a> \r
-       <a href="#currentrow">CurrentRow</a> <a href="#atfirstpage">AtFirstPage</a> \r
-       <a href="#atlastpage">AtLastPage</a> <a href="#absolutepage">AbsolutePage</a> \r
-       </font> <font size="2"><br>\r
+       <font size="2">Returns one row:<a href="#fetchrow">FetchRow</a> <a href="#fetchinto">FetchInto</a> \r
+       <a href="#fetchobject">FetchObject</a> <a href="#fetchnextobject">FetchNextObject</a> \r
+       <a href="#fetchobj">FetchObj</a> <a href="#fetchnextobj">FetchNextObj</a><br>\r
+       Returns all rows:<a href="#getarray">GetArray</a> <a href="#getrows">GetRows</a> \r
+       <a href="#getassoc">GetAssoc</a><br>\r
+       Scrolling:<a href="#move">Move</a> <a href="#movenext">MoveNext</a> <a href="#movefirst">MoveFirst</a> \r
+       <a href="#movelast">MoveLast</a> <a href="#abspos">AbsolutePosition</a> <a href="#currentrow">CurrentRow</a> \r
+       <a href="#atfirstpage">AtFirstPage</a> <a href="#atlastpage">AtLastPage</a> \r
+       <a href="#absolutepage">AbsolutePage</a> </font> <font size="2"><br>\r
        Menu generation:<a href="#getmenu">GetMenu</a> <a href="#getmenu2">GetMenu2</a><br>\r
        Dates:<a href="#userdate">UserDate</a> <a href="#usertimestamp">UserTimeStamp</a> \r
        <a href="#unixdate">UnixDate</a> <a href="#unixtimestamp">UnixTimeStamp<br>\r
-       </a>Recordset Info:<a href="#recordcount">RecordCount</a></font><font size="2"\r
-       <a href="#po_recordcount">PO_RecordSet</a><br>\r
-       Field Info:</font><font size="2"><a href="#fieldcount">FieldCount</a> <a href="#fetchfield">FetchField</a> \r
-       <a href="#metatype">MetaType</a></font><font size="2"><br>\r
-       Cleanup: </font><font size="2"><a href="#rsclose">Close</a></font> <br>\r
-       <font size="2">Deprecated: <a href="#getrowassoc">GetRowAssoc</a> <a href="#fields">Fields</a></font> \r
+       </a>Recordset Info:<a href="#recordcount">RecordCount</a> <a href="#po_recordcount">PO_RecordSet</a\r
+       <a href="#nextrecordset">NextRecordSet</a><br>\r
+       Field Info:<a href="#fieldcount">FieldCount</a> <a href="#fetchfield">FetchField</a> \r
+       <a href="#metatype">MetaType</a><br>\r
+       Cleanup: <a href="#rsclose">Close</a></font> <font size="2"><br>\r
+       Deprecated: <a href="#getrowassoc">GetRowAssoc</a> <a href="#fields">Fields</a></font> \r
 <p><font size="2"><a href="#rs2html"><b>rs2html</b></a>&nbsp; <a href="#exrs2html">example</a></font><br>\r
   <a href="#adodiff">Differences between ADOdb and ADO</a><br>\r
   <a href="#driverguide"><b>Database Driver Guide<br>\r
@@ -105,7 +109,8 @@ This means you can use it in proprietary and commercial products.</p>
 <h2>Introduction<a name="intro"></a></h2>\r
 <p>PHP's database access functions are not standardised. This creates a need for \r
   a database class library to hide the differences between the different database \r
-  API's (encapsulate the differences) so we can easily switch databases.</p>\r
+  API's (encapsulate the differences) so we can easily switch databases. PHP 4.0.5 or later\r
+  is now required (because we use array-based str_replace).</p>\r
 <p>We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, Informix, \r
   PostgreSQL, FrontBase,  Interbase (Firebird and Borland variants), Foxpro, Access, ADO and ODBC. We have had successful reports of connecting\r
   to Progress and DB2 via ODBC. We hope more people \r
@@ -203,8 +208,10 @@ You will use <code>$conn-><a href=#connect>Connect()</a></code> or
   <tr valign="top"> \r
        <td><b><font size="2">ado</font></b></td>\r
        <td><font size="2">B</font></td>\r
-       <td><font size="2">Generic ADO, not tuned for specific databases. Allows DSN-less \r
-         connections. For best performance, use an OLEDB provider.</font></td>\r
+       <td><p><font size="2">Generic ADO, not tuned for specific databases. Allows \r
+                               DSN-less connections. For best performance, use an OLEDB provider. \r
+                               This is the base class for all ado drivers.</font></p>\r
+                       <p><font size="2">You can set $db-&gt;codePage before connecting.</font></p></td>\r
        <td><font size="2">? depends on database</font></td>\r
        <td><font size="2">ADO or OLEDB provider</font></td>\r
        <td><font size="2">Windows only</font></td>\r
@@ -260,10 +267,13 @@ You will use <code>$conn-><a href=#connect>Connect()</a></code> or
   <tr valign="top"> \r
        <td><b><font size="2">ibase</font></b></td>\r
        <td><font size="2">B</font></td>\r
-       <td><font size="2">Interbase 6 or earlier. Some users report you might need \r
-         to use this<br>\r
-         $db->PConnect('localhost:c:/ibase/employee.gdb', "sysdba", "masterkey") \r
-         to connect. Lacks Affected_Rows currently.</font></td>\r
+           <td><font size="2">Interbase 6 or earlier. Some users report you might need \r
+                       to use this<br>\r
+                       $db->PConnect('localhost:c:/ibase/employee.gdb', "sysdba", "masterkey") \r
+                       to connect. Lacks Affected_Rows currently.<br>\r
+                       <br>\r
+                       You can set $db->dialect, $db-&gt;buffers and $db->charSet before \r
+                       connecting.</font></td>\r
        <td><font size="2">Y/N</font></td>\r
        <td><font size="2">Interbase client</font></td>\r
        <td><font size="2">Unix and Windows</font></td>\r
@@ -313,8 +323,10 @@ You will use <code>$conn-><a href=#connect>Connect()</a></code> or
        <td height="73"><font size="2">Y/N</font></td>\r
        <td height="73"><font size="2">Mssql client</font></td>\r
        <td height="73"> \r
-         <p><font size="2">Unix and Windows. <a href="http://phpbuilder.com/columns/alberto20000919.php3"><br>\r
-               Unix install howto</a>.</font></p>\r
+         <p><font size="2">Unix and Windows. <br>\r
+         <a href="http://phpbuilder.com/columns/alberto20000919.php3">Unix install howto</a> and\r
+         <a href=http://linuxjournal.com/article.php?sid=6636&mode=thread&order=0>another one</a>.\r
+         </font></p>\r
        </td>\r
   </tr>\r
        <tr valign="top"> \r
@@ -335,7 +347,8 @@ You will use <code>$conn-><a href=#connect>Connect()</a></code> or
   <tr valign="top"> \r
        <td><b><font size="2">mysql</font></b></td>\r
        <td><font size="2">A</font></td>\r
-       <td><font size="2">MySQL without transaction support</font></td>\r
+           <td><font size="2">MySQL without transaction support. You can also set \r
+                       $db-&gt;clientFlags before connecting.</font></td>\r
        <td><font size="2">Y/N</font></td>\r
        <td><font size="2">MySQL client</font></td>\r
        <td><font size="2">Unix and Windows</font></td>\r
@@ -399,8 +412,9 @@ You will use <code>$conn-><a href=#connect>Connect()</a></code> or
        <td><font size="2">A</font></td>\r
        <td><font size="2">Generic ODBC, not tuned for specific databases. To connect, \r
          use <br>\r
-         PConnect('DSN','user','pwd').</font></td>\r
-       <td><font size="2">? depends on database</font></td>\r
+                       PConnect('DSN','user','pwd'). This is the base class for all odbc \r
+                       derived drivers.</font></td>\r
+           <td><font size="2">? depends on database</font></td>\r
        <td><font size="2">ODBC</font></td>\r
        <td><font size="2">Unix and Windows. <a href="http://phpbuilder.com/columns/alberto20000919.php3?page=4">Unix \r
          hints.</a></font></td>\r
@@ -487,17 +501,15 @@ You will use <code>$conn-><a href=#connect>Connect()</a></code> or
   C = user contributed or experimental driver. Might not fully support all of \r
   the latest features of ADOdb. </p>\r
 <p>The column &quot;RecordCount() usable&quot; indicates whether RecordCount() \r
-  return the number of rows, or returns -1 when a SELECT statement is executed. \r
-  If this column displays Y/N then the RecordCount() is emulated when the global \r
-  variable $ADODB_COUNTRECS=true, which is the default. Note that for large recordsets, \r
-  it might be better to disable RecordCount() emulation because substantial amounts \r
-  of memory are required to cache the recordset for counting. This variable is \r
-  checked every time a query is executed, so you can selectively choose which \r
-  recordsets to count.</p>\r
-<p>All databases that support $ADODB_FETCH_MODE work with ADODB_FETCH_NUM and \r
-  ADODB_FETCH_ASSOC. How it supports ADODB_FETCH_DEFAULT is implementation dependant \r
-  and might not be portable. Similarly ADODB_FETCH_BOTH is implementation dependant \r
-  and is not supported by all databases.</p>\r
+       return the number of rows, or returns -1 when a SELECT statement is executed. \r
+       If this column displays Y/N then the RecordCount() is emulated when the global \r
+       variable $ADODB_COUNTRECS=true (this is the default). Note that for large \r
+       recordsets, it might be better to disable RecordCount() emulation because \r
+       substantial amounts of memory are required to cache the recordset for counting. Also\r
+       there is a speed penalty of 40-50% if emulation is required. This is emulated in\r
+       most databases except for PostgreSQL and MySQL.\r
+       This variable is checked every time a query is executed, so you can selectively \r
+       choose which recordsets to count.</p>\r
 <p>\r
 \r
 <hr>\r
@@ -542,14 +554,14 @@ $<font color="#660000">conn</font>->Close(); # optional
   property is set to true when end-of-file is reached. If an error occurs in Execute(), \r
   we return false instead of a recordset.</p>\r
 <p>The <code>$recordSet-&gt;fields[]</code> array is generated by the PHP database \r
-  extension. Some database extensions only index by number and do not index the \r
-  array by field name. To force indexing by name - that is associative arrays \r
-  - use the $ADODB_FETCH_MODE global variable. Each recordset saves and uses whatever \r
-  fetch mode was set when the recordset was created in Execute() or SelectLimit().\r
+       extension. Some database extensions only index by number and do not index \r
+       the array by field name. To force indexing by name - that is associative arrays \r
+       - use the SetFetchMode function. Each recordset saves and uses whatever fetch \r
+       mode was set when the recordset was created in Execute() or SelectLimit(). \r
 <pre>\r
-       $ADODB_<b>FETCH_MODE</b> = ADODB_FETCH_NUM;\r
+       $db->SetFetchMode(ADODB_FETCH_NUM);\r
        $rs1 = $db->Execute('select * from table');\r
-       $ADODB_<b>FETCH_MODE</b> = ADODB_FETCH_ASSOC;\r
+       $db->SetFetchMode(ADODB_FETCH_ASSOC);\r
        $rs2 = $db->Execute('select * from table');\r
        print_r($rs1->fields); # shows <i>array([0]=>'v0',[1] =>'v1')</i>\r
        print_r($rs2->fields); # shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i>\r
@@ -557,7 +569,7 @@ $<font color="#660000">conn</font>->Close(); # optional
 <p>\r
  </p>\r
 <p>To get the number of rows in the select statement, you can use <font face="Courier New, Courier, mono">$recordSet-&gt;<a href="#recordcount">RecordCount</a>()</font>. \r
- Note that it can return -1 if the number of rows returned cannot be determined.</p>\r
      Note that it can return -1 if the number of rows returned cannot be determined.</p>\r
 <h3>Example 2: Advanced Select with Field Objects<a name="ex2"></a></h3>\r
 <p>Select a table, display the first two columns. If the second column is a date or timestamp, reformat the date to US format.</p>\r
 <pre>\r
@@ -678,13 +690,9 @@ $<font color="#663300">rs</font> = $<font color="#663300">conn</font>->Execute($
 <b>print</b> <b><font color="#336600">$<font color="#663300">rs</font>-&gt;GetMenu('GetCust','Mary Rosli');\r
 ?&gt;</font></b></font></pre>\r
 <p>Here we define a menu named GetCust, with the menu option 'Mary Rosli' selected. \r
- See <a href="#getmenu"><font face="Courier New, Courier, mono">GetMenu</font></a><font face="Courier New, Courier, mono">()</font>. \r
- We also have functions that return the recordset as an array: <font face="Courier New, Courier, mono"><a href="#getarray">GetArray</a>()</font>, \r
- and as an associative array with the key being the first column: <a href="#getassoc">GetAssoc</a>().</p>\r
-<p>\r
-Aslo new to ADOdb 1.50 or later is the global variable $ADODB_FETCH_MODE. This allows you to define\r
-whether you want associative or numeric indexing for your arrays.<p>\r
-\r
+       See <a href="#getmenu"><font face="Courier New, Courier, mono">GetMenu</font></a><font face="Courier New, Courier, mono">()</font>. \r
+       We also have functions that return the recordset as an array: <font face="Courier New, Courier, mono"><a href="#getarray">GetArray</a>()</font>, \r
+       and as an associative array with the key being the first column: <a href="#getassoc">GetAssoc</a>().</p>\r
 <h3>Example 6: Connecting to 2 Databases At Once<a name="ex6"></a></h3>\r
 <pre>&lt;?\r
 <b>include</b>('adodb.inc.php');        # load code common to ADOdb\r
@@ -732,9 +740,10 @@ $rs = $conn->Execute($sql); # Execute the query and get the empty recordset
 $record = array(); # Initialize an array to hold the record data to insert\r
 \r
 # Set the values for the fields in the record\r
+# Note that field names are case-insensitive\r
 $record["firstname"] = "Bob";\r
-$record["lastname"] = "Smith";\r
-$record["created"] = time();\r
+$record["lastNamE"] = "Smith";\r
+$record["creaTed"] = time();\r
 \r
 # Pass the empty recordset and the array containing the data to insert\r
 # into the GetInsertSQL function. The function will process the data and return\r
@@ -754,8 +763,9 @@ $rs = $conn->Execute($sql); # Execute the query and get the existing record to u
 $record = array(); # Initialize an array to hold the record data to update\r
 \r
 # Set the values for the fields in the record\r
+# Note that field names are case-insensitive\r
 $record["firstname"] = "Caroline";\r
-$record["lastname"] = "Smith"; # Update Caroline's lastname from Miranda to Smith\r
+$record["LasTnAme"] = "Smith"; # Update Caroline's lastname from Miranda to Smith\r
 \r
 # Pass the single record recordset and the array containing the data to update\r
 # into the GetUpdateSQL function. The function will process the data and return\r
@@ -784,7 +794,7 @@ $sql = "select * from adoxyz ";
 \r
 $pager = new ADODB_Pager($db,$sql);\r
 $pager->Render($rows_per_page=5);</pre>\r
-<p>This will create a basic record pager that looks like this: <a name=scr></a>\r
+<p>This will create a basic record pager that looks like this: <a name="scr"></a>\r
 <p>\r
 <table border=1 bgcolor=beige><tr>\r
        <td> <a href="#scr"><code>|&lt;</code></a> &nbsp; <a href="#scr"><code>&lt;&lt;</code></a> \r
@@ -847,7 +857,7 @@ $pager->Render($rows_per_page=5);</pre>
 <p>You can also allow display of html by setting $pager->htmlSpecialChars = false.\r
 <p>Some of the code used here was contributed by Iv&aacute;n Oliva and Cornel \r
   G. </p>\r
-<h3><a name=ex9></a>Example 9: Exporting in CSV or Tab-Delimited Format</h3>\r
+<h3><a name="ex9"></a>Example 9: Exporting in CSV or Tab-Delimited Format</h3>\r
 <p>We provide some helper functions to export in comma-separated-value (CSV) and \r
   tab-delimited formats:</p>\r
 <pre><b>include_once('/path/to/adodb/toexport.inc.php');</b><br>include_once('/path/to/adodb/adodb.inc.php');<br>\r
@@ -1178,19 +1188,19 @@ to 60 minutes.
        GROUP BY CompanyName</font></code><font size="2"><br>\r
        </font> </p>\r
 <font color="#000000"><hr>\r
-<h1>Class Reference<a name="Ref"></a></h1>\r
+<h1>Class Reference<a name="ref"></a></h1>\r
 <p>Function parameters with [ ] around them are optional.</p>\r
 </font> \r
 <h2>Global Variables</h2>\r
-<h3>$ADODB_COUNTRECS</h3>\r
+<h3><font color="#000000"><a name="adodb_countrecs"></a></font>$ADODB_COUNTRECS</h3>\r
 <p>If the database driver API does not support counting the number of records \r
-  returned in a SELECT statement, the function RecordCount() is emulated when \r
-  the global variable $ADODB_COUNTRECS is set to true, which is the default. We \r
-  emulate this by buffering the records, which can take up large amounts of memory \r
-  for big recordsets. Set this variable to false for the best performance. This \r
-  variable is checked every time a query is executed, so you can selectively choose \r
-  which recordsets to count.</p>\r
-<h3><font color="#000000">$ADODB_CACHE_DIR</font></h3>\r
+       returned in a SELECT statement, the function RecordCount() is emulated when \r
+       the global variable $ADODB_COUNTRECS is set to true, which is the default. \r
+       We emulate this by buffering the records, which can take up large amounts \r
+       of memory for big recordsets. Set this variable to false for the best performance. \r
+       This variable is checked every time a query is executed, so you can selectively \r
+       choose which recordsets to count.</p>\r
+<h3><font color="#000000"><a name="adodb_cache_dir"></a>$ADODB_CACHE_DIR</font></h3>\r
 <font color="#000000"> \r
 <p>If you are using recordset caching, this is the directory to save your recordsets \r
   in. Define this before you call any caching functions such as CacheExecute( \r
@@ -1230,18 +1240,36 @@ to 60 minutes.
        The behaviour of this default mode varies from driver to driver, so do not \r
        rely on ADODB_FETCH_DEFAULT. For portability, we recommend sticking to ADODB_FETCH_NUM \r
        or ADODB_FETCH_ASSOC. Many drivers do not support ADODB_FETCH_BOTH.</p>\r
-<p>For the odbc and ibase drivers and all drivers derived from them, ADODB_FETCH_ASSOC \r
-       will by default generate recordsets where the field name keys are lower-cased. \r
-       Use the constant ADODB_FETCH_CASE to change the case of the keys. There are \r
-       3 possible values:</p>\r
-<p>0 = assoc lowercase field names. $rs-&gt;fields['orderid'] -- this is the default<br>\r
+<p><strong>SetFetchMode Function</strong></p>\r
+<p>Some programmers prefer to use a more object-oriented solution, where the fetch \r
+       mode is set by a object function, <a href="#setfetchmode">SetFetchMode</a>. \r
+       Once this function is called for a connection object, that connection object \r
+       will ignore the global variable $ADODB_FETCH_MODE and will use the internal \r
+       fetchMode property exclusively.</p>\r
+<pre>\r
+       $db->SetFetchMode(ADODB_FETCH_NUM);\r
+       $rs1 = $db->Execute('select * from table');\r
+       $db->SetFetchMode(ADODB_FETCH_ASSOC);\r
+       $rs2 = $db->Execute('select * from table');\r
+       print_r($rs1->fields); # shows <i>array([0]=>'v0',[1] =>'v1')</i>\r
+       print_r($rs2->fields); # shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i></pre>\r
+<p>To retrieve the previous fetch mode, you can use check the $db-&gt;fetchMode \r
+       property, or use the return value of SetFetchMode( ). \r
+<p><strong><a name="adodb_assoc_case"></a>ADODB_ASSOC_CASE</strong></p>\r
+<p>You can control the associative fetch case for certain drivers which behave \r
+       differently. For the sybase, oci8po, mssql, odbc and ibase drivers and all \r
+       drivers derived from them, ADODB_ASSOC_CASE will by default generate recordsets \r
+       where the field name keys are lower-cased. Use the constant ADODB_ASSOC_CASE \r
+       to change the case of the keys. There are 3 possible values:</p>\r
+<p>0 = assoc lowercase field names. $rs-&gt;fields['orderid']<br>\r
        1 = assoc uppercase field names. $rs-&gt;fields['ORDERID']<br>\r
-       2 = use native-case field names. $rs-&gt;fields['OrderID']</p>\r
+       2 = use native-case field names. $rs-&gt;fields['OrderID'] -- this is the \r
+       default since ADOdb 2.90</p>\r
 <p>To use it, declare it before you incldue adodb.inc.php.</p>\r
-<p>define('ADODB_FETCH_CASE', 2); # use native-case for ADODB_FETCH_ASSOC<br>\r
+<p>define('ADODB_ASSOC_CASE', 2); # use native-case for ADODB_FETCH_ASSOC<br>\r
        include('adodb.inc.php'); </p>\r
 <hr>\r
-<h2>ADOConnection<a name="ADOConnection"></a></h2>\r
+<h2>ADOConnection<a name="adoconnection"></a></h2>\r
 <p>Object that performs the connection to the database, executes SQL statements \r
        and has a set of utility functions for standardising the format of SQL statements \r
        for issues such as concatenation and date formats.</p>\r
@@ -1340,13 +1368,16 @@ to 60 minutes.
   not guaranteed to rollback existing failed transactions when \r
   persistent connections are used. This is implemented in Oracle, \r
   MySQL, PgSQL, MSSQL, ODBC currently. \r
-</p>\r
+<p>Since ADOdb 3.11, you can force non-persistent \r
+connections even if PConnect is called by defining the constant \r
+ADODB_NEVER_PERSIST  before you call PConnect.\r
 <p><b>NConnect<a name="nconnect"></a>($host,[$user],[$password],[$database])</b></p>\r
-<p>Always force new connection. In contrast, PHP sometimes reuses connections when you use Connect() or\r
-PConnect(). Currently works only on oci8 drivers. For other drivers, NConnect() works like\r
-Connect().\r
+<p>Always force new connection. In contrast, PHP sometimes reuses connections \r
+       when you use Connect() or PConnect(). Currently works only on mysql (PHP 4.3.0 \r
+       or later) and oci8-derived drivers. For other drivers, NConnect() works like \r
+       Connect(). \r
 <font color="#000000"> \r
-<p><b>Execute<a name="Execute"></a>($sql,$inputarr=false)</b></p>\r
+<p><b>Execute<a name="execute"></a>($sql,$inputarr=false)</b></p>\r
 <p>Execute SQL statement $<b>sql</b> and return derived class of ADORecordSet \r
        if successful. Note that a record set is always returned on success, even \r
        if we are executing an insert or update statement.</p>\r
@@ -1375,7 +1406,7 @@ Variable binding in the oci8 driver.
 $rs = $db->Execute('select name from table where val=:key', \r
   array('key' => 10));\r
 </pre>\r
-<p><b>CacheExecute<a name="CacheExecute"></a>([$secs2cache,]$sql,$inputarr=false)</b></p>\r
+<p><b>CacheExecute<a name="cacheexecute"></a>([$secs2cache,]$sql,$inputarr=false)</b></p>\r
 <p>Similar to Execute, except that the recordset is cached for $secs2cache seconds \r
        in the $ADODB_CACHE_DIR directory. If CacheExecute() is called again with \r
        the same parameters, same database, same userid, same password, and the cached \r
@@ -1404,21 +1435,23 @@ only with SELECT statements.
        overloaded </i>then ADOdb's caching is good because it reduces the load on \r
        your database server. If your database server is lightly loaded or much faster \r
        than your Web server, then caching could actually reduce performance. </p>\r
-<p><b>ExecuteCursor<a name="executecursor"></a>($sql,$cursorName='rs')</b></p>\r
+<p><b>ExecuteCursor<a name="executecursor"></a>($sql,$cursorName='rs',$parameters=false)</b></p>\r
 <p>Execute an Oracle stored procedure, and returns an Oracle REF cursor variable as \r
        a regular ADOdb recordset. Does not work with any other database except oci8. \r
        Thanks to Robert Tuttle for the design.\r
 <pre>\r
     $db = ADONewConnection("oci8"); \r
     $db->Connect("foo.com:1521", "uid", "pwd", "FOO"); \r
-    $rs = $db->ExecuteCursor("begin :cursorvar := getdata('param1'); end;", 'cursorvar'); \r
+    $rs = $db->ExecuteCursor("begin :cursorvar := getdata(:param1); end;", \r
+                                       'cursorvar',\r
+                                       array('param1'=>10)); \r
     # $rs is now just like any other ADOdb recordset object<br>    rs2html($rs);</pre>\r
 <p>ExecuteCursor() is a helper function that does the following internally: \r
 <pre>\r
        $stmt = $db->Prepare("BEGIN :RS := SP_FOO(); END;");\r
        $db->Parameter($stmt, $cur, 'RS', false, -1, OCI_B_CURSOR);\r
        $rs = $db->Execute($stmt);</pre>\r
-<p><b>SelectLimit<a name="SelectLimit"></a>($sql,$numrows=-1,$offset=-1,$inputarr=false)</b></p>\r
+<p><b>SelectLimit<a name="selectlimit"></a>($sql,$numrows=-1,$offset=-1,$inputarr=false)</b></p>\r
 <p>Returns a recordset if successful. Returns false otherwise. Performs a select \r
        statement, simulating PostgreSQL's SELECT statement, LIMIT $numrows OFFSET \r
        $offset clause.</p>\r
@@ -1444,67 +1477,79 @@ only with SELECT statements.
 </pre>\r
 <p> \r
 <p>Ron Wilson reports that SelectLimit does not work with UNIONs. \r
-<p><b>CacheSelectLimit<a name="CacheSelectLimit"></a>([$secs2cache,] $sql, $numrows=-1,$offset=-1,$inputarr=false)</b></p>\r
+<p><b>CacheSelectLimit<a name="cacheselectlimit"></a>([$secs2cache,] $sql, $numrows=-1,$offset=-1,$inputarr=false)</b></p>\r
 <p>Similar to SelectLimit, except that the recordset returned is cached for $secs2cache \r
        seconds in the $ADODB_CACHE_DIR directory. </p>\r
 <p>Since 1.80, $secs2cache has been optional, and you can define the caching time \r
        in $connection-&gt;cacheSecs.</p>\r
 </font> \r
 <pre><font color="#000000">    $conn-&gt;Connect(...);\r
-       $conn-&gt;cacheSecs = 3600*24; // cache 24 hours\r
+   $conn-&gt;cacheSecs = 3600*24; // cache 24 hours\r
        $rs = $conn-&gt;CacheSelectLimit('select * from table',10);</font></pre>\r
 <font color="#000000"> \r
-<p><b>CacheFlush<a name="CacheFlush"></a>($sql=false)</b></p>\r
+<p><b>CacheFlush<a name="cacheflush"></a>($sql=false,$inputarr=false)</b></p>\r
 <p>Flush (delete) any cached recordsets for the SQL statement $sql in $ADODB_CACHE_DIR. \r
-<p>If no parameter is passed in, then all adodb_*.cache files are deleted.\r
-<p>\r
-  If you want to flush all cached recordsets manually, execute the following PHP code (works \r
-  only under Unix): <br>\r
-  <code> &nbsp; system(&quot;rm -f `find &quot;.$ADODB_CACHE_DIR.&quot; \r
-  -name adodb_*.cache`&quot;);</code></p>\r
+<p>If no parameter is passed in, then all adodb_*.cache files are deleted. \r
+<p> If you want to flush all cached recordsets manually, execute the following \r
+       PHP code (works only under Unix): <br>\r
+       <code> &nbsp; system(&quot;rm -f `find &quot;.$ADODB_CACHE_DIR.&quot; -name \r
+       adodb_*.cache`&quot;);</code></p>\r
 <p>For general cleanup of all expired files, you should use <a href="http://www.superscripts.com/tutorial/crontab.html">crontab</a> \r
-  on Unix, or at.exe on Windows, and a shell script similar to the following:</p>\r
-<p><font face="Courier New, Courier, mono">#------------------------------------------------------ \r
-  <br>\r
-  # TRUNCATING OUTPUT FILES OLDER THAN N DAYS <br>\r
-  # <br>\r
-  # Everything between the 3 lines above and their matching <br>\r
-  # lines at the bottom of this section show you how to <br>\r
-  # delete any log files whose modification time <br>\r
-  # is older than AGED. The AGED variable can be coded in the <br>\r
-  # script or passed on the command line. <br>\r
-  #------------------------------------------------------ <br>\r
-  # This particular example deletes files in the TMPPATH <br>\r
-  # directory with the string &quot;.cache&quot; in their name that <br>\r
-  # are more than 7 days old. <br>\r
-  #------------------------------------------------------ <br>\r
-  AGED=7 <br>\r
-  find ${TMPPATH} -mtime +$AGED | grep &quot;\.cache&quot; | xargs rm -f <br>\r
-</font>\r
-<p><b>ErrorMsg<a name="ErrorMsg"></a>()</b></p>\r
+       on Unix, or at.exe on Windows, and a shell script similar to the following:<font face="Courier New, Courier, mono"><br>\r
+       #------------------------------------------------------ <br>\r
+       # This particular example deletes files in the TMPPATH <br>\r
+       # directory with the string &quot;.cache&quot; in their name that <br>\r
+       # are more than 7 days old. <br>\r
+       #------------------------------------------------------ <br>\r
+       AGED=7 <br>\r
+       find ${TMPPATH} -mtime +$AGED | grep &quot;\.cache&quot; | xargs rm -f <br>\r
+       </font> </p>\r
+<p><b>MetaError<a name="metaerror"></a>($errno=false)</b></p>\r
+<p>Returns a virtualized error number, based on PEAR DB's error number system. You might\r
+need to include adodb-error.inc.php before you call this function. The parameter $errno\r
+is the native error number you want to convert. If you do not pass any parameter, MetaError\r
+will call ErrorNo() for you and convert it. If the error number cannot be virtualized, MetaError \r
+will return -1 (DB_ERROR).</p>\r
+\r
+<p><b>MetaErrorMsg<a name="metaerrormsg"></a>($errno)</b></p>\r
+<p>Pass the error number returned by MetaError() for the equivalent textual error message.</p>\r
+<p><b>ErrorMsg<a name="errormsg"></a>()</b></p>\r
 <p>Returns the last status or error message. This can return a string even if \r
-  no error occurs. In general you do not need to call this function unless an \r
-  ADOdb function returns false on an error. </p>\r
+       no error occurs. In general you do not need to call this function unless an \r
+       ADOdb function returns false on an error. </p>\r
 <p>Note: If <b>debug</b> is enabled, the SQL error message is always displayed \r
-  when the <b>Execute</b> function is called.</p>\r
+       when the <b>Execute</b> function is called.</p>\r
 <p><b>ErrorNo<a name="errorno"></a>()</b></p>\r
 <p>Returns the last error number. Note that old versions of PHP (pre 4.0.6) do \r
-  not support error number for ODBC. In general you do not need to call this function \r
-  unless an ADOdb function returns false on an error.</p>\r
-<p><b>GenID<a name="genid"></a>($seqName = 'ADOdbseq',$startID=1)</b></p>\r
+       not support error number for ODBC. In general you do not need to call this \r
+       function unless an ADOdb function returns false on an error.</p>\r
+</font>\r
+<p><font color="#000000"><b>SetFetchMode<a name="setfetchmode"></a>($mode)</b></font></p>\r
+<p><font color="#000000">Sets the current fetch mode for the connection and stores \r
+       it in $db-&gt;fetchMode. Legal modes are ADODB_FETCH_ASSOC and ADODB_FETCH_NUM. \r
+       For more info, see <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a>.</font></p>\r
+<p><font color="#000000">Returns the previous fetch mode, which could be false \r
+       if SetFetchMode( ) has not been called before.</font></p>\r
+<font color="#000000"> \r
+<p><b>CreateSequence<a name="createseq"></a>($seqName = 'adodbseq',$startID=1)</b></p>\r
+<p>Create a sequence. The next time GenID( ) is called, the value returned will \r
+       be $startID. Added in 2.60. \r
+<p><b>DropSequenceD<a name="dropseq"></a>($seqName = 'adodbseq')</b></p>\r
+<p>Delete a sequence. Added in 2.60. \r
+<p><b>GenID<a name="genid"></a>($seqName = 'adodbseq',$startID=1)</b></p>\r
 <p>Generate a sequence number (an integer except for mssql). Works for interbase, \r
-  mysql, postgresql, oci8, oci8po, mssql, ODBC based (access,vfp,db2,etc) drivers \r
-  currently. Uses $seqName as the name of the sequence. GenID() will automatically \r
-  create the sequence for you if it does not exist (provided the userid has permission \r
-  to do so). Otherwise you will have to create the sequence yourself. \r
+       mysql, postgresql, oci8, oci8po, mssql, ODBC based (access,vfp,db2,etc) drivers \r
+       currently. Uses $seqName as the name of the sequence. GenID() will automatically \r
+       create the sequence for you if it does not exist (provided the userid has \r
+       permission to do so). Otherwise you will have to create the sequence yourself. \r
 <p> If your database driver emulates sequences, the name of the table is the sequence \r
-  name. The table has one column, "id" which should be of type integer, or if \r
-  you need something larger - numeric(16). \r
+       name. The table has one column, "id" which should be of type integer, or if \r
+       you need something larger - numeric(16). \r
 <p> For ODBC and databases that do not support sequences natively (eg mssql, mysql), \r
-  we create a table for each sequence. If the sequence has not been defined earlier, \r
-  it is created with the starting value set in $startID.</p>\r
+       we create a table for each sequence. If the sequence has not been defined \r
+       earlier, it is created with the starting value set in $startID.</p>\r
 <p>Note that the mssql driver's GenID() used to generate 16 byte GUID's. We now \r
-  return integers since 1.90.</p>\r
+       return integers since 1.90.</p>\r
 <p><b>UpdateBlob<a name="updateblob"></a>($table,$column,$val,$where)</b></p>\r
 Allows you to store a blob (in $val) into $table into $column in a row at $where. \r
 <p> Usage: \r
@@ -1519,16 +1564,21 @@ Allows you to store a blob (in $val) into $table into $column in a row at $where
        $conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');\r
 </pre>\r
 <p> Returns true if succesful, false otherwise. Supported by MySQL, PostgreSQL, \r
-  Oci8, Oci8po and Interbase drivers. Other drivers might work, depending on the \r
-  state of development.</p>\r
+       Oci8, Oci8po and Interbase drivers. Other drivers might work, depending on \r
+       the state of development.</p>\r
 <p>Note that when an Interbase blob is retrieved using SELECT, it still needs \r
-  to be decoded using $connection->DecodeBlob($blob); to derive the original value \r
-  in versions of PHP before 4.1.0. \r
+       to be decoded using $connection->DecodeBlob($blob); to derive the original \r
+       value in versions of PHP before 4.1.0. \r
+<p>For PostgreSQL, you can store your blob using blob oid's or as a bytea field. \r
+       You can use bytea fields but not blob oid's currently with UpdateBlob( ). \r
+       Conversely UpdateBlobFile( ) supports oid's, but not bytea data.<br>\r
+       <br>\r
+       If you do not pass in an oid, then UpdateBlob() assumes that you are storing \r
+       in bytea fields.\r
 <p><b>UpdateClob<a name="updateclob"></a>($table,$column,$val,$where)</b></p>\r
 Allows you to store a clob (in $val) into $table into $column in a row at $where. \r
 Similar to UpdateBlob (see above), but for Character Large OBjects. \r
-<p> Usage: \r
-<p> \r
+<p> Usage:\r
 <pre>\r
        # for oracle\r
        $conn->Execute('INSERT INTO clobtable (id, clobcol) VALUES (1, empty_clob())');\r
@@ -1540,21 +1590,48 @@ Similar to UpdateBlob (see above), but for Character Large OBjects.
 </pre>\r
 <p><b>UpdateBlobFile<a name="updateblobfile"></a>($table,$column,$path,$where,$blobtype='BLOB')</b></p>\r
 <p>Similar to UpdateBlob, except that we pass in a file path to where the blob \r
-  resides. \r
-<p>returns true if successful, false otherwise.\r
+       resides.\r
+<p>For PostgreSQL, if you are using blob oid's, use this interface. This interface \r
+       does not support bytea fields.\r
+<p>Returns true if successful, false otherwise. \r
+<p><b>BlobEncode<a name="blobencode" id="blobencode"></a>($blob)</b> \r
+<p>Some databases require blob's to be encoded manually before upload. Note if \r
+       you use UpdateBlob( ) or UpdateBlobFile( ) the conversion is done automatically \r
+       for you and you do not have to call this function. For PostgreSQL, currently, \r
+       BlobEncode() can only be used for bytea fields.\r
+<p>Returns the encoded blob value.\r
+<p>Note that there is a connection property called <em>blobEncodeType</em> which \r
+       has 3 legal values: \r
+<p>false - no need to perform encoding or decoding.<br>\r
+       'I' - blob encoding required, and returned encoded blob is a numeric value \r
+       (no need to quote).<br>\r
+       'C' - blob encoding required, and returned encoded blob is a character value \r
+       (requires quoting).\r
+<p>This is purely for documentation purposes, so that programs that accept multiple \r
+       database drivers know what is the right thing to do when processing blobs.\r
+<p><strong>BlobDecode<a name="blobdecode"></a>($blob)</strong> \r
+<p>Some databases require blob's to be decoded manually after doing a select statement. \r
+       If the database does not require decoding, then this function will return \r
+       the blob unchanged. Currently BlobDecode is only required for one database, \r
+       PostgreSQL, and only if you are using blob oid's (if you are using bytea fields, \r
+       we auto-decode for you).</font><font color="#000000">\r
+<pre>$rs = $db-&gt;Execute(&quot;select bloboid from postgres_table where id=$key&quot;);\r
+$blob = $db-&gt;BlobDecode( reset($rs-&gt;fields) );</pre>\r
 <p><b>Replace<a name="replace"></a>($table, $arrFields, $keyCols,$autoQuote=false)</b></p>\r
-<p>Try to update a record, and if the record is not found,\r
-an insert statement is generated and executed. \r
-Returns 0 on failure, 1 if update statement worked, 2 if no record\r
-was found and the insert was executed successfully. This differs from MySQL's replace which deletes\r
-the record and inserts a new record. This also means you cannot update the primary key. The only exception\r
-to this is Interbase and its derivitives, which uses delete and insert because of some Interbase API\r
-limitations.\r
-<p>The parameters are $table which is the table name, the $keyCols which is an associative array where\r
-the keys are the field names, and keyCols is the name of the primary key, or an array of field names if\r
-it is a compound key. If $autoQuote is set to true, then Replace() will quote all values that are non-numeric; \r
-auto-quoting will not quote nulls. Note that auto-quoting will not work if you use SQL functions or operators.\r
-<p>Examples:\r
+<p>Try to update a record, and if the record is not found, an insert statement \r
+       is generated and executed. Returns 0 on failure, 1 if update statement worked, \r
+       2 if no record was found and the insert was executed successfully. This differs \r
+       from MySQL's replace which deletes the record and inserts a new record. This \r
+       also means you cannot update the primary key. The only exception to this is \r
+       Interbase and its derivitives, which uses delete and insert because of some \r
+       Interbase API limitations. \r
+<p>The parameters are $table which is the table name, the $keyCols which is an \r
+       associative array where the keys are the field names, and keyCols is the name \r
+       of the primary key, or an array of field names if it is a compound key. If \r
+       $autoQuote is set to true, then Replace() will quote all values that are non-numeric; \r
+       auto-quoting will not quote nulls. Note that auto-quoting will not work if \r
+       you use SQL functions or operators. \r
+<p>Examples: \r
 <pre>\r
 # single field primary key\r
 $ret = $db->Replace('atable', \r
@@ -1577,21 +1654,21 @@ $ret = $db->Replace('atable2',
        'firstname');   \r
 \r
 </pre>\r
-\r
 <p><b>GetUpdateSQL<a name="getupdatesql"></a>(&$rs, $arrFields, $forceUpdate=false,$magicq=false)</b></p>\r
 <p>Generate SQL to update a table given a recordset $rs, and the modified fields \r
-  of the array $arrFields (which must be an associative array holding the column \r
-  names and the new values) are compared with the current recordset. If $forceUpdate \r
-  is true, then we also generate the SQL even if $arrFields is identical to $rs-&gt;fields.    \r
-  Requires the recordset to be associative. $magicq is used to indicate whether \r
-  magic quotes are enabled (see qstr()).</p>\r
+       of the array $arrFields (which must be an associative array holding the column \r
+       names and the new values) are compared with the current recordset. If $forceUpdate \r
+       is true, then we also generate the SQL even if $arrFields is identical to \r
+       $rs-&gt;fields. Requires the recordset to be associative. $magicq is used \r
+       to indicate whether magic quotes are enabled (see qstr()). The field names in the array \r
+       are case-insensitive.</p>\r
 <p><b>GetInsertSQL<a name="getinsertsql"></a>(&$rs, $arrFields,$magicq=false)</b></p>\r
 <p>Generate SQL to insert into a table given a recordset $rs. Requires the query \r
-  to be associative. $magicq is used to indicate whether magic quotes are enabled \r
-  (for qstr()).</p>\r
+       to be associative. $magicq is used to indicate whether magic quotes are enabled \r
+       (for qstr()). The field names in the array are case-insensitive.</p>\r
 <b>PageExecute<a name="pageexecute"></a>($sql, $nrows, $page, $inputarr=false)</b> \r
 <p>Used for pagination of recordset. $page is 1-based. See <a href="#ex8">Example \r
-  8</a>.</p>\r
+       8</a>.</p>\r
 </font> \r
 <p><font color="#000000"><b>CachePageExecute<a name="cachepageexecute"></a>($secs2cache, \r
   $sql, $nrows, $page, $inputarr=false)</b> </font></p>\r
@@ -1599,16 +1676,17 @@ $ret = $db->Replace('atable2',
   <a href="#ex8">Example 8</a>. Caching version of PageExecute.</font></p>\r
 <font color="#000000"> \r
 <p></p>\r
-<p><b>Close<a name="Close"></a>( )</b></p>\r
+<p><b>Close<a name="close"></a>( )</b></p>\r
 <p>Close the database connection. PHP4 proudly states that we no longer have to \r
   clean up at the end of the connection because the reference counting mechanism \r
   of PHP4 will automatically clean up for us.</p>\r
-<p><b>BeginTrans<a name="Begintrans"></a>( )</b></p>\r
-<p>Begin a transaction. Turns off autoCommit. Returns true if successful. Some \r
-  databases will always return false if transaction support is not available. \r
-  Interbase, Oracle and MSSQL support transactions. Any open transactions will \r
-  be rolled back when the connection is closed.</p>\r
-<p> The following is the wrong way to use transactions: \r
+  <p><b>StartTrans<a name="starttrans"></a>( )</b></p>\r
+  <p>Start a monitored transaction. As SQL statements are executed, ADOdb will monitor\r
+  for SQL errors, and if any are detected, when CompleteTrans() is called, we auto-rollback.\r
+  <p>\r
+  <p> To understand why StartTrans() is superior to BeginTrans(), \r
+  let us examine a few ways of using BeginTrans().\r
+  The following is the wrong way to use transactions: \r
 <pre>\r
 $DB->BeginTrans();\r
 $DB->Execute("update table1 set val=$val1 where id=$id");\r
@@ -1631,6 +1709,33 @@ $ok = $DB->Execute("update table1 set val=$val1 where id=$id");
 if ($ok) $ok = $DB->Execute("update table2 set val=$val2 where id=$id");\r
 $DB->CommitTrans($ok);\r
 </pre>\r
+<p> Now it is a headache monitoring $ok all over the place. StartTrans() is an\r
+improvement because it monitors all SQL errors for you. This is particularly\r
+useful if you are calling black-box functions in which SQL queries might be executed.\r
+ Also all BeginTrans, CommitTrans and RollbackTrans calls inside a StartTrans block \r
+  will be disabled, so even if the black box function does a commit, it will be ignored.\r
+<pre>\r
+$DB->StartTrans();\r
+CallBlackBox();\r
+$DB->Execute("update table1 set val=$val1 where id=$id");\r
+$DB->Execute("update table2 set val=$val2 where id=$id");\r
+$DB->CompleteTrans($ok);\r
+</pre>\r
+<p>Note that a StartTrans blocks are nestable, the inner blocks are ignored.\r
+ <p><b>CompleteTrans<a name="completetrans"></a>($autoComplete=true)</b></p>\r
+  <p>Complete a transaction called with StartTrans(). This function monitors\r
+  for SQL errors, and will commit if no errors have occured, otherwise it will rollback. \r
+  Returns true on commit, false on rollback. If the parameter $autoComplete is true\r
+  monitor sql errors and commit and rollback as appropriate. Set $autoComplete to false \r
+  to force rollback even if no SQL error detected.\r
+<p><b>BeginTrans<a name="begintrans"></a>( )</b></p>\r
+<p>Begin a transaction. Turns off autoCommit. Returns true if successful. Some \r
+  databases will always return false if transaction support is not available. \r
+  Interbase, Oracle and MSSQL support transactions. Any open transactions will \r
+  be rolled back when the connection is closed.</p>\r
+ <p>Note that <a href=#starttrans>StartTrans()</a> and CompleteTrans() is a superior method of \r
+ handling transactions, available since ADOdb 3.40. For a explanation, see the <a href=#starttrans>StartTrans()</a> documentation.\r
+\r
 <p>You can also use the ADOdb <a href=#errorhandling>error handler</a> to die \r
   and rollback your transactions for you transparently. Some buggy database extensions \r
   are known to commit all outstanding tranasactions, so you might want to explicitly \r
@@ -1639,21 +1744,21 @@ $DB->CommitTrans($ok);
  <p>Since ADOdb 2.50, you are able to detect when you are inside a transaction. Check\r
  that $connection->transCnt > 0. This variable is incremented whenever BeginTrans() is called,\r
  and decremented whenever RollbackTrans() or CommitTrans() is called.\r
-<p><b>CommitTrans<a name="CommitTrans"></a>($ok=true)</b></p>\r
+<p><b>CommitTrans<a name="committrans"></a>($ok=true)</b></p>\r
 <p>End a transaction successfully. Returns true if successful. If the database \r
   does not support transactions, will return true also as data is always committed. \r
 </p>\r
 <p>If you pass the parameter $ok=false, the data is rolled back. See example in \r
   BeginTrans().</p>\r
-<p><b>RollbackTrans<a name="RollbackTrans"></a>( )</b></p>\r
+<p><b>RollbackTrans<a name="rollbacktrans"></a>( )</b></p>\r
 <p>End a transaction, rollback all changes. Returns true if successful. If the \r
   database does not support transactions, will return false as data is never rollbacked. \r
 </p>\r
-<p><b>GetOne<a name="getone"></a>($sql)</b></p>\r
+<p><b>GetOne<a name="getone"></a>($sql,$inputarr=false)</b></p>\r
 <p>Executes the SQL and returns the first field of the first row. The recordset \r
   and remaining rows are discarded for you automatically. If an error occur, false \r
   is returned.</p>\r
-<p><b>GetRow<a name="getrow"></a>($sql)</b></p>\r
+<p><b>GetRow<a name="getrow"></a>($sql,$inputarr=false)</b></p>\r
 <p>Executes the SQL and returns the first row as an array. The recordset and remaining \r
   rows are discarded for you automatically. If an error occurs, false is returned.</p>\r
 <p><b>GetAll<a name="getall"></a>($sql)</b></p>\r
@@ -1661,22 +1766,22 @@ $DB->CommitTrans($ok);
 <p><font color="#000000">Executes the SQL and returns the all the rows as a 2-dimensional \r
   array. The recordset is discarded for you automatically. If an error occurs, \r
   false is returned.</font></p>\r
- <p><b>GetCol<a name="getcol"></a>($sql)</b></p>\r
+ <p><b>GetCol<a name="getcol"></a>($sql,$inputarr=false,$trim=false)</b></p>\r
 \r
 <p><font color="#000000">Executes the SQL and returns all elements of the first column as a \r
 1-dimensional array. The recordset is discarded for you automatically. If an error occurs, \r
   false is returned.</font></p>\r
 <p><font color="#000000"><b>CacheGetOne<a name="cachegetone"></a>([$secs2cache,] \r
-  $sql), CacheGetRow<a name="cachegetrow"></a>([$secs2cache,] $sql), CacheGetAll<a name="cachegetall"></a>([$secs2cache,] \r
-  $sql), CacheGetCol<a name="cachegetcol"></a>([$secs2cache,] \r
-  $sql)</b></font></p>\r
+  $sql,$inputarr=false), CacheGetRow<a name="cachegetrow"></a>([$secs2cache,] $sql,$inputarr=false), CacheGetAll<a name="cachegetall"></a>([$secs2cache,] \r
+  $sql,$inputarr=false), CacheGetCol<a name="cachegetcol"></a>([$secs2cache,] \r
+  $sql,$inputarr=false,$trim=false)</b></font></p>\r
 <font color="#000000"> \r
 <p>Similar to above Get* functions, except that the recordset is serialized and \r
   cached in the $ADODB_CACHE_DIR directory for $secs2cache seconds. Good for speeding \r
   up queries on rarely changing data. Note that the $secs2cache parameter is optional. \r
   If omitted, we use the value in $connection-&gt;cacheSecs (default is 3600 seconds, \r
   or 1 hour).</p>\r
-<p><b>Prepare<a name="Prepare"></a>($sql )</b></p>\r
+<p><b>Prepare<a name="prepare"></a>($sql )</b></p>\r
 </font> \r
 <p><font color="#000000">Prepares an SQL query for repeated execution. Only supported \r
   internally by interbase, oci8 and selected ODBC-based drivers, otherwise it \r
@@ -1690,7 +1795,10 @@ $DB->CommitTrans($ok);
 <p>Example:</p>\r
 <pre><font color="#000000">$stmt = $DB-&gt;Prepare('insert into table (col1,col2) values (?,?)');\r
 for ($i=0; $i &lt; $max; $i++)<br></font>      $DB-&gt;<font color="#000000">Execute($stmt,array((string) rand(), $i));\r
-</font></pre><font color="#000000"> \r
+</font></pre><font color="#000000">\r
+<p>\r
+Important: Due to limitations or bugs in PHP, if you are getting errors when you using prepared queries, try\r
+setting $ADODB_COUNTRECS = false before preparing. This behaviour has been observed with ODBC. \r
 <p><b>PrepareSP</b><b><a name="preparesp"></a></b><b>($sql)</b></p>\r
 <p>In the mssql driver, preparing stored procedures requires a special function \r
   call, mssql_init( ), which is called by this function. PrepareSP( ) is available \r
@@ -1703,7 +1811,7 @@ for ($i=0; $i &lt; $max; $i++)<br></font> $DB-&gt;<font color="#000000">Execute(
   and Oracle oci8. The parameters are:<br>\r
   <br>\r
   $<i><b>stmt</b></i> Statement returned by Prepare() or PrepareSP().<br>\r
-  $<i><b>var</b></i> PHP variable to bind to.<br>\r
+  $<i><b>var</b></i> PHP variable to bind to. Make sure you pre-initialize it!<br>\r
   $<i><b>name</b></i> Name of stored procedure variable name to bind to.<br>\r
   [$<i><b>isOutput</b></i>] Indicates direction of parameter 0/false=IN 1=OUT \r
   2= IN/OUT. This is ignored in oci8 as this driver auto-detects the direction.<br>\r
@@ -1739,7 +1847,7 @@ $db-&gt;Parameter($stmt,$i, 'i');
 for ($cnt=0; $cnt &lt; 1000; $cnt++) {\r
        $id = $cnt; <br>        $i = $cnt * $cnt; <font color="green"># works with oci8!</font>\r
        $db-&gt;Execute($stmt); <br>}</pre>\r
-<p><b>Bind<a name="Bind"></a>($stmt, $var, $size=4001, $type=false, $name=false)</b></p>\r
+<p><b>Bind<a name="bind"></a>($stmt, $var, $size=4001, $type=false, $name=false)</b></p>\r
 </font> \r
 <p><font color="#000000">This is a low-level function supported only by the oci8 \r
   driver. <b>Avoid using</b> unless you only want to support Oracle. The Parameter( \r
@@ -1775,170 +1883,206 @@ for ($i = 0; $i &lt; $max; $i++) {
    $p1 = ?; $p2 = ?; $p3 = ?;\r
    $DB-&gt;Execute($stmt);\r
 }</pre>\r
-<font color="#000000"> \r
+<font color="#000000"> </font>\r
+<p><font color="#000000"><b>fnExecute and fnCacheExecute properties<a name="fnexecute" id="fnexecute"></a></b></font></p>\r
+<p>These two properties allow you to define bottleneck functions for all sql statements \r
+       processed by ADOdb. This allows you to perform statistical analysis and query-rewriting \r
+       of your sql. For example, to count all cached queries and non-cached queries, \r
+       you can do this:</p>\r
+<pre><font color="#006600"># $db is the connection object</font>\r
+function CountExecs($db, $sql, $inputarray)\r
+{<br>global $EXECS;  $EXECS++;\r
+}\r
+\r
+<font color="#006600"># $db is the connection object</font>\r
+function CountCachedExecs($db, $secs2cache, $sql, $inputarray)\r
+{<br>global $CACHED; $CACHED++;\r
+}\r
+<br>$db = NewADOConnection('mysql');\r
+$db-&gt;Connect(...);\r
+$db-&gt;<strong>fnExecute</strong> = 'CountExecs';\r
+$db-&gt;<strong>fnCacheExecute</strong> = 'CountCachedExecs';\r
+ :\r
+ :<br><font color="#006600"># After many sql statements:</font>`\r
+printf(&quot;&lt;p&gt;Total queries=%d; total cached=%d&lt;/p&gt;&quot;,$EXECS+$CACHED, $CACHED);</pre>\r
+<p>The fnExecute function is called before the sql is parsed and executed, so \r
+       you can perform a query rewrite. If you are passing in a prepared statement, \r
+       then $sql is an array (see <a href="#prepare">Prepare</a>). The fnCacheExecute \r
+       function is only called if the recordset returned was cached.<font color="#000000"> \r
+       The function parameters match the Execute and CacheExecute functions respectively, \r
+       except that $this (the connection object) is passed as the first parameter.</font></p>\r
+<font color="#000000">\r
 <hr>\r
 <h3>ADOConnection Utility Functions</h3>\r
 <p><b>BlankRecordSet<a name="blankrecordset"></a>([$queryid])</b></p>\r
 <p>No longer available - removed since 1.99.</p>\r
-<p><b>Concat<a name="Concat"></a>($s1,$s2,....)</b></p>\r
+<p><b>Concat<a name="concat"></a>($s1,$s2,....)</b></p>\r
 <p>Generates the sql string used to concatenate $s1, $s2, etc together. Uses the \r
-  string in the concat_operator field to generate the concatenation. Override \r
-  this function if a concatenation operator is not used, eg. MySQL.</p>\r
+       string in the concat_operator field to generate the concatenation. Override \r
+       this function if a concatenation operator is not used, eg. MySQL.</p>\r
 <p>Returns the concatenated string.</p>\r
-<p><b>DBDate<a name="DBDate"></a>($date)</b></p>\r
+<p><b>DBDate<a name="dbdate"></a>($date)</b></p>\r
 <p>Format the $<b>date</b> in the format the database accepts; this can be a Unix \r
-  integer timestamp or an ISO format Y-m-d. Uses the fmtDate field, which holds \r
-  the format to use. If null or false or '' is passed in, it will be converted \r
-  to an SQL null.</p>\r
+       integer timestamp or an ISO format Y-m-d. Uses the fmtDate field, which holds \r
+       the format to use. If null or false or '' is passed in, it will be converted \r
+       to an SQL null.</p>\r
 <p>Returns the date as a quoted string.</p>\r
-<p><b>DBTimeStamp<a name="DBTimeStamp"></a>($ts)</b></p>\r
+<p><b>DBTimeStamp<a name="dbtimestamp"></a>($ts)</b></p>\r
 <p>Format the timestamp $<b>ts</b> in the format the database accepts; this can \r
-  be a Unix integer timestamp or an ISO format Y-m-d H:i:s. Uses the fmtTimeStamp \r
-  field, which holds the format to use. If null or false or '' is passed in, it \r
-  will be converted to an SQL null.</p>\r
+       be a Unix integer timestamp or an ISO format Y-m-d H:i:s. Uses the fmtTimeStamp \r
+       field, which holds the format to use. If null or false or '' is passed in, \r
+       it will be converted to an SQL null.</p>\r
 <p>Returns the timestamp as a quoted string.</p>\r
 <p><b>qstr<a name="qstr"></a>($s,[$magic_quotes_enabled</b>=false]<b>)</b></p>\r
 <p>Quotes a string to be sent to the database. The $<b>magic_quotes_enabled</b> \r
-  parameter may look funny, but the idea is if you are quoting a string extracted \r
-  from a POST/GET variable, then pass get_magic_quotes_gpc() as the second parameter. \r
-  This will ensure that the variable is not quoted twice, once by <i>qstr</i> \r
-  and once by the <i>magic_quotes_gpc</i>.</p>\r
+       parameter may look funny, but the idea is if you are quoting a string extracted \r
+       from a POST/GET variable, then pass get_magic_quotes_gpc() as the second parameter. \r
+       This will ensure that the variable is not quoted twice, once by <i>qstr</i> \r
+       and once by the <i>magic_quotes_gpc</i>.</p>\r
 <p>Eg.<font face="Courier New, Courier, mono"> $s = $db-&gt;qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc());</font></p>\r
 <p>Returns the quoted string.</p>\r
 <p><b>Quote<a name="quote"></a>($s)</b></p>\r
-<p>Quotes the string, automatically checking get_magic_quotes_gpc() first. \r
-If get_magic_quotes_gpc() is set, then we do not quote the string.\r
-<p><b>Affected_Rows<a name="Affected_Rows"></a>( )</b></p>\r
+<p>Quotes the string, automatically checking get_magic_quotes_gpc() first. If \r
+       get_magic_quotes_gpc() is set, then we do not quote the string. \r
+<p><b>Affected_Rows<a name="affected_rows"></a>( )</b></p>\r
 <p>Returns the number of rows affected by a update or delete statement. Returns \r
-  false if function not supported.</p>\r
+       false if function not supported.</p>\r
 <p>Not supported by interbase/firebird currently. </p>\r
-<p><b>Insert_ID<a name="Inserted_ID"></a>( )</b></p>\r
+<p><b>Insert_ID<a name="inserted_id"></a>( )</b></p>\r
 <p>Returns the last autonumbering ID inserted. Returns false if function not supported. \r
 </p>\r
 <p>Only supported by databases that support auto-increment or object id's, such \r
-  as PostgreSQL, MySQL and MSSQL currently. PostgreSQL returns the OID, which \r
-  can change on a database reload. This function might only give accurate results \r
-  if you perform it in a transaction if you are using persistent connections. \r
-  This is because the connection you are assigned for one Execute(&nbsp;) might \r
-  differ from the next Execute(&nbsp;).</p>\r
+       as PostgreSQL, MySQL and MSSQL currently. PostgreSQL returns the OID, which \r
+       can change on a database reload.</p>\r
 <p><b>MetaDatabases<a name="metadatabases"></a>()</b></p>\r
 <p>Returns a list of databases available on the server as an array. You have to \r
-  connect to the server first. Only available for ODBC, MySQL and ADO.</p>\r
+       connect to the server first. Only available for ODBC, MySQL and ADO.</p>\r
 <p><b>MetaTables<a name="metatables"></a>()</b></p>\r
 <p>Returns an array of tables and views for the current database as an array. \r
-  The array should exclude system catalog tables if possible.</p>\r
+       The array should exclude system catalog tables if possible.</p>\r
 <p><b>MetaColumns<a name="metacolumns"></a>($table)</b></p>\r
 <p>Returns an array of ADOFieldObject's, one field object for every column of \r
-  $table. Currently Sybase does not recognise date types, and ADO cannot identify \r
-  the correct data type (so we default to varchar).. </p>\r
+       $table. Currently Sybase does not recognise date types, and ADO cannot identify \r
+       the correct data type (so we default to varchar).. </p>\r
 <p><b>MetaColumnNames<a name="metacolumnames"></a>($table)</b></p>\r
 <p>Returns an array of column names for $table. \r
+<p><font color="#000000"><b>MetaPrimaryKeys<a name="metaprimarykeys"></a>($table)</b></font></font> \r
+<p><font color="#000000">Returns an array containing column names that are the \r
+       primary keys of $table. Only supported by mysql, postgres, oci8 currently. </font><font color="#000000">\r
+<p><font color="#000000"><b>ServerInfo<a name="serverinfo" id="serverinfo"></a>($table)</b></font></font> \r
+<p><font color="#000000">Returns an array of containing two elements 'description' \r
+       and 'version'. The 'description' element contains the string description of \r
+       the database. The 'version' naturally holds the version number (which is also \r
+       a string).</font><font color="#000000">\r
 <hr>\r
-<h2>ADORecordSet<a name="ADORecordSet"></a></h2>\r
+<h2>ADORecordSet<a name="adorecordset"></a></h2>\r
 <p>When an SQL statement successfully is executed by <font face="Courier New, Courier, mono">ADOConnection-&gt;Execute($sql),</font>an \r
-  ADORecordSet object is returned. This object contains a virtual cursor so we \r
-  can move from row to row, functions to obtain information about the columns \r
-  and column types, and helper functions to deal with formating the results to \r
-  show to the user.</p>\r
+       ADORecordSet object is returned. This object contains a virtual cursor so \r
+       we can move from row to row, functions to obtain information about the columns \r
+       and column types, and helper functions to deal with formating the results \r
+       to show to the user.</p>\r
 <h3>ADORecordSet Fields</h3>\r
 <p><b>fields: </b>Array containing the current row. This is not associative, but \r
-  is an indexed array from 0 to columns-1. See also the function <b><a href="#fields">Fields</a></b>, \r
-  which behaves like an associative array.</p>\r
+       is an indexed array from 0 to columns-1. See also the function <b><a href="#fields">Fields</a></b>, \r
+       which behaves like an associative array.</p>\r
 <p><b>dataProvider</b>: The underlying mechanism used to connect to the database. \r
-  Normally set to <b>native</b>, unless using <b>odbc</b> or <b>ado</b>.</p>\r
+       Normally set to <b>native</b>, unless using <b>odbc</b> or <b>ado</b>.</p>\r
 <p><b>blobSize</b>: Maximum size of a char, string or varchar object before it \r
-  is treated as a Blob (Blob's should be shown with textarea's). See the <a href="#metatype">MetaType</a> \r
-  function.</p>\r
+       is treated as a Blob (Blob's should be shown with textarea's). See the <a href="#metatype">MetaType</a> \r
+       function.</p>\r
 <p><b>sql</b>: Holds the sql statement used to generate this record set.</p>\r
 <p><b>canSeek</b>: Set to true if Move( ) function works.</p>\r
 <p><b>EOF</b>: True if we have scrolled the cursor past the last record.</p>\r
 <h3>ADORecordSet Functions</h3>\r
 <p><b>ADORecordSet( )</b></p>\r
 <p>Constructer. Normally you never call this function yourself.</p>\r
-<p><b>GetAssoc<a name="GetAssoc"></a>([$force_array])</b></p>\r
+<p><b>GetAssoc<a name="getassoc"></a>([$force_array])</b></p>\r
 <p>Generates an associative array from the recordset if the number of columns \r
-  is greater than 2. The array is generated from the current cursor position till \r
-  EOF. The first column of the recordset becomes the key to the rest of the array. \r
-  If the columns is equal to two, then the key directly maps to the value unless \r
-  $force_array is set to true, when an array is created for each key. Inspired \r
-  by PEAR's getAssoc.</p>\r
+       is greater than 2. The array is generated from the current cursor position \r
+       till EOF. The first column of the recordset becomes the key to the rest of \r
+       the array. If the columns is equal to two, then the key directly maps to the \r
+       value unless $force_array is set to true, when an array is created for each \r
+       key. Inspired by PEAR's getAssoc.</p>\r
 <p>Example:</p>\r
 <p>We have the following data in a recordset:</p>\r
 <p>row1: Apple, Fruit, Edible<br>\r
-  row2: Cactus, Plant, Inedible<br>\r
-  row3: Rose, Flower, Edible</p>\r
+       row2: Cactus, Plant, Inedible<br>\r
+       row3: Rose, Flower, Edible</p>\r
 <p>GetAssoc will generate the following associative array:</p>\r
 <p>Apple =&gt; [Fruit, Edible]<br>\r
-  Cactus =&gt; [Plant, Inedible]<br>\r
-  Rose =&gt; [Flower,Edible]</p>\r
+       Cactus =&gt; [Plant, Inedible]<br>\r
+       Rose =&gt; [Flower,Edible]</p>\r
 <p>Returns:</p>\r
 <p>The associative array, or false if an error occurs.</p>\r
-<p><b>GetArray<a name="GetArray"></a>([$number_of_rows])</b></p>\r
-<p>Generate a 2-dimensional array of records from the current cursor position, indexed from \r
-  0 to $number_of_rows - 1. If $number_of_rows is undefined, till EOF.</p>\r
-<p><b>GetRows<a name="GetRows"></a>([$number_of_rows])</b></p>\r
-Generate a 2-dimensional array of records from the current cursor position. Synonym for GetArray() \r
-for compatibility with Microsoft ADO. \r
-<p> <b>GetMenu<a name="GetMenu"></a>($name, [$default_str=''], [$blank1stItem=true], \r
-  [$multiple_select=false], [$size=0], [$moreAttr=''])</b></p>\r
+<p><b>GetArray<a name="getarray"></a>([$number_of_rows])</b></p>\r
+<p>Generate a 2-dimensional array of records from the current cursor position, \r
+       indexed from 0 to $number_of_rows - 1. If $number_of_rows is undefined, till \r
+       EOF.</p>\r
+<p><b>GetRows<a name="getrows"></a>([$number_of_rows])</b></p>\r
+Generate a 2-dimensional array of records from the current cursor position. Synonym \r
+for GetArray() for compatibility with Microsoft ADO. \r
+<p> <b>GetMenu<a name="getmenu"></a>($name, [$default_str=''], [$blank1stItem=true], \r
+       [$multiple_select=false], [$size=0], [$moreAttr=''])</b></p>\r
 <p>Generate a HTML menu (&lt;select&gt;&lt;option&gt;&lt;option&gt;&lt;/select&gt;). \r
-  The first column of the recordset (fields[0]) will hold the string to display \r
-  in the option tags. If the recordset has more than 1 column, the second column \r
-  (fields[1]) is the value to send back to the web server.. The menu will be given \r
-  the name $<i>name</i>. \r
+       The first column of the recordset (fields[0]) will hold the string to display \r
+       in the option tags. If the recordset has more than 1 column, the second column \r
+       (fields[1]) is the value to send back to the web server.. The menu will be \r
+       given the name $<i>name</i>. \r
 <p> If $<i>default_str</i> is defined, then if $<i>default_str</i> == fields[0], \r
-  that field is selected. If $<i>blank1stItem</i> is true, the first option is \r
-  empty. $<i>Default_str</i> can be array for a multiple select listbox.</p>\r
+       that field is selected. If $<i>blank1stItem</i> is true, the first option \r
+       is empty. You can also set the first option strings by setting $blank1stItem \r
+       = "$value:$text".</p>\r
+<p>$<i>Default_str</i> can be array for a multiple select listbox.</p>\r
 <p>To get a listbox, set the $<i>size</i> to a non-zero value (or pass $default_str \r
-  as an array). If $<i>multiple_select</i> is true then a listbox will be generated \r
-  with $<i>size</i> items (or if $size==0, then 5 items) visible, and we will \r
-  return an array to a server. Lastly use $<i>moreAttr </i> to add additional \r
-  attributes such as javascript or styles. </p>\r
+       as an array). If $<i>multiple_select</i> is true then a listbox will be generated \r
+       with $<i>size</i> items (or if $size==0, then 5 items) visible, and we will \r
+       return an array to a server. Lastly use $<i>moreAttr </i> to add additional \r
+       attributes such as javascript or styles. </p>\r
 <p>Menu Example 1: <code>GetMenu('menu1','A',true)</code> will generate a menu: \r
-  <select name='menu1'>\r
-       <option> \r
-       <option value=1 selected>A \r
-       <option value=2>B \r
-       <option value=3>C \r
-  </select>\r
-  for the data (A,1), (B,2), (C,3). Also see <a href="#ex5">example 5</a>.</p>\r
+       <select name='menu1'>\r
+               <option> \r
+               <option value=1 selected>A \r
+               <option value=2>B \r
+               <option value=3>C \r
+       </select>\r
+       for the data (A,1), (B,2), (C,3). Also see <a href="#ex5">example 5</a>.</p>\r
 <p>Menu Example 2: For the same data, <code>GetMenu('menu1',array('A','B'),false)</code> \r
-  will generate a menu with both A and B selected: <br>\r
-  <select name='menu1' multiple size=3>\r
-       <option value=1 selected>A \r
-       <option value=2 selected>B \r
-       <option value=3>C \r
-  </select>\r
-<p> <b>GetMenu2<a name="GetMenu2"></a>($name, [$default_str=''], [$blank1stItem=true], \r
-  [$multiple_select=false], [$size=0], [$moreAttr=''])</b></p>\r
+       will generate a menu with both A and B selected: <br>\r
+       <select name='menu1' multiple size=3>\r
+               <option value=1 selected>A \r
+               <option value=2 selected>B \r
+               <option value=3>C \r
+       </select>\r
+<p> <b>GetMenu2<a name="getmenu2"></a>($name, [$default_str=''], [$blank1stItem=true], \r
+       [$multiple_select=false], [$size=0], [$moreAttr=''])</b></p>\r
 <p>This is nearly identical to GetMenu, except that the $<i>default_str</i> is \r
-  matched to fields[1] (the option values).</p>\r
+       matched to fields[1] (the option values).</p>\r
 <p>Menu Example 3: Given the data in menu example 2, <code>GetMenu2('menu1',array('1','2'),false)</code> \r
-  will generate a menu with both A and B selected in menu example 2, but this \r
-  time the selection is based on the 2nd column, which holds the values to return \r
-  to the Web server. \r
-<p><b>UserDate<a name="UserDate"></a>($str, [$fmt])</b></p>\r
+       will generate a menu with both A and B selected in menu example 2, but this \r
+       time the selection is based on the 2nd column, which holds the values to return \r
+       to the Web server. \r
+<p><b>UserDate<a name="userdate"></a>($str, [$fmt])</b></p>\r
 <p>Converts the date string $<b>str</b> to another format.UserDate calls UnixDate \r
-  to parse $<b>str</b>, and $<b>fmt</b> defaults to Y-m-d if not defined.</p>\r
-<p><b>UserTimeStamp<a name="UserTimeStamp"></a>($str, [$fmt])</b></p>\r
+       to parse $<b>str</b>, and $<b>fmt</b> defaults to Y-m-d if not defined.</p>\r
+<p><b>UserTimeStamp<a name="usertimestamp"></a>($str, [$fmt])</b></p>\r
 <p>Converts the timestamp string $<b>str</b> to another format. The timestamp \r
-  format is Y-m-d H:i:s, as in '2002-02-28 23:00:12'. UserTimeStamp calls UnixTimeStamp \r
-  to parse $<b>str</b>, and $<b>fmt</b> defaults to Y-m-d H:i:s if not defined. \r
+       format is Y-m-d H:i:s, as in '2002-02-28 23:00:12'. UserTimeStamp calls UnixTimeStamp \r
+       to parse $<b>str</b>, and $<b>fmt</b> defaults to Y-m-d H:i:s if not defined. \r
 </p>\r
 <p><b>UnixDate<a name="unixdate"></a>($str)</b></p>\r
 <p>Parses the date string $<b>str</b> and returns it in unix mktime format (eg. \r
-  a number indicating the seconds after January 1st, 1970). Expects the date to \r
-  be in Y-m-d H:i:s format, except for Sybase and Microsoft SQL Server, where \r
-  M d Y is also accepted (the 3 letter month strings are controlled by a global \r
-  array, which might need localisation).</p>\r
+       a number indicating the seconds after January 1st, 1970). Expects the date \r
+       to be in Y-m-d H:i:s format, except for Sybase and Microsoft SQL Server, where \r
+       M d Y is also accepted (the 3 letter month strings are controlled by a global \r
+       array, which might need localisation).</p>\r
 <p>This function is available in both ADORecordSet and ADOConnection since 1.91.</p>\r
 <p><b>UnixTimeStamp<a name="unixtimestamp"></a>($str)</b></p>\r
 <p>Parses the timestamp string $<b>str</b> and returns it in unix mktime format \r
-  (eg. a number indicating the seconds after January 1st, 1970). Expects the dat\r
-  to be in Y-m-d H:i:s format, except for Sybase and Microsoft SQL Server, where \r
-  M d Y h:i:sA is also accepted (the 3 letter month strings are controlled by \r
-  a global array, which might need localisation).</p>\r
-</font>\r
+       (eg. a number indicating the seconds after January 1st, 1970). Expects th\r
+       date to be in Y-m-d H:i:s format, except for Sybase and Microsoft SQL Server, \r
+       where M d Y h:i:sA is also accepted (the 3 letter month strings are controlled \r
+       by a global array, which might need localisation).</p>\r
+</font> \r
 <p><font color="#000000">This function is available in both ADORecordSet and ADOConnection \r
   since 1.91. </font></p>\r
 <p><font color="#000000"><b>OffsetDate<a name="offsetdate"></a>($dayFraction, \r
@@ -1976,9 +2120,12 @@ $conn-&gt;Execute(&quot;UPDATE TABLE SET dodate=$fld WHERE ID=$id&quot;);</pre>
  $sqlfn = $db->SQLDate('Y-\QQ','postdate'); # get sql that formats postdate to output 2002-Q1\r
  $sql = "SELECT $sqlfn,SUM(cogs) FROM table GROUP BY $sqlfn ORDER BY 1 desc";\r
  </pre>\r
-<p><b>MoveNext<a name="MoveNext"></a>( )</b></p>\r
-<p>Move the internal cursor to the next row. The <b>fields</b> array is automatically \r
-  updated. Return false if unable to do so, otherwise true.</p>\r
+<p><b>MoveNext<a name="movenext"></a>( )</b></p>\r
+<p>Move the internal cursor to the next row. The <i>$this->fields</i> array is automatically \r
+  updated. Return false if unable to do so (normally because EOF has been reached), otherwise true.\r
+  If EOF is reached, then the $this->fields array is set to false (this was only implemented consistently\r
+  in ADOdb 3.30).\r
+  Note that if false is returned, then the previous array in <b>$this->fields</b> is preserved.</p>\r
 <p>Example:</p>\r
 <pre>$rs = $db-&gt;Execute($sql);\r
 if ($rs) \r
@@ -1986,7 +2133,7 @@ if ($rs)
                ProcessArray($rs->fields);      \r
                $rs->MoveNext();\r
        } </pre>\r
-<p><b>Move<a name="Move"></a>($to)</b></p>\r
+<p><b>Move<a name="move"></a>($to)</b></p>\r
 <p>Moves the internal cursor to a specific row $<b>to</b>. Rows are zero-based \r
   eg. 0 is the first row. The <b>fields</b> array is automatically updated. For \r
   databases that do not support scrolling internally, ADOdb will simulate forward \r
@@ -1998,9 +2145,9 @@ if ($rs)
 <p>Returns true or false. If false, the internal cursor is not moved in most implementations, \r
   so AbsolutePosition( ) will return the last cursor position before the Move( \r
   ). </p>\r
-<p><b>MoveFirst<a name="MoveFirst"></a>()</b></p>\r
+<p><b>MoveFirst<a name="movefirst"></a>()</b></p>\r
 <p>Internally calls Move(0). Note that some databases do not support this function.</p>\r
-<p><b>MoveLast<a name="MoveLast"></a>()</b></p>\r
+<p><b>MoveLast<a name="movelast"></a>()</b></p>\r
 <p>Internally calls Move(RecordCount()-1). Note that some databases do not support \r
   this function.</p>\r
 <p><b>GetRowAssoc</b><a name="getrowassoc"></a>($toUpper=true)</p>\r
@@ -2018,10 +2165,10 @@ if ($rs)
 <p><font color="#000000"><b>AbsolutePage<a name="absolutepage"></a>($page=-1) </b></font></p>\r
 <p>Returns the current page. Requires PageExecute()/CachePageExecute() to be called. See <a href=#ex8>Example 8</a>.</p>\r
 <font color="#000000"> \r
-<p><b>AtFirstPage<a name="AtFirstPage">($status='')</a></b></p>\r
+<p><b>AtFirstPage<a name="atfirstpage">($status='')</a></b></p>\r
 <p>Returns true if at first page (1-based). Requires PageExecute()/CachePageExecute() \r
   to be called. See <a href=#ex8>Example 8</a>.</p>\r
-<p><b>AtLastPage<a name="AtLastPage">($status='')</a></b></p>\r
+<p><b>AtLastPage<a name="atlastpage">($status='')</a></b></p>\r
 <p>Returns true if at last page (1-based). Requires PageExecute()/CachePageExecute() \r
   to be called. See <a href=#ex8>Example 8</a>.</p>\r
 <p><b>Fields</b><a name="fields"></a>(<b>$colname</b>)</p>\r
@@ -2050,34 +2197,44 @@ if ($rs)
   record after returning the current row. </font></p>\r
 <p><font color="#000000"> FetchRow() is easier to use. See above.</font></p>\r
 <font color="#000000"> \r
-<p><b>FetchField<a name="FetchField"></a>($column_number)</b></p>\r
+<p><b>FetchField<a name="fetchfield"></a>($column_number)</b></p>\r
 <p>Returns an object containing the <b>name</b>, <b>type</b> and <b>max_length</b> \r
-  of the associated field. If the max_length cannot be determined reliably, it \r
-  will be set to -1. The column numbers are zero-based. See <a href="#ex2">example \r
-  2.</a></p>\r
-<p><b>FieldCount<a name="FieldCount"></a>( )</b></p>\r
+       of the associated field. If the max_length cannot be determined reliably, \r
+       it will be set to -1. The column numbers are zero-based. See <a href="#ex2">example \r
+       2.</a></p>\r
+<p><b>FieldCount<a name="fieldcount"></a>( )</b></p>\r
 <p>Returns the number of fields (columns) in the record set.</p>\r
-<p><b>RecordCount<a name="RecordCount"></a>( )</b></p>\r
+<p><b>RecordCount<a name="recordcount"></a>( )</b></p>\r
 <p>Returns the number of rows in the record set. If the number of records returned \r
-  cannot be determined from the database driver API, we will buffer all rows and \r
-  return a count of the rows after all the records have been retrieved. This buffering \r
-  can be disabled (for performance reasons) by setting the global variable $ADODB_COUNTRECS \r
-  = false. When disabled, RecordCount( ) will return -1 for certain databases. \r
-  See the supported databases list above for more details. </p>\r
+       cannot be determined from the database driver API, we will buffer all rows \r
+       and return a count of the rows after all the records have been retrieved. \r
+       This buffering can be disabled (for performance reasons) by setting the global \r
+       variable $ADODB_COUNTRECS = false. When disabled, RecordCount( ) will return \r
+       -1 for certain databases. See the supported databases list above for more \r
+       details. </p>\r
 <p> RowCount is a synonym for RecordCount.</p>\r
 <p><b>PO_RecordCount<a name="po_recordcount"></a>($table, $where)</b></p>\r
 <p>Returns the number of rows in the record set. If the database does not support \r
-  this, it will perform a SELECT COUNT(*) on the table $table, with the given \r
-  $where condition to return an estimate of the recordset size.</p>\r
+       this, it will perform a SELECT COUNT(*) on the table $table, with the given \r
+       $where condition to return an estimate of the recordset size.</p>\r
 <p>$numrows = $rs-&gt;PO_RecordCount(&quot;articles_table&quot;, &quot;group=$group&quot;);</p>\r
-<p><b>FetchObject<a name="FetchObject"></a>($toupper=true)</b></p>\r
+<b> NextRecordSet<a name="nextrecordset" id="nextrecordset"></a>()</b> \r
+<p>For databases that allow multiple recordsets to be returned in one query, this \r
+       function allows you to switch to the next recordset. Currently only supported \r
+       by mssql driver.</p>\r
+<pre>\r
+$rs = $db-&gt;Execute('execute return_multiple_rs');\r
+$arr1 = $rs-&gt;GetArray();\r
+$rs-&gt;NextRecordSet();\r
+$arr2 = $rs-&gt;GetArray();</pre>\r
+<p><b>FetchObject<a name="fetchobject"></a>($toupper=true)</b></p>\r
 <p>Returns the current row as an object. If you set $toupper to true, then the \r
-  object fields are set to upper-case. Note: The newer FetchNextObject() is the \r
-  recommended way of accessing rows as objects. See below.</p>\r
-<p><b>FetchNextObject<a name="FetchNextObject"></a>($toupper=true)</b></p>\r
+       object fields are set to upper-case. Note: The newer FetchNextObject() is \r
+       the recommended way of accessing rows as objects. See below.</p>\r
+<p><b>FetchNextObject<a name="fetchnextobject"></a>($toupper=true)</b></p>\r
 <p>Gets the current row as an object and moves to the next row automatically. \r
-  Returns false if at end-of-file. If you set $toupper to true, then the object \r
-  fields are set to upper-case.</p>\r
+       Returns false if at end-of-file. If you set $toupper to true, then the object \r
+       fields are set to upper-case.</p>\r
 <pre>\r
 $rs = $db->Execute('select firstname,lastname from table');\r
 if ($rs) &#123;\r
@@ -2087,49 +2244,62 @@ if ($rs) &#123;
 &#125;\r
 </pre>\r
 <p>There is some trade-off in speed in using FetchNextObject(). If performance \r
-  is important, you should access rows with the <code>fields[]</code> array. \r
-<p> \r
-<p><b>CurrentRow<a name="CurrentRow"></a>( )</b></p>\r
+       is important, you should access rows with the <code>fields[]</code> array. \r
+<b>FetchObj<a name="fetchobj" id="fetchobj"></a>()</b> \r
+<p>Returns the current record as an object. Fields are not upper-cased, unlike \r
+       FetchObject.\r
+</font>\r
+<p><font color="#000000"><b>FetchNextObj<a name="fetchnextobj" id="fetchnextobj"></a>()</b> </font></p>\r
+<p><font color="#000000">Returns the current record as an object and moves to \r
+       the next record. If EOF, false is returned. Fields are not upper-cased, unlike \r
+       FetctNextObject. </font></p>\r
+<font color="#000000">\r
+<p><b>CurrentRow<a name="currentrow"></a>( )</b></p>\r
 <p>Returns the current row of the record set. 0 is the first row.</p>\r
 <p><b>AbsolutePosition<a name="abspos"></a>( )</b></p>\r
 <p>Synonym for <b>CurrentRow</b> for compatibility with ADO. Returns the current \r
-  row of the record set. 0 is the first row.</p>\r
-<p><b>MetaType<a name="MetaType"></a>($nativeDBType[,$field_max_length],[$fieldobj])</b></p>\r
+       row of the record set. 0 is the first row.</p>\r
+<p><b>MetaType<a name="metatype"></a>($nativeDBType[,$field_max_length],[$fieldobj])</b></p>\r
 <p>Determine what <i>generic</i> meta type a database field type is given its \r
-  native type $<b>nativeDBType</b> and the length of the field $<b>field_max_length</b>. \r
-  Note that field_max_length can be -1 if it is not known. The field object returned \r
-  by the database driver can be passed in $<b>fieldobj</b>. This is useful for \r
-  databases such as <i>mysql</i> which has additional properties in the field \r
-  object such as <i>primary_key</i>.</p>\r
+       native type $<b>nativeDBType</b> as a string and the length of the field $<b>field_max_length</b>. \r
+       Note that field_max_length can be -1 if it is not known. The field object \r
+       returned by the database driver can be passed in $<b>fieldobj</b>. This is \r
+       useful for databases such as <i>mysql</i> which has additional properties \r
+       in the field object such as <i>primary_key</i>. </p>\r
 <p>Uses the field <b>blobSize</b> and compares it with $<b>field_max_length</b> \r
-  to determine whether the character field is actually a blob.</p>\r
+       to determine whether the character field is actually a blob.</p>\r
+For example, $db-&gt;MetaType('char') will return 'C'. \r
 <p>Returns:</p>\r
 <ul>\r
-  <li><b>C</b>: Character fields that should be shown in a &lt;input type=&quot;text&quot;&gt; \r
-       tag. </li>\r
-  <li><b>X</b>: Clob (character large objects), or large text fields that should \r
-       be shown in a &lt;textarea&gt;</li>\r
-  <li><b>D</b>: Date field</li>\r
-  <li><b>T</b>: Timestamp field</li>\r
-  <li><b>L</b>: Logical field (boolean or bit-field)</li>\r
-  <li><b>N</b>: Numeric field. Includes decimal, numeric, floating point, and \r
-       real. </li>\r
-  <li><b>I</b>:&nbsp; Integer field. </li>\r
-  <li><b>R</b>: Counter or Autoincrement field. Must be numeric.</li>\r
-  <li><b>B</b>: Blob, or binary large objects.</li>\r
+       <li><b>C</b>: Character fields that should be shown in a &lt;input type=&quot;text&quot;&gt; \r
+               tag. </li>\r
+       <li><b>X</b>: Clob (character large objects), or large text fields that should \r
+               be shown in a &lt;textarea&gt;</li>\r
+       <li><b>D</b>: Date field</li>\r
+       <li><b>T</b>: Timestamp field</li>\r
+       <li><b>L</b>: Logical field (boolean or bit-field)</li>\r
+       <li><b>N</b>: Numeric field. Includes decimal, numeric, floating point, and \r
+               real. </li>\r
+       <li><b>I</b>:&nbsp; Integer field. </li>\r
+       <li><b>R</b>: Counter or Autoincrement field. Must be numeric.</li>\r
+       <li><b>B</b>: Blob, or binary large objects.<font color="#000000"> </font></li>\r
 </ul>\r
+</font> \r
+<p><font color="#000000"> Since ADOdb 3.0, MetaType accepts $fieldobj as the first \r
+       parameter, instead of $nativeDBType. </font></p>\r
+<font color="#000000">\r
 <p><b>Close( )<a name="rsclose"></a></b></p>\r
 <p>Close the recordset.</p>\r
 <hr>\r
 <h3>function rs2html<a name="rs2html"></a>($adorecordset,[$tableheader_attributes], \r
-  [$col_titles])</h3>\r
+       [$col_titles])</h3>\r
 <p>This is a standalone function (rs2html = recordset to html) that is similar \r
-  to PHP's <i>odbc_result_all</i> function, it prints a ADORecordSet, $<b>adorecordset</b> \r
-  as a HTML table. $<b>tableheader_attributes</b> allow you to control the table \r
-  <i>cellpadding</i>, <i>cellspacing</i> and <i>border</i> attributes. Lastly \r
-  you can replace the database column names with your own column titles with the \r
-  array $<b>col_titles</b>. This is designed more as a quick debugging mechanism, \r
-  not a production table recordset viewer.</p>\r
+       to PHP's <i>odbc_result_all</i> function, it prints a ADORecordSet, $<b>adorecordset</b> \r
+       as a HTML table. $<b>tableheader_attributes</b> allow you to control the table \r
+       <i>cellpadding</i>, <i>cellspacing</i> and <i>border</i> attributes. Lastly \r
+       you can replace the database column names with your own column titles with \r
+       the array $<b>col_titles</b>. This is designed more as a quick debugging mechanism, \r
+       not a production table recordset viewer.</p>\r
 <p>You will need to include the file <i>tohtml.inc.php</i>.</p>\r
 <p>Example of rs2html:<b><font color="#336600"><a name="exrs2html"></a></font></b></p>\r
 <pre><b><font color="#336600">&lt;?\r
@@ -2144,60 +2314,58 @@ $<font color="#663300">rs</font>   = $<font color="#663300">conn</font>->Execute
 <hr>\r
 <h3>Differences between this ADOdb library and Microsoft ADO<a name="adodiff"></a></h3>\r
 <ol>\r
-  <li>ADOdb only supports recordsets created by a connection object. Recordsets \r
-       cannot be created independently.</li>\r
-  <li>ADO properties are implemented as functions in ADOdb. This makes it easier \r
-       to implement any enhanced ADO functionality in the future.</li>\r
-  <li>ADOdb's <font face="Courier New, Courier, mono">ADORecordSet-&gt;Move()</font> \r
-       uses absolute positioning, not relative. Bookmarks are not supported.</li>\r
-  <li><font face="Courier New, Courier, mono">ADORecordSet-&gt;AbsolutePosition() \r
-       </font>cannot be used to move the record cursor.</li>\r
-  <li>ADO Parameter objects are not supported. Instead we have the ADOConnection::<a href="#parameter">Parameter</a>( \r
-       ) function, which provides a simpler interface for calling preparing parameters \r
-       and calling stored procedures.</li>\r
-  <li>Recordset properties for paging records are available, but implemented as \r
-       in <a href=#ex8>Example 8</a>.</li>\r
+       <li>ADOdb only supports recordsets created by a connection object. Recordsets \r
+               cannot be created independently.</li>\r
+       <li>ADO properties are implemented as functions in ADOdb. This makes it easier \r
+               to implement any enhanced ADO functionality in the future.</li>\r
+       <li>ADOdb's <font face="Courier New, Courier, mono">ADORecordSet-&gt;Move()</font> \r
+               uses absolute positioning, not relative. Bookmarks are not supported.</li>\r
+       <li><font face="Courier New, Courier, mono">ADORecordSet-&gt;AbsolutePosition() \r
+               </font>cannot be used to move the record cursor.</li>\r
+       <li>ADO Parameter objects are not supported. Instead we have the ADOConnection::<a href="#parameter">Parameter</a>( \r
+               ) function, which provides a simpler interface for calling preparing parameters \r
+               and calling stored procedures.</li>\r
+       <li>Recordset properties for paging records are available, but implemented \r
+               as in <a href=#ex8>Example 8</a>.</li>\r
 </ol>\r
 <hr>\r
-<h1>Database Driver Guide<a name="DriverGuide"></a></h1>\r
+<h1>Database Driver Guide<a name="driverguide"></a></h1>\r
 <p>This describes how to create a class to connect to a new database. To ensure \r
-  there is no duplication of work, kindly email me at jlim#natsoft.com.my if you \r
-  decide to create such a class.</p>\r
+       there is no duplication of work, kindly email me at jlim#natsoft.com.my if \r
+       you decide to create such a class.</p>\r
 <p>First decide on a name in lower case to call the database type. Let's say we \r
-  call it xbase. </p>\r
-<p>Then we need to create two classes ADOConnection_xbase and ADORecordSet_xbase \r
-  in the file adodb-xbase.inc.php.</p>\r
+       call it xbase. </p>\r
+<p>Then we need to create two classes ADODB_xbase and ADORecordSet_xbase \r
+       in the file adodb-xbase.inc.php.</p>\r
 <p>The simplest form of database driver is an adaptation of an existing ODBC driver. \r
-  Then we just need to create the class <i>ADOConnection_xbase extends ADOConnection_odbc</i> \r
-  to support the new <b>date</b> and <b>timestamp</b> formats, the <b>concatenation</b> \r
-  operator used, <b>true</b> and <b>false</b>. For the<i> ADORecordSet_xbase extends \r
-  ADORecordSet_odbc </i>we need to change the <b>MetaType</b> function. See<b> \r
-  adodb-vfp.inc.php</b> as an example.</p>\r
+       Then we just need to create the class <i>ADODB_xbase extends ADODB_odbc</i> \r
+       to support the new <b>date</b> and <b>timestamp</b> formats, the <b>concatenation</b> \r
+       operator used, <b>true</b> and <b>false</b>. For the<i> ADORecordSet_xbase \r
+       extends ADORecordSet_odbc </i>we need to change the <b>MetaType</b> function. \r
+       See<b> adodb-vfp.inc.php</b> as an example.</p>\r
 <p>More complicated is a totally new database driver that connects to a new PHP \r
-  extension. Then you will need to implement several functions. Fortunately, you \r
-  do not have to modify most of the complex code. You only need to override a \r
-  few stub functions. See <b>adodb-mysql.inc.php</b> for example.</p>\r
+       extension. Then you will need to implement several functions. Fortunately, \r
+       you do not have to modify most of the complex code. You only need to override \r
+       a few stub functions. See <b>adodb-mysql.inc.php</b> for example.</p>\r
 <p>The default date format of ADOdb internally is YYYY-MM-DD (Ansi-92). All dates \r
-  should be converted to that format when passing to an ADOdb date function. See \r
-  Oracle for an example how we use ALTER SESSION to change the default date format \r
-  in _pconnect _connect.</p>\r
+       should be converted to that format when passing to an ADOdb date function. \r
+       See Oracle for an example how we use ALTER SESSION to change the default date \r
+       format in _pconnect _connect.</p>\r
 <p><b>ADOConnection Functions to Override</b></p>\r
 <p>Defining a constructor for your ADOConnection derived function is optional. \r
-  There is no need to call the base class constructor.</p>\r
+       There is no need to call the base class constructor.</p>\r
 <p>_<b>connect</b>: Low level implementation of Connect. Returns true or false. \r
-  Should set the _<b>connectionID</b>.</p>\r
+       Should set the _<b>connectionID</b>.</p>\r
 <p>_<b>pconnect:</b> Low level implemention of PConnect. Returns true or false. \r
-  Should set the _<b>connectionID</b>.</p>\r
+       Should set the _<b>connectionID</b>.</p>\r
 <p>_<b>query</b>: Execute a query. Returns the queryID, or false.</p>\r
 <p>_<b>close: </b>Close the connection -- PHP should clean up all recordsets. \r
 </p>\r
 <p><b>ErrorMsg</b>: Stores the error message in the private variable _errorMsg. \r
 </p>\r
-<p>The ADOConnection functions BeginTrans( ), CommitTrans( ), RollbackTrans( ) \r
-  are reserved for future expansion.</p>\r
 <p><b>ADOConnection Fields to Set</b></p>\r
 <p>_<b>bindInputArray</b>: Set to true if binding of parameters for SQL inserts \r
-  and updates is allowed using ?, eg. as with ODBC.</p>\r
+       and updates is allowed using ?, eg. as with ODBC.</p>\r
 <p><b>fmtDate</b></p>\r
 <p><b>fmtTimeStamp</b></p>\r
 <p><b>true</b></p>\r
@@ -2208,34 +2376,188 @@ $<font color="#663300">rs</font>   = $<font color="#663300">conn</font>->Execute
 <p><b>hasTop</b> support Microsoft style SELECT TOP 10 * FROM TABLE.</p>\r
 <p><b>ADORecordSet Functions to Override</b></p>\r
 <p>You will need to define a constructor for your ADORecordSet derived class that \r
-  calls the parent class constructor.</p>\r
+       calls the parent class constructor.</p>\r
 <p><b>FetchField: </b> as documented above in ADORecordSet</p>\r
 <p>_<b>initrs</b>: low level initialization of the recordset: setup the _<b>numOfRows</b> \r
-  and _<b>numOfFields</b> fields -- called by the constructor.</p>\r
+       and _<b>numOfFields</b> fields -- called by the constructor.</p>\r
 <p>_<b>seek</b>: seek to a particular row. Do not load the data into the fields \r
-  array. This is done by _fetch. Returns true or false. Note that some implementations \r
-  such as Interbase do not support seek. Set canSeek to false.</p>\r
+       array. This is done by _fetch. Returns true or false. Note that some implementations \r
+       such as Interbase do not support seek. Set canSeek to false.</p>\r
 <p>_<b>fetch</b>: fetch a row using the database extension function and then move \r
-  to the next row. Sets the <b>fields</b> array. If the parameter $ignore_fields \r
-  is true then there is no need to populate the <b>fields</b> array, just move \r
-  to the next row. then Returns true or false.</p>\r
+       to the next row. Sets the <b>fields</b> array. If the parameter $ignore_fields \r
+       is true then there is no need to populate the <b>fields</b> array, just move \r
+       to the next row. then Returns true or false.</p>\r
 <p>_<b>close</b>: close the recordset</p>\r
 <p><b>Fields</b>: If the array row returned by the PHP extension is not an associative \r
-  one, you will have to override this. See adodb-odbc.inc.php for an example. \r
-  For databases such as MySQL and MSSQL where an associative array is returned, \r
-  there is no need to override this function.</p>\r
+       one, you will have to override this. See adodb-odbc.inc.php for an example. \r
+       For databases such as MySQL and MSSQL where an associative array is returned, \r
+       there is no need to override this function.</p>\r
 <p><b>ADOConnection Fields to Set</b></p>\r
 <p>canSeek: Set to true if the _seek function works.</p>\r
 <h2>ToDo:</h2>\r
 <p>See the <a href=http://php.weblogs.com/adodb-todo-roadmap>RoadMap</a> article.</p>\r
 <p>Also see the ADOdb <a href=http://php.weblogs.com/adodb_csv>proxy</a> article \r
-  for bridging Windows and Unix databases using http remote procedure calls. For \r
-  your education, visit <a href=http://palslib.com/>palslib.com</a> for database \r
-  info, and read this article on <a href=http://phplens.com/lens/php-book/optimizing-debugging-php.php>Optimizing \r
-  PHP</a>. </p>\r
+       for bridging Windows and Unix databases using http remote procedure calls. \r
+       For your education, visit <a href=http://palslib.com/>palslib.com</a> for \r
+       database info, and read this article on <a href=http://phplens.com/lens/php-book/optimizing-debugging-php.php>Optimizing \r
+       PHP</a>. </p>\r
 </font> \r
-<h2>Change Log<a name="Changes"></a><a name=ChangeLog></a></h2>\r
-<p>2.50, 14 Nov 2002\r
+<h2>Change Log<a name="Changes"></a><a name="changelog"></a></h2>\r
+<p><b>3.40 ?? March 2003</b></p>\r
+<p>Modified postgresql UpdateBlobFile() because it did not work in safe mode.\r
+<p>Now connection object is passed to raiseErrorFn as last parameter. Needed by StartTrans().\r
+<p>Added StartTrans() and CompleteTrans(). It is recommended that you do not modify transOff, but\r
+use the above functions.\r
+<p>oci8po now obeys ADODB_ASSOC_CASE settings.\r
+<p>Added virtualized error codes, using PEAR DB equivalents. Requires you to manually include\r
+       adodb-error.inc.php yourself, with MetaError() and MetaErrorMsg($errno).\r
+<p>GetRowAssoc for mysql and pgsql were flawed. Fix by Ross Smith.\r
+<p>Added to datadict types I1, I2, I4 and I8. Changed datadict type 'T' to map to\r
+timestamp instead of datetime for postgresql.\r
+<p>Error handling in ExecuteSQLArray(), adodb-datadict.inc.php did not work. \r
+<p>We now auto-quote postgresql connection parameters when building connection string.\r
+<p>Added session expiry notification.\r
+<p>We now test with odbc mysql - made some changes to odbc recordset constructor.\r
+<p>MetaColumns now special cases access and other databases for odbc.\r
+<p><b>3.31 17 March 2003</b></p>\r
+<p>Added row checking for _fetch in postgres.\r
+<p>Added Interval type to MetaType for postgres.\r
+<p>Remapped postgres driver to call postgres7 driver internally.\r
+<p>Adorecordset_array::getarray() did not return array when nRows >= 0.\r
+<p>Postgresql: at times, no error message returned by pg_result_error()\r
+ but error message returned in pg_last_error(). Recoded again.\r
+<p>Interbase blob's now use chunking for updateblob.\r
+<p>Move() did not set EOF correctly. Reported by Jorma T.\r
+<p>We properly support mysql timestamp fields when we are creating mysql\r
+ tables using the data-dict interface.\r
+<p>Table regex includes backticks character now.\r
+<p><b>3.30 3 March 2003</b></p>\r
+<p>Added $ADODB_EXTENSION and $ADODB_COMPAT_FETCH constant.\r
+<p>Made blank1stItem configurable using syntax "value:text" in GetMenu/GetMenu2. Thx to Gabriel Birke.\r
+<p>Previously ADOdb differed from the Microsoft standard because it did not define \r
+       what to set $this->fields when EOF was reached. Now at EOF, ADOdb sets $this->fields \r
+       to false for all databases, which is consist with Microsoft's implementation. \r
+       Postgresql and mysql have always worked this way (in 3.11 and earlier). If \r
+       you are experiencing compatibility problems (and you are not using postgresql \r
+       nor mysql) on upgrading to 3.30, try setting the global variables $ADODB_COUNTRECS \r
+       = true (which is the default) and $ADODB_FETCH_COMPAT = true (this is a new \r
+       global variable). \r
+<p>We now check both pg_result_error and pg_last_error as sometimes pg_result_error does not display anything.\r
+ Iman Mayes \r
+<p>\r
+We no longer check for magic quotes gpc in Quote().\r
+<p>\r
+Misc fixes for table creation in adodb-datadict.inc.php. Thx to iamsure.\r
+<p>\r
+Time calculations use adodb_time library for all negative timestamps\r
+due to problems in Red Hat 7.3 or later. Formerly, only did this for \r
+Windows.\r
+<p>\r
+In mssqlpo, we now check if $sql in _query is a string before we change || to +. This is\r
+to support prepared stmts.\r
+<p>\r
+Move() and MoveLast() internals changed to support to support EOF and $this->fields change.\r
+<p>\r
+Added ADODB_FETCH_BOTH support to mssql. Thx to Angel Fradejas afradejas#mediafusion.es\r
+<p>\r
+We now check if link resource exists before we run mysql_escape_string in qstr().\r
+<p>\r
+Before we flock in csv code, we check that it is not a http url.\r
+<p><b>3.20 17 Feb 2003</b></p>\r
+<p>Added new Data Dictionary classes for creating tables and indexes. Warning - this is very much alpha quality code.\r
+The API can still change. See adodb/tests/test-datadict.php for more info.\r
+<p>We now ignore $ADODB_COUNTRECS for mysql, because PHP truncates incomplete recordsets \r
+       when mysql_unbuffered_query() is called a second time.\r
+<p>Now postgresql works correctly when $ADODB_COUNTRECS = false.\r
+<p>Changed _adodb_getcount to properly support SELECT DISTINCT.\r
+<p>Discovered that $ADODB_COUNTRECS=true has some problems with prepared queries - suspect\r
+PHP bug.\r
+<p>Now GetOne and GetRow run in $ADODB_COUNTRECS=false mode for better performance.\r
+<p>Added support for mysql_real_escape_string() and pg_escape_string() in qstr().\r
+<p>Added an intermediate variable for mysql _fetch() and MoveNext() to store fields, to prevent\r
+overwriting field array with boolean when mysql_fetch_array() returns false.\r
+<p>Made arrays for getinsertsql and getupdatesql case-insensitive. Suggested by Tim Uckun" tim#diligence.com\r
+<p><b>3.11 11 Feb 2003</b></p>\r
+<p>Added check for ADODB_NEVER_PERSIST constant in PConnect(). \r
+If defined, then PConnect() will actually call non-persistent Connect().\r
+<p>Modified interbase to properly work with Prepare().\r
+<p>Added $this->ibase_timefmt to allow you to change the date and time format.\r
+<p>Added support for $input_array parameter in CacheFlush().\r
+<p>Added experimental support for dbx, which was then removed when i found that\r
+it was slower than using native calls.\r
+<p>Added MetaPrimaryKeys for mssql and ibase/firebird.\r
+<p>Added new $trim parameter to GetCol and CacheGetCol\r
+<p>Uses updated adodb-time.inc.php 0.06.\r
+<p><b>3.10 27 Jan 2003</b>\r
+<p>Added adodb_date(), adodb_getdate(), adodb_mktime() and adodb-time.inc.php.\r
+<p>For interbase, added code to handle unlimited number of bind parameters. \r
+From Daniel Hasan daniel#hasan.cl.\r
+<p>Added BlobDecode and UpdateBlob for informix. Thx to Fernando Ortiz.\r
+<p>Added constant ADODB_WINDOWS. If defined, means that running on Windows.\r
+<p>Added constant ADODB_PHPVER which stores php version as a hex num. Removed $ADODB_PHPVER variable.\r
+<p>Felho Bacsi reported a minor white-space regular expression problem in GetInsertSQL.\r
+<p>Modified ADO to use variant to store _affectedRows\r
+<p>Changed ibase to use base class Replace(). Modified base class Replace() to support ibase.\r
+<p>Changed odbc to auto-detect when 0 records returned is wrong due to bad odbc drivers.\r
+<p>Changed mssql to use datetimeconvert ini setting only when 4.30 or later (does not work in 4.23).\r
+<p>ExecuteCursor($stmt, $cursorname, $params) now accepts a new $params array of additional bind \r
+parameters -- William Lovaton walovaton#yahoo.com.mx.\r
+<p>Added support for sybase_unbuffered_query if ADODB_COUNTRECS == false. Thx to chuck may.\r
+<p>Fixed FetchNextObj() bug. Thx to Jorma Tuomainen.\r
+<p>We now use SCOPE_IDENTITY() instead of @@IDENTITY for mssql - thx to marchesini#eside.it\r
+<p>Changed postgresql movenext logic to prevent illegal row number from being passed to pg_fetch_array().\r
+<p>Postgresql initrs bug found by "Bogdan RIPA" bripa#interakt.ro $f1 accidentally named $f\r
+<p><b>3.00 6 Jan 2003</b>\r
+<p>Fixed adodb-pear.inc.php syntax error.\r
+<p>Improved  _adodb_getcount() to use SELECT COUNT(*) FROM ($sql) for languages that\r
+accept it.\r
+<p>Fixed _adodb_getcount() caching error.\r
+<p>Added sql to retrive table and column info for odbc_mssql.\r
+<p><strong>2.91 3 Jan 2003</strong>\r
+<p>Revised PHP version checking to use $ADODB_PHPVER with legal values 0x4000, 0x4050, 0x4200, 0x4300.\r
+<p>Added support for bytea fields and oid blobs in postgres by allowing BlobDecode() \r
+       to detect and convert non-oid fields. Also added BlobEncode to postgres when \r
+       you want to encode oid blobs.\r
+<p>Added blobEncodeType property for connections to inform phpLens what encoding\r
+method to use for blobs.\r
+<p>Added BlobDecode() and BlobEncode() to base ADOConnection class.\r
+<p>Added umask() to _gencachename() when creating directories.\r
+<p>Added charPage for ado drivers, so you can set the code page.\r
+<pre>\r
+$conn->charPage = CP_UTF8;\r
+$conn->Connect($dsn);\r
+</pre>\r
+<p>Modified _seek in mysql to check for num rows=0.\r
+<p>Added to metatypes new informix types for IDS 9.30. Thx Fernando Ortiz.\r
+<p>_maxrecordcount returned in CachePageExecute $rsreturn \r
+<p>Fixed sybase cacheselectlimit( ) problems\r
+<p>MetaColumns() max_length should use precision for types X and C for ms access. Fixed.\r
+<p>Speedup of odbc non-SELECT sql statements.\r
+<p>Added support in MetaColumns for Wide Char types for ODBC. We halve max_length \r
+       if unicode/wide char. \r
+<p>Added 'B' to types handled by GetUpdateSQL/GetInsertSQL.\r
+<p>Fixed warning message in oci8 driver with $persist variable when using PConnect.\r
+<p><b>2.90 11 Dec 2002</b>\r
+<p>Mssql and mssqlpo and oci8po now support ADODB_ASSOC_CASE. \r
+<p>Now MetaType() can accept a field object as the first parameter. \r
+<p>New $arr = $db-&gt;ServerInfo( ) function. Returns $arr['description'] which \r
+       is the string description, and $arr['version'].\r
+<p>PostgreSQL and MSSQL speedups for insert/updates. \r
+<p> Implemented new SetFetchMode() that removes the need to use $ADODB_FETCH_MODE. \r
+       Each connection has independant fetchMode. \r
+<p>ADODB_ASSOC_CASE now defaults to 2, use native defaults. This is because we would\r
+break backward compat for too many applications otherwise.\r
+<p>Patched encrypted sessions to use replace()\r
+<p>The qstr function supports quoting of nulls when escape character is \\r
+<p>Rewrote bits and pieces of session code to check for time synch and improve reliability.\r
+<p>Added property ADOConnection::hasTransactions = true/false;\r
+<p>Added CreateSequence and DropSequence functions\r
+<p>Found misplaced MoveNext() in adodb-postgres.inc.php. Fixed.\r
+<p>Sybase SelectLimit not reliable because 'set rowcount' not cached - fixed.\r
+<p>Moved ADOConnection to adodb-connection.inc.php and ADORecordSet to adodb-recordset.inc.php. \r
+This allows us to use doxygen to generate documentation. Doxygen doesn't like the classes \r
+in the main adodb.inc.php file for some mysterious reason.\r
+<p><b>2.50, 14 Nov 2002</b>\r
 <p>Added transOff and transCnt properties for disabling (transOff = true) \r
 and tracking transaction status (transCnt>0).\r
 <p>Added inputarray handling into _adodb_pageexecute_all_rows - "Ross Smith" RossSmith#bnw.com.\r
@@ -2246,14 +2568,14 @@ and tracking transaction status (transCnt>0).
 <p>Fixed pager problems with some databases that returned -1 for _currentRow on MoveLast() by \r
 switching to MoveNext() in adodb-lib.inc.php.\r
 <p>Also fixed uninited $discard in adodb-lib.inc.php.\r
-<p>2.43, 25 Oct 2002</p>\r
+<p><b>2.43, 25 Oct 2002</b></p>\r
 Added ADODB_ASSOC_CASE constant to better support ibase and odbc field names.\r
 <p>Added support for NConnect() for oracle OCINLogin.\r
 <p>Fixed NumCols() bug.\r
 <p>Changed session handler to use Replace() on write.\r
 <p>Fixed oci8 SelectLimit aggregate function bug again.\r
 <p>Rewrote pivoting code.\r
-<p>2.42, 4 Oct 2002</p>\r
+<p><b>2.42, 4 Oct 2002</b></p>\r
 <p>Fixed ibase_fetch() problem with nulls. Also interbase now does automatic blob decoding,\r
 and is backward compatible. Suggested by Heinz Hombergs heinz#hhombergs.de.\r
 <p>Fixed postgresql MoveNext() problems when called repeatedly after EOF. \r
@@ -2285,465 +2607,11 @@ trickery there as there seems to be a bug in Zend Engine
 <p>Added render_pagelinks to adodb-pager.inc.php. Code by "Pablo Costa" pablo#cbsp.com.br.\r
 <p>MetaType() speedup in adodb.inc.php by using hashing instead of switch. Best performance\r
 if constant arrays are supported, as they are in PHP5.\r
-<p>adodb-session.php now updates only the expiry date if the crc32 check indicates that the data\r
-has not been modified.\r
-<p><b>2.31 20 Aug 2002</b></p>\r
-<p>Made changes to pivottable.inc.php due to daniel lucuzaeu's suggestions (we sum the pivottable column if desired).\r
-<p>Fixed ErrorNo() in postgres so it does not depend on _errorMsg property.\r
-<p>Robert Tuttle added support for oracle cursors. See ExecuteCursor().\r
-<p>Fixed Replace() so it works with mysql when updating record where data has not changed. Reported by\r
-Cal Evans (cal#calevans.com).\r
-<p><b>2.30 1 Aug 2002</b></p>\r
-<p>Added pivottable.inc.php. Thanks to daniel.lucazeau#ajornet.com for the original \r
-  concept.\r
-<p>Added ADOConnection::outp($msg,$newline) to output error and debugging messages. Now \r
-you can override this using the ADODB_OUTP constant and use your own output handler.\r
-<p>Changed == to === for 'null' comparison. Reported by ericquil#yahoo.com \r
-<p>Fixed mssql SelectLimit( ) bug when distinct used.\r
-<p><b>2.30 1 Aug 2002</b></p>\r
-<p>New GetCol() and CacheGetCol() from ross#bnw.com that returns the first field as a 1 dim array.\r
-<p>We have an empty recordset, but RecordCount() could return -1. Fixed. Reported by  "Jonathan Polansky" jonathan#polansky.com.\r
-<p>We now check for session variable changes using strlen($sessval).crc32($sessval). \r
-Formerly we only used crc32().\r
-<p>Informix SelectLimit() problem with $ADODB_COUNTRECS fixed.\r
-<p>Fixed informix SELECT FIRST x DISTINCT, and not SELECT DISTINCT FIRST x - reported by F Riosa\r
-<p>Now default adodb error handlers ignores error if @ used.\r
-<p>If you set $conn->autoRollback=true, we auto-rollback persistent connections for odbc, mysql, oci8, mssql. \r
-Default for autoRollback is false. No need to do so for postgres. \r
-As interbase requires a transaction id (what a flawed api), we don't do it for interbase.\r
-<p>Changed PageExecute() to use non-greedy preg_match when searching for "FROM" keyword.\r
-<p><b>2.20 9 July 2002</b></p>\r
-<p>Added CacheGetOne($secs2cache,$sql), CacheGetRow($secs2cache,$sql), CacheGetAll($secs2cache,$sql).\r
-<p>Added $conn->OffsetDate($dayFraction,$date=false) to generate sql that calcs \r
-  date offsets. Useful for scheduling appointments.\r
-<p>Added connection properties: leftOuter, rightOuter that hold left and right \r
-  outer join operators.\r
-<p>Added connection property: ansiOuter to indicate whether ansi outer joins supported.\r
-<p>New driver <i>mssqlpo</i>, the portable mssql driver, which converts string \r
-  concat operator from || to +.\r
-<p>Fixed ms access bug - SelectLimit() did not support ties - fixed.\r
-<p>Karsten Kraus (Karsten.Kraus#web.de), contributed error-handling code to ADONewConnection. \r
-  Unfortunately due to backward compat problems, had to rollback most of the changes.\r
-<p>Added new parameter to GetAssoc() to allow returning an array of key-value pairs, \r
-ignoring any additional columns in the recordset. Off by default.\r
-<p>Corrected mssql $conn->sysDate to return only date using convert().\r
-<p>CacheExecute() improved debugging output.\r
-<p>Changed rs2html() so newlines are converted to BR tags. Also optimized rs2html() based\r
-on feedback by "Jerry Workman" jerry#mtncad.com.\r
-<p>Added support for Replace() with Interbase, using DELETE and INSERT.\r
-<p>Some minor optimizations (mostly removing & references when passing arrays).\r
-<p>Changed  GenID() to allows id's larger than the size of an integer.\r
-<p>Added force_session property to oci8 for better updateblob() support.\r
-<p>Fixed PageExecute() which did not work properly with sql containing GROUP BY.\r
-<p><b>2.12 12 June 2002</b></p>\r
-<p>Added toexport.inc.php to export recordsets in CSV and tab-delimited format.\r
-<p>CachePageExecute() does not work - fixed - thx John Huong.\r
-<p>Interbase aliases not set properly in FetchField() - fixed. Thx Stefan Goethals.\r
-<p>Added cache property to adodb pager class. The number of secs to cache recordsets.\r
-<p>SQL rewriting bug in pageexecute() due to skipping of newlines due to missing /s modifier. Fixed.\r
-<p>Max size of cached recordset due to a bug was 256000 bytes. Fixed.\r
-<p>Speedup of 1st invocation of CacheExecute() by tuning code.\r
-<p>We compare $rewritesql with $sql in pageexecute code in case of rewrite failure.\r
-<p><b>2.11 7 June 2002</b></p>\r
-<p>Fixed PageExecute() rewrite sql problem - COUNT(*) and ORDER BY don't go together with\r
-       mssql, access and postgres. Thx to Alexander Zhukov alex#unipack.ru\r
-<p>DB2 support for CHARACTER type added - thx John Huong huongch#bigfoot.com\r
-<p>For ado, $argProvider not properly checked. Fixed - kalimero#ngi.it\r
-<p>Added $conn->Replace() function for update with automatic insert if the record does not exist. \r
-       Supported by all databases except interbase.\r
-<p><b>2.10 4 June 2002</b></p>\r
-<p>Added uniqueSort property to indicate mssql ORDER BY cols must be unique.\r
-<p>Optimized session handler by crc32 the data. We only write if session data has changed.\r
-<p>adodb_sess_read in adodb-session.php now returns ''correctly - thanks to Jorma Tuomainen, webmaster#wizactive.com\r
-<p>Mssql driver did not throw EXECUTE errors correctly because ErrorMsg() and ErrorNo() called in wrong order. \r
-Pointed out by Alexios Fakos. Fixed.\r
-<p>Changed ado to use client cursors. This fixes BeginTran() problems with ado.\r
-<p>Added handling of timestamp type in ado.\r
-<p>Added to ado_mssql support for insert_id() and affected_rows().\r
-<p>Added support for mssql.datetimeconvert=0, available since php 4.2.0.\r
-<p>Made UnixDate() less strict, so that the time is ignored if present.\r
-<p>Changed quote() so that it checks for magic_quotes_gpc.\r
-<p>Changed maxblobsize for odbc to default to 64000.\r
-<p><b>2.00 13 May 2002</b></p>\r
-<p>Added drivers <i>informix72</i> for pre-7.3 versions, and <i>oci805</i> for \r
-  oracle 8.0.5, and postgres64 for postgresql 6.4 and earlier. The postgres and postgres7 drivers\r
-  are now identical.\r
-<p>Interbase now partially supports ADODB_FETCH_BOTH, by defaulting to ASSOC mode.\r
-<p>Proper support for blobs in mssql. Also revised blob support code \r
-is base class. Now UpdateBlobFile() calls UpdateBlob() for consistency.\r
-<p>Added support for changed odbc_fetch_into api in php 4.2.0 \r
-with $conn-&gt;_has_stupid_odbc_fetch_api_change.\r
-<p>Fixed spelling of tablock locking hint in GenID( ) for mssql. \r
-<p>Added RowLock( ) to several databases, including oci8, informix, sybase, etc. \r
-  Fixed where error in mssql RowLock().\r
-<p>Added sysDate and sysTimeStamp properties to most database drivers. These are the sql\r
-functions/constants for that database that return the current date and current timestamp, and \r
-are useful for portable inserts and updates.\r
-<p>Support for RecordCount() caused date handling in sybase and mssql to break. \r
-Fixed, thanks to Toni Tunkkari, by creating derived classes for ADORecordSet_array for\r
-both databases. Generalized using arrayClass property. Also to support RecordCount(), \r
-changed metatype handling for ado drivers. Now the type returned in FetchField \r
-  is no longer a number, but the 1-char data type returned by MetaType.\r
-  At the same time, fixed a lot of date handling. Now mssql support dmy and mdy date formats. \r
-Also speedups in sybase and mssql with preg_match and ^ in date/timestamp handling.\r
-Added support in sybase and mssql for 24 hour clock in timestamps (no AM/PM).\r
-<p>Extensive revisions to informix driver - thanks to Samuel CARRIERE samuel_carriere#hotmail.com \r
-<p>Added $ok parameter to CommitTrans($ok) for easy rollbacks.\r
-<p>Fixed odbc MetaColumns and MetaTables to save and restore $ADODB_FETCH_MODE.\r
-<p>Some odbc drivers did not call the base connection class constructor. Fixed.\r
-<p>Fixed regex for GetUpdateSQL() and GetInsertSQL() to support more legal character combinations.\r
-\r
-<p><b>1.99 21 April 2002</b></p>\r
-<p>Added emulated RecordCount() to all database drivers if $ADODB_COUNTRECS = true \r
-  (which it is by default). Inspired by Cristiano Duarte (cunha17#uol.com.br). \r
-<p>Unified stored procedure support for mssql and oci8. Parameter() and PrepareSP() \r
-  functions implemented. \r
-<p>Added support for SELECT FIRST in informix, modified hasTop property to support \r
-  this. \r
-<p>Changed csv driver to handle updates/deletes/inserts properly (when Execute() returns true).\r
-Bind params also work now, and raiseErrorFn with csv driver. Added csv driver to QA process. \r
-<p>Better error checking in oci8 UpdateBlob() and UpdateBlobFile().\r
-<p>Added TIME type to MySQL - patch by Manfred h9125297#zechine.wu-wien.ac.at\r
-<p>Prepare/Execute implemented for Interbase/Firebird \r
-<p>Changed some regular expressions to be anchored by /^ $/ for speed.\r
-<p>Added UnixTimeStamp() and UnixDate() to ADOConnection(). Now these functions \r
-  are in both ADOConnection and ADORecordSet classes.\r
-<p>Empty recordsets were not cached - fixed.\r
-<p>Thanks to Gaetano Giunta (g.giunta#libero.it) for the oci8 code review. We \r
-  didn't agree on everything, but i hoped we agreed to disagree! \r
-<p><b>1.90 6 April 2002</b></p>\r
-<p>Now all database drivers support fetch modes ADODB_FETCH_NUM and ADODB_FETCH_ASSOC, though\r
-       still not fully tested. Eg. Frontbase, Sybase, Informix.\r
-<p>NextRecordSet() support for mssql. Contributed by "Sven Axelsson" sven.axelsson#bokochwebb.se\r
-<p>Added blob support for SQL Anywhere. Contributed by Wade Johnson wade#wadejohnson.de\r
-<p>Fixed some security loopholes in server.php. Server.php also supports fetch mode.\r
-<p>Generalized GenID() to support odbc and mssql drivers. Mssql no longer generates GUID's.\r
-<p>Experimental RowLock($table,$where) for mssql.\r
-<p>Properly implemented Prepare() in oci8 and ODBC.\r
-<p>Added Bind() support to oci8 to support Prepare().\r
-<p>Improved error handler. Catches CacheExecute() and GenID() errors now.\r
-<p>Now if you are running php from the command line, debugging messages do not output html formating.\r
-Not 100% complete, but getting there.\r
-<p><b>1.81 22 March 2002</b></p>\r
-<p>Restored default $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT for backward compatibility.\r
-<p>SelectLimit for oci8 improved - Our FIRST_ROWS optimization now does not overwrite existing hint.\r
-<p>New Sybase SQL Anywhere driver. Contributed by Wade Johnson wade#wadejohnson.de\r
-<p><b>1.80 15 March 2002</b></p>\r
-<p>Redesigned directory structure of ADOdb files. Added new driver directory where\r
-all database drivers reside.\r
-<p>Changed caching algorithm to create subdirectories. Now we scale better.\r
-<p>Informix driver now supports insert_id(). Contribution by "Andrea Pinnisi" pinnisi#sysnet.it\r
-<p>Added experimental ISO date and FetchField support for informix.\r
-<p>Fixed a quoting bug in Execute() with bind parameters, causing problems with blobs.\r
-<p>Mssql driver speedup by 10-15%.\r
-<p>Now in CacheExecute($secs2cache,$sql,...), $secs2cache is optional. If missing, it will\r
-take the value defined in $connection->cacheSecs (default is 3600 seconds). Note that\r
-CacheSelectLimit(), the secs2cache is still compulsory - sigh.\r
-<p>Sybase SQL Anywhere driver (using ODBC) contributed by Wade Johnson wade#wadejohnson.de\r
-<p><b>1.72 8 March 2002</b></p>\r
-<p>Added @ when returning Fields() to prevent spurious error - "Michael William Miller" mille562#pilot.msu.edu\r
-<p>MetaDatabases() for postgres contributed by Phil pamelant#nerim.net\r
- <p>Mitchell T. Young (mitch#youngfamily.org) contributed informix driver.\r
- <p>Fixed rs2html() problem. I cannot reproduce, so probably a problem with pre PHP 4.1.0 versions,\r
-  when supporting new ADODB_FETCH_MODEs.\r
- <p>Mattia Rossi (mattia#technologist.com) contributed BlobDecode() and UpdateBlobFile() for postgresql\r
- using the postgres specific pg_lo_import()/pg_lo_open() - i don't use them but hopefully others will\r
- find this useful. See <a href="http://phplens.com/lens/lensforum/msgs.php?id=1262">this posting</a>\r
- for an example of usage.\r
- <p>Added UpdateBlobFile() for uploading files to a database.\r
- <p>Made UpdateBlob() compatible with oci8po driver.\r
- <p>Added noNullStrings support to oci8 driver. Oracle changes all ' ' strings to nulls,\r
-  so you need to set strings to ' ' to prevent the nullifying of strings. $conn->noNullStrings = true;\r
-  will do this for you automatically. This is useful when you define a char column as NOT NULL.\r
-  <p>Fixed UnixTimeStamp() bug - wasn't setting minutes and seconds properly. Patch from Agusti Fita i Borrell agusti#anglatecnic.com.\r
-  <p>Toni Tunkkari added patch for sybase dates. Problem with spaces in day part of date fixed.\r
- <p><b>1.71 18 Jan 2002</b></p>\r
- <p>Sequence start id support. Now $conn->Gen_ID('seqname', 50) to start sequence from 50.\r
- <p>CSV driver fix for selectlimit, from Andreas - akaiser#vocote.de.\r
-<P>Gam3r spotted that a global variable was undefined in the session handler. \r
-<p>Mssql date regex had error. Fixed - reported by Minh Hoang vb_user#yahoo.com.\r
-<p>DBTimeStamp() and DBDate() now accept iso dates and unix timestamps. This means\r
-that the PostgreSQL handling of dates in GetInsertSQL() and GetUpdateSQL() can\r
-be removed. Also if these functions are passed '' or null or false, we return a SQL null.\r
-<p>GetInsertSQL() and GetUpdateSQL() now accept a new parameter, $magicq to \r
-indicate whether quotes should be inserted based on magic quote settings - suggested by\r
-dj#4ict.com.\r
-<p>Reformated docs slightly based on suggestions by Chris Small.\r
- <p><b>1.65 28 Dec 2001</b></p>\r
- <p>Fixed borland_ibase class naming bug.\r
- <p>Now instead of using $rs->fields[0] internally, we use reset($rs->fields) so \r
- that we are compatible with ADODB_FETCH_ASSOC mode. Reported by Nico S.\r
- <p>Changed recordset constructor and _initrs() for oci8 so that it returns the field definitions even\r
- if no rows in the recordset. Reported by Rick Hickerson (rhickers#mv.mv.com).\r
- <p>Improved support for postgresql in GetInsertSQL and GetUpdateSQL by\r
-  "mike" mike#partner2partner.com  and "Ryan Bailey" rebel#windriders.com\r
- <p><b>1.64 20 Dec 2001</b></p>\r
-<p>Danny Milosavljevic &lt;danny.milo#gmx.net> added some patches for MySQL error handling\r
-and displaying default values.\r
-<p>Fixed some ADODB_FETCH_BOTH inconsistencies in odbc and interbase.\r
-<p>Added more tests to test suite to cover ADODB_FETCH_* and ADODB_ERROR_HANDLER.\r
-<p>Added firebird (ibase) driver\r
-<p>Added borland_ibase driver for interbase 6.5\r
-<p><b>1.63 13 Dec 2001</b></p>\r
-Absolute to the adodb-lib.inc.php file not set properly. Fixed.<p>\r
-\r
-<p><b>1.62 11 Dec 2001</b></p>\r
-<p>Major speedup of ADOdb for low-end web sites by reducing the php code loading and compiling\r
-cycle. We conditionally compile not so common functions. \r
-Moved csv code to adodb-csvlib.inc.php to reduce adodb.inc.php parsing. This file\r
-is loaded only when the csv/proxy driver is used, or CacheExecute() is run.\r
-Also moved PageExecute(), GetSelectSQL() and GetUpdateSQL() core code to adodb-lib.inc.php.\r
-This reduced the 70K main adodb.inc.php file to 55K, and since at least 20K of the file\r
-is comments, we have reduced 50K of code in adodb.inc.php to 35K. There\r
- should be 35% reduction in memory and thus 35% speedup in compiling the php code for the\r
-main adodb.inc.php file.\r
-<p>Highly tuned SelectLimit() for oci8 for massive speed improvements on large files. \r
-Selecting 20 rows starting from the 20,000th row of a table is now 7 times faster. \r
-Thx to Tomas V V Cox.\r
-<p>Allow . and # in table definitions in GetInsertSQL and GetUpdateSQL.\r
- See ADODB_TABLE_REGEX constant. Thx to Ari Kuorikoski.\r
-<p>Added ADODB_PREFETCH_ROWS constant, defaulting to 10. This determines the number\r
-of records to prefetch in a SELECT statement. Only used by oci8.</p>\r
-<p>Added high portability Oracle class called oci8po. This uses ? for bind variables, and \r
-lower cases column names.</p>\r
-<p>Now all database drivers support $ADODB_FETCH_MODE, including interbase, ado, and odbc:\r
-ADODB_FETCH_NUM and ADODB_FETCH_ASSOC. ADODB_FETCH_BOTH is not fully implemented for all \r
-database drivers.\r
-<p><b>1.61 Nov 2001</b></p>\r
-<p>Added PO_RecordCount() and PO_Insert_ID(). PO stands for portable. Pablo Roca \r
-  [pabloroca#mvps.org]</p>\r
-<p>GenID now returns 0 if not available. Safer is that you should check $conn->hasGenID \r
-  for availability.</p>\r
-<p>M'soft ADO we now correctly close recordset in _close() peterd#telephonetics.co.uk</p>\r
-<p>MSSQL now supports GenID(). It generates a 16-byte GUID from mssql newid() \r
-  function.</p>\r
-<p>Changed ereg_replace to preg_replace in SelectLimit. This is a fix for mssql. \r
-  Ereg doesn't support t or n! Reported by marino Carlos xaplo#postnuke-espanol.org</p>\r
-<p>Added $recordset->connection. This is the ADOConnection object for the recordset. \r
-Works with cached and normal recordsets. Surprisingly, this had no affect on performance!</p>\r
-<p><b>1.54 15 Nov 2001</b></p>\r
-Fixed some more bugs in PageExecute().  I am getting sick of bug in this and will have to \r
-reconsider my QA here. The main issue is that I don't use PageExecute() and \r
-to check whether it is working requires a visual inspection of the html generated currently.\r
-It is possible to write a test script but it would be quite complicated :(\r
-<p> More speedups of SelectLimit() for DB2, Oci8, access, vfp, mssql.\r
-<p>\r
-\r
-<p><b>1.53 7 Nov 2001</b></p>\r
-Added support for ADODB_FETCH_ASSOC for ado and odbc drivers.<p>\r
-Tuned GetRowAssoc(false) in postgresql and mysql.<p>\r
-Stephen Van Dyke contributed ADOdb icon, accepted with some minor mods.<p>\r
-Enabled Affected_Rows() for postgresql<p>\r
-Speedup for Concat() using implode() - Benjamin Curtis ben_curtis#yahoo.com<p>\r
-Fixed some more bugs in PageExecute() to prevent infinite loops<p>\r
-<p><b>1.52 5 Nov 2001</b></p>\r
-Spelling error in CacheExecute() caused it to fail. $ql should be $sql in line 625!<p>\r
-Added fixes for parsing [ and ] in GetUpdateSQL().\r
-<p><b>1.51 5 Nov 2001</b></p>\r
-<p>Oci8 SelectLimit() speedup by using OCIFetch().\r
-<p>Oci8 was mistakenly reporting errors when $db->debug = true.\r
-<p>If a connection failed with ODBC, it was not correctly reported - fixed.\r
-<p>_connectionID was inited to -1, changed to false.\r
-<p>Added $rs->FetchRow(), to simplify API, ala PEAR DB\r
-<p>Added PEAR DB compat mode, which is still faster than PEAR! See adodb-pear.inc.php.\r
-<p>Removed postgres pconnect debugging statement.\r
-<p><b>1.50 31 Oct 2001</b></p>\r
-<p>ADOdbConnection renamed to ADOConnection, and ADOdbFieldObject to ADOFieldObject.\r
-<p>PageExecute() now checks for empty $rs correctly, and the errors in the docs on this subject have been fixed.\r
-<p>odbc_error() does not return 6 digit error correctly at times. Implemented workaround.\r
-<p>Added ADORecordSet_empty class. This will speedup INSERTS/DELETES/UPDATES because the return\r
-object created is much smaller.\r
-<p>Added Prepare() to odbc, and oci8 (but doesn't work properly for oci8 still).\r
-<p>Made pgsql a synonym for postgre7, and changed SELECT LIMIT to use OFFSET for compat with \r
-postgres 7.2.\r
-<p>Revised adodb-cryptsession.php thanks to Ari.\r
-<p>Set resources to false on _close, to force freeing of resources.\r
-<p>Added adodb-errorhandler.inc.php, adodb-errorpear.inc.php and raiseErrorFn on Freek's urging.\r
-<p>GetRowAssoc($toUpper=true): $toUpper added as default.\r
-<p>Errors when connecting to a database were not captured formerly. Now we do it correctly.\r
-<p><b>1.40 19 September 2001</b></p>\r
-<p>PageExecute() to implement page scrolling added. Code and idea by Iv&aacute;n Oliva.</p>\r
-<p>Some minor postgresql fixes.</p>\r
-<p>Added sequence support using GenID() for postgresql, oci8, mysql, interbase.</p>\r
-<p>Added UpdateBlob support for interbase (untested).</p>\r
-<p>Added encrypted sessions (see adodb-cryptsession.php). By Ari Kuorikoski &lt;kuoriari#finebyte.com></p>\r
-<p><b>1.31 21 August 2001</b></p>\r
-<p>Many bug fixes thanks to "GaM3R (Cameron)" &lt;gamr#outworld.cx>. Some session changes due to Gam3r.\r
-<p>Fixed qstr() to quote  also.\r
-<p>rs2html() now pretty printed.\r
-<p>Jonathan Younger jyounger#unilab.com contributed the great idea GetUpdateSQL() and GetInsertSQL() which\r
-generates SQL to update and insert into a table from a recordset. Modify the recordset fields\r
-array, then can this function to generate the SQL (the SQL is not executed).\r
-<p>"Nicola Fankhauser" &lt;nicola.fankhauser#couniq.com> found some bugs in date handling for mssql.</p>\r
-<p>Added minimal Oracle support for LOBs. Still under development.</p>\r
-Added $ADODB_FETCH_MODE so you can control whether recordsets return arrays which are\r
-numeric, associative or both. This is a global variable you set. Currently only MySQL, Oci8, Postgres\r
-drivers support this.\r
-<p>PostgreSQL properly closes recordsets now. Reported by several people.\r
-<p>\r
-Added UpdateBlob() for Oracle. A hack to make it easier to save blobs.\r
-<p>\r
-Oracle timestamps did not display properly. Fixed.\r
-<p><b>1.20 6 June 2001</b></p>\r
-<p>Now Oracle can connect using tnsnames.ora or server and service name</p>\r
-<p>Extensive Oci8 speed optimizations. \r
-Oci8 code revised to support variable binding, and /*+ FIRST_ROWS */ hint.</p>\r
-<p>Worked around some 4.0.6 bugs in odbc_fetch_into().</p>\r
-<p>Paolo S. Asioli paolo.asioli#libero.it suggested GetRowAssoc().</p>\r
-<p>Escape quotes for oracle wrongly set to '. Now '' is used.</p>\r
-<p>Variable binding now works in ODBC also.</p>\r
-<p>Jumped to version 1.20 because I don't like 13 :-)</p>\r
-<p><b>1.12 6 June 2001</b></p>\r
-<p>Changed $ADODB_DIR to ADODB_DIR constant to plug a security loophole.</p>\r
-<p>Changed _close() to close persistent connections also. Prevents connection leaks.</p>\r
-<p>Major revision of oracle and oci8 drivers. \r
-Added OCI_RETURN_NULLS and OCI_RETURN_LOBS to OCIFetchInto(). BLOB, CLOB and VARCHAR2 recognition\r
-in MetaType() improved. MetaColumns() returns columns in correct sort order.</p>\r
-<p>Interbase timestamp input format was wrong. Fixed.</p>\r
-<p><b>1.11 20 May 2001</b></p>\r
-<p>Improved file locking for Windows.</p>\r
-<p>Probabilistic flushing of cache to avoid avalanche updates when cache timeouts.</p>\r
-<p>Cached recordset timestamp not saved in some scenarios. Fixed.</p>\r
-<p><b>1.10 19 May 2001</b></p>\r
-<p>Added caching. CacheExecute() and CacheSelectLimit().\r
-<p>Added csv driver. See <a href="http://php.weblogs.com/adodb_csv">http://php.weblogs.com/ADODB_csv</a>. \r
-<p>Fixed SelectLimit(), SELECT TOP not working under certain circumstances.\r
-<p>Added better Frontbase support of MetaTypes() by Frank M. Kromann.\r
-<p><b>1.01 24 April 2001</b></p>\r
-<p>Fixed SelectLimit bug.  not quoted properly.\r
-<p>SelectLimit: SELECT TOP -1 * FROM TABLE not support by Microsoft. Fixed.</p>\r
-<p>GetMenu improved by glen.davies#cce.ac.nz to support multiple hilited items<p>\r
-<p>FetchNextObject() did not work with only 1 record returned. Fixed bug reported by $tim#orotech.net</p>\r
-<p>Fixed mysql field max_length problem. Fix suggested by Jim Nicholson (jnich#att.com)</p>\r
-<p><b>1.00 16 April 2001</b></p>\r
-<p>Given some brilliant suggestions on how to simplify ADOdb by akul. You no longer need to\r
-setup $ADODB_DIR yourself, and ADOLoadCode() is automatically called by ADONewConnection(), \r
-simplifying the startup code.</p>\r
-<p>FetchNextObject() added. Suggested by Jakub Marecek. This makes FetchObject() obsolete, as\r
-this is more flexible and powerful.</p>\r
-<p>Misc fixes to SelectLimit() to support Access (top must follow distinct) and Fields() \r
-in the array recordset. From Reinhard Balling.</p>\r
-<p><b>0.96 27 Mar 2001</b></p>\r
-<p>ADOConnection Close() did not return a value correctly. Thanks to akul#otamedia.com.</p>\r
-<p>When the horrible magic_quotes is enabled, back-slash () is changed to double-backslash (\).\r
-This doesn't make sense for Microsoft/Sybase databases. We fix this in qstr().</p>\r
-<p>Fixed Sybase date problem in UnixDate() thanks to Toni Tunkkari. Also fixed MSSQL problem\r
-in UnixDate() - thanks to milhouse31#hotmail.com.</p>\r
-<p>MoveNext() moved to leaf classes for speed in MySQL/PostgreSQL. 10-15% speedup.</p>\r
-<p>Added null handling in bindInputArray in Execute() -- Ron Baldwin suggestion.</p>\r
-<p>Fixed some option tags. Thanks to john#jrmstudios.com.</p>\r
-<p><b>0.95 13 Mar 2001</b></p>\r
-<p>Added postgres7 database driver which supports LIMIT and other version 7 stuff in the future.</p>\r
-<p>Added SelectLimit to ADOConnection to simulate PostgreSQL's "select * from table limit 10 offset 3".\r
-Added helper function GetArrayLimit() to ADORecordSet.</p>\r
-<p>Fixed mysql metacolumns bug. Thanks to Freek Dijkstra (phpeverywhere#macfreek.com).</p>\r
-<p>Also many PostgreSQL changes by Freek. He almost rewrote the whole PostgreSQL driver!</p>\r
-<p>Added fix to input parameters in Execute for non-strings by Ron Baldwin.</p>\r
-<p>Added new metatype, X for TeXt. Formerly, metatype B for Blob also included\r
-text fields. Now 'B' is for binary/image data. 'X' for textual data.</p>\r
-<p>Fixed $this->GetArray() in GetRows().</p>\r
-<p>Oracle and OCI8: 1st parameter is always blank -- now warns if it is filled.</p>\r
-<p>Now <i>hasLimit</i> and <i>hasTop</i> added to indicate whether \r
-SELECT * FROM TABLE LIMIT 10 or SELECT TOP 10 * FROM TABLE are supported.</p>\r
-<p><b>0.94 04 Feb 2001</b></p>\r
-<p>Added ADORecordSet::GetRows() for compatibility with Microsoft ADO. Synonym for GetArray().</p>\r
-<p>Added new metatype 'R' to represent autoincrement numbers.</p>\r
-<p>Added ADORecordSet.FetchObject() to return a row as an object.</p>\r
-<p>Finally got a Linux box to test PostgreSql. Many fixes.</p>\r
-<p>Fixed copyright misspellings in 0.93.</p>\r
-<p>Fixed mssql MetaColumns type bug.</p>\r
-<p>Worked around odbc bug in PHP4 for sessions.</p>\r
-<p>Fixed many documentation bugs (affected_rows, metadatabases, qstr).</p>\r
-<p>Fixed MySQL timestamp format (removed comma).</p>\r
-<p>Interbase driver did not call ibase_pconnect(). Fixed.</p>\r
-<p><b>0.93 18 Jan 2002</b></p>\r
-<p>Fixed GetMenu bug.</p>\r
-<p>Simplified Interbase commit and rollback.</p>\r
-<p>Default behaviour on closing a connection is now to rollback all active transactions.</p>\r
-<p>Added field object handling for array recordset for future XML compatibility.</p>\r
-<p>Added arr2html() to convert array to html table.</p>\r
-<p><b>0.92 2 Jan 2002</b></p>\r
-<p>Interbase Commit and Rollback should be working again.</p>\r
-<p>Changed initialisation of ADORecordSet. This is internal and should not affect users. We\r
-are doing this to support cached recordsets in the future.</p>\r
-\r
-<p>Implemented ADORecordSet_array class. This allows you to simulate a database recordset\r
-with an array.</p>\r
-<p>Added UnixDate() and UnixTimeStamp() to ADORecordSet.</p>\r
-<p><b>0.91 21 Dec 2000</b></p>\r
-<p>Fixed ODBC so ErrorMsg() is working.</p>\r
-<p>Worked around ADO unrecognised null (0x1) value problem in COM.</p>\r
-<p>Added Sybase support for FetchField() type</p>\r
-<p>Removed debugging code and unneeded html from various files</p>\r
-<p>Changed to javadoc style comments to adodb.inc.php.</p>\r
-<p>Added maxsql as synonym for mysqlt</p>\r
-<p>Now ODBC downloads first 8K of blob by default\r
-<p><b>0.90 15 Nov 2000</b></p>\r
-<p>Lots of testing of Microsoft ADO. Should be more stable now.</p>\r
-<p>Added $ADODB_COUNTREC. Set to false for high speed selects.</p>\r
-<p>Added Sybase support. Contributed by Toni Tunkkari (toni.tunkkari#finebyte.com). Bug in Sybase \r
-  API: GetFields is unable to determine date types.</p>\r
-<p>Changed behaviour of RecordSet.GetMenu() to support size parameter (listbox) properly.</p>\r
-<p>Added emptyDate and emptyTimeStamp to RecordSet class that defines how to represent \r
-  empty dates.</p>\r
-<p>Added MetaColumns($table) that returns an array of ADOFieldObject's listing \r
-  the columns of a table.</p>\r
-<p>Added transaction support for PostgresSQL -- thanks to "Eric G. Werk" egw#netguide.dk.</p>\r
-<p>Added adodb-session.php for session support.</p>\r
-<p><b>0.80 30 Nov 2000</b></p>\r
-<p>Added support for charSet for interbase. Implemented MetaTables for most databases. \r
-  PostgreSQL more extensively tested.</p>\r
-<p><b>0.71 22 Nov 2000</b></p>\r
-<p>Switched from using require_once to include/include_once for backward compatability with PHP 4.02 and earlier.</p>\r
-<p><b>0.70 15 Nov 2000</b></p>\r
-<p>Calls by reference have been removed (call_time_pass_reference=Off) to ensure compatibility with future versions of PHP, \r
-except in Oracle 7 driver due to a bug in php_oracle.dll.</p>\r
-<p>PostgreSQL database driver contributed by Alberto Cerezal (acerezalp#dbnet.es). \r
-</p>\r
-<p>Oci8 driver for Oracle 8 contributed by George Fourlanos (fou#infomap.gr).</p>\r
-<p>Added <i>mysqlt</i> database driver to support MySQL 3.23 which has transaction \r
- support. </p>\r
-<p>Oracle default date format (DD-MON-YY) did not match ADOdb default date format (which is YYYY-MM-DD). Use ALTER SESSION to force the default date.</p>\r
-<p>Error message checking is now included in test suite.</p>\r
-<p>MoveNext() did not check EOF properly -- fixed.</p>\r
-<p><b>0.60 Nov 8 2000</b></p>\r
-<p>Fixed some constructor bugs in ODBC and ADO. Added ErrorNo function to ADOConnection \r
- class. </p>\r
-<p><b>0.51 Oct 18 2000</b></p>\r
-<p>Fixed some interbase bugs.</p>\r
-<p><b>0.50 Oct 16 2000</b></p>\r
-<p>Interbase commit/rollback changed to be compatible with PHP 4.03. </p>\r
-<p>CommitTrans( ) will now return true if transactions not supported. </p>\r
-<p>Conversely RollbackTrans( ) will return false if transactions not supported. \r
-</p>\r
-<p><b>0.46 Oct 12</b></p>\r
-Many Oracle compatibility issues fixed. \r
-<p><b>0.40 Sept 26</b></p>\r
-<p>Many bug fixes</p>\r
-<p>Now Code for BeginTrans, CommitTrans and RollbackTrans is working. So is the Affected_Rows\r
-and Insert_ID. Added above functions to test.php.</p>\r
-<p>ADO type handling was busted in 0.30. Fixed.</p>\r
-<p>Generalised Move( ) so it works will all databases, including ODBC.</p>\r
-<p><b>0.30 Sept 18</b></p>\r
-<p>Renamed ADOLoadDB to ADOLoadCode. This is clearer.</p>\r
-<p>Added BeginTrans, CommitTrans and RollbackTrans functions.</p>\r
-<p>Added Affected_Rows() and Insert_ID(), _affectedrows() and _insertID(), ListTables(), \r
- ListDatabases(), ListColumns().</p>\r
-<p>Need to add New_ID() and hasInsertID and hasAffectedRows, autoCommit </p>\r
-<p><b>0.20 Sept 12</b></p>\r
-<p>Added support for Microsoft's ADO.</p>\r
-<p>Added new field to ADORecordSet -- canSeek</p>\r
-<p>Added new parameter to _fetch($ignore_fields = false). Setting to true will \r
- not update fields array for faster performance.</p>\r
-<p>Added new field to ADORecordSet/ADOConnection -- dataProvider to indicate whether \r
- a class is derived from odbc or ado.</p>\r
-<p>Changed class ODBCFieldObject to ADOFieldObject -- not documented currently.</p>\r
-<p>Added benchmark.php and testdatabases.inc.php to the test suite.</p>\r
-<p>Added to ADORecordSet FastForward( ) for future high speed scrolling. Not documented.</p>\r
-<p>Realised that ADO's Move( ) uses relative positioning. ADOdb uses absolute. \r
-</p>\r
-<p><b>0.10 Sept 9 2000</b></p>\r
-<p>First release</p>\r
+<p>adodb-session.php now updates only the expiry date if the crc32 check indicates \r
+       that the data has not been modified. <hr>\r
+<p><strong>0.10 Sept 9 2000</strong> First release \r
+<h3><strong>Old changelog history moved to old-changelog.htm. </strong></h3>\r
+<p>&nbsp;</p>\r
 <p>\r
 </body>\r
 </html>\r
index 1ce0d1e0392fcee9291983d1e1ad17cfe53e7160..64daae7dea85b1686f7d6313785a985ab2b9ea16 100644 (file)
@@ -1,59 +1,59 @@
->> ADODB Library for PHP4\r
-\r
-(c) 2000-2002 John Lim (jlim@natsoft.com.my)\r
-\r
-Released under both BSD and GNU Lesser GPL library license. \r
-This means you can use it in proprietary products.\r
\r
\r
->> Introduction\r
-\r
-PHP's database access functions are not standardised. This creates a \r
-need for a database class library to hide the differences between the \r
-different databases (encapsulate the differences) so we can easily \r
-switch databases.\r
-\r
-We currently support MySQL, Interbase, Sybase, PostgreSQL, Oracle, \r
-Microsoft SQL server,  Foxpro ODBC, Access ODBC, Informix, DB2 ODBC,\r
-Sybase SQL Anywhere, generic ODBC and Microsoft's ADO. \r
-\r
-We hope more people will contribute drivers to support other databases.\r
-\r
-\r
->> Documentation and Examples\r
-\r
-Refer to readme.htm for full documentation and examples. There is also a \r
-tutorial tute.htm that contrasts ADODB code with mysql code.\r
-\r
-\r
->>> Files\r
-Adodb.inc.php is the main file. You need to include only this file.\r
-\r
-Adodb-*.inc.php are the database specific driver code.\r
-\r
-Test.php contains a list of test commands to exercise the class library.\r
-\r
-Adodb-session.php is the PHP4 session handling code.\r
-\r
-Testdatabases.inc.php contains the list of databases to apply the tests on.\r
-\r
-Benchmark.php is a simple benchmark to test the throughput of a simple SELECT \r
-statement for databases described in testdatabases.inc.php. The benchmark\r
-tables are created in test.php.\r
-\r
-readme.htm is the main documentation.\r
-\r
-tute.htm is the tutorial.\r
-\r
-\r
->> More Info\r
-\r
-For more information, including installation see readme.htm\r
-\r
-\r
->> Feature Requests and Bug Reports\r
-\r
-Email to jlim@natsoft.com.my \r
-\r
-\r
+>> ADODB Library for PHP4
+
+(c) 2000-2002 John Lim (jlim@natsoft.com.my)
+
+Released under both BSD and GNU Lesser GPL library license. 
+This means you can use it in proprietary products.
+>> Introduction
+
+PHP's database access functions are not standardised. This creates a 
+need for a database class library to hide the differences between the 
+different databases (encapsulate the differences) so we can easily 
+switch databases.
+
+We currently support MySQL, Interbase, Sybase, PostgreSQL, Oracle, 
+Microsoft SQL server,  Foxpro ODBC, Access ODBC, Informix, DB2 ODBC,
+Sybase SQL Anywhere, generic ODBC and Microsoft's ADO. 
+
+We hope more people will contribute drivers to support other databases.
+
+
+>> Documentation and Examples
+
+Refer to readme.htm for full documentation and examples. There is also a 
+tutorial tute.htm that contrasts ADODB code with mysql code.
+
+
+>>> Files
+Adodb.inc.php is the main file. You need to include only this file.
+
+Adodb-*.inc.php are the database specific driver code.
+
+Test.php contains a list of test commands to exercise the class library.
+
+Adodb-session.php is the PHP4 session handling code.
+
+Testdatabases.inc.php contains the list of databases to apply the tests on.
+
+Benchmark.php is a simple benchmark to test the throughput of a simple SELECT 
+statement for databases described in testdatabases.inc.php. The benchmark
+tables are created in test.php.
+
+readme.htm is the main documentation.
+
+tute.htm is the tutorial.
+
+
+>> More Info
+
+For more information, including installation see readme.htm
+
+
+>> Feature Requests and Bug Reports
+
+Email to jlim@natsoft.com.my 
+
+
  
\ No newline at end of file
index df277d5cae78d6a8fe75620f95625e3f02e96a5e..1cf60124f99f88b61acd11c76f0372e41ceab506 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
  * Whenever there is any discrepancy between the two licenses, \r
  * the BSD license will take precedence. \r
index 1ddd319fab234266e8cbeebebac63c30a9087371..e809ab3bf72ead36219d99800125359300c71dfc 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
index 22d0215e2a9d82646d155aa25356206f24914428..bc62b9d963b0b72d7efb5b8d9876b4bb9b01a2a6 100644 (file)
@@ -8,7 +8,7 @@
 <body>\r
 <?php \r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
index 5acbf97c08138a5cb30c8e17c54066164055e8cd..4d598dfdb7c751de5683c28e9b3b71efb9cede46 100644 (file)
@@ -2,7 +2,7 @@
 <body bgcolor=white>\r
 <?php\r
 /** \r
- * V2.50 14 Nov 2002  (c) 2001-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * V3.40 7 April 2003  (c) 2001-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
diff --git a/lib/adodb/tests/test-datadict.php b/lib/adodb/tests/test-datadict.php
new file mode 100644 (file)
index 0000000..9d1b44c
--- /dev/null
@@ -0,0 +1,333 @@
+<?php\r
+/*\r
+\r
+  V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  Released under both BSD license and Lesser GPL library license. \r
+  Whenever there is any discrepancy between the two licenses, \r
+  the BSD license will take precedence.\r
+       \r
+  Set tabs to 4 for best viewing.\r
+\r
+USAGE:\r
+\r
+       // First create a normal connection\r
+       $db->NewADOConnection('mysql');\r
+       $db->Connect(...);\r
+       \r
+       // Then create a data dictionary object, using this connection\r
+       $dict = NewDataDictionary($db);\r
+       \r
+       // We demonstrate creating tables and indexes\r
+       $sqlarray = $dict->CreateTableSQL($tabname, $fldarray, $taboptarray);\r
+       $dict->ExecuteSQLArray($sqlarray);\r
+       \r
+       $sqlarray = $dict->CreateIndexSQL($idxname, $tabname, $flds);\r
+       $dict->ExecuteSQLArray($sqlarray);\r
+       \r
+FUNCTIONS:\r
+\r
+       ========\r
+       function CreateDatabase($dbname, $optionsarray)\r
+       \r
+       \r
+       ========\r
+       function CreateTableSQL($tabname, $fldarray, $taboptarray=false)\r
+       \r
+       RETURNS:                an array of strings, the sql to be executed, or false\r
+       $tabname:               name of table\r
+       $fldarray:              array containing field info\r
+       $taboptarray:   array containing table options\r
+       \r
+       The format of $fldarray is a 2-dimensional array, where each row in the \r
+       1st dimension represents one field. Each row has this format:\r
+       \r
+               array($fieldname, $type, [,$colsize] [,$otheroptions]*)\r
+       \r
+       The first 2 fields must be the field name and the field type. The field type\r
+       can be a portable type codes or the actual type for that database. \r
+       Legal portable type codes include:\r
+\r
+               C:  varchar\r
+               X:  CLOB (character large object) or largest varchar size \r
+                       if CLOB is not supported\r
+               C2: Multibyte varchar\r
+               X2: Multibyte CLOB\r
+               \r
+               B:  BLOB (binary large object)\r
+               \r
+               D:  Date (some databases do not support this, and we return a datetime type)\r
+               T:  Datetime or Timestamp\r
+               L:  Integer field suitable for storing booleans (0 or 1)\r
+               I:  Integer (mapped to I4)\r
+               I1: 1-byte integer\r
+               I2: 2-byte integer\r
+               I4: 4-byte integer\r
+               I8: 8-byte integer\r
+               F:  Floating point number\r
+               N:  Numeric or decimal number\r
+               \r
+       The $colsize field represents the size of the field. If a decimal number is \r
+       used, then it is assumed that the number following the dot is the precision,\r
+       so 6.2 means a number of size 6 digits and 2 decimal places. It is \r
+       recommended that the default for number types be represented as a string to \r
+       avoid any rounding errors.\r
+       \r
+       The $otheroptions include the following keywords (case-insensitive):\r
+\r
+               AUTO                    For autoincrement number. Emulated with triggers if not available.\r
+                                               Sets NOTNULL also.\r
+               AUTOINCREMENT   Same as auto.\r
+               KEY                             Primary key field. Sets NOTNULL also. Compound keys are supported.\r
+               PRIMARY                 Same as KEY.\r
+               DEFAULT                 The default value. Character strings are auto-quoted unless\r
+                                               the string begins and ends with spaces, eg ' SYSDATE '.\r
+               NOTNULL                 If field is not null.\r
+               DEFDATE                 Set default value to call function to get today's date.\r
+               DEFTIMESTAMP    Set default to call function to get today's datetime.\r
+               NOQUOTE                 Prevents autoquoting of default string values.\r
+               CONSTRAINTS             Additional constraints defined at the end of the field\r
+                                               definition.\r
+               \r
+       Examples:\r
+               array('COLNAME', 'DECIMAL', '8.4', 'DEFAULT' => 0, 'NotNull')\r
+               array('ID',      'I'      , 'AUTO')\r
+               array('MYDATE',  'D'      , 'DEFDATE')\r
+               array('NAME',    'C'      ,'32', \r
+                         'CONSTRAINTS' => 'FOREIGN KEY REFERENCES reftable')\r
+                         \r
+       The $taboptarray is the 3rd parameter of the CreateTableSQL function. \r
+       This contains table specific settings. Legal keywords include\r
+       \r
+               REPLACE                 Indicates that the previous table definition should be removed\r
+                                               together with ALL data.\r
+               CONSTRAINTS             Additional constraints defined for the whole table. You will\r
+                                               probably need to prefix this with a comma.\r
+               \r
+       Database specific table options can be defined also using the name of the\r
+       database type as the array key. For example:\r
+       \r
+       $taboptarray = array('mysql' => 'TYPE=ISAM', 'oci8' => 'tablespace users');\r
+       \r
+       You can also define foreignkey constraints. The following is syntax for \r
+       postgresql:\r
+       \r
+       $taboptarray = array('constraints' => \r
+                                       ', FOREIGN KEY (col1) REFERENCES reftable (refcol)');\r
+\r
+       \r
+       ========\r
+       function CreateIndexSQL($idxname, $tabname, $flds, $idxoptarray=false)\r
+       \r
+       RETURNS:                an array of strings, the sql to be executed, or false\r
+       $idxname:               name of index\r
+       $tabname:               name of table\r
+       $fldarray:              list of fields as a comma delimited string or an array of strings\r
+       $idxoptarray:   array of index creation options\r
+       \r
+       $idxoptarray is similar to $taboptarray in that index specific information can\r
+       be embedded in the array. Other options include:\r
+       \r
+               CLUSTERED               Create clustered index (only mssql)\r
+               BITMAP                  Create bitmap index (only oci8)\r
+               UNIQUE                  Make unique index\r
+               FULLTEXT                Make fulltext index (only mysql)\r
+               HASH                    Create hash index (only postgres)\r
+               \r
+       ========        \r
+       function AddColumnSQL($tabname, $flds)\r
+       \r
+       ========\r
+       function AlterColumnSQL($tabname, $flds)\r
+       \r
+       ========\r
+       function DropColumnSQL($tabname, $flds)\r
+       \r
+       ========\r
+       function ExecuteSQLArray($sqlarray, $contOnError = true)\r
+       \r
+       RETURNS:                0 if failed, 1 if executed all but with errors, 2 if executed successfully\r
+       $sqlarray:              an array of strings with sql code (no semicolon at the end of string)\r
+       $contOnError:   if true, then continue executing even if error occurs\r
+*/\r
+\r
+error_reporting(E_ALL);\r
+include_once('../adodb.inc.php');\r
+\r
+foreach(array('mysql','oci8','postgres','odbc_mssql') as $dbType) {\r
+       echo "<h3>$dbType</h3><p>";\r
+       $db = NewADOConnection($dbType);\r
+       $dict = NewDataDictionary($db);\r
+\r
+       if (!$dict) continue;\r
+       $dict->debug = 1;\r
+       \r
+       $opts = array('REPLACE','mysql' => 'TYPE=ISAM', 'oci8' => 'TABLESPACE USERS');\r
+       $flds = array(\r
+               array('id',     'I',                                                            \r
+                                                       'AUTO','KEY'),\r
+                                                       \r
+               array('name' => 'firstname', 'type' => 'varchar','size' => 30,\r
+                                                       'DEFAULT'=>'Joan'),\r
+                                                       \r
+               array('lastname','varchar',28,\r
+                                                       'DEFAULT'=>'Chen','key'),\r
+                                                       \r
+               array('averylonglongfieldname','X',1024,\r
+                                                       'NOTNULL','default' => 'test'),\r
+                                                       \r
+               array('price','N','7.2',\r
+                                                       'NOTNULL','default' => '0.00'),\r
+                                                       \r
+               array('MYDATE', 'D', \r
+                                                       'DEFDATE'),\r
+               array('TS','T',\r
+                                                       'DEFTIMESTAMP')\r
+       );\r
+       \r
+       $sqla = $dict->CreateDatabase('KUTU',array('postgres'=>"LOCATION='/u01/postdata'"));\r
+       $dict->SetSchema('KUTU');\r
+       \r
+       $sqli = ($dict->CreateTableSQL('testtable',$flds, $opts));\r
+       $sqla = array_merge($sqla,$sqli);\r
+       \r
+       $sqli = $dict->CreateIndexSQL('idx','testtable','firstname,lastname',array('BITMAP','FULLTEXT','CLUSTERED','HASH'));\r
+       $sqla = array_merge($sqla,$sqli);\r
+       $sqli = $dict->CreateIndexSQL('idx2','testtable','price,lastname');//,array('BITMAP','FULLTEXT','CLUSTERED'));\r
+       $sqla = array_merge($sqla,$sqli);\r
+       \r
+       $addflds = array(array('height', 'F'),array('weight','F'));\r
+       $sqli = $dict->AddColumnSQL('testtable',$addflds);\r
+       $sqla = array_merge($sqla,$sqli);\r
+       $addflds = array(array('height', 'F','NOTNULL'),array('weight','F','NOTNULL'));\r
+       $sqli = $dict->AlterColumnSQL('testtable',$addflds);\r
+       $sqla = array_merge($sqla,$sqli);\r
+       \r
+       print "<pre>";\r
+       //print_r($dict->MetaTables());\r
+       foreach($sqla as $s) {\r
+               $s = htmlspecialchars($s);\r
+               print "$s;\n";\r
+               if ($dbType == 'oci8') print "/\n";\r
+       }\r
+       print "</pre><hr>";\r
+}\r
+\r
+/***\r
+\r
+Generated SQL:\r
+\r
+mysql\r
+\r
+CREATE DATABASE KUTU;\r
+DROP TABLE KUTU.testtable;\r
+CREATE TABLE KUTU.testtable (\r
+id               INTEGER NOT NULL AUTO_INCREMENT,\r
+firstname        VARCHAR(30) DEFAULT 'Joan',\r
+lastname         VARCHAR(28) NOT NULL DEFAULT 'Chen',\r
+averylonglongfieldname LONGTEXT NOT NULL,\r
+price            NUMERIC(7,2) NOT NULL DEFAULT 0.00,\r
+MYDATE           DATE DEFAULT CURDATE(),\r
+                 PRIMARY KEY (id, lastname)\r
+)TYPE=ISAM;\r
+CREATE FULLTEXT INDEX idx ON KUTU.testtable (firstname,lastname);\r
+CREATE INDEX idx2 ON KUTU.testtable (price,lastname);\r
+ALTER TABLE KUTU.testtable  ADD height           DOUBLE;\r
+ALTER TABLE KUTU.testtable  ADD weight           DOUBLE;\r
+ALTER TABLE KUTU.testtable  MODIFY COLUMN height           DOUBLE NOT NULL;\r
+ALTER TABLE KUTU.testtable  MODIFY COLUMN weight           DOUBLE NOT NULL;\r
+\r
+\r
+--------------------------------------------------------------------------------\r
+\r
+oci8\r
+\r
+CREATE USER KUTU IDENTIFIED BY tiger;\r
+/\r
+GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO KUTU;\r
+/\r
+DROP TABLE KUTU.testtable CASCADE CONSTRAINTS;\r
+/\r
+CREATE TABLE KUTU.testtable (\r
+id               NUMBER(16) NOT NULL,\r
+firstname        VARCHAR(30) DEFAULT 'Joan',\r
+lastname         VARCHAR(28) DEFAULT 'Chen' NOT NULL,\r
+averylonglongfieldname CLOB NOT NULL,\r
+price            NUMBER(7,2) DEFAULT 0.00 NOT NULL,\r
+MYDATE           DATE DEFAULT TRUNC(SYSDATE),\r
+                 PRIMARY KEY (id, lastname)\r
+)TABLESPACE USERS;\r
+/\r
+DROP SEQUENCE KUTU.SEQ_testtable;\r
+/\r
+CREATE SEQUENCE KUTU.SEQ_testtable;\r
+/\r
+CREATE OR REPLACE TRIGGER KUTU.TRIG_SEQ_testtable BEFORE insert ON KUTU.testtable \r
+               FOR EACH ROW\r
+               BEGIN\r
+                 select KUTU.SEQ_testtable.nextval into :new.id from dual;\r
+               END;\r
+/\r
+CREATE BITMAP INDEX idx ON KUTU.testtable (firstname,lastname);\r
+/\r
+CREATE INDEX idx2 ON KUTU.testtable (price,lastname);\r
+/\r
+ALTER TABLE testtable ADD (\r
+ height           NUMBER,\r
+ weight           NUMBER);\r
+/\r
+ALTER TABLE testtable MODIFY(\r
+ height           NUMBER NOT NULL,\r
+ weight           NUMBER NOT NULL);\r
+/\r
+\r
+\r
+--------------------------------------------------------------------------------\r
+\r
+postgres\r
+AlterColumnSQL not supported for PostgreSQL\r
+\r
+\r
+CREATE DATABASE KUTU LOCATION='/u01/postdata';\r
+DROP TABLE KUTU.testtable;\r
+CREATE TABLE KUTU.testtable (\r
+id               SERIAL,\r
+firstname        VARCHAR(30) DEFAULT 'Joan',\r
+lastname         VARCHAR(28) DEFAULT 'Chen' NOT NULL,\r
+averylonglongfieldname TEXT NOT NULL,\r
+price            NUMERIC(7,2) DEFAULT 0.00 NOT NULL,\r
+MYDATE           DATE DEFAULT CURRENT_DATE,\r
+                 PRIMARY KEY (id, lastname)\r
+);\r
+CREATE INDEX idx ON KUTU.testtable USING HASH (firstname,lastname);\r
+CREATE INDEX idx2 ON KUTU.testtable (price,lastname);\r
+ALTER TABLE KUTU.testtable  ADD height           FLOAT8;\r
+ALTER TABLE KUTU.testtable  ADD weight           FLOAT8;\r
+\r
+\r
+--------------------------------------------------------------------------------\r
+\r
+odbc_mssql\r
+\r
+CREATE DATABASE KUTU;\r
+DROP TABLE KUTU.testtable;\r
+CREATE TABLE KUTU.testtable (\r
+id               INT IDENTITY(1,1) NOT NULL,\r
+firstname        VARCHAR(30) DEFAULT 'Joan',\r
+lastname         VARCHAR(28) DEFAULT 'Chen' NOT NULL,\r
+averylonglongfieldname TEXT NOT NULL,\r
+price            NUMERIC(7,2) DEFAULT 0.00 NOT NULL,\r
+MYDATE           DATETIME DEFAULT GetDate(),\r
+                 PRIMARY KEY (id, lastname)\r
+);\r
+CREATE CLUSTERED INDEX idx ON KUTU.testtable (firstname,lastname);\r
+CREATE INDEX idx2 ON KUTU.testtable (price,lastname);\r
+ALTER TABLE KUTU.testtable  ADD\r
+ height           REAL,\r
+ weight           REAL;\r
+ALTER TABLE KUTU.testtable  ALTER COLUMN height           REAL NOT NULL;\r
+ALTER TABLE KUTU.testtable  ALTER COLUMN weight           REAL NOT NULL;\r
+\r
+\r
+--------------------------------------------------------------------------------\r
+*/\r
+?>
\ No newline at end of file
index 284ec0ead97bf7705acb373def90391621181603..61c75feebc69c9eeaaf5e948d832bc055ae24cea 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -8,19 +8,31 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
        \r
   Latest version is available at http://php.weblogs.com/\r
 */\r
+\r
 error_reporting(E_ALL);\r
 \r
-//--------------------------------------------------------------------------------------\r
 \r
+define('ADODB_ASSOC_CASE',0);\r
+\r
+include_once('../adodb-pear.inc.php');\r
+//--------------------------------------------------------------------------------------\r
+//define('ADODB_ASSOC_CASE',1);\r
+//\r
 function Err($msg)\r
 {\r
        print "<b>$msg</b><br>";\r
+       flush();\r
 }\r
 \r
 function CheckWS($conn)\r
-{ \r
+{\r
+global $ADODB_EXTENSION;\r
+\r
        include_once('../adodb-session.php');\r
+       \r
+       $saved = $ADODB_EXTENSION;\r
        $db = ADONewConnection($conn);\r
+       $ADODB_EXTENSION = $saved;\r
        if (headers_sent()) {\r
                print "<p><b>White space detected in adodb-$conn.inc.php or include file...</b></p>";\r
                die();\r
@@ -35,6 +47,16 @@ function do_strtolower(&$arr)
 }\r
 \r
 \r
+function CountExecs($db, $sql, $inputarray)\r
+{\r
+global $EXECS;  $EXECS++;\r
+}\r
+\r
+function CountCachedExecs($db, $secs2cache, $sql, $inputarray)\r
+{\r
+global $CACHED; $CACHED++;\r
+}\r
+\r
 // the table creation code is specific to the database, so we allow the user \r
 // to define their own table creation stuff\r
 \r
@@ -47,16 +69,29 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU
        </p>\r
 <?php  \r
        $create =false;\r
+       \r
+       GLOBAL $EXECS, $CACHED;\r
+       \r
+       $EXECS = 0;\r
+       $CACHED = 0;\r
+       \r
+       $db->fnExecute = 'CountExecs';\r
+       $db->fnCacheExecute = 'CountCachedExecs';\r
+       \r
        $ADODB_CACHE_DIR = dirname(TempNam('/tmp','testadodb'));\r
-               \r
        $db->debug = false;\r
        \r
        //print $db->UnixTimeStamp('2003-7-22 23:00:00');\r
        \r
        $phpv = phpversion();\r
-       print "<h3>ADODB Version: $ADODB_vers Host: <i>$db->host</i> &nbsp; Database: <i>$db->database</i> &nbsp; PHP: $phpv</h3>";\r
-       $e = error_reporting(E_ALL-E_WARNING);\r
+       if (defined('ADODB_EXTENSION')) $ext = ' &nbsp; Extension '.ADODB_EXTENSION.' installed';\r
+       else $ext = '';\r
+       print "<h3>ADODB Version: $ADODB_vers Host: <i>$db->host</i> &nbsp; Database: <i>$db->database</i> &nbsp; PHP: $phpv $ext</h3>";\r
        \r
+       $arr = $db->ServerInfo();\r
+       print_r($arr);\r
+       $e = error_reporting(E_ALL-E_WARNING);\r
+       flush();\r
        print "<i>date1</i> (1969-02-20) = ".$db->DBDate('1969-2-20');\r
        print "<br><i>date1</i> (1999-02-20) = ".$db->DBDate('1999-2-20');\r
        print "<br><i>date2</i> (1970-1-2) = ".$db->DBDate(24*3600)."<p>";\r
@@ -66,8 +101,9 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU
        print "<br> Fractional TS (1999-2-20 13:40:50.91): ".$db->DBTimeStamp($db->UnixTimeStamp('1999-2-20 13:40:50.91+1'));\r
         $dd = $db->UnixDate('1999-02-20');\r
        print "<br>unixdate</i> 1999-02-20 = ".date('Y-m-d',$dd)."<p>";\r
+       flush();\r
        // mssql too slow in failing bad connection\r
-       if ($db->databaseType != 'mssql') {\r
+       if (false && $db->databaseType != 'mssql') {\r
                print "<p>Testing bad connection. Ignore following error msgs:<br>";\r
                $db2 = ADONewConnection();\r
                $rez = $db2->Connect("bad connection");\r
@@ -76,20 +112,22 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU
                if ($rez) print "<b>Cannot check if connection failed.</b> The Connect() function returned true.</p>";\r
        }\r
        error_reporting($e);\r
+       flush();\r
        \r
        //$ADODB_COUNTRECS=false;\r
        $rs=$db->Execute('select * from adoxyz order by id');\r
+\r
        //print_r($rs);\r
        //OCIFetchStatement($rs->_queryID,$rez,0,-1);//,OCI_ASSOC | OCI_FETCHSTATEMENT_BY_ROW);\r
        //print_r($rez);\r
        //die();\r
        if($rs === false) $create = true;\r
        else $rs->Close();\r
-       \r
+               \r
        //if ($db->databaseType !='vfp') $db->Execute("drop table ADOXYZ");\r
                \r
        if ($create) {\r
-               if ($db->databaseType == 'ibase') {\r
+               if (false && $db->databaseType == 'ibase') {\r
                        print "<b>Please create the following table for testing:</b></p>$createtab</p>";\r
                        return;\r
                } else {\r
@@ -99,24 +137,26 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU
                        error_reporting($e);\r
                }\r
        }\r
-       \r
        $rs = &$db->Execute("delete from ADOXYZ"); // some ODBC drivers will fail the drop so we delete\r
+       \r
        if ($rs) {\r
-               if(! $rs->EOF)print "<b>Error: </b>RecordSet returned by Execute('delete...') should show EOF</p>";\r
+               if(! $rs->EOF) print "<b>Error: </b>RecordSet returned by Execute('delete...') should show EOF</p>";\r
                $rs->Close();\r
        } else print "err=".$db->ErrorMsg();\r
-       \r
+\r
        print "<p>Test select on empty table</p>";\r
        $rs = &$db->Execute("select * from ADOXYZ where id=9999");\r
        if ($rs && !$rs->EOF) print "<b>Error: </b>RecordSet returned by Execute(select...') on empty table should show EOF</p>";\r
        if ($rs) $rs->Close();\r
-       \r
-       \r
+       flush();\r
        //$db->debug=true;      \r
        print "<p>Testing Commit: ";\r
        $time = $db->DBDate(time());\r
-       if (!$db->BeginTrans()) print '<b>Transactions not supported</b></p>';\r
-       else { /* COMMIT */\r
+       if (!$db->BeginTrans()) {\r
+               print '<b>Transactions not supported</b></p>';\r
+               if ($db->hasTransactions) Err("hasTransactions should be false");\r
+       } else { /* COMMIT */\r
+               if (!$db->hasTransactions) Err("hasTransactions should be true");\r
                if ($db->transCnt != 1) Err("Invalid transCnt = $db->transCnt (should be 1)");\r
                $rs = $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (99,'Should Not','Exist (Commit)',$time)");\r
                if ($rs && $db->CommitTrans()) {\r
@@ -183,7 +223,16 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU
        \r
        $db->debug = false;\r
        \r
-       if ($db->databaseType == 'mssql') {\r
+       \r
+       switch ($db->databaseType) {\r
+       case 'postgres7':\r
+       case 'postgres64':\r
+       case 'postgres':\r
+       case 'ibase':\r
+               print "<p>Encode=".$db->BlobEncode("abc\0d\"'\r
+ef")."</p>";\r
+               break;\r
+       case 'mssql': \r
 /*\r
 ASSUME Northwind available...\r
 \r
@@ -229,26 +278,55 @@ GO
                $rs = $db->Execute($stmt);\r
                rs2html($rs);\r
                \r
+               /*\r
+               Test out params - works in 4.2.3 but not 4.3.0???:\r
+               \r
+                       CREATE PROCEDURE at_date_interval \r
+                               @days INTEGER, \r
+                               @start VARCHAR(20) OUT, \r
+                               @end VARCHAR(20) OUT    \r
+                       AS \r
+                       BEGIN \r
+                               set @start = CONVERT(VARCHAR(20), getdate(), 101) \r
+                               set @end =CONVERT(VARCHAR(20), dateadd(day, @days, getdate()), 101 ) \r
+                       END\r
+                       GO\r
+               */\r
+               $stmt = $db->PrepareSP('at_date_interval');\r
+               $days = 10;\r
+               $begin_date = '';\r
+               $end_date = '';\r
+               $db->Parameter($stmt,$days,'days', false, 4, SQLINT4); \r
+               $db->Parameter($stmt,$begin_date,'start', 1, 20, SQLVARCHAR ); \r
+               $db->Parameter($stmt,$end_date,'end', 1, 20, SQLVARCHAR ); \r
+               $db->Execute($stmt);\r
+               if (empty($begin_date) or empty($end_date)) {\r
+                       Err("MSSQL SP Test for OUT Failed");\r
+                       print "begin=$begin_date end=$end_date<p>";\r
+               } else print "(Today +10days) = (begin=$begin_date end=$end_date)<p>";\r
                $db->debug = $saved;\r
-       } else if (substr($db->databaseType,0,4) == 'oci8') {\r
+               break;\r
+       case 'oci8': \r
+       case 'oci8po':\r
                $saved = $db->debug;\r
                $db->debug=true;\r
                \r
                print "<h4>Testing Cursor Variables</h4>";\r
 /*\r
 -- TEST PACKAGE\r
-CREATE or replace PACKAGE adodb AS\r
-       TYPE TabType IS REF CURSOR RETURN tab%ROWTYPE;\r
-       PROCEDURE open_tab (tab IN OUT TabType,param in varchar);\r
+CREATE OR REPLACE PACKAGE adodb AS\r
+TYPE TabType IS REF CURSOR RETURN tab%ROWTYPE;\r
+PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames in varchar);\r
 END adodb;\r
 /\r
 \r
-CREATE or replace PACKAGE BODY adodb AS\r
-       PROCEDURE open_tab (tab IN OUT TabType,param in varchar) IS\r
-               BEGIN\r
-                       OPEN tab FOR SELECT * FROM tab;\r
-               END open_tab;\r
+CREATE OR REPLACE PACKAGE BODY adodb AS\r
+PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames in varchar) IS\r
+       BEGIN\r
+               OPEN tabcursor FOR SELECT * FROM tab where tname like tablenames;\r
+       END open_tab;\r
 END adodb;\r
+\r
 /\r
 */             \r
                $stmt = $db->Prepare("BEGIN adodb.open_tab(:RS,'A%'); END;");\r
@@ -261,7 +339,7 @@ END adodb;
                        print "<b>Error in using Cursor Variables 1</b><p>";\r
                }\r
                \r
-               $rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:RS2,'A%'); END;",'RS2');\r
+               $rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:RS2,:TAB); END;",'RS2',array('TAB'=>'A%'));\r
                if ($rs && !$rs->EOF) {\r
                        print "Test 2 RowCount: ".$rs->RecordCount()."<p>";\r
                } else {\r
@@ -279,6 +357,10 @@ END adodb;
                rs2html($rs);\r
                \r
                $db->debug = $saved;\r
+               break;\r
+       \r
+       default:\r
+               break;\r
        }\r
        print "<p>Inserting 50 rows</p>";\r
 \r
@@ -291,6 +373,7 @@ END adodb;
                $arr = array(0=>'Caroline',1=>'Miranda');\r
                $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,?,?,$time)";\r
                break;\r
+               \r
        case 'oci8':\r
        case 'oci805':\r
                $arr = array('first'=>'Caroline','last'=>'Miranda');\r
@@ -307,42 +390,55 @@ END adodb;
        else $rs->Close();\r
        $db->debug = false;\r
        $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+1,'John','Lim',$time)");\r
+       echo "Insert ID=";var_dump($db->Insert_ID());\r
        $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+2,'Mary','Lamb',$time )");\r
        $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+3,'George','Washington',$time )");\r
        $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+4,'Mr. Alan','Tam',$time )");\r
-       $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+5,'Alan','Turing',$time )");\r
+       $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+5,'Alan',".$db->quote("Turing'ton").",$time )");\r
        $db->Execute("insert into ADOXYZ (id,firstname,lastname,created)values ($i*10+6,'Serena','Williams',$time )");\r
        $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+7,'Yat Sun','Sun',$time )");\r
        $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+8,'Wai Hun','See',$time )");\r
        $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+9,'Steven','Oey',$time )");\r
        } // for\r
-       \r
        if (1) {\r
        $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;\r
        //$db->debug=1;\r
-       $db->Execute('update ADOXYZ set id=id+1');      \r
-   $nrows = $db->Affected_Rows();   \r
+       $rs = $db->Execute('update ADOXYZ set id=id+1');        \r
+       if (!is_object($rs)) {\r
+               print_r($rs);\r
+               err("Update should return object");\r
+       }\r
+       if (!$rs) err("Update generated error");\r
+       \r
+       $nrows = $db->Affected_Rows();   \r
        if ($nrows === false) print "<p><b>Affected_Rows() not supported</b></p>";\r
        else if ($nrows != 50)  print "<p><b>Affected_Rows() Error: $nrows returned (should be 50) </b></p>";\r
        else print "<p>Affected_Rows() passed</p>";\r
        }\r
        $db->debug = false;\r
-\r
-       $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;\r
+       \r
+       $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;\r
  //////////////////////////////////////////////////////////////////////////////////////////\r
        \r
        $rs = $db->Execute("select * from ADOXYZ where firstname = 'not known'");\r
        if (!$rs ||  !$rs->EOF) print "<p><b>Error on empty recordset</b></p>";\r
-       if ($rs->RecordCount() != 0) print "<p><b>Error on RecordCount. Should be 0. Was ".$rs->RecordCount()."</b></p>"; \r
-       $rs = &$db->Execute("select id,firstname as TheFirstName,lastname,created from ADOXYZ order by id");\r
+       else if ($rs->RecordCount() != 0) {\r
+               print "<p><b>Error on RecordCount. Should be 0. Was ".$rs->RecordCount()."</b></p>"; \r
+               print_r($rs->fields);\r
+       }\r
+       $rs = &$db->Execute("select id,firstname,lastname,created from ADOXYZ order by id");\r
        if ($rs) {\r
                if ($rs->RecordCount() != 50) {\r
-                       print "<p><b>RecordCount returns -1</b></p>";\r
-                       if ($rs->PO_RecordCount('ADOXYZ') == 50) print "<p> &nbsp; &nbsp; PO_RecordCount passed</p>";\r
-                       else print "<p><b>PO_RecordCount returns wrong value</b></p>";\r
+                       print "<p><b>RecordCount returns ".$rs->RecordCount()."</b></p>";\r
+                       $poc = $rs->PO_RecordCount('ADOXYZ');\r
+                       if ($poc == 50) print "<p> &nbsp; &nbsp; PO_RecordCount passed</p>";\r
+                       else print "<p><b>PO_RecordCount returns wrong value: $poc</b></p>";\r
                } else print "<p>RecordCount() passed</p>";\r
                if (isset($rs->fields['firstname'])) print '<p>The fields columns can be indexed by column name.</p>';\r
-               else print '<p>The fields columns <i>cannot</i> be indexed by column name.</p>';\r
+               else {\r
+                       Err( '<p>The fields columns <i>cannot</i> be indexed by column name.</p>');\r
+                       print_r($rs->fields);\r
+               }\r
                if (empty($HTTP_GET_VARS['hide'])) rs2html($rs);\r
        }\r
        else print "<b>Error in Execute of SELECT</b></p>";\r
@@ -361,6 +457,7 @@ END adodb;
 \r
        print "<p>FetchObject/FetchNextObject Test</p>";\r
        $rs = &$db->Execute('select * from ADOXYZ');\r
+       \r
        if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";\r
        \r
        while ($o = $rs->FetchNextObject()) { // calls FetchObject internally\r
@@ -373,9 +470,10 @@ END adodb;
        \r
        $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;\r
        print "<p>FetchObject/FetchNextObject Test 2</p>";\r
+       \r
        $rs = &$db->Execute('select * from ADOXYZ');\r
        if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";\r
-       \r
+       print_r($rs->fields);\r
        while ($o = $rs->FetchNextObject()) { // calls FetchObject internally\r
                if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) {\r
                        print_r($o);\r
@@ -415,7 +513,11 @@ END adodb;
                $rs->MoveNext();\r
                if ($rs->fields['id'] != 2)  {Err("Error 3"); print_r($rs->fields);};\r
                $rs->MoveNext();\r
-               if (!$rs->EOF)Err("Error EOF");\r
+               if (!$rs->EOF) Err("Error EOF");\r
+               else if (is_array($rs->fields) || $rs->fields) {\r
+                       Err("Error: ## fields should be set to false on EOF");\r
+                       print_r($rs->fields);\r
+               }\r
        }\r
        \r
        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;\r
@@ -501,7 +603,8 @@ END adodb;
        }\r
         else Err("Failed SelectLimit Test 3");\r
                $db->debug = false;\r
-               \r
+       \r
+       \r
        $rs = &$db->Execute("select * from ADOXYZ order by id");\r
        print "<p>Testing Move()</p>";  \r
        if (!$rs)Err( "Failed Move SELECT");\r
@@ -520,23 +623,40 @@ END adodb;
                        $rs->Move(3);\r
                        if (trim($rs->Fields("firstname")) != 'George') {\r
                                print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) failed</b></p>";\r
-                               print_r($rs);\r
                        } else print "Move(3) OK<BR>";\r
                                                \r
-                                       $rs->Move(7);\r
+                       $rs->Move(7);\r
                        if (trim($rs->Fields("firstname")) != 'Yat Sun') {\r
                                print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(7) failed</b></p>";\r
                                print_r($rs);\r
                        } else print "Move(7) OK<BR>";\r
-\r
+                       if ($rs->EOF) Err("Move(7) is EOF already");\r
                        $rs->MoveLast();\r
                        if (trim($rs->Fields("firstname")) != 'Steven'){\r
                                 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: MoveLast() failed</b></p>";\r
                                 print_r($rs);\r
                        }else print "MoveLast() OK<BR>";\r
+                       $rs->MoveNext();\r
+                       if (!$rs->EOF) err("Bad MoveNext");\r
+                       if ($rs->canSeek) {\r
+                               $rs->Move(3);\r
+                               if (trim($rs->Fields("firstname")) != 'George') {\r
+                                       print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) after MoveLast failed</b></p>";\r
+                                       \r
+                               } else print "Move(3) after MoveLast() OK<BR>";\r
+                       }\r
+                       \r
+                       print "<p>Empty Move Test";\r
+                       $rs = $db->Execute("select * from ADOXYZ where id > 0 and id < 0");\r
+                       $rs->MoveFirst();\r
+                       if (!$rs->EOF || $rs->fields) Err("Error in empty move first");\r
                }\r
        }\r
        \r
+       $rs = $db->Execute('select * from ADOXYZ where id = 2');\r
+       if ($rs->EOF || !is_array($rs->fields)) Err("Error in select");\r
+       $rs->MoveNext();\r
+       if (!$rs->EOF) Err("Error in EOF (xx) ");\r
  //    $db->debug=true;\r
        print "<p>Testing ADODB_FETCH_ASSOC and concat: concat firstname and lastname</p>";\r
 \r
@@ -574,12 +694,17 @@ END adodb;
        else print "<b>FAILED</b><BR>";\r
        \r
        print "Testing GetAssoc() ";\r
+       $savecrecs = $ADODB_COUNTRECS;\r
+       $ADODB_COUNTRECS = false;\r
        $rs = &$db->Execute("select distinct lastname,firstname from ADOXYZ");\r
        if ($rs) {\r
                $arr = $rs->GetAssoc();\r
+               //print_r($arr);\r
                if (trim($arr['See']) != 'Wai Hun') print $arr['See']." &nbsp; <b>ERROR</b><br>";\r
                else print " OK<BR>";\r
        }\r
+       // Comment this out to test countrecs = false\r
+       $ADODB_COUNTRECS = $savecrecs;\r
        \r
        for ($loop=0; $loop < 1; $loop++) {\r
        print "Testing GetMenu() and CacheExecute<BR>";\r
@@ -615,24 +740,34 @@ END adodb;
        }\r
        \r
        $db->debug = false;\r
-       $rs1 = &$db->Execute("select id from ADOXYZ where id = 2 or id = 1 order by 1");\r
+       $rs1 = &$db->Execute("select id from ADOXYZ where id <= 2 order by 1");\r
        $rs2 = &$db->Execute("select id from ADOXYZ where id = 3 or id = 4 order by 1");\r
-       \r
+\r
        if ($rs1) $rs1->MoveLast();\r
        if ($rs2) $rs2->MoveLast();\r
        \r
        if (empty($rs1) || empty($rs2) || $rs1->fields[0] != 2 || $rs2->fields[0] != 4) {\r
                $a = $rs1->fields[0];\r
                $b = $rs2->fields[0];\r
-               print "<p><b>Error in multiple recordset test rs1=$a rs2=%b (should be rs1=2 rs2=4)</b></p>";\r
+               print "<p><b>Error in multiple recordset test rs1=$a rs2=$b (should be rs1=2 rs2=4)</b></p>";\r
        } else\r
                print "<p>Testing multiple recordsets OK</p>";\r
                \r
        \r
        echo "<p> GenID test: ";\r
        for ($i=1; $i <= 10; $i++) \r
-               echo  "($i: ",$val = $db->GenID('abcseq5' ,5), ") ";\r
-       if ($val == 0) echo " <p><b>GenID not supported</b>";\r
+               echo  "($i: ",$val = $db->GenID('abcseq6' ,5), ") ";\r
+       if ($val == 0) Err("GenID not supported");\r
+       \r
+       if ($val) {\r
+               $db->DropSequence('abc_seq2');\r
+               $db->CreateSequence('abc_seq2');\r
+               $val = $db->GenID('abc_seq2');\r
+               $db->DropSequence('abc_seq2');\r
+               $db->CreateSequence('abc_seq2');\r
+               $val = $db->GenID('abc_seq2');\r
+               if ($val != 1) Err("Drop and Create Sequence not supported ($val)");\r
+       }\r
        echo "<p>";\r
        \r
        if (substr($db->dataProvider,0,3) != 'notused') { // used to crash ado\r
@@ -738,14 +873,14 @@ END adodb;
        if ($d != $rs->fields[0]) Err("SQLDate failed expected: $d, sql:".$rs->fields[0]);\r
        \r
        print "<p>Test Filter</p>";\r
-       $rs = $db->SelectLimit('select * from ADOXYZ where id < 3');\r
+       $rs = $db->SelectLimit('select * from ADOXYZ where id < 3 order by id');\r
        $rs = RSFilter($rs,'do_strtolower');\r
        if (trim($rs->fields[1]) != 'caroline'  && trim($rs->fields[2]) != 'miranda') {\r
                err('**** RSFilter failed');\r
                print_r($rs->fields);\r
        }\r
        rs2html($rs);\r
-       \r
+               \r
        $db->debug=1;\r
        \r
        \r
@@ -759,9 +894,16 @@ END adodb;
        else {\r
                $saved = $db->debug;\r
                $db->debug = 0;\r
+               $savec = $ADODB_COUNTRECS;\r
+               $ADODB_COUNTRECS = true;\r
                $rs = $db->Execute('select * FROM ADOXYZ where id=1');\r
                $db->debug = $saved;\r
-               if ($rs->RecordCount() != 1) print "<b>Error - update failed</b><p>";\r
+               if ($rs->RecordCount() != 1) {\r
+                       $cnt = $rs->RecordCount();\r
+                       rs2html($rs);\r
+                       print "<b>Error - Replace failed, count=$cnt</b><p>";\r
+               }\r
+               $ADODB_COUNTRECS = $savec;\r
        }\r
        $ret = $db->Replace('adoxyz', \r
                array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'),\r
@@ -781,13 +923,14 @@ END adodb;
        \r
        print "<h3>rs2rs Test</h3>";\r
        \r
-       $db->Execute('select * from adoxyz');\r
+       $rs = $db->Execute('select * from adoxyz order by id');\r
        $rs = $db->_rs2rs($rs);\r
        $rs->valueX = 'X';\r
        $rs->MoveNext();\r
        $rs = $db->_rs2rs($rs);\r
        if (!isset($rs->valueX)) err("rs2rs does not preserve array recordsets");\r
        if (reset($rs->fields) != 1) err("rs2rs does not move to first row");\r
+\r
        /////////////////////////////////////////////////////////////\r
        include_once('../pivottable.inc.php');\r
        print "<h3>Pivot Test</h3>";\r
@@ -858,13 +1001,50 @@ END adodb;
        if ($pear) print "<p>PEAR DB emulation passed.</p>";\r
        \r
 \r
+       if ($db->hasTransactions) {\r
+               //$db->debug=1;\r
+               echo "<p>Testing StartTrans CompleteTrans</p>";\r
+               $db->raiseErrorFn = false;\r
+               $db->StartTrans();\r
+               $rs = $db->Execute('select * from notable');\r
+                       $db->StartTrans();\r
+                               $db->BeginTrans();\r
+                       $db->Execute("update ADOXYZ set firstname='Carolx' where id=1");\r
+                               $db->CommitTrans();\r
+                       $db->CompleteTrans();\r
+               $rez = $db->CompleteTrans();\r
+               if ($rez !== false) {\r
+                       if (is_null($rez)) Err("Error: _transOK not modified");\r
+                       else Err("Error: CompleteTrans (1) should have failed");\r
+               } else {\r
+                       $name = $db->GetOne("Select firstname from ADOXYZ where id=1");\r
+                       if ($name == "Carolx") Err("Error: CompleteTrans (2) should have failed");\r
+                       else echo "<p> -- Passed StartTrans test1 - rolling back</p>";\r
+               }\r
+               \r
+               $db->StartTrans();\r
+                       $db->BeginTrans();\r
+               $db->Execute("update ADOXYZ set firstname='Carolx' where id=1");\r
+                       $db->RollbackTrans();\r
+               $rez = $db->CompleteTrans();\r
+               if ($rez !== true) Err("Error: CompleteTrans (1) should have succeeded");\r
+               else {\r
+                       $name = $db->GetOne("Select firstname from ADOXYZ where id=1");\r
+                       if (trim($name) != "Carolx") Err("Error: CompleteTrans (2) should have succeeded, returned name=$name");\r
+                       else echo "<p> -- Passed StartTrans test2 - commiting</p>";\r
+               }\r
+       }\r
        global $TESTERRS;\r
        $debugerr = true;\r
                \r
        $db->debug = false;\r
        $TESTERRS = 0;\r
        $db->raiseErrorFn = 'adodb_test_err';\r
+       global $ERRNO; // from adodb_test_err\r
        $db->Execute('select * from nowhere');\r
+       $metae = $db->MetaError($ERRNO);\r
+       if ($metae !== DB_ERROR_NOSUCHTABLE) print "<p><b>MetaError=".$metae." wrong</b>, should be ".DB_ERROR_NOSUCHTABLE."</p>";\r
+       else print "<p>MetaError ok (".DB_ERROR_NOSUCHTABLE.")</p>";\r
        if ($TESTERRS != 1) print "<b>raiseErrorFn select nowhere failed</b><br>";\r
        $rs = $db->Execute('select * from adoxyz');\r
        if ($debugerr) print " Move";\r
@@ -872,14 +1052,47 @@ END adodb;
        $rs->_queryID = false;\r
        if ($debugerr) print " MoveNext";\r
        $rs->MoveNext();\r
-       \r
        if ($debugerr) print " $rs=false";\r
        $rs = false;\r
+\r
+       print "<p>SetFetchMode() tests</p>";\r
+       $db->SetFetchMode(ADODB_FETCH_ASSOC);\r
+       $rs = $db->SelectLimit('select firstname from adoxyz',1);\r
+       //      var_dump($rs->fields);\r
+       if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC");\r
+       \r
+       $ADODB_FETCH_MODE = ADODB_FETCH_NUM;    \r
+       $rs = $db->SelectLimit('select firstname from adoxyz',1);\r
+       //var_dump($rs->fields);\r
+       if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC");\r
+       \r
+       $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;  \r
+       $db->SetFetchMode(ADODB_FETCH_NUM);\r
+       $rs = $db->SelectLimit('select firstname from adoxyz',1);\r
+       if (!isset($rs->fields[0])) Err("BAD FETCH NUM");\r
+       \r
+       print "<p>Test MetaTables again with SetFetchMode()</p>";\r
+       $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;\r
+       $db->SetFetchMode(ADODB_FETCH_ASSOC);\r
+       print_r($db->MetaTables());\r
+       print "<p>";\r
+       ////////////////////////////////////////////////////////////////////\r
+       \r
        $conn = NewADOConnection($db->databaseType);\r
        $conn->raiseErrorFn = 'adodb_test_err';\r
        @$conn->Connect('abc');\r
        if ($TESTERRS == 2) print "raiseErrorFn tests passed<br>";\r
        else print "<b>raiseErrorFn tests failed ($TESTERRS)</b><br>";\r
+       \r
+       \r
+       ////////////////////////////////////////////////////////////////////\r
+       \r
+       global $nocountrecs;\r
+       \r
+       if (isset($nocountrecs) && $ADODB_COUNTRECS) err("Error: \$ADODB_COUNTRECS is set");\r
+       if (empty($nocountrecs) && $ADODB_COUNTRECS==false) err("Error: \$ADODB_COUNTRECS is not set");\r
+\r
+       \r
 ?>\r
        </p>\r
        <table width=100% ><tr><td bgcolor=beige>&nbsp;</td></tr></table>\r
@@ -892,12 +1105,16 @@ END adodb;
        $db->Close();\r
        \r
        if ($db->transCnt != 0) Err("Error in transCnt=$db->transCnt (should be 0)");\r
+       \r
+       \r
+       printf("<p>Total queries=%d; total cached=%d</p>",$EXECS+$CACHED, $CACHED);\r
 }\r
 \r
 function adodb_test_err($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)\r
 {\r
-global $TESTERRS;\r
+global $TESTERRS,$ERRNO;\r
 \r
+       $ERRNO = $errno;\r
        $TESTERRS += 1;\r
        print "<i>** $dbms ($fn): errno=$errno &nbsp; errmsg=$errmsg ($p1,$p2)</i><br>";\r
        \r
@@ -915,7 +1132,7 @@ include("../adodb.inc.php");
 include("../rsfilter.inc.php");\r
 \r
 /* White Space Check */\r
-if (@$HTTP_SERVER_VARS['COMPUTERNAME'] == 'xJAGUAR') {\r
+if (@$HTTP_SERVER_VARS['COMPUTERNAME'] == 'JAGUAR') {\r
        CheckWS('mysqlt');\r
        CheckWS('postgres');\r
        CheckWS('oci8po');\r
@@ -958,15 +1175,17 @@ There is also support for Sybase, PostgreSQL.</p>
 For the latest version of ADODB, visit <a href=http://php.weblogs.com/ADODB>php.weblogs.com</a>.</p>\r
 \r
 <form method=get>\r
-<input type=checkbox name="testaccess" value="1" <?php echo !empty($testaccess) ? 'checked' : '' ?>> Access<br>\r
-<input type=checkbox name="testibase" value="1" <?php echo !empty($testibase) ? 'checked' : '' ?>> Interbase<br>\r
-<input type=checkbox name="testmssql" value="1" <?php echo !empty($testmssql) ? 'checked' : '' ?>> MSSQL<br>\r
- <input type=checkbox name="testmysql" value="1" <?php echo !empty($testmysql) ? 'checked' : '' ?>> <b>MySQL</b><br>\r
+<input type=checkbox name="testaccess" value=1 <?php echo !empty($testaccess) ? 'checked' : '' ?>> <b>Access</b><br>\r
+<input type=checkbox name="testibase" value=1 <?php echo !empty($testibase) ? 'checked' : '' ?>> <b>Interbase</b><br>\r
+<input type=checkbox name="testmssql" value=1 <?php echo !empty($testmssql) ? 'checked' : '' ?>> <b>MSSQL</b><br>\r
+ <input type=checkbox name="testmysql" value=1 <?php echo !empty($testmysql) ? 'checked' : '' ?>> <b>MySQL</b><br>\r
+<input type=checkbox name="testmysqlodbc" value=1 <?php echo !empty($testmysqlodbc) ? 'checked' : '' ?>> <b>MySQL ODBC</b><br>\r
 <input type=checkbox name="testproxy" value=1 <?php echo !empty($testproxy) ? 'checked' : '' ?>> <b>MySQL Proxy</b><br>\r
-<input type=checkbox name="testoracle" value="1" <?php echo !empty($testoracle) ? 'checked' : '' ?>> <b>Oracle (oci8)</b> <br>\r
+<input type=checkbox name="testoracle" value=1 <?php echo !empty($testoracle) ? 'checked' : '' ?>> <b>Oracle (oci8)</b> <br>\r
 <input type=checkbox name="testpostgres" value=1 <?php echo !empty($testpostgres) ? 'checked' : '' ?>> <b>PostgreSQL</b><br>\r
 <input type=checkbox name="testvfp" value=1 <?php echo !empty($testvfp) ? 'checked' : '' ?>> VFP<br>\r
 <input type=checkbox name="testado" value=1 <?php echo !empty($testado) ? 'checked' : '' ?>> ADO (for mssql and access)<br>\r
+<input type=checkbox name="nocountrecs" value=1 <?php echo !empty($nocountrecs) ? 'checked' : '' ?>> $ADODB_COUNTRECS=false<br>\r
 <input type=submit>\r
 </form>\r
 \r
@@ -977,9 +1196,13 @@ Test <a href=test4.php>GetInsertSQL/GetUpdateSQL</a> &nbsp;
 \r
 if ($ADODB_FETCH_MODE != ADODB_FETCH_DEFAULT) print "<h3>FETCH MODE IS NOT ADODB_FETCH_DEFAULT</h3>";\r
 \r
-\r
+if (isset($nocountrecs)) $ADODB_COUNTRECS = false;\r
 include('./testdatabases.inc.php');\r
+\r
+\r
+include_once('../adodb-time.inc.php');\r
+adodb_date_test();\r
 ?>\r
-<p><i>ADODB Database Library  (c) 2000-2002 John Lim. All rights reserved. Released under BSD and LGPL.</i></p>\r
+<p><i>ADODB Database Library  (c) 2000-2003 John Lim. All rights reserved. Released under BSD and LGPL.</i></p>\r
 </body>\r
-</html>
\ No newline at end of file
+</html>\r
index 9d831350382a1524de8d051cbedfecc5433a3fd3..7adaa314c797039ee7ae46104612da88e7964ddd 100644 (file)
@@ -8,7 +8,7 @@
 <body>\r
 <?php\r
 /*\r
-  V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -28,9 +28,11 @@ $c1 = ADONewConnection('oci8');
 if (!$c1->PConnect('','scott','tiger')) \r
        die("Cannot connect to server");\r
 $c1->debug=1;\r
-\r
-$rs = $c1->CacheExecute(1200,'select rownum, p1.firstname,p2.lastname,p2.firstname,p1.lastname from adoxyz p1, adoxyz p2');\r
-print "Records=".$rs->RecordCount()."<br>";\r
+$rs = $c1->Execute('select rownum, p1.firstname,p2.lastname,p2.firstname,p1.lastname from adoxyz p1, adoxyz p2');\r
+print "Records=".$rs->RecordCount()."<br><pre>";\r
+//$rs->_array = false;\r
+//$rs->connection = false;\r
+//print_r($rs);\r
 rs2html($rs);\r
 ?>\r
 \r
index d07c61684a35b0f20c67abb9a4f6e5348634af24..58664c22a90b9160ea99307309ca2855af1d0857 100644 (file)
@@ -1,7 +1,7 @@
 <code>\r
 <?php\r
 /*\r
-  V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
index 2fe4531d77058af6d8697263c42bbc79cdd32a1f..2af902a8deffc8f287048147d533f3f66a0d990c 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
  * Whenever there is any discrepancy between the two licenses, \r
  * the BSD license will take precedence. \r
@@ -23,7 +23,9 @@ include('../tohtml.inc.php');
 //==========================\r
 // This code tests an insert\r
 \r
-$sql = "SELECT * FROM ADOXYZ WHERE id = -1"; \r
+$sql = "\r
+SELECT * \r
+FROM ADOXYZ WHERE id = -1"; \r
 // Select an empty record from the database \r
 \r
 $conn = &ADONewConnection("mysql");  // create a connection\r
@@ -52,7 +54,9 @@ $conn->Execute($insertSQL); // Insert the record into the database
 //==========================\r
 // This code tests an update\r
 \r
-$sql = "SELECT * FROM ADOXYZ WHERE lastname=".$conn->qstr($record['lastname']); \r
+$sql = "\r
+SELECT * \r
+FROM ADOXYZ WHERE lastname=".$conn->qstr($record['lastname']); \r
 // Select a record to update \r
 \r
 $rs = $conn->Execute($sql); // Execute the query and get the existing record to update\r
@@ -60,9 +64,9 @@ if (!$rs) print "<p>No record found!</p>";
 $record = array(); // Initialize an array to hold the record data to update\r
 \r
 // Set the values for the fields in the record\r
-$record["firstname"] = "Caroline".rand();\r
-$record["lastname"] = "Smithy"; // Update Caroline's lastname from Miranda to Smith\r
-$record["created"] = '2002-12-'.(rand()%30+1);\r
+$record["firstName"] = "Caroline".rand();\r
+$record["lasTname"] = "Smithy"; // Update Caroline's lastname from Miranda to Smith\r
+$record["creAted"] = '2002-12-'.(rand()%30+1);\r
 \r
 // Pass the single record recordset and the array containing the data to update\r
 // into the GetUpdateSQL function. The function will process the data and return\r
index 8d513653585e972f9603955b2ae8c7c0756cc02e..5bbf03de208db75c573e9823047d87651fce894e 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
index 5669bdb806605732f3b27b5a1a88bdcbce003df7..2848b4716397f744605e03993bb16a030fb907c0 100644 (file)
@@ -2,7 +2,7 @@
 <body>\r
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
index 92bce70dcd22aa3faa7bcdede9062420cacd5e0c..c0871cc4cee2304800b273a4eb34023ad2306bcc 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
   \r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -9,6 +9,7 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
  \r
  /* this file is used by the ADODB test program: test.php */\r
  \r
+\r
 // cannot test databases below, but we include them anyway to check\r
 // if they parse ok...\r
 ADOLoadCode("sybase");\r
@@ -18,10 +19,10 @@ ADOLoadCode("firebird");
 ADOLoadCode("borland_ibase");\r
 ADOLoadCode("informix");\r
 ADOLoadCode("sqlanywhere");\r
-\r
+flush();\r
 if (!empty($testpostgres)) {\r
        //ADOLoadCode("postgres");\r
-       $db = &ADONewConnection('postgres7');\r
+       $db = &ADONewConnection('postgres');\r
        print "<h1>Connecting $db->databaseType...</h1>";\r
        if (@$db->PConnect("localhost","tester","test","test")) {\r
                testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname varchar,created date)");\r
@@ -30,17 +31,16 @@ if (!empty($testpostgres)) {
 }\r
 if (!empty($testibase)) {\r
        \r
-       $db = &ADONewConnection('ibase');\r
+       $db = &ADONewConnection('firebird');\r
        print "<h1>Connecting $db->databaseType...</h1>";\r
-       if (@$db->PConnect("localhost:e:\\interbase\\examples\\database\\employee.gdb", "sysdba", "masterkey", ""))\r
-               testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname char(24),created date)");\r
+       if (@$db->PConnect("localhost:e:\\firebird\\examples\\employee.gdb", "sysdba", "masterkey", ""))\r
+               testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname char(24),price numeric(12,2),created date)");\r
         else print "ERROR: Interbase test requires a database called employee.gdb".'<BR>'.$db->ErrorMsg();\r
        \r
 }\r
 \r
 // REQUIRES ODBC DSN CALLED nwind\r
 if (!empty($testaccess)) {\r
-\r
        $db = &ADONewConnection('access');\r
        print "<h1>Connecting $db->databaseType...</h1>";\r
        \r
@@ -51,7 +51,7 @@ if (!empty($testaccess)) {
 }\r
 \r
 if (!empty($testaccess) && !empty($testado)) { // ADO ACCESS\r
-       \r
+\r
        $db = &ADONewConnection("ado_access");\r
        print "<h1>Connecting $db->databaseType...</h1>";\r
        \r
@@ -68,13 +68,12 @@ if (!empty($testaccess) && !empty($testado)) { // ADO ACCESS
 }\r
 \r
 if (!empty($testvfp)) { // ODBC\r
-\r
-       \r
        $db = &ADONewConnection('vfp');\r
-       print "<h1>Connecting $db->databaseType...</h1>";\r
-       if (@$db->PConnect("logos2", "", "", ""))\r
-               testdb($db,"create table d:\\inetpub\\wwwroot\\logos2\\data\\ADOXYZ (id int, firstname char(24), lastname char(24),created date)");\r
-        else print "ERROR: Visual FoxPro test requires a Windows ODBC DSN=logos2, VFP driver";\r
+       print "<h1>Connecting $db->databaseType...</h1>";flush();\r
+\r
+       if ( $db->PConnect("vfp-adoxyz")) {\r
+               testdb($db,"create table d:\\inetpub\\wwwroot\\php\\vfp\\ADOXYZ (id int, firstname char(24), lastname char(24),created date)");\r
+        } else print "ERROR: Visual FoxPro test requires a Windows ODBC DSN=logos2, VFP driver";\r
        \r
 }\r
 \r
@@ -82,15 +81,30 @@ if (!empty($testvfp)) { // ODBC
 // REQUIRES MySQL server at localhost with database 'test'\r
 if (!empty($testmysql)) { // MYSQL\r
        \r
-       $db = &ADONewConnection('maxsql');\r
+       $db = &ADONewConnection('mysql');\r
+       print "<h1>Connecting $db->databaseType...</h1>";\r
+       if ($HTTP_SERVER_VARS['HTTP_HOST'] == 'localhost') $server = 'localhost';\r
+       else $server = "mangrove";\r
+       if ($db->PConnect('jaguar', "mobydick", "", "test"))\r
+               testdb($db,\r
+               "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");\r
+       else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();\r
+}\r
+\r
+// REQUIRES MySQL server at localhost with database 'test'\r
+if (!empty($testmysqlodbc)) { // MYSQL\r
+       \r
+       $db = &ADONewConnection('odbc');\r
+       $db->hasTransactions = false;\r
        print "<h1>Connecting $db->databaseType...</h1>";\r
        if ($HTTP_SERVER_VARS['HTTP_HOST'] == 'localhost') $server = 'localhost';\r
        else $server = "mangrove";\r
-       if ($db->PConnect($server, "root", "", "test"))\r
+       if ($db->PConnect('mysql', "mobydick", ""))\r
                testdb($db,\r
                "create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");\r
        else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();\r
 }\r
+\r
 if (!empty($testproxy)){\r
        $db = &ADONewConnection('proxy');\r
        print "<h1>Connecting $db->databaseType...</h1>";\r
@@ -149,7 +163,7 @@ if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC
        print "<h1>Connecting DSN-less $db->databaseType...</h1>";\r
        \r
        $myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};"\r
-               . "SERVER=JAGUAR\VSDOTNET;DATABASE=NorthWind;UID=sa;PWD=natsoft;Trusted_Connection=Yes"  ;\r
+               . "SERVER=JAGUAR\VSDOTNET;DATABASE=NorthWind;UID=adodb;PWD=natsoft;Trusted_Connection=No"  ;\r
 \r
                \r
        if (@$db->PConnect($myDSN, "", "", ""))\r
@@ -159,7 +173,7 @@ if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC
 }\r
 \r
 \r
-ADOLoadCode("mssql");\r
+ADOLoadCode("mssqlpo");\r
 if (!empty($testmssql)) { // MS SQL Server -- the extension is buggy -- probably better to use ODBC\r
        $db = ADONewConnection();\r
        $db->debug=1;\r
index 63b28609d33e805c72f298981b53bb20f2e8fc84..d52770355790f47c3a80131c4f49c9f05d775d06 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-       V2.50 14 Nov 2002 \r
+       V3.40 7 April 2003 \r
        \r
        Run multiple copies of this php script at the same time\r
        to test unique generation of id's in multiuser mode\r
index d76367dd0dbb21f21652b178dac71df450965a09..f1a2d93d3094125934dff1a07bc71f8011e015d5 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
  * Whenever there is any discrepancy between the two licenses, \r
  * the BSD license will take precedence. \r
index d93733789857ce3f1f4698680605c714e4277fe7..02f5f02022738ad1424fad5e1e684422b8a550c2 100644 (file)
@@ -2,7 +2,7 @@
 <body>\r
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
index 5bc2e1589549e9819cdbc27bf2583dc242c0804f..3fd21307ef3cb7df1f7f087fadeac9223e067b0a 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
index 7349b5011c612961d4424058a6254912acba4c31..cbbbb211fdaf72e33155a5b46016c557bd0d5fe3 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -15,9 +15,15 @@ error_reporting(E_ALL);
 include_once('../adodb.inc.php');\r
 include_once('../adodb-pager.inc.php');\r
 \r
-$driver = 'mysql';\r
-$sql = 'select ID, firstname as "First Name", lastname as "Last Name", created as "Date Created" from adoxyz  order  by  id';\r
-//$sql = 'select count(unitsinstock),categoryid from products group by categoryid order by 1 ';\r
+$driver = 'oci8';\r
+$sql = 'select  ID, firstname as "First Name", lastname as "Last Name" from adoxyz  order  by  id';\r
+//$sql = 'select count(*),firstname from adoxyz group by firstname order by 2 ';\r
+$sql = 'select distinct firstname, lastname from adoxyz  order  by  firstname';\r
+\r
+if ($driver == 'postgres') {\r
+       $db = NewADOConnection('postgres');\r
+       $db->PConnect('localhost','tester','test','test');\r
+}\r
 \r
 if ($driver == 'access') {\r
        $db = NewADOConnection('access');\r
@@ -26,12 +32,13 @@ if ($driver == 'access') {
 \r
 if ($driver == 'ibase') {\r
        $db = NewADOConnection('ibase');\r
-       $db->PConnect("localhost:e:\\interbase\\examples\\database\\employee.gdb", "sysdba", "masterkey", "");\r
-       $sql = 'select ID, firstname , lastname , created  from adoxyz order by id';\r
+       $db->PConnect("localhost:e:\\firebird\\examples\\employee.gdb", "sysdba", "masterkey", "");\r
+       $sql = 'select distinct firstname, lastname  from adoxyz  order  by  firstname';\r
+\r
 }\r
 if ($driver == 'mssql') {\r
        $db = NewADOConnection('mssql');\r
-       $db->Connect('(local)\NetSDK','','','northwind');\r
+       $db->Connect('JAGUAR\vsdotnet','adodb','natsoft','northwind');\r
 }\r
 if ($driver == 'oci8') {\r
        $db = NewADOConnection('oci8');\r
@@ -71,6 +78,6 @@ print "</pre>";
 $pager = new ADODB_Pager($db,$sql);\r
 $pager->showPageLinks = true;\r
 $pager->linksPerPage = 3;\r
-//$pager->cache = 60;\r
+$pager->cache = 60;\r
 $pager->Render($rows=7);\r
 ?>
\ No newline at end of file
index ba2adad58d682518b73dbd415ffd5ccb63ac2eab..e52ccfd241cd662f25adff0d5414d8ec6452d23e 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
index 4ea455eddae677ca6e99c481f1c0979a7565364f..47ed3f81f781c3e4dc1939fc1e7714cd89d54120 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence. \r
@@ -9,12 +9,19 @@ V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights rese
   Latest version is available at http://php.weblogs.com/\r
 */\r
 \r
-GLOBAL $HTTP_SESSION_VARS;\r
+function NotifyExpire($ref,$key)\r
+{\r
+       print "<p><b>Notify Expiring=$ref, sessionkey=$key</b></p>";\r
+}\r
+$USER = 'JLIM'.rand();\r
+$ADODB_SESSION_EXPIRE_NOTIFY = array('USER','NotifyExpire');\r
 \r
+GLOBAL $HTTP_SESSION_VARS;\r
+       ob_start();\r
        error_reporting(E_ALL);\r
        \r
        $ADODB_SESS_DEBUG = true;\r
-       include('../adodb-session.php');\r
+       include('../adodb-cryptsession.php');\r
        session_start();\r
        \r
        print "<h3>PHP ".PHP_VERSION."</h3>";\r
@@ -28,4 +35,6 @@ GLOBAL $HTTP_SESSION_VARS;
                print "<p>Random session destroy</p>";\r
                session_destroy();\r
        }\r
+       print "<hr>";\r
+       print_r($HTTP_COOKIE_VARS);\r
 ?>
\ No newline at end of file
diff --git a/lib/adodb/tests/time.php b/lib/adodb/tests/time.php
new file mode 100644 (file)
index 0000000..c773f32
--- /dev/null
@@ -0,0 +1,5 @@
+<?php\r
+\r
+include_once('../adodb-time.inc.php');\r
+adodb_date_test();\r
+?>
\ No newline at end of file
diff --git a/lib/adodb/tests/tmssql.php b/lib/adodb/tests/tmssql.php
new file mode 100644 (file)
index 0000000..a3b743c
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+error_reporting(E_ALL);
+ini_set('mssql.datetimeconvert',0); 
+
+function tmssql()
+{
+       print "<h3>mssql</h3>";
+       $db = mssql_connect('JAGUAR\vsdotnet','adodb','natsoft') or die('No Connection');
+       mssql_select_db('northwind',$db);
+       
+       $rs = mssql_query('select getdate() as date',$db);
+       $o = mssql_fetch_row($rs);
+       print_r($o);
+       mssql_free_result($rs);
+       
+       print "<p>Delete</p>"; flush();
+       $rs2 = mssql_query('delete from adoxyz',$db);
+       $p = mssql_num_rows($rs2);
+       mssql_free_result($rs2);
+
+}
+
+function tpear()
+{
+include_once('DB.php');
+
+       print "<h3>PEAR</h3>";
+       $username = 'adodb';
+       $password = 'natsoft';
+       $hostname = 'JAGUAR\vsdotnet';
+       $databasename = 'northwind';
+       
+       $dsn = "mssql://$username:$password@$hostname/$databasename";
+       $conn = &DB::connect($dsn);
+       print "date=".$conn->GetOne('select getdate()')."<br>";
+       @$conn->query('create table tester (id integer)');
+       print "<p>Delete</p>"; flush();
+       $rs = $conn->query('delete from tester');
+       print "date=".$conn->GetOne('select getdate()')."<br>";
+}
+
+function tadodb()
+{
+include_once('../adodb.inc.php');
+
+       print "<h3>ADOdb</h3>";
+       $conn = NewADOConnection('mssql');
+       $conn->Connect('JAGUAR\vsdotnet','adodb','natsoft','northwind');
+//     $conn->debug=1;
+       print "date=".$conn->GetOne('select getdate()')."<br>";
+       $conn->Execute('create table tester (id integer)');
+       print "<p>Delete</p>"; flush();
+       $rs = $conn->Execute('delete from tester');
+       print "date=".$conn->GetOne('select getdate()')."<br>";
+}
+?>
+<a href=tmssql.php?do=tmssql>mssql</a>
+<a href=tmssql.php?do=tpear>pear</a>
+<a href=tmssql.php?do=tadodb>adodb</a>
+<?php
+if (!empty($_GET['do'])) {
+       $do = $_GET['do'];
+       $do();
+}
+?>
\ No newline at end of file
index 60295dfbbe37216afdd485c4c6a54a81a0ee22f1..fa7e0e00ffe7d25d4425ba08d942cedd83f6c98d 100644 (file)
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\r
-\r
-<html>\r
-<head>\r
-       <title>Tips on Writing Portable SQL for Multiple Databases for PHP</title>\r
-</head>\r
-\r
-<body bgcolor=white>\r
-<table width=100% border=0><tr><td><h2>Tips on Writing Portable SQL &nbsp;</h2></td><td>\r
- <div align=right><img src="cute_icons_for_site/adodb.gif"></div></td></tr></table>\r
\r
- If you are writing an application that is used in multiple environments and \r
-  operating systems, you need to plan to support multiple databases. This article \r
-  is based on my experiences with multiple database systems, stretching from 4th \r
-  Dimension in my Mac days, to the databases I currently use, which are: Oracle, \r
-  FoxPro, Access, MS SQL Server and MySQL. Although most of the advice here applies \r
-  to using SQL with Perl, Python and other programming languages, I will focus on PHP and how \r
-  the <a href="http://php.weblogs.com/adodb">ADOdb</a> database abstraction library \r
-  offers some solutions.<p></p>\r
-<p>Most database vendors practice product lock-in. The best or fastest way to \r
-  do things is often implemented using proprietary extensions to SQL. This makes \r
-  it extremely hard to write portable SQL code that performs well under all conditions. \r
-  When the first ANSI committee got together in 1984 to standardize SQL, the database \r
-  vendors had such different implementations that they could only agree on the \r
-  core functionality of SQL. Many important application specific requirements \r
-  were not standardized, and after so many years since the ANSI effort began, \r
-  it looks as if much useful database functionality will never be standardized. \r
-  Even though ANSI-92 SQL has codified much more, we still have to implement portability \r
-  at the application level.</p>\r
-<h3><b>Selects</b></h3>\r
-<p>The SELECT statement has been standardized to a great degree. Nearly every \r
-  database supports the following:</p>\r
-<p>SELECT [cols] FROM [tables]<br>\r
-  &nbsp;&nbsp;[WHERE conditions]<br>\r
-  &nbsp; [GROUP BY cols]<br>\r
-  &nbsp; [HAVING conditions] <br>\r
-  &nbsp; [ORDER BY cols]</p>\r
-<p>But so many useful techniques can only be implemented by using proprietary \r
-  extensions. For example, when writing SQL to retrieve the first 10 rows for \r
-  paging, you could write...</p>\r
-<table width="80%" border="1" cellspacing="0" cellpadding="0" align="center">\r
-  <tr> \r
-       <td><b>Database</b></td>\r
-       <td><b>SQL Syntax</b></td>\r
-  </tr>\r
-  <tr> \r
-       <td>DB2</td>\r
-       <td>select * from table fetch first 10 rows only</td>\r
-  </tr>\r
-  <tr> \r
-       <td>Informix</td>\r
-       <td>select first 10 * from table</td>\r
-  </tr>\r
-  <tr> \r
-       <td>Microsoft SQL Server and Access</td>\r
-       <td>select top 10 * from table</td>\r
-  </tr>\r
-  <tr> \r
-       <td>MySQL and PostgreSQL</td>\r
-       <td>select * from table limit 10</td>\r
-  </tr>\r
-  <tr> \r
-       <td>Oracle 8i</td>\r
-       <td>select * from (select * from table) where rownum &lt;= 10</td>\r
-  </tr>\r
-</table>\r
-<p>This feature of getting a subset of data is so useful that in the PHP class \r
-  library ADOdb, we have a SelectLimit( ) function that allows you to hide the \r
-  implementation details within a function that will rewrite your SQL for you:</p>\r
-<pre>$connection-&gt;SelectLimit('select * from table', 10);\r
-</pre>\r
-<p><b>Selects: Fetch Modes</b></p>\r
-<p>PHP allows you to retrieve database records as arrays. You can choose to have \r
-  the arrays indexed by field name or number. However different low-level PHP \r
-  database drivers are inconsistent in their indexing efforts. ADOdb allows you \r
-  to determine your prefered mode. You set this by setting the variable $ADODB_FETCH_MODE \r
-  to either of the constants ADODB_FETCH_NUM (for numeric indexes) or ADODB_FETCH_ASSOC \r
-  (using field names as an associative index).</p>\r
-<p>The default behaviour of ADOdb varies depending on the database you are using. \r
-  For consistency, set the fetch mode to either ADODB_FETCH_NUM (for speed) or \r
-  ADODB_FETCH_ASSOC (for convenience) at the beginning of your code. </p>\r
-<p><b>Selects: Counting Records</b></p>\r
-<p>Another problem with SELECTs is that some databases do not return the number \r
-  of rows retrieved from a select statement. This is because the highest performance \r
-  databases will return records to you even before the last record has been found. \r
-</p>\r
-<p>In ADOdb, RecordCount( ) returns the number of rows returned, or will emulate \r
-  it by buffering the rows and returning the count after all rows have been returned. \r
-  This can be disabled for performance reasons when retrieving large recordsets \r
-  by setting the global variable $ADODB_COUNTRECS = false. This variable is checked \r
-  every time a query is executed, so you can selectively choose which recordsets \r
-  to count.</p>\r
-<p>If you prefer to set $ADODB_COUNTRECS = false, ADOdb still has the PO_RecordCount( \r
-  ) function. This will return the number of rows, or if it is not found, it will \r
-  return an estimate using SELECT COUNT(*):</p>\r
-<pre>$rs = $db-&gt;Execute(&quot;select * from table where state=$state&quot;);\r
-$numrows = $rs-&gt;PO_RecordCount('table', &quot;state=$state&quot;);</pre>\r
-<p><b>Selects: Locking</b> </p>\r
-<p>SELECT statements are commonly used to implement row-level locking of tables. \r
-  Other databases such as Oracle, Interbase, PostgreSQL and MySQL with InnoDB \r
-  do not require row-level locking because they use versioning to display data \r
-  consistent with a specific point in time.</p>\r
-<p>Currently, I recommend encapsulating the row-level locking in a separate function, \r
-  such as RowLock($table, $where):</p>\r
-<pre>$connection-&gt;BeginTrans( );\r
-$connection-&gt;RowLock($table, $where); </pre>\r
-<pre><font color=green># some operation</font></pre>\r
-<pre>if ($ok) $connection-&gt;CommitTrans( );\r
-else $connection-&gt;RollbackTrans( );\r
-</pre>\r
-<p><b>Selects: Outer Joins</b></p>\r
-<p>Not all databases support outer joins. Furthermore the syntax for outer joins \r
-  differs dramatically between database vendors. One portable (and possibly slower) \r
-  method of implementing outer joins is using UNION.</p>\r
-<p>For example, an ANSI-92 left outer join between two tables t1 and t2 could \r
-  look like:</p>\r
-<pre>SELECT t1.col1, t1.col2, t2.cola <br>  FROM t1 <i>LEFT JOIN</i> t2 ON t1.col = t2.col</pre>\r
-<p>This can be emulated using:</p>\r
-<pre>SELECT t1.col1, t1.col2, t2.cola FROM t1, t2 <br>    WHERE t1.col = t2.col \r
-   UNION ALL\r
-SELECT col1, col2, null FROM t1 <br>      WHERE t1.col not in (select distinct col from t2)\r
-</pre>\r
-<p>Since ADOdb 2.13, we provide some hints in the connection object as to legal \r
-  join variations. This is still incomplete and sometimes depends on the database \r
-  version you are using, but is useful as a general guideline:</p>\r
-<p><font face="Courier New, Courier, mono">$conn-&gt;leftOuter</font>: holds the \r
-  operator used for left outer joins (eg. '*='), or false if not known or not \r
-  available.<br>\r
-  <font face="Courier New, Courier, mono">$conn-&gt;rightOuter</font>: holds the \r
-  operator used for right outer joins (eg '=*'), or false if not known or not \r
-  available.<br>\r
-  <font face="Courier New, Courier, mono">$conn-&gt;ansiOuter</font>: boolean \r
-  that if true means that ANSI-92 style outer joins are supported, or false if \r
-  not known.</p>\r
-<h3><b>Inserts</b> </h3>\r
-<p>When you create records, you need to generate unique id's for each record. \r
-  There are two common techniques: (1) auto-incrementing columns and (2) sequences. \r
-</p>\r
-<p>Auto-incrementing columns are supported by MySQL, Sybase and Microsoft Access \r
-  and SQL Server. However most other databases do not support this feature. So \r
-  for portability, you have little choice but to use sequences. Sequences are \r
-  special functions that return a unique incrementing number every time you call \r
-  it, suitable to be used as database keys. In ADOdb, we use the GenID( ) function. \r
-  It has takes a parameter, the sequence name. Different tables can have different \r
-  sequences. </p>\r
-<pre>$id = $connection-&gt;GenID('sequence_name');<br>$connection-&gt;Execute(&quot;insert into table (id, firstname, lastname) <br>                      values ($id, $firstname, $lastname)&quot;);</pre>\r
-<p>For databases that do not support sequences natively, ADOdb emulates sequences \r
-  by creating a table for every sequence.</p>\r
-<h3><b>Binding</b></h3>\r
-<p>Binding variables in an SQL statement is another tricky feature. Binding is \r
-  useful because it allows pre-compilation of SQL. When inserting multiple records \r
-  into a database in a loop, binding can offer a 50% (or greater) speedup. However \r
-  many databases such as Access and MySQL do not support binding natively and \r
-  there is some overhead in emulating binding. Furthermore, different databases \r
-  (specificly Oracle!) implement binding differently. My recommendation is to \r
-  use binding if your database queries are too slow, but make sure you are using \r
-  a database that supports it like Oracle. </p>\r
-<p>ADOdb supports portable Prepare/Execute with:</p>\r
-<pre>$stmt = $db-&gt;Prepare('select * from customers where custid=? and state=?');\r
-$rs = $db-&gt;Execute($stmt, array($id,'New York'));</pre>\r
-<h2>DDL and Tuning</h2>\r
-<p>There are database design tools such as ERWin or Dezign that allow you to generate \r
-  data definition language commands such as ALTER TABLE or CREATE INDEX from Entity-Relationship \r
-  diagrams. Other developers such as Manuel Lemos have developed portable XML \r
-  based schemas for PHP with Metabase. I think this might suit many developers, \r
-  but I prefer to manually define the database tables. This is because for high \r
-  performance, the placement of tables and selection of the different types of \r
-  indexes has to be planned based on the number of hard disks and the i/o characteristics \r
-  of the data. This can only be done manually. Here are some tuning hints:</p>\r
-<ul>\r
-  <li>The most important and frequently used tables deserve to be placed on their \r
-       own separate hard disks. </li>\r
-  <li>Indexes and data should be kept on different hard disks. </li>\r
-  <li>Transaction logs and rollback segments deserve their own hard disks.</li>\r
-  <li>Using Striping (RAID 5) is only useful when you rarely write to your database. \r
-       Mirroring is a better compromise between reading and writing.</li>\r
-  <li>Consider bypassing the file system and using raw disks.</li>\r
-  <li>Make sure you have asynchronous IO enabled for your database and operating \r
-       system.</li>\r
-  <li>Be prepared to waste space. You probably need at least 5 hard disks for \r
-       a high-performance database system:<br>\r
-       - 1 hard disk for the operating system and temporary data, <br>\r
-       - 1 for data,<br>\r
-       - 1 for indexes, <br>\r
-       - 1 for rollback, <br>\r
-       - 1 for transaction logs.</li>\r
-</ul>\r
-<h3>Data Types</h3>\r
-<p>Stick to a few data types that are available in most databases. Char, varchar \r
-  and numeric/number are supported by most databases. Most other data types (including \r
-  integer, boolean and float) cannot be relied on being available. I recommend \r
-  using char(1) or number(1) to hold booleans. </p>\r
-<p>Different databases have different ways of representing dates and timestamps/datetime. \r
-  ADOdb attempts to display all dates in ISO (YYYY-MM-DD) format. ADOdb also provides \r
-  DBDate( ) and DBTimeStamp( ) to convert dates to formats that are acceptable \r
-  to that database. Both functions accept Unix integer timestamps and date strings \r
-  in ISO format.</p>\r
-<pre>$date1 = $connection-&gt;DBDate(time( ));<br>$date2 = $connection-&gt;DBTimeStamp('2002-02-23 13:03:33');</pre>\r
-<p>We also provide functions to convert database dates to Unix timestamps:</p>\r
-<pre>$unixts = $recordset-&gt;UnixDate('#2002-02-30#'); <font color="green"># MS Access date =&gt; unix timestamp</font></pre>\r
-<p>The maximum length of a char/varchar field is also database specific. You can \r
-  only assume that field lengths of up to 250 characters are supported. This is \r
-  normally impractical for web based forum or content management systems. You \r
-  will need to be familiar with how databases handle large objects (LOBs). ADOdb \r
-  implements two functions, UpdateBlob( ) and UpdateClob( ) that allow you to \r
-  update fields holding Binary Large Objects (eg. pictures) and Character Large \r
-  Objects (eg. HTML articles):</p>\r
-<pre><font color=green># for oracle </font>\r
-$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1,empty_blob())'); \r
-$conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1'); \r
-   \r
-<font color=green># non-oracle databases</font>\r
-$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); \r
-$conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');\r
-</pre>\r
-<p>Null handling is another area where differences can occur. This is a mine-field, \r
-  because 3-value logic is tricky.\r
-<p>In general, I avoid using nulls except for dates and default all my numeric \r
-  and character fields to 0 or the empty string. This maintains consistency with \r
-  PHP, where empty strings and zero are treated as equivalent, and avoids SQL \r
-  ambiguities when you use the ANY and EXISTS operators. However if your database \r
-  has significant amounts of missing or unknown data, using nulls might be a good \r
-  idea. \r
-<h3><b>Stored Procedures</b></h3>\r
-<p>Stored procedures are another problem area. Some databases allow recordsets \r
-  to be returned in a stored procedure (Microsoft SQL Server and Sybase), and \r
-  others only allow output parameters to be returned. Stored procedures sometimes \r
-  need to be wrapped in special syntax. For example, Oracle requires such code \r
-  to be wrapped in an anonymous block with BEGIN and END. Also internal sql operators \r
-  and functions such as +, ||, TRIM( ), SUBSTR( ) or INSTR( ) vary between vendors. \r
-</p>\r
-<p>An example of how to call a stored procedure with 2 parameters and 1 return \r
-  value follows:</p>\r
-<pre>  switch ($db->databaseType) {\r
-       case '<font color="#993300">mssql</font>':\r
-         $sql = <font color="#000000"><font color="#993333">'<font color="#993300">SP_RUNSOMETHING</font>'</font></font>; break;\r
-       case '<font color="#993300">oci8</font>':\r
-         $sql = \r
-<font color="#993300">   </font><font color="#000000"><font color="#993300">&quot;declare RETVAL integer;begin :RETVAL := </font><font color="#000000"><font color="#993333"><font color="#993300">SP_RUNSOMETHING</font></font></font><font color="#993300">(:myid,:group);end;&quot;;\r
-</font>          break;</font>\r
-       default:\r
-         die('<font color="#993300">Unsupported feature</font>');\r
-       }\r
-<font color="#000000"><font color="green">     # @RETVAL = SP_RUNSOMETHING @myid,@group</font>\r
-       $stmt = $db-&gt;PrepareSP($sql);        <br>    $db-&gt;Parameter($stmt,$id,'<font color="#993300">myid</font>'); \r
-       $db-&gt;Parameter($stmt,$group,'<font color="#993300">group</font>');\r
-       <font color="green"># true indicates output parameter<br>       </font>$db-&gt;Parameter($stmt,$ret,'<font color="#993300">RETVAL</font>',true); \r
-       $db-&gt;Execute($stmt); </font></pre>\r
-<p>As you can see, the ADOdb API is the same for both databases. But the stored \r
-  procedure SQL syntax is quite different between databases and is not portable, \r
-  so be forewarned! However sometimes you have little choice as some systems only \r
-  allow data to be accessed via stored procedures. This is when the ultimate portability \r
-  solution might be the only solution: <i>treating portable SQL as a localization \r
-  exercise...</i></p>\r
-<h3><b>SQL as a Localization Exercise</b></h3>\r
-<p> In general to provide real portability, you will have to treat SQL coding \r
-  as a localization exercise. In PHP, it has become common to define separate \r
-  language files for English, Russian, Korean, etc. Similarly, I would suggest \r
-  you have separate Sybase, Intebase, MySQL, etc files, and conditionally include \r
-  the SQL based on the database. For example, each MySQL SQL statement would be \r
-  stored in a separate variable, in a file called 'mysql-lang.inc.php'.</p>\r
-<pre>$sqlGetPassword = '<font color="#993300">select password from users where userid=%s</font>';\r
-$sqlSearchKeyword = &quot;<font color="#993300">SELECT * FROM articles WHERE match (title,body) against (%s</font>)&quot;;</pre>\r
-<p>In our main PHP file:</p>\r
-<pre><font color=green># define which database to load...</font>\r
-<b>$database = '<font color="#993300">mysql</font>';\r
-include_once(&quot;<font color="#993300">$database-lang.inc.php</font>&quot;);</b>\r
-\r
-$db = &amp;NewADOConnection($database);\r
-$db->PConnect(...) or die('<font color="#993300">Failed to connect to database</font>');\r
-\r
-<font color=green># search for a keyword $word</font>\r
-$rs = $db-&gt;Execute(sprintf($sqlSearchKeyWord,$db-&gt;qstr($word)));</pre>\r
-<p>Note that we quote the $word variable using the qstr( ) function. This is because \r
-  each database quotes strings using different conventions.</p>\r
-<p>\r
-<h3>Final Thoughts</h3>\r
-<p>The best way to ensure that you have portable SQL is to have your data tables designed using \r
-sound principles. Learn the theory of normalization and entity-relationship diagrams and model \r
-your data carefully. Understand how joins and indexes work and how they are used to tune performance.\r
-<p> Visit the following page for more references on database theory and vendors: \r
-  <a href="http://php.weblogs.com/sql_tutorial">http://php.weblogs.com/sql_tutorial</a>. \r
-  Also read this article on <a href=http://phplens.com/lens/php-book/optimizing-debugging-php.php>Optimizing PHP</a>.\r
-<p>\r
-<font size=1>(c) 2002 John Lim.</font>\r
-\r
-</body>\r
-</html>\r
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+
+<html>
+<head>
+       <title>Tips on Writing Portable SQL for Multiple Databases for PHP</title>
+</head>
+
+<body bgcolor=white>
+<table width=100% border=0><tr><td><h2>Tips on Writing Portable SQL &nbsp;</h2></td><td>
+ <div align=right><img src="cute_icons_for_site/adodb.gif"></div></td></tr></table>
+ If you are writing an application that is used in multiple environments and 
+  operating systems, you need to plan to support multiple databases. This article 
+  is based on my experiences with multiple database systems, stretching from 4th 
+  Dimension in my Mac days, to the databases I currently use, which are: Oracle, 
+  FoxPro, Access, MS SQL Server and MySQL. Although most of the advice here applies 
+  to using SQL with Perl, Python and other programming languages, I will focus on PHP and how 
+  the <a href="http://php.weblogs.com/adodb">ADOdb</a> database abstraction library 
+  offers some solutions.<p></p>
+<p>Most database vendors practice product lock-in. The best or fastest way to 
+  do things is often implemented using proprietary extensions to SQL. This makes 
+  it extremely hard to write portable SQL code that performs well under all conditions. 
+  When the first ANSI committee got together in 1984 to standardize SQL, the database 
+  vendors had such different implementations that they could only agree on the 
+  core functionality of SQL. Many important application specific requirements 
+  were not standardized, and after so many years since the ANSI effort began, 
+  it looks as if much useful database functionality will never be standardized. 
+  Even though ANSI-92 SQL has codified much more, we still have to implement portability 
+  at the application level.</p>
+<h3><b>Selects</b></h3>
+<p>The SELECT statement has been standardized to a great degree. Nearly every 
+  database supports the following:</p>
+<p>SELECT [cols] FROM [tables]<br>
+  &nbsp;&nbsp;[WHERE conditions]<br>
+  &nbsp; [GROUP BY cols]<br>
+  &nbsp; [HAVING conditions] <br>
+  &nbsp; [ORDER BY cols]</p>
+<p>But so many useful techniques can only be implemented by using proprietary 
+  extensions. For example, when writing SQL to retrieve the first 10 rows for 
+  paging, you could write...</p>
+<table width="80%" border="1" cellspacing="0" cellpadding="0" align="center">
+  <tr> 
+       <td><b>Database</b></td>
+       <td><b>SQL Syntax</b></td>
+  </tr>
+  <tr> 
+       <td>DB2</td>
+       <td>select * from table fetch first 10 rows only</td>
+  </tr>
+  <tr> 
+       <td>Informix</td>
+       <td>select first 10 * from table</td>
+  </tr>
+  <tr> 
+       <td>Microsoft SQL Server and Access</td>
+       <td>select top 10 * from table</td>
+  </tr>
+  <tr> 
+       <td>MySQL and PostgreSQL</td>
+       <td>select * from table limit 10</td>
+  </tr>
+  <tr> 
+       <td>Oracle 8i</td>
+       <td>select * from (select * from table) where rownum &lt;= 10</td>
+  </tr>
+</table>
+<p>This feature of getting a subset of data is so useful that in the PHP class 
+  library ADOdb, we have a SelectLimit( ) function that allows you to hide the 
+  implementation details within a function that will rewrite your SQL for you:</p>
+<pre>$connection-&gt;SelectLimit('select * from table', 10);
+</pre>
+<p><b>Selects: Fetch Modes</b></p>
+<p>PHP allows you to retrieve database records as arrays. You can choose to have 
+  the arrays indexed by field name or number. However different low-level PHP 
+  database drivers are inconsistent in their indexing efforts. ADOdb allows you 
+  to determine your prefered mode. You set this by setting the variable $ADODB_FETCH_MODE 
+  to either of the constants ADODB_FETCH_NUM (for numeric indexes) or ADODB_FETCH_ASSOC 
+  (using field names as an associative index).</p>
+<p>The default behaviour of ADOdb varies depending on the database you are using. 
+  For consistency, set the fetch mode to either ADODB_FETCH_NUM (for speed) or 
+  ADODB_FETCH_ASSOC (for convenience) at the beginning of your code. </p>
+<p><b>Selects: Counting Records</b></p>
+<p>Another problem with SELECTs is that some databases do not return the number 
+  of rows retrieved from a select statement. This is because the highest performance 
+  databases will return records to you even before the last record has been found. 
+</p>
+<p>In ADOdb, RecordCount( ) returns the number of rows returned, or will emulate 
+  it by buffering the rows and returning the count after all rows have been returned. 
+  This can be disabled for performance reasons when retrieving large recordsets 
+  by setting the global variable $ADODB_COUNTRECS = false. This variable is checked 
+  every time a query is executed, so you can selectively choose which recordsets 
+  to count.</p>
+<p>If you prefer to set $ADODB_COUNTRECS = false, ADOdb still has the PO_RecordCount( 
+  ) function. This will return the number of rows, or if it is not found, it will 
+  return an estimate using SELECT COUNT(*):</p>
+<pre>$rs = $db-&gt;Execute(&quot;select * from table where state=$state&quot;);
+$numrows = $rs-&gt;PO_RecordCount('table', &quot;state=$state&quot;);</pre>
+<p><b>Selects: Locking</b> </p>
+<p>SELECT statements are commonly used to implement row-level locking of tables. 
+  Other databases such as Oracle, Interbase, PostgreSQL and MySQL with InnoDB 
+  do not require row-level locking because they use versioning to display data 
+  consistent with a specific point in time.</p>
+<p>Currently, I recommend encapsulating the row-level locking in a separate function, 
+  such as RowLock($table, $where):</p>
+<pre>$connection-&gt;BeginTrans( );
+$connection-&gt;RowLock($table, $where); </pre>
+<pre><font color=green># some operation</font></pre>
+<pre>if ($ok) $connection-&gt;CommitTrans( );
+else $connection-&gt;RollbackTrans( );
+</pre>
+<p><b>Selects: Outer Joins</b></p>
+<p>Not all databases support outer joins. Furthermore the syntax for outer joins 
+  differs dramatically between database vendors. One portable (and possibly slower) 
+  method of implementing outer joins is using UNION.</p>
+<p>For example, an ANSI-92 left outer join between two tables t1 and t2 could 
+  look like:</p>
+<pre>SELECT t1.col1, t1.col2, t2.cola <br>  FROM t1 <i>LEFT JOIN</i> t2 ON t1.col = t2.col</pre>
+<p>This can be emulated using:</p>
+<pre>SELECT t1.col1, t1.col2, t2.cola FROM t1, t2 <br>    WHERE t1.col = t2.col 
+   UNION ALL
+SELECT col1, col2, null FROM t1 <br>      WHERE t1.col not in (select distinct col from t2)
+</pre>
+<p>Since ADOdb 2.13, we provide some hints in the connection object as to legal 
+  join variations. This is still incomplete and sometimes depends on the database 
+  version you are using, but is useful as a general guideline:</p>
+<p><font face="Courier New, Courier, mono">$conn-&gt;leftOuter</font>: holds the 
+  operator used for left outer joins (eg. '*='), or false if not known or not 
+  available.<br>
+  <font face="Courier New, Courier, mono">$conn-&gt;rightOuter</font>: holds the 
+  operator used for right outer joins (eg '=*'), or false if not known or not 
+  available.<br>
+  <font face="Courier New, Courier, mono">$conn-&gt;ansiOuter</font>: boolean 
+  that if true means that ANSI-92 style outer joins are supported, or false if 
+  not known.</p>
+<h3><b>Inserts</b> </h3>
+<p>When you create records, you need to generate unique id's for each record. 
+  There are two common techniques: (1) auto-incrementing columns and (2) sequences. 
+</p>
+<p>Auto-incrementing columns are supported by MySQL, Sybase and Microsoft Access 
+  and SQL Server. However most other databases do not support this feature. So 
+  for portability, you have little choice but to use sequences. Sequences are 
+  special functions that return a unique incrementing number every time you call 
+  it, suitable to be used as database keys. In ADOdb, we use the GenID( ) function. 
+  It has takes a parameter, the sequence name. Different tables can have different 
+  sequences. </p>
+<pre>$id = $connection-&gt;GenID('sequence_name');<br>$connection-&gt;Execute(&quot;insert into table (id, firstname, lastname) <br>                      values ($id, $firstname, $lastname)&quot;);</pre>
+<p>For databases that do not support sequences natively, ADOdb emulates sequences 
+  by creating a table for every sequence.</p>
+<h3><b>Binding</b></h3>
+<p>Binding variables in an SQL statement is another tricky feature. Binding is 
+  useful because it allows pre-compilation of SQL. When inserting multiple records 
+  into a database in a loop, binding can offer a 50% (or greater) speedup. However 
+  many databases such as Access and MySQL do not support binding natively and 
+  there is some overhead in emulating binding. Furthermore, different databases 
+  (specificly Oracle!) implement binding differently. My recommendation is to 
+  use binding if your database queries are too slow, but make sure you are using 
+  a database that supports it like Oracle. </p>
+<p>ADOdb supports portable Prepare/Execute with:</p>
+<pre>$stmt = $db-&gt;Prepare('select * from customers where custid=? and state=?');
+$rs = $db-&gt;Execute($stmt, array($id,'New York'));</pre>
+<h2>DDL and Tuning</h2>
+<p>There are database design tools such as ERWin or Dezign that allow you to generate 
+  data definition language commands such as ALTER TABLE or CREATE INDEX from Entity-Relationship 
+  diagrams. Other developers such as Manuel Lemos have developed portable XML 
+  based schemas for PHP with Metabase. I think this might suit many developers, 
+  but I prefer to manually define the database tables. This is because for high 
+  performance, the placement of tables and selection of the different types of 
+  indexes has to be planned based on the number of hard disks and the i/o characteristics 
+  of the data. This can only be done manually. Here are some tuning hints:</p>
+<ul>
+  <li>The most important and frequently used tables deserve to be placed on their 
+       own separate hard disks. </li>
+  <li>Indexes and data should be kept on different hard disks. </li>
+  <li>Transaction logs and rollback segments deserve their own hard disks.</li>
+  <li>Using Striping (RAID 5) is only useful when you rarely write to your database. 
+       Mirroring is a better compromise between reading and writing.</li>
+  <li>Consider bypassing the file system and using raw disks.</li>
+  <li>Make sure you have asynchronous IO enabled for your database and operating 
+       system.</li>
+  <li>Be prepared to waste space. You probably need at least 5 hard disks for 
+       a high-performance database system:<br>
+       - 1 hard disk for the operating system and temporary data, <br>
+       - 1 for data,<br>
+       - 1 for indexes, <br>
+       - 1 for rollback, <br>
+       - 1 for transaction logs.</li>
+</ul>
+<h3>Data Types</h3>
+<p>Stick to a few data types that are available in most databases. Char, varchar 
+  and numeric/number are supported by most databases. Most other data types (including 
+  integer, boolean and float) cannot be relied on being available. I recommend 
+  using char(1) or number(1) to hold booleans. </p>
+<p>Different databases have different ways of representing dates and timestamps/datetime. 
+  ADOdb attempts to display all dates in ISO (YYYY-MM-DD) format. ADOdb also provides 
+  DBDate( ) and DBTimeStamp( ) to convert dates to formats that are acceptable 
+  to that database. Both functions accept Unix integer timestamps and date strings 
+  in ISO format.</p>
+<pre>$date1 = $connection-&gt;DBDate(time( ));<br>$date2 = $connection-&gt;DBTimeStamp('2002-02-23 13:03:33');</pre>
+<p>We also provide functions to convert database dates to Unix timestamps:</p>
+<pre>$unixts = $recordset-&gt;UnixDate('#2002-02-30#'); <font color="green"># MS Access date =&gt; unix timestamp</font></pre>
+<p>The maximum length of a char/varchar field is also database specific. You can 
+  only assume that field lengths of up to 250 characters are supported. This is 
+  normally impractical for web based forum or content management systems. You 
+  will need to be familiar with how databases handle large objects (LOBs). ADOdb 
+  implements two functions, UpdateBlob( ) and UpdateClob( ) that allow you to 
+  update fields holding Binary Large Objects (eg. pictures) and Character Large 
+  Objects (eg. HTML articles):</p>
+<pre><font color=green># for oracle </font>
+$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1,empty_blob())'); 
+$conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1'); 
+   
+<font color=green># non-oracle databases</font>
+$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); 
+$conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');
+</pre>
+<p>Null handling is another area where differences can occur. This is a mine-field, 
+  because 3-value logic is tricky.
+<p>In general, I avoid using nulls except for dates and default all my numeric 
+  and character fields to 0 or the empty string. This maintains consistency with 
+  PHP, where empty strings and zero are treated as equivalent, and avoids SQL 
+  ambiguities when you use the ANY and EXISTS operators. However if your database 
+  has significant amounts of missing or unknown data, using nulls might be a good 
+  idea. 
+<h3><b>Stored Procedures</b></h3>
+<p>Stored procedures are another problem area. Some databases allow recordsets 
+  to be returned in a stored procedure (Microsoft SQL Server and Sybase), and 
+  others only allow output parameters to be returned. Stored procedures sometimes 
+  need to be wrapped in special syntax. For example, Oracle requires such code 
+  to be wrapped in an anonymous block with BEGIN and END. Also internal sql operators 
+  and functions such as +, ||, TRIM( ), SUBSTR( ) or INSTR( ) vary between vendors. 
+</p>
+<p>An example of how to call a stored procedure with 2 parameters and 1 return 
+  value follows:</p>
+<pre>  switch ($db->databaseType) {
+       case '<font color="#993300">mssql</font>':
+         $sql = <font color="#000000"><font color="#993333">'<font color="#993300">SP_RUNSOMETHING</font>'</font></font>; break;
+       case '<font color="#993300">oci8</font>':
+         $sql = 
+<font color="#993300">   </font><font color="#000000"><font color="#993300">&quot;declare RETVAL integer;begin :RETVAL := </font><font color="#000000"><font color="#993333"><font color="#993300">SP_RUNSOMETHING</font></font></font><font color="#993300">(:myid,:group);end;&quot;;
+</font>          break;</font>
+       default:
+         die('<font color="#993300">Unsupported feature</font>');
+       }
+<font color="#000000"><font color="green">     # @RETVAL = SP_RUNSOMETHING @myid,@group</font>
+       $stmt = $db-&gt;PrepareSP($sql);        <br>    $db-&gt;Parameter($stmt,$id,'<font color="#993300">myid</font>'); 
+       $db-&gt;Parameter($stmt,$group,'<font color="#993300">group</font>');
+       <font color="green"># true indicates output parameter<br>       </font>$db-&gt;Parameter($stmt,$ret,'<font color="#993300">RETVAL</font>',true); 
+       $db-&gt;Execute($stmt); </font></pre>
+<p>As you can see, the ADOdb API is the same for both databases. But the stored 
+  procedure SQL syntax is quite different between databases and is not portable, 
+  so be forewarned! However sometimes you have little choice as some systems only 
+  allow data to be accessed via stored procedures. This is when the ultimate portability 
+  solution might be the only solution: <i>treating portable SQL as a localization 
+  exercise...</i></p>
+<h3><b>SQL as a Localization Exercise</b></h3>
+<p> In general to provide real portability, you will have to treat SQL coding 
+  as a localization exercise. In PHP, it has become common to define separate 
+  language files for English, Russian, Korean, etc. Similarly, I would suggest 
+  you have separate Sybase, Intebase, MySQL, etc files, and conditionally include 
+  the SQL based on the database. For example, each MySQL SQL statement would be 
+  stored in a separate variable, in a file called 'mysql-lang.inc.php'.</p>
+<pre>$sqlGetPassword = '<font color="#993300">select password from users where userid=%s</font>';
+$sqlSearchKeyword = &quot;<font color="#993300">SELECT * FROM articles WHERE match (title,body) against (%s</font>)&quot;;</pre>
+<p>In our main PHP file:</p>
+<pre><font color=green># define which database to load...</font>
+<b>$database = '<font color="#993300">mysql</font>';
+include_once(&quot;<font color="#993300">$database-lang.inc.php</font>&quot;);</b>
+
+$db = &amp;NewADOConnection($database);
+$db->PConnect(...) or die('<font color="#993300">Failed to connect to database</font>');
+
+<font color=green># search for a keyword $word</font>
+$rs = $db-&gt;Execute(sprintf($sqlSearchKeyWord,$db-&gt;qstr($word)));</pre>
+<p>Note that we quote the $word variable using the qstr( ) function. This is because 
+  each database quotes strings using different conventions.</p>
+<p>
+<h3>Final Thoughts</h3>
+<p>The best way to ensure that you have portable SQL is to have your data tables designed using 
+sound principles. Learn the theory of normalization and entity-relationship diagrams and model 
+your data carefully. Understand how joins and indexes work and how they are used to tune performance.
+<p> Visit the following page for more references on database theory and vendors: 
+  <a href="http://php.weblogs.com/sql_tutorial">http://php.weblogs.com/sql_tutorial</a>. 
+  Also read this article on <a href=http://phplens.com/lens/php-book/optimizing-debugging-php.php>Optimizing PHP</a>.
+<p>
+<font size=1>(c) 2002 John Lim.</font>
+
+</body>
+</html>
index c18bc07e971be42e9bd85e952b6ba473d5aac2f5..36894a2ef4f0039e0a95395d3a48e416e1d10205 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /** \r
- * @version V2.50 14 Nov 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
  * Released under both BSD license and Lesser GPL library license. \r
  * Whenever there is any discrepancy between the two licenses, \r
  * the BSD license will take precedence. \r
index 76dc1111250ba26abb21dcd1c4a8a197c116d7bc..d25580f762c42a291b2e19fa234de9115d3231ac 100644 (file)
@@ -1,6 +1,6 @@
 <?php \r
 /*\r
-V2.50 14 Nov 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V3.40 7 April 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.\r
   Released under both BSD license and Lesser GPL library license. \r
   Whenever there is any discrepancy between the two licenses, \r
   the BSD license will take precedence.\r
@@ -62,10 +62,11 @@ GLOBAL $gSQLMaxRows,$gSQLBlockRows;
        }\r
 \r
        print $hdr."\n\n";\r
-       \r
        // smart algorithm - handles ADODB_FETCH_MODE's correctly!\r
        $numoffset = isset($rs->fields[0]);\r
+\r
        while (!$rs->EOF) {\r
+               \r
                $s .= "<TR valign=top>\n";\r
                \r
                for ($i=0, $v=($numoffset) ? $rs->fields[0] : reset($rs->fields); \r
index b060a98513b9192bf12c564c989021419a4b4e6e..3f2261e62de9808f5ac794d12c6ab860a1b1dee7 100644 (file)
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\r
-\r
-<html>\r
-<head>\r
-       <title>Tutorial: Moving from MySQL to ADODB</title>\r
-</head>\r
-\r
-<body bgcolor=white>\r
-<h1>Tutorial: Moving from MySQL to ADODB</h1>\r
-\r
-<pre>          You say eether and I say eyether, \r
-               You say neether and I say nyther; \r
-               Eether, eyether, neether, nyther - \r
-               Let's call the whole thing off ! \r
-<br>\r
-               You like potato and I like po-tah-to, \r
-               You like tomato and I like to-mah-to; \r
-               Potato, po-tah-to, tomato, to-mah-to - \r
-               Let's call the whole thing off ! \r
-</pre>\r
-<p>I love this song, especially the version with Louis Armstrong and Ella singing \r
-  duet. It is all about how hard it is for two people in love to be compatible \r
-  with each other. It's about compromise and finding a common ground, and that's \r
-  what this article is all about. \r
-<p>PHP is all about creating dynamic web-sites with the least fuss and the most \r
-  fun. To create these websites we need to use databases to retrieve login information, \r
-  to splash dynamic news onto the web page and store forum postings. So let's \r
-  say we were using the popular MySQL database for this. Your company has done \r
-  such a fantastic job that the Web site is more popular than your wildest dreams. \r
-  You find that MySQL cannot scale to handle the workload; time to switch databases. \r
-<p> Unfortunately in PHP every database is accessed slightly differently. To connect \r
-  to MySQL, you would use <i>mysql_connect()</i>; when you decide to upgrade to \r
-  Oracle or Microsoft SQL Server, you would use <i>ocilogon() </i>or <i>mssql_connect()</i> \r
-  respectively. What is worse is that the parameters you use for the different \r
-  connect functions are different also.. One database says po-tato, the other \r
-  database says pota-to. Oh-oh. \r
-<h3>Let's NOT call the whole thing off</h3>\r
-<p>A database wrapper library such as ADODB comes in handy when you need to ensure portability. It provides \r
-  you with a common API to communicate with any supported database so you don't have to call things off. <p>\r
-\r
-<p>ADODB stands for Active Data Objects DataBase (sorry computer guys are sometimes \r
-  not very original). ADODB currently supports MySQL, PostgreSQL, Oracle, Interbase, \r
-  Microsoft SQL Server, Access, FoxPro, Sybase, ODBC and ADO. You can download \r
-  ADODB from <a href=http://php.weblogs.com/adodb></a><a href="http://php.weblogs.com/adodb">http://php.weblogs.com/adodb</a>.\r
-<h3>MySQL Example</h3>\r
-<p>The most common database used with PHP is MySQL, so I guess you should be familiar \r
-  with the following code. It connects to a MySQL server at <i>localhost</i>, \r
-  database <i>mydb</i>, and executes an SQL select statement. The results are \r
-  printed, one line per row. \r
-<pre><font color="#666600">$db = <b>mysql_connect</b>(&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;);\r
-<b>mysql_select_db</b>(&quot;mydb&quot;,$db);</font>\r
-<font color="#660000">$result = <b>mysql_query</b>(&quot;SELECT * FROM employees&quot;,$db)</font><code><font color="#663300">;\r
-if ($result === false) die(&quot;failed&quot;);</font></code> \r
-<font color="#006666"><b>while</b> ($fields =<b> mysql_fetch_row</b>($result)) &#123;\r
- <b>for</b> ($i=0, $max=sizeof($fields); $i &lt; $max; $i++) &#123;\r
-               <b>print</b> $fields[$i].' ';\r
- &#125;\r
- <b>print</b> &quot;&lt;br&gt;\n&quot;;\r
-&#125;</font> \r
-</pre>\r
-<p>The above code has been color-coded by section. The first section is the connection \r
-  phase. The second is the execution of the SQL, and the last section is displaying \r
-  the fields. The <i>while</i> loop scans the rows of the result, while the <i>for</i> \r
-  loop scans the fields in one row.</p>\r
-<p>Here is the equivalent code in ADODB</p>\r
-<pre><b><font color="#666600"> include(&quot;adodb.inc.php&quot;);</font></b><font color="#666600">\r
- $db = <b>NewADOConnection</b>('mysql');\r
- $db-&gt;<b>Connect</b>(&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;, &quot;mydb&quot;);</font>\r
- <font color="#663300">$result = $db-&gt;<b>Execute</b>(&quot;SELECT * FROM employees&quot;);\r
- </font><font color="#663300"></font><code><font color="#663300">if ($result === false) die(&quot;failed&quot;)</font></code><code><font color="#663300">;</font></code>  \r
- <font color="#006666"><b>while</b> (!$result-&gt;EOF) &#123;\r
-       <b>for</b> ($i=0, $max=$result-&gt;<b>FieldCount</b>(); $i &lt; $max; $i++)\r
-                  <b>print</b> $result-&gt;fields[$i].' ';\r
-       $result-&gt;<b>MoveNext</b>();\r
-       <b>print</b> &quot;&lt;br&gt;\n&quot;;\r
- &#125;</font> </pre>\r
-<p></p>\r
-<p>Now porting to Oracle is as simple as changing the second line to <code>NewADOConnection('oracle')</code>. \r
-  Let's walk through the code...</p>\r
-<h3>Connecting to the Database</h3>\r
-<p></p>\r
-<pre><b><font color="#666600">include(&quot;adodb.inc.php&quot;);</font></b><font color="#666600">\r
-$db = <b>NewADOConnection</b>('mysql');\r
-$db-&gt;<b>Connect</b>(&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;, &quot;mydb&quot;);</font></pre>\r
-<p>The connection code is a bit more sophisticated than MySQL's because our needs \r
-  are more sophisticated. In ADODB, we use an object-oriented approach to managing \r
-  the complexity of handling multiple databases. We have different classes to \r
-  handle different databases. If you aren't familiar with object-oriented programing, \r
-  don't worry -- the complexity is all hidden away in the<code> NewADOConnection()</code> \r
-  function.</p>\r
-<p>To conserve memory, we only load the PHP code specific to the database you \r
-  are connecting to. We do this by calling <code>NewADOConnection(databasedriver)</code>. \r
-  Legal database drivers include <i>mysql, mssql, oracle, oci8, postgres, sybase, \r
-  vfp, access, ibase </i>and many others.</p>\r
-<p>Then we create a new instance of the connection class by calling <code>NewADOConnection()</code>. \r
-  Finally we connect to the database using <code>$db-&gt;Connect(). </code></p>\r
-<h3>Executing the SQL</h3>\r
-<p><code><font color="#663300">$result = $db-&gt;<b>Execute</b>(&quot;SELECT * \r
-  FROM employees&quot;);<br>\r
-  if ($result === false) die(&quot;failed&quot;)</font></code><code><font color="#663300">;</font></code> \r
-  <br>\r
-</p>\r
-<p>Sending the SQL statement to the server is straight forward. Execute() will \r
-  return a recordset object on successful execution. You should check $result \r
-  as we do above.\r
-<p>An issue that confuses beginners is the fact that we have two types of objects \r
-  in ADODB, the connection object and the recordset object. When do we use each?\r
-<p>The connection object ($db) is responsible for connecting to the database, \r
-  formatting your SQL and querying the database server. The recordset object ($result) \r
-  is responsible for retrieving the results and formatting the reply as text or \r
-  as an array.\r
-<p>The only thing I need to add is that ADODB provides several helper functions \r
-  for making INSERT and UPDATE statements easier, which we will cover in the Advanced \r
-  section. \r
-<h3>Retrieving the Data<br>\r
-</h3>\r
-<pre><font color="#006666"><b>while</b> (!$result-&gt;EOF) &#123;\r
-   <b>for</b> ($i=0, $max=$result-&gt;<b>FieldCount</b>(); $i &lt; $max; $i++)\r
-          <b>print</b> $result-&gt;fields[$i].' ';\r
-   $result-&gt;<b>MoveNext</b>();\r
-   <b>print</b> &quot;&lt;br&gt;\n&quot;;\r
-&#125;</font></pre>\r
-<p>The paradigm for getting the data is that it's like reading a file. For every \r
-  line, we check first whether we have reached the end-of-file (EOF). While not \r
-  end-of-file, loop through each field in the row. Then move to the next line \r
-  (MoveNext) and repeat. \r
-<p>The <code>$result-&gt;fields[]</code> array is generated by the PHP database \r
-  extension. Some database extensions do not index the array by field name. \r
-  To force indexing by name - that is associative arrays - \r
-  use the $ADODB_FETCH_MODE global variable. \r
-<pre>\r
-       $<b>ADODB_FETCH_MODE</b> = ADODB_FETCH_NUM;\r
-       $rs1 = $db->Execute('select * from table');\r
-       $<b>ADODB_FETCH_MODE</b> = ADODB_FETCH_ASSOC;\r
-       $rs2 = $db->Execute('select * from table');\r
-       print_r($rs1->fields); // shows <i>array([0]=>'v0',[1] =>'v1')</i>\r
-       print_r($rs2->fields); // shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i>\r
-</pre>\r
-<p>\r
-As you can see in the above example, both recordsets store and use different fetch modes\r
-based on the $ADODB_FETCH_MODE setting when the recordset was created by Execute().</p>\r
-<h2>ADOConnection<a name="ADOConnection"></a></h2>\r
-<p>Object that performs the connection to the database, executes SQL statements \r
-  and has a set of utility functions for standardising the format of SQL statements \r
-  for issues such as concatenation and date formats.</p>\r
-  \r
-<h3>Other Useful Functions</h3>\r
-<p><code>$recordset-&gt;Move($pos)</code> scrolls to that particular row. ADODB supports forward \r
-  scrolling for all databases. Some databases will not support backwards scrolling. \r
-  This is normally not a problem as you can always cache records to simulate backwards \r
-  scrolling. \r
-<p><code>$recordset-&gt;RecordCount()</code> returns the number of records accessed by the \r
-  SQL statement. Some databases will return -1 because it is not supported. \r
-<p><code>$recordset-&gt;GetArray()</code> returns the result as an array. \r
-<p><code>rs2html($recordset)</code> is a function that is generates a HTML table based on the \r
-  $recordset passed to it. An example with the relevant lines in bold:\r
-<pre>   include('adodb.inc.php'); \r
-   <b>include('tohtml.inc.php');</b> /* includes the rs2html function */\r
-   $conn = &amp;ADONewConnection('mysql'); \r
-   $conn-&gt;PConnect('localhost','userid','password','database');\r
-   $rs = $conn-&gt;Execute('select * from table');\r
-  <b> rs2html($rs)</b>; /* recordset to html table */ </pre>\r
-<p>There are many other helper functions that are listed in the documentation available at <a href="http://php.weblogs.com/adodb_manual"></a><a href="http://php.weblogs.com/adodb_manual">http://php.weblogs.com/adodb_manual</a>. \r
-<h2>Advanced Material</h2>\r
-<h3>Inserts and Updates </h3>\r
-<p>Let's say you want to insert the following data into a database. \r
-<p><b>ID</b> = 3<br>\r
-  <b>TheDate</b>=mktime(0,0,0,8,31,2001) /* 31st August 2001 */<br>\r
-  <b>Note</b>= sugar why don't we call it off \r
-<p>When you move to another database, your insert might no longer work.</p>\r
-<p>The first problem is that each database has a different default date format. \r
-  MySQL expects YYYY-MM-DD format, while other databases have different defaults. \r
-  ADODB has a function called DBDate() that addresses this issue by converting \r
-  converting the date to the correct format.</p>\r
-<p>The next problem is that the <b>don't</b> in the Note needs to be quoted. In \r
-  MySQL, we use <b>don\'t</b> but in some other databases (Sybase, Access, Microsoft \r
-  SQL Server) we use <b>don''t. </b>The qstr() function addresses this issue.</p>\r
-<p>So how do we use the functions? Like this:</p>\r
-<pre>$sql = &quot;INSERT INTO table (id, thedate,note) values (&quot; \r
-   . $<b>ID</b> . ','\r
-   . $db-&gt;DBDate($<b>TheDate</b>) .','\r
-   . $db-&gt;qstr($<b>Note</b>).&quot;)&quot;;\r
-$db-&gt;Execute($sql);</pre>\r
-<p>ADODB also supports <code>$connection-&gt;Affected_Rows()</code> (returns the \r
-  number of rows affected by last update or delete) and <code>$recordset-&gt;Insert_ID()</code> \r
-  (returns last autoincrement number generated by an insert statement). Be forewarned \r
-  that not all databases support the two functions.<br>\r
-</p>\r
-<h3>MetaTypes</h3>\r
-<p>You can find out more information about each of the fields (I use the words \r
-  fields and columns interchangebly) you are selecting by calling the recordset \r
-  method <code>FetchField($fieldoffset)</code>. This will return an object with \r
-  3 properties: name, type and max_length. \r
-<pre>For example:</pre>\r
-<pre>$recordset = $conn-&gt;Execute(&quot;select adate from table&quot;);<br>$f0 = $recordset-&gt;FetchField(0);\r
-</pre>\r
-<p>Then <code>$f0-&gt;name</code> will hold <i>'adata'</i>, <code>$f0-&gt;type</code> \r
-  will be set to '<i>date'</i>. If the max_length is unknown, it will be set to \r
-  -1. \r
-<p>One problem with handling different databases is that each database often calls \r
-  the same type by a different name. For example a <i>timestamp</i> type is called \r
-  <i>datetime</i> in one database and <i>time</i> in another. So ADODB has a special \r
-  <code>MetaType($type, $max_length)</code> function that standardises the types \r
-  to the following: \r
-<p>C: character and varchar types<br>\r
-  X: text or long character (eg. more than 255 bytes wide).<br>\r
-  B: blob or binary image<br>\r
-  D: date<br>\r
-  T: timestamp<br>\r
-  L: logical (boolean)<br>\r
-  I: integer<br>\r
-  N: numeric (float, double, money) \r
-<p>In the above date example, \r
-<p><code>$recordset = $conn-&gt;Execute(&quot;select adate from table&quot;);<br>\r
-  $f0 = $recordset-&gt;FetchField(0);<br>\r
-  $type = $recordset-&gt;MetaType($f0-&gt;type, $f0-&gt;max_length);<br>\r
-  print $type; /* should print 'D'</code> */\r
-<p> \r
-<p><b>Select Limit and Top Support</b> \r
-<p>ADODB has a function called $connection->SelectLimit($sql,$nrows,$offset) that allows\r
-you to retrieve a subset of the recordset. This will take advantage of native\r
-SELECT TOP on Microsoft products and SELECT ... LIMIT with PostgreSQL and MySQL, and\r
-emulated if the database does not support it.\r
-<p><b>Caching Support</b> \r
-<p>ADODB allows you to cache recordsets in your file system, and only requery the database\r
-server after a certain timeout period with $connection->CacheExecute($secs2cache,$sql) and \r
-$connection->CacheSelectLimit($secs2cache,$sql,$nrows,$offset).\r
-<p><b>PHP4 Session Handler Support</b> \r
-<p>ADODB also supports PHP4 session handlers. You can store your session variables \r
-  in a database for true scalability using ADODB. For further information, visit \r
-  <a href="http://php.weblogs.com/adodb-sessions"></a><a href="http://php.weblogs.com/adodb-sessions">http://php.weblogs.com/adodb-sessions</a>\r
-<h3>Commercial Use Encouraged</h3>\r
-<p>If you plan to write commercial PHP applications that you want to resell, you should consider ADODB. It has been released using the lesser GPL, which means you can legally include it in commercial applications, while keeping your code proprietary. Commercial use of ADODB is strongly encouraged! We are using it internally for this reason.<p>\r
-\r
-<h2>Conclusion</h2>\r
-<p>As a thank you for finishing this article, here are the complete lyrics for \r
-  <i>let's call the whole thing off</i>.<br>\r
-  <br>\r
-<pre>\r
-   Refrain \r
-<br>\r
-               You say eether and I say eyether, \r
-               You say neether and I say nyther; \r
-               Eether, eyether, neether, nyther - \r
-               Let's call the whole thing off ! \r
-<br>\r
-               You like potato and I like po-tah-to, \r
-               You like tomato and I like to-mah-to; \r
-               Potato, po-tah-to, tomato, to-mah-to - \r
-               Let's call the whole thing off ! \r
-<br>\r
-But oh, if we call the whole thing off, then we must part. \r
-And oh, if we ever part, then that might break my heart. \r
-<br>\r
-               So, if you like pajamas and I like pa-jah-mas, \r
-               I'll wear pajamas and give up pa-jah-mas. \r
-               For we know we \r
-               Need each other, so we \r
-               Better call the calling off off. \r
-               Let's call the whole thing off ! \r
-<br>\r
-   Second Refrain \r
-<br>\r
-               You say laughter and I say lawfter, \r
-               You say after and I say awfter; \r
-               Laughter, lawfter, after, awfter - \r
-               Let's call the whole thing off ! \r
-<br>\r
-               You like vanilla and I like vanella, \r
-               You, sa's'parilla and I sa's'parella; \r
-               Vanilla, vanella, choc'late, strawb'ry - \r
-               Let's call the whole thing off ! \r
-<br>\r
-But oh, if we call the whole thing off, then we must part. \r
-And oh, if we ever part, then that might break my heart. \r
-<br>\r
-               So, if you go for oysters and I go for ersters, \r
-               I'll order oysters and cancel the ersters. \r
-               For we know we \r
-               Need each other, so we \r
-               Better call the calling off off. \r
-               Let's call the whole thing off ! \r
-  </pre>\r
-<p><font size=2>Song and lyrics by George and Ira Gershwin, introduced by Fred Astaire and Ginger Rogers\r
-in the film "Shall We Dance?"  </font><p>\r
-<p>\r
-(c)2001-2002 John Lim.\r
-\r
-</body>\r
-</html>\r
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+
+<html>
+<head>
+       <title>Tutorial: Moving from MySQL to ADODB</title>
+</head>
+
+<body bgcolor=white>
+<h1>Tutorial: Moving from MySQL to ADODB</h1>
+
+<pre>          You say eether and I say eyether, 
+               You say neether and I say nyther; 
+               Eether, eyether, neether, nyther - 
+               Let's call the whole thing off ! 
+<br>
+               You like potato and I like po-tah-to, 
+               You like tomato and I like to-mah-to; 
+               Potato, po-tah-to, tomato, to-mah-to - 
+               Let's call the whole thing off ! 
+</pre>
+<p>I love this song, especially the version with Louis Armstrong and Ella singing 
+  duet. It is all about how hard it is for two people in love to be compatible 
+  with each other. It's about compromise and finding a common ground, and that's 
+  what this article is all about. 
+<p>PHP is all about creating dynamic web-sites with the least fuss and the most 
+  fun. To create these websites we need to use databases to retrieve login information, 
+  to splash dynamic news onto the web page and store forum postings. So let's 
+  say we were using the popular MySQL database for this. Your company has done 
+  such a fantastic job that the Web site is more popular than your wildest dreams. 
+  You find that MySQL cannot scale to handle the workload; time to switch databases. 
+<p> Unfortunately in PHP every database is accessed slightly differently. To connect 
+  to MySQL, you would use <i>mysql_connect()</i>; when you decide to upgrade to 
+  Oracle or Microsoft SQL Server, you would use <i>ocilogon() </i>or <i>mssql_connect()</i> 
+  respectively. What is worse is that the parameters you use for the different 
+  connect functions are different also.. One database says po-tato, the other 
+  database says pota-to. Oh-oh. 
+<h3>Let's NOT call the whole thing off</h3>
+<p>A database wrapper library such as ADODB comes in handy when you need to ensure portability. It provides 
+  you with a common API to communicate with any supported database so you don't have to call things off. <p>
+
+<p>ADODB stands for Active Data Objects DataBase (sorry computer guys are sometimes 
+  not very original). ADODB currently supports MySQL, PostgreSQL, Oracle, Interbase, 
+  Microsoft SQL Server, Access, FoxPro, Sybase, ODBC and ADO. You can download 
+  ADODB from <a href=http://php.weblogs.com/adodb></a><a href="http://php.weblogs.com/adodb">http://php.weblogs.com/adodb</a>.
+<h3>MySQL Example</h3>
+<p>The most common database used with PHP is MySQL, so I guess you should be familiar 
+  with the following code. It connects to a MySQL server at <i>localhost</i>, 
+  database <i>mydb</i>, and executes an SQL select statement. The results are 
+  printed, one line per row. 
+<pre><font color="#666600">$db = <b>mysql_connect</b>(&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;);
+<b>mysql_select_db</b>(&quot;mydb&quot;,$db);</font>
+<font color="#660000">$result = <b>mysql_query</b>(&quot;SELECT * FROM employees&quot;,$db)</font><code><font color="#663300">;
+if ($result === false) die(&quot;failed&quot;);</font></code> 
+<font color="#006666"><b>while</b> ($fields =<b> mysql_fetch_row</b>($result)) &#123;
+ <b>for</b> ($i=0, $max=sizeof($fields); $i &lt; $max; $i++) &#123;
+               <b>print</b> $fields[$i].' ';
+ &#125;
+ <b>print</b> &quot;&lt;br&gt;\n&quot;;
+&#125;</font> 
+</pre>
+<p>The above code has been color-coded by section. The first section is the connection 
+  phase. The second is the execution of the SQL, and the last section is displaying 
+  the fields. The <i>while</i> loop scans the rows of the result, while the <i>for</i> 
+  loop scans the fields in one row.</p>
+<p>Here is the equivalent code in ADODB</p>
+<pre><b><font color="#666600"> include(&quot;adodb.inc.php&quot;);</font></b><font color="#666600">
+ $db = <b>NewADOConnection</b>('mysql');
+ $db-&gt;<b>Connect</b>(&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;, &quot;mydb&quot;);</font>
+ <font color="#663300">$result = $db-&gt;<b>Execute</b>(&quot;SELECT * FROM employees&quot;);
+ </font><font color="#663300"></font><code><font color="#663300">if ($result === false) die(&quot;failed&quot;)</font></code><code><font color="#663300">;</font></code>  
+ <font color="#006666"><b>while</b> (!$result-&gt;EOF) &#123;
+       <b>for</b> ($i=0, $max=$result-&gt;<b>FieldCount</b>(); $i &lt; $max; $i++)
+                  <b>print</b> $result-&gt;fields[$i].' ';
+       $result-&gt;<b>MoveNext</b>();
+       <b>print</b> &quot;&lt;br&gt;\n&quot;;
+ &#125;</font> </pre>
+<p></p>
+<p>Now porting to Oracle is as simple as changing the second line to <code>NewADOConnection('oracle')</code>. 
+  Let's walk through the code...</p>
+<h3>Connecting to the Database</h3>
+<p></p>
+<pre><b><font color="#666600">include(&quot;adodb.inc.php&quot;);</font></b><font color="#666600">
+$db = <b>NewADOConnection</b>('mysql');
+$db-&gt;<b>Connect</b>(&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;, &quot;mydb&quot;);</font></pre>
+<p>The connection code is a bit more sophisticated than MySQL's because our needs 
+  are more sophisticated. In ADODB, we use an object-oriented approach to managing 
+  the complexity of handling multiple databases. We have different classes to 
+  handle different databases. If you aren't familiar with object-oriented programing, 
+  don't worry -- the complexity is all hidden away in the<code> NewADOConnection()</code> 
+  function.</p>
+<p>To conserve memory, we only load the PHP code specific to the database you 
+  are connecting to. We do this by calling <code>NewADOConnection(databasedriver)</code>. 
+  Legal database drivers include <i>mysql, mssql, oracle, oci8, postgres, sybase, 
+  vfp, access, ibase </i>and many others.</p>
+<p>Then we create a new instance of the connection class by calling <code>NewADOConnection()</code>. 
+  Finally we connect to the database using <code>$db-&gt;Connect(). </code></p>
+<h3>Executing the SQL</h3>
+<p><code><font color="#663300">$result = $db-&gt;<b>Execute</b>(&quot;SELECT * 
+  FROM employees&quot;);<br>
+  if ($result === false) die(&quot;failed&quot;)</font></code><code><font color="#663300">;</font></code> 
+  <br>
+</p>
+<p>Sending the SQL statement to the server is straight forward. Execute() will 
+  return a recordset object on successful execution. You should check $result 
+  as we do above.
+<p>An issue that confuses beginners is the fact that we have two types of objects 
+  in ADODB, the connection object and the recordset object. When do we use each?
+<p>The connection object ($db) is responsible for connecting to the database, 
+  formatting your SQL and querying the database server. The recordset object ($result) 
+  is responsible for retrieving the results and formatting the reply as text or 
+  as an array.
+<p>The only thing I need to add is that ADODB provides several helper functions 
+  for making INSERT and UPDATE statements easier, which we will cover in the Advanced 
+  section. 
+<h3>Retrieving the Data<br>
+</h3>
+<pre><font color="#006666"><b>while</b> (!$result-&gt;EOF) &#123;
+   <b>for</b> ($i=0, $max=$result-&gt;<b>FieldCount</b>(); $i &lt; $max; $i++)
+          <b>print</b> $result-&gt;fields[$i].' ';
+   $result-&gt;<b>MoveNext</b>();
+   <b>print</b> &quot;&lt;br&gt;\n&quot;;
+&#125;</font></pre>
+<p>The paradigm for getting the data is that it's like reading a file. For every 
+  line, we check first whether we have reached the end-of-file (EOF). While not 
+  end-of-file, loop through each field in the row. Then move to the next line 
+  (MoveNext) and repeat. 
+<p>The <code>$result-&gt;fields[]</code> array is generated by the PHP database 
+  extension. Some database extensions do not index the array by field name. 
+  To force indexing by name - that is associative arrays - 
+  use the $ADODB_FETCH_MODE global variable. 
+<pre>
+       $<b>ADODB_FETCH_MODE</b> = ADODB_FETCH_NUM;
+       $rs1 = $db->Execute('select * from table');
+       $<b>ADODB_FETCH_MODE</b> = ADODB_FETCH_ASSOC;
+       $rs2 = $db->Execute('select * from table');
+       print_r($rs1->fields); // shows <i>array([0]=>'v0',[1] =>'v1')</i>
+       print_r($rs2->fields); // shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i>
+</pre>
+<p>
+As you can see in the above example, both recordsets store and use different fetch modes
+based on the $ADODB_FETCH_MODE setting when the recordset was created by Execute().</p>
+<h2>ADOConnection<a name="ADOConnection"></a></h2>
+<p>Object that performs the connection to the database, executes SQL statements 
+  and has a set of utility functions for standardising the format of SQL statements 
+  for issues such as concatenation and date formats.</p>
+  
+<h3>Other Useful Functions</h3>
+<p><code>$recordset-&gt;Move($pos)</code> scrolls to that particular row. ADODB supports forward 
+  scrolling for all databases. Some databases will not support backwards scrolling. 
+  This is normally not a problem as you can always cache records to simulate backwards 
+  scrolling. 
+<p><code>$recordset-&gt;RecordCount()</code> returns the number of records accessed by the 
+  SQL statement. Some databases will return -1 because it is not supported. 
+<p><code>$recordset-&gt;GetArray()</code> returns the result as an array. 
+<p><code>rs2html($recordset)</code> is a function that is generates a HTML table based on the 
+  $recordset passed to it. An example with the relevant lines in bold:
+<pre>   include('adodb.inc.php'); 
+   <b>include('tohtml.inc.php');</b> /* includes the rs2html function */
+   $conn = &amp;ADONewConnection('mysql'); 
+   $conn-&gt;PConnect('localhost','userid','password','database');
+   $rs = $conn-&gt;Execute('select * from table');
+  <b> rs2html($rs)</b>; /* recordset to html table */ </pre>
+<p>There are many other helper functions that are listed in the documentation available at <a href="http://php.weblogs.com/adodb_manual"></a><a href="http://php.weblogs.com/adodb_manual">http://php.weblogs.com/adodb_manual</a>. 
+<h2>Advanced Material</h2>
+<h3>Inserts and Updates </h3>
+<p>Let's say you want to insert the following data into a database. 
+<p><b>ID</b> = 3<br>
+  <b>TheDate</b>=mktime(0,0,0,8,31,2001) /* 31st August 2001 */<br>
+  <b>Note</b>= sugar why don't we call it off 
+<p>When you move to another database, your insert might no longer work.</p>
+<p>The first problem is that each database has a different default date format. 
+  MySQL expects YYYY-MM-DD format, while other databases have different defaults. 
+  ADODB has a function called DBDate() that addresses this issue by converting 
+  converting the date to the correct format.</p>
+<p>The next problem is that the <b>don't</b> in the Note needs to be quoted. In 
+  MySQL, we use <b>don\'t</b> but in some other databases (Sybase, Access, Microsoft 
+  SQL Server) we use <b>don''t. </b>The qstr() function addresses this issue.</p>
+<p>So how do we use the functions? Like this:</p>
+<pre>$sql = &quot;INSERT INTO table (id, thedate,note) values (&quot; 
+   . $<b>ID</b> . ','
+   . $db-&gt;DBDate($<b>TheDate</b>) .','
+   . $db-&gt;qstr($<b>Note</b>).&quot;)&quot;;
+$db-&gt;Execute($sql);</pre>
+<p>ADODB also supports <code>$connection-&gt;Affected_Rows()</code> (returns the 
+  number of rows affected by last update or delete) and <code>$recordset-&gt;Insert_ID()</code> 
+  (returns last autoincrement number generated by an insert statement). Be forewarned 
+  that not all databases support the two functions.<br>
+</p>
+<h3>MetaTypes</h3>
+<p>You can find out more information about each of the fields (I use the words 
+  fields and columns interchangebly) you are selecting by calling the recordset 
+  method <code>FetchField($fieldoffset)</code>. This will return an object with 
+  3 properties: name, type and max_length. 
+<pre>For example:</pre>
+<pre>$recordset = $conn-&gt;Execute(&quot;select adate from table&quot;);<br>$f0 = $recordset-&gt;FetchField(0);
+</pre>
+<p>Then <code>$f0-&gt;name</code> will hold <i>'adata'</i>, <code>$f0-&gt;type</code> 
+  will be set to '<i>date'</i>. If the max_length is unknown, it will be set to 
+  -1. 
+<p>One problem with handling different databases is that each database often calls 
+  the same type by a different name. For example a <i>timestamp</i> type is called 
+  <i>datetime</i> in one database and <i>time</i> in another. So ADODB has a special 
+  <code>MetaType($type, $max_length)</code> function that standardises the types 
+  to the following: 
+<p>C: character and varchar types<br>
+  X: text or long character (eg. more than 255 bytes wide).<br>
+  B: blob or binary image<br>
+  D: date<br>
+  T: timestamp<br>
+  L: logical (boolean)<br>
+  I: integer<br>
+  N: numeric (float, double, money) 
+<p>In the above date example, 
+<p><code>$recordset = $conn-&gt;Execute(&quot;select adate from table&quot;);<br>
+  $f0 = $recordset-&gt;FetchField(0);<br>
+  $type = $recordset-&gt;MetaType($f0-&gt;type, $f0-&gt;max_length);<br>
+  print $type; /* should print 'D'</code> */
+<p> 
+<p><b>Select Limit and Top Support</b> 
+<p>ADODB has a function called $connection->SelectLimit($sql,$nrows,$offset) that allows
+you to retrieve a subset of the recordset. This will take advantage of native
+SELECT TOP on Microsoft products and SELECT ... LIMIT with PostgreSQL and MySQL, and
+emulated if the database does not support it.
+<p><b>Caching Support</b> 
+<p>ADODB allows you to cache recordsets in your file system, and only requery the database
+server after a certain timeout period with $connection->CacheExecute($secs2cache,$sql) and 
+$connection->CacheSelectLimit($secs2cache,$sql,$nrows,$offset).
+<p><b>PHP4 Session Handler Support</b> 
+<p>ADODB also supports PHP4 session handlers. You can store your session variables 
+  in a database for true scalability using ADODB. For further information, visit 
+  <a href="http://php.weblogs.com/adodb-sessions"></a><a href="http://php.weblogs.com/adodb-sessions">http://php.weblogs.com/adodb-sessions</a>
+<h3>Commercial Use Encouraged</h3>
+<p>If you plan to write commercial PHP applications that you want to resell, you should consider ADODB. It has been released using the lesser GPL, which means you can legally include it in commercial applications, while keeping your code proprietary. Commercial use of ADODB is strongly encouraged! We are using it internally for this reason.<p>
+
+<h2>Conclusion</h2>
+<p>As a thank you for finishing this article, here are the complete lyrics for 
+  <i>let's call the whole thing off</i>.<br>
+  <br>
+<pre>
+   Refrain 
+<br>
+               You say eether and I say eyether, 
+               You say neether and I say nyther; 
+               Eether, eyether, neether, nyther - 
+               Let's call the whole thing off ! 
+<br>
+               You like potato and I like po-tah-to, 
+               You like tomato and I like to-mah-to; 
+               Potato, po-tah-to, tomato, to-mah-to - 
+               Let's call the whole thing off ! 
+<br>
+But oh, if we call the whole thing off, then we must part. 
+And oh, if we ever part, then that might break my heart. 
+<br>
+               So, if you like pajamas and I like pa-jah-mas, 
+               I'll wear pajamas and give up pa-jah-mas. 
+               For we know we 
+               Need each other, so we 
+               Better call the calling off off. 
+               Let's call the whole thing off ! 
+<br>
+   Second Refrain 
+<br>
+               You say laughter and I say lawfter, 
+               You say after and I say awfter; 
+               Laughter, lawfter, after, awfter - 
+               Let's call the whole thing off ! 
+<br>
+               You like vanilla and I like vanella, 
+               You, sa's'parilla and I sa's'parella; 
+               Vanilla, vanella, choc'late, strawb'ry - 
+               Let's call the whole thing off ! 
+<br>
+But oh, if we call the whole thing off, then we must part. 
+And oh, if we ever part, then that might break my heart. 
+<br>
+               So, if you go for oysters and I go for ersters, 
+               I'll order oysters and cancel the ersters. 
+               For we know we 
+               Need each other, so we 
+               Better call the calling off off. 
+               Let's call the whole thing off ! 
+  </pre>
+<p><font size=2>Song and lyrics by George and Ira Gershwin, introduced by Fred Astaire and Ginger Rogers
+in the film "Shall We Dance?"  </font><p>
+<p>
+(c)2001-2002 John Lim.
+
+</body>
+</html>