]> git.mjollnir.org Git - moodle.git/commitdiff
Upgraded to ADOdb 2.12
authormartin <martin>
Thu, 13 Jun 2002 12:31:58 +0000 (12:31 +0000)
committermartin <martin>
Thu, 13 Jun 2002 12:31:58 +0000 (12:31 +0000)
58 files changed:
lib/adodb/adodb-cryptsession.php
lib/adodb/adodb-csvlib.inc.php
lib/adodb/adodb-errorhandler.inc.php
lib/adodb/adodb-errorpear.inc.php
lib/adodb/adodb-lib.inc.php
lib/adodb/adodb-pager.inc.php [new file with mode: 0644]
lib/adodb/adodb-pear.inc.php
lib/adodb/adodb-session.php
lib/adodb/adodb.inc.php
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-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/readme.htm
lib/adodb/server.php
lib/adodb/tests/benchmark.php
lib/adodb/tests/client.php
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 [new file with mode: 0644]
lib/adodb/tests/testoci8.php
lib/adodb/tests/testpaging.php
lib/adodb/tests/testpear.php
lib/adodb/tests/testsessions.php
lib/adodb/tips_portable_sql.htm
lib/adodb/toexport.inc.php [new file with mode: 0644]
lib/adodb/tohtml.inc.php

index 9aec4a26a161f4e27a2cff01cff5e3aaac51bb3b..f17eee1450c151d9683fa622c854ccc2fd4ae8d9 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 4b93f22741c139076bbf8595ea42f6ad78732c91..3a1b127aeb0c64bcfab0edb080462e10da7bb4f8 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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. See License.txt. \r
@@ -18,13 +18,13 @@ V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reser
 */\r
 \r
        /**\r
-        * convert a recordset into CSV format\r
+        * convert a recordset into special format\r
         *\r
         * @param rs    the recordset\r
         *\r
         * @return      the CSV formated data\r
         */\r
-       function &rs2csv(&$rs,$conn=false,$sql='')\r
+       function _rs2serialize(&$rs,$conn=false,$sql='')\r
        {\r
                $max = ($rs) ? $rs->FieldCount() : 0;\r
                \r
@@ -196,12 +196,13 @@ V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reser
                // slurp in the data\r
                $MAXSIZE = 128000;\r
                $text = fread($fp,$MAXSIZE);\r
-               if (strlen($text) == $MAXSIZE) {\r
-                       $text .= fread($fp,filesize($url)-$MAXSIZE);\r
+               $cnt = 1;\r
+               while (strlen($text) == $MAXSIZE*$cnt) {\r
+                       $text .= fread($fp,$MAXSIZE);\r
+                       $cnt += 1;\r
                }\r
                        \r
                fclose($fp);\r
-               //$text = substr($text,0,44);\r
                $arr = @unserialize($text);\r
                \r
                //var_dump($arr);\r
index 9bf1c3632c5211334828e13fd241039eb3632125..68c3480a804159d82fad9db9a70b02a801c7be1b 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /**\r
- * @version V2.00 13 May 2002  (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V2.12 12 June 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
index 0ca4aa5b9bcad32dd708f55fb116088b140da8c9..b198a528438467de474c071a53ee948548671e17 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V2.12 12 June 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
index e20d81c6c5e73f4667850164764c9fe6c3364166..0223336eef27a99e86032db3613d0fe31de54ee3 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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. See License.txt. \r
@@ -9,14 +9,6 @@ V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reser
   Less commonly used functions are placed here to reduce size of adodb.inc.php. \r
 */ \r
 \r
-function _adodb_totalpages(&$rs)\r
-{\r
-       if  ($rs->rowsPerPage) {\r
-               $rows = ($rs->RecordCount()+$rs->rowsPerPage-1) / $rs->rowsPerPage;\r
-               if ($rows < 0) return -1;\r
-               else return $rows;\r
-       } else return -1;\r
-}\r
 \r
 // Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM\r
 function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false,\r
@@ -30,38 +22,43 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
                if (!strpos($name,'[]')) $name .= '[]';\r
        } else if ($size) $attr = " size=$size";\r
        else $attr ='';\r
-       \r
-                       \r
+\r
        $s = "<select name=\"$name\"$attr $selectAttr>";\r
        if ($blank1stItem) $s .= "\n<option></option>";\r
 \r
        if ($zthis->FieldCount() > 1) $hasvalue=true;\r
        else $compareFields0 = true;\r
        \r
+       $value = '';\r
        while(!$zthis->EOF) {\r
-               $zval = trim($zthis->fields[0]);\r
-               $selected = trim($zthis->fields[$compareFields0 ? 0 : 1]);\r
+               $zval = trim(reset($zthis->fields));\r
+               if (sizeof($zthis->fields) > 1) {\r
+                       if (isset($zthis->fields[1]))\r
+                               $zval2 = trim($zthis->fields[1]);\r
+                       else\r
+                               $zval2 = trim(next($zthis->fields));\r
+               }\r
+               $selected = ($compareFields0) ? $zval : $zval2;\r
                \r
                if ($blank1stItem && $zval=="") {\r
                        $zthis->MoveNext();\r
                        continue;\r
                }\r
                if ($hasvalue) \r
-                       $value = 'value="'.htmlspecialchars(trim($zthis->fields[1])).'"';\r
-               \r
+                       $value = ' value="'.htmlspecialchars($zval2).'"';\r
                \r
                if (is_array($defstr))  {\r
                        \r
                        if (in_array($selected,$defstr)) \r
-                               $s .= "<option selected $value>".htmlspecialchars($zval).'</option>';\r
+                               $s .= "<option selected$value>".htmlspecialchars($zval).'</option>';\r
                        else \r
-                               $s .= "\n<option ".$value.'>'.htmlspecialchars($zval).'</option>';\r
+                               $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';\r
                }\r
                else {\r
                        if (strcasecmp($selected,$defstr)==0) \r
-                               $s .= "<option selected $value>".htmlspecialchars($zval).'</option>';\r
+                               $s .= "<option selected$value>".htmlspecialchars($zval).'</option>';\r
                        else \r
-                               $s .= "\n<option ".$value.'>'.htmlspecialchars($zval).'</option>';\r
+                               $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';\r
                }\r
                $zthis->MoveNext();\r
        } // while\r
@@ -69,7 +66,106 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
        return $s ."\n</select>\n";\r
 }\r
 \r
-function &_adodb_pageexecute(&$zthis, $sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2cache=0) \r
+/*\r
+       Code originally from "Cornel G" <conyg@fx.ro>\r
+\r
+       This code will not work with SQL that has UNION in it   \r
+       \r
+       Also if you are using CachePageExecute(), there is a strong possibility that\r
+       data will get out of synch. use CachePageExecute() only with tables that\r
+       rarely change.\r
+*/\r
+function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page, \r
+                                               $inputarr=false, $arg3=false, $secs2cache=0) \r
+{\r
+       $atfirstpage = false;\r
+       $atlastpage = false;\r
+       $lastpageno=1;\r
+\r
+       // If an invalid nrows is supplied, \r
+       // we assume a default value of 10 rows per page\r
+       if (!isset($nrows) || $nrows <= 0) $nrows = 10;\r
+\r
+       $qryRecs = false; //count records for no offset\r
+       \r
+       // jlim - attempt query rewrite first\r
+       $rewritesql = preg_replace(\r
+               '/^\s*SELECT\s.*\sFROM\s/is','SELECT COUNT(*) FROM ',$sql);\r
+               \r
+       if ($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);\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
+               //save total records\r
+                   $qryRecs = $rstest->RecordCount();\r
+                       if ($qryRecs == -1)\r
+                               if (!$rstest->EOF) {\r
+                                       $rstest->MoveLast();\r
+                                       $qryRecs = $zthis->_currentRow;\r
+                               } else\r
+                                       $qryRecs = 0;\r
+                                       \r
+               $lastpageno = (int) ceil($qryRecs / $nrows);\r
+               }\r
+               if ($rstest) $rstest->Close();\r
+       }\r
+       \r
+       $zthis->_maxRecordCount = $qryRecs;\r
+    \r
+       // If page number <= 1, then we are at the first page\r
+       if (!isset($page) || $page <= 1) {      \r
+               $page = 1;\r
+               $atfirstpage = true;\r
+       }\r
+\r
+       // ***** Here we check whether $page is the last page or \r
+       // whether we are trying to retrieve \r
+       // a page number greater than the last page number.\r
+       if ($page >= $lastpageno) {\r
+               $page = $lastpageno;\r
+               $atlastpage = true;\r
+       }\r
+       \r
+       // We get the data we want\r
+       $offset = $nrows * ($page-1);\r
+       if ($secs2cache > 0) \r
+               $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr, $arg3);\r
+       else \r
+               $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $arg3, $secs2cache);\r
+\r
+       \r
+       // Before returning the RecordSet, we set the pagination properties we need\r
+       if ($rsreturn) {\r
+               $rsreturn->rowsPerPage = $nrows;\r
+               $rsreturn->AbsolutePage($page);\r
+               $rsreturn->AtFirstPage($atfirstpage);\r
+               $rsreturn->AtLastPage($atlastpage);\r
+               $rsreturn->LastPageNo($lastpageno);\r
+       }\r
+       return $rsreturn;\r
+}\r
+\r
+// Iván Oliva version\r
+function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2cache=0) \r
 {\r
 \r
        $atfirstpage = false;\r
diff --git a/lib/adodb/adodb-pager.inc.php b/lib/adodb/adodb-pager.inc.php
new file mode 100644 (file)
index 0000000..8b34d8f
--- /dev/null
@@ -0,0 +1,239 @@
+<?php\r
+/*\r
+       V2.12 12 June 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
+         Set tabs to 4 for best viewing.\r
+\r
+       This class provides recordset pagination with \r
+       First/Prev/Next/Last links. \r
+       \r
+       Feel free to modify this class for your own use as\r
+       it is very basic. To learn how to use it, see the \r
+       example in adodb/tests/testpaging.php.\r
+       \r
+       Please note, this class is entirely unsupported, \r
+       and no free support requests except for bug reports\r
+       will be entertained by the author.\r
+       \r
+       My company also sells a commercial pagination \r
+       object at http://phplens.com/ with much more \r
+       functionality, including search, create, edit,\r
+       delete records. \r
+*/\r
+class ADODB_Pager {\r
+       var $id;        // unique id for pager (defaults to 'adodb')\r
+       var $db;        // ADODB connection object\r
+       var $sql;       // sql used\r
+       var $rs;        // recordset generated\r
+       var $curr_page; // current page number before Render() called, calculated in constructor\r
+       var $rows;              // number of rows per page\r
+       \r
+       var $gridAttributes = 'width=100% border=1 bgcolor=white';\r
+       \r
+       // Localize text strings here\r
+       var $first = '<code>|&lt;</code>';\r
+       var $prev = '<code>&lt;&lt;</code>';\r
+       var $next = '<code>>></code>';\r
+       var $last = '<code>>|</code>';\r
+       var $page = 'Page';\r
+       var $cache = 0;  #secs to cache with CachePageExecute()\r
+       \r
+       //----------------------------------------------\r
+       // constructor\r
+       //\r
+       // $db  adodb connection object\r
+       // $sql sql statement\r
+       // $id  optional id to identify which pager, \r
+       //              if you have multiple on 1 page. \r
+       //              $id should be only be [a-z0-9]*\r
+       //\r
+       function ADODB_Pager(&$db,$sql,$id = 'adodb')\r
+       {\r
+       global $HTTP_SERVER_VARS,$PHP_SELF,$HTTP_SESSION_VARS,$HTTP_GET_VARS;\r
+       \r
+               $curr_page = $id.'_curr_page';\r
+               if (empty($PHP_SELF)) $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];\r
+               \r
+               $this->sql = $sql;\r
+               $this->id = $id;\r
+               $this->db = $db;\r
+               \r
+               $next_page = $id.'_next_page';  \r
+               \r
+               if (isset($HTTP_GET_VARS[$next_page])) {\r
+                       $HTTP_SESSION_VARS[$curr_page] = $HTTP_GET_VARS[$next_page];\r
+               }\r
+               if (empty($HTTP_SESSION_VARS[$curr_page])) $HTTP_SESSION_VARS[$curr_page] = 1; ## at first page\r
+               \r
+               $this->curr_page = $HTTP_SESSION_VARS[$curr_page];\r
+               \r
+       }\r
+       \r
+       //---------------------------\r
+       // Display link to first page\r
+       function Render_First($anchor=true)\r
+       {\r
+       global $PHP_SELF;\r
+               if ($anchor) {\r
+       ?>\r
+               <a href="<?php echo $PHP_SELF,'?',$this->id;?>_next_page=1"><?php echo $this->first;?></a> &nbsp; \r
+       <?php\r
+               } else {\r
+                       print "$this->first &nbsp; ";\r
+               }\r
+       }\r
+       \r
+       //--------------------------\r
+       // Display link to next page\r
+       function render_next($anchor=true)\r
+       {\r
+       global $PHP_SELF;\r
+       \r
+               if ($anchor) {\r
+               ?>\r
+               <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() + 1 ?>"><?php echo $this->next;?></a> &nbsp; \r
+               <?php\r
+               } else {\r
+                       print "$this->next &nbsp; ";\r
+               }\r
+       }\r
+       \r
+       //------------------\r
+       // Link to last page\r
+       // \r
+       // for better performance with large recordsets, you can set\r
+       // $this->db->pageExecuteCountRows = false, which disables\r
+       // last page counting.\r
+       function render_last($anchor=true)\r
+       {\r
+       global $PHP_SELF;\r
+       \r
+               if (!$this->db->pageExecuteCountRows) return;\r
+               \r
+               if ($anchor) {\r
+               ?>\r
+                       <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->LastPageNo() ?>"><?php echo $this->last;?></a> &nbsp; \r
+               <?php\r
+               } else {\r
+                       print "$this->last &nbsp; ";\r
+               }\r
+       }\r
+       \r
+       //----------------------\r
+       // Link to previous page\r
+       function render_prev($anchor=true)\r
+       {\r
+       global $PHP_SELF;\r
+               if ($anchor) {\r
+       ?>\r
+               <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() - 1 ?>"><?php echo $this->prev;?></a> &nbsp; \r
+       <?php \r
+               } else {\r
+                       print "$this->prev &nbsp; ";\r
+               }\r
+       }\r
+       \r
+       //--------------------------------------------------------\r
+       // Simply rendering of grid. You should override this for\r
+       // better control over the format of the grid\r
+       //\r
+       // We use output buffering to keep code clean and readable.\r
+       function RenderGrid()\r
+       {\r
+       global $gSQLBlockRows; // used by rs2html to indicate how many rows to display\r
+               include_once(ADODB_DIR.'/tohtml.inc.php');\r
+               ob_start();\r
+               $gSQLBlockRows = $this->rows;\r
+               rs2html($this->rs,$this->gridAttributes);\r
+               $s = ob_get_contents();\r
+               ob_end_clean();\r
+               return $s;\r
+       }\r
+       \r
+       //-------------------------------------------------------\r
+       // Navigation bar\r
+       //\r
+       // we use output buffering to keep the code easy to read.\r
+       function RenderNav()\r
+       {\r
+               ob_start();\r
+               if (!$this->rs->AtFirstPage()) {\r
+                       $this->Render_First();\r
+                       $this->Render_Prev();\r
+               } else {\r
+                       $this->Render_First(false);\r
+                       $this->Render_Prev(false);\r
+               }\r
+               if (!$this->rs->AtLastPage()) {\r
+                       $this->Render_Next();\r
+                       $this->Render_Last();\r
+               } else {\r
+                       $this->Render_Next(false);\r
+                       $this->Render_Last(false);\r
+               }\r
+               $s = ob_get_contents();\r
+               ob_end_clean();\r
+               return $s;\r
+       }\r
+       \r
+       //-------------------\r
+       // This is the footer\r
+       function RenderPageCount()\r
+       {\r
+               if (!$this->db->pageExecuteCountRows) return '';\r
+               return "<font size=-1>$this->page ".$this->curr_page."/".$this->rs->LastPageNo()."</font>";\r
+       }\r
+       \r
+       //-----------------------------------\r
+       // Call this class to draw everything.\r
+       function Render($rows=10)\r
+       {\r
+       global $ADODB_COUNTRECS;\r
+       \r
+               $this->rows = $rows;\r
+               \r
+               $savec = $ADODB_COUNTRECS;\r
+               if ($this->db->pageExecuteCountRows) $ADODB_COUNTRECS = true;\r
+               if ($this->cache)\r
+                       $rs = &$this->db->CachePageExecute($this->cache,$this->sql,$rows,$this->curr_page);\r
+               else\r
+                       $rs = &$this->db->PageExecute($this->sql,$rows,$this->curr_page);\r
+               $ADODB_COUNTRECS = $savec;\r
+               \r
+               $this->rs = &$rs;\r
+               if (!$rs) {\r
+                       print "<h3>Query failed: $this->sql</h3>";\r
+                       return;\r
+               }\r
+               \r
+               if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) \r
+                       $header = $this->RenderNav();\r
+               else\r
+                       $header = "&nbsp;";\r
+               \r
+               $grid = $this->RenderGrid();\r
+               $footer = $this->RenderPageCount();\r
+               $rs->Close();\r
+               $this->rs = false;\r
+               \r
+               $this->RenderLayout($header,$grid,$footer);\r
+       }\r
+       \r
+       //------------------------------------------------------\r
+       // override this to control overall layout and formating\r
+       function RenderLayout($header,$grid,$footer)\r
+       {\r
+               echo "<table border=1 bgcolor=beige><tr><td>",\r
+                               $header,\r
+                       "</td></tr><tr><td>",\r
+                               $grid,\r
+                       "</td></tr><tr><td>",\r
+                               $footer,\r
+                       "</td></tr></table>";\r
+       }\r
+}\r
+\r
+\r
+?>
\ No newline at end of file
index 474c30124dfd21e830efe896f25367a98c0d5d72..df2714a60df5faa530f8f7295a0611a963fa53af 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V2.12 12 June 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
index 0306f6ee7e0a17fe76b1e27a3bbced12b1b6cd7e..e5d7e4acd741f6e6d168157c738cebf089c7cea7 100644 (file)
@@ -1,12 +1,10 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
-       Made table name configurable - by David Johnson djohnson@inpro.net\r
-\r
-  Set tabs to 4 for best viewing.\r
+         Set tabs to 4 for best viewing.\r
   \r
   Latest version of ADODB is available at http://php.weblogs.com/adodb\r
   ======================================================================\r
@@ -28,8 +26,7 @@ wrapper library.
  \r
  Installation\r
  ============\r
- 1. Create a new database in MySQL or Access "sessions" like\r
-so:\r
+ 1. Create this table in your database (syntax might vary depending on your db):\r
  \r
   create table sessions (\r
        SESSKEY char(32) not null,\r
@@ -37,7 +34,8 @@ so:
        DATA text not null,\r
       primary key (sesskey)\r
   );\r
-  \r
+\r
+\r
   2. Then define the following parameters in this file:\r
        $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';\r
        $ADODB_SESSION_CONNECT='server to connect to';\r
@@ -46,22 +44,22 @@ so:
        $ADODB_SESSION_DB ='database';\r
        $ADODB_SESSION_TBL = 'sessions'\r
        \r
-  3. Recommended is PHP 4.0.2 or later. There are documented\r
-session bugs in \r
-     earlier versions of PHP.\r
+  3. Recommended is PHP 4.0.6 or later. There are documented\r
+     session bugs in earlier versions of PHP.\r
 \r
 */\r
 \r
 if (!defined('_ADODB_LAYER')) {\r
-       include ('adodb.inc.php');\r
+       include (dirname(__FILE__).'/adodb.inc.php');\r
 }\r
 \r
-\r
-\r
 if (!defined('ADODB_SESSION')) {\r
 \r
  define('ADODB_SESSION',1);\r
\r
+\r
+/****************************************************************************************\\r
+       Global definitions\r
+\****************************************************************************************/\r
 GLOBAL         $ADODB_SESSION_CONNECT, \r
        $ADODB_SESSION_DRIVER,\r
        $ADODB_SESSION_USER,\r
@@ -70,29 +68,40 @@ GLOBAL      $ADODB_SESSION_CONNECT,
        $ADODB_SESS_CONN,\r
        $ADODB_SESS_LIFE,\r
        $ADODB_SESS_DEBUG,\r
-       $ADODB_SESS_INSERT; \r
-\r
+       $ADODB_SESS_INSERT, \r
+       $ADODB_SESSION_CRC;\r
+       \r
+       $ADODB_SESS_LIFE = get_cfg_var('session.gc_maxlifetime');\r
+       if ($ADODB_SESS_LIFE <= 1) {\r
+        // bug in PHP 4.0.3 pl 1  -- how about other versions?\r
+        //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";\r
+               $ADODB_SESS_LIFE=1440;\r
+       }\r
+       $ADODB_SESSION_CRC = false;\r
        //$ADODB_SESS_DEBUG = true;\r
        \r
+       //////////////////////////////////\r
        /* SET THE FOLLOWING PARAMETERS */\r
-if (empty($ADODB_SESSION_DRIVER)) {\r
-       $ADODB_SESSION_DRIVER='mysql';\r
-       $ADODB_SESSION_CONNECT='localhost';\r
-       $ADODB_SESSION_USER ='root';\r
-       $ADODB_SESSION_PWD ='';\r
-       $ADODB_SESSION_DB ='xphplens_2';\r
-}\r
-if (empty($ADODB_SESSION_TBL)){\r
-       $ADODB_SESSION_TBL = 'sessions';\r
-}\r
-\r
-$ADODB_SESS_LIFE = get_cfg_var('session.gc_maxlifetime');\r
-if ($ADODB_SESS_LIFE <= 1) {\r
-       // bug in PHP 4.0.3 pl 1  -- how about other versions?\r
-       //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";\r
-       $ADODB_SESS_LIFE=1440;\r
-}\r
+       //////////////////////////////////\r
+       \r
+       if (empty($ADODB_SESSION_DRIVER)) {\r
+               $ADODB_SESSION_DRIVER='mysql';\r
+               $ADODB_SESSION_CONNECT='localhost';\r
+               $ADODB_SESSION_USER ='root';\r
+               $ADODB_SESSION_PWD ='';\r
+               $ADODB_SESSION_DB ='xphplens_2';\r
+       }\r
+       \r
+       //  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
+       Create the connection to the database. \r
+       \r
+       If $ADODB_SESS_CONN already exists, reuse that connection\r
+\****************************************************************************************/\r
 function adodb_sess_open($save_path, $session_name,$persist=true) \r
 {\r
 GLOBAL $ADODB_SESS_CONN;\r
@@ -106,18 +115,23 @@ GLOBAL    $ADODB_SESSION_CONNECT,
        $ADODB_SESSION_DB,\r
        $ADODB_SESS_DEBUG;\r
        \r
+       // cannot use & below - do not know why...\r
        $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);\r
        if (!empty($ADODB_SESS_DEBUG)) {\r
                $ADODB_SESS_CONN->debug = true;\r
-               print" conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ";\r
+               print " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ";\r
        }\r
-       if ($persist) $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,\r
+       if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,\r
                        $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
-       else $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,\r
+       else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,\r
                        $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
        \r
+       if (!$ok) print "<p>Session: connection failed</p>";\r
 }\r
 \r
+/****************************************************************************************\\r
+       Close the connection\r
+\****************************************************************************************/\r
 function adodb_sess_close() \r
 {\r
 global $ADODB_SESS_CONN;\r
@@ -126,10 +140,14 @@ global $ADODB_SESS_CONN;
        return true;\r
 }\r
 \r
+/****************************************************************************************\\r
+       Slurp in the session variables and return the serialized string\r
+\****************************************************************************************/\r
 function adodb_sess_read($key) \r
 {\r
-global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL;\r
-       $ADODB_SESS_INSERT = false;\r
+global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$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
@@ -139,19 +157,38 @@ global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL;
                        $v = rawurldecode(reset($rs->fields));\r
                        \r
                $rs->Close();\r
+               \r
+               // new optimization adodb 2.1\r
+               $ADODB_SESSION_CRC = crc32($v);\r
+               \r
                return $v;\r
        }\r
        else $ADODB_SESS_INSERT = true;\r
        \r
-       return false;\r
+       return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com\r
 }\r
 \r
+/****************************************************************************************\\r
+       Write the serialized data to a database.\r
+       \r
+       If the data has not been modified since adodb_sess_read(), we do not write.\r
+\****************************************************************************************/\r
 function adodb_sess_write($key, $val) \r
 {\r
-       global $ADODB_SESS_INSERT,$ADODB_SESS_CONN, $ADODB_SESS_LIFE, $ADODB_SESSION_TBL;\r
+       global $ADODB_SESS_INSERT,\r
+               $ADODB_SESS_CONN, \r
+               $ADODB_SESS_LIFE, \r
+               $ADODB_SESSION_TBL,\r
+               $ADODB_SESS_DEBUG, \r
+               $ADODB_SESSION_CRC;\r
 \r
        $expiry = time() + $ADODB_SESS_LIFE;\r
        \r
+       // new optimization adodb 2.1\r
+       if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == crc32($val)) {\r
+               if ($ADODB_SESS_DEBUG) echo "<p>Session: No need to update - crc32 not changed</p>";\r
+               return true;\r
+       }\r
        $val = rawurlencode($val);\r
        $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry,data='$val' WHERE sesskey='$key'";\r
        $rs = $ADODB_SESS_CONN->Execute($qry);\r
@@ -180,7 +217,8 @@ function adodb_sess_destroy($key)
        return $rs ? true : false;\r
 }\r
 \r
-function adodb_sess_gc($maxlifetime) {\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
index a33969a5fc887174aca56a4c9defd9e66b56c00b..ccec7c8eb8415c4c64ecc0fec5f900c95fb99526 100644 (file)
@@ -1,7 +1,7 @@
 <?php \r
 \r
 /** \r
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V2.12 12 June 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
        if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));\r
        \r
+       if (strpos(strtoupper(PHP_OS),'WIN') !== false) {\r
+       // 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
@@ -84,7 +90,7 @@
        /**\r
         * ADODB version as a string.\r
         */\r
-       $ADODB_vers = 'V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved. Released BSD & LGPL.';\r
+       $ADODB_vers = 'V2.12 12 June 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
        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 = 8000;        // maximum size of blobs or large text fields -- some databases die otherwise like foxpro\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 $arrayClass = 'ADORecordSet_array';\r
        // oracle specific stuff\r
        var $noNullStrings = false;\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
        \r
        /*\r
         * PRIVATE VARS\r
                } else \r
                        if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true;\r
 \r
-               if ($this->debug) print $this->host.': '.$this->ErrorMsg()."<br>\n";\r
+               if ($this->debug) print $this->host.': '.$this->ErrorMsg()."<br />\n";\r
                \r
                return false;\r
        }       \r
                } else \r
                        if ($this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;\r
 \r
-               if ($this->debug) print $this->host.': '.$this->ErrorMsg()."<br>\n";\r
+               if ($this->debug) print $this->host.': '.$this->ErrorMsg()."<br />\n";\r
                \r
                return false;\r
        }\r
        }\r
        \r
        /**\r
-       * PEAR DB Compat - do not use internally. \r
+       * PEAR DB Compat - Quote with auto-checking of magic-quotes-gpc.\r
        */\r
        function Quote($s)\r
        {\r
-               return $this->qstr($s);\r
+               return $this->qstr($s,get_magic_quotes_gpc());\r
        }\r
 \r
        \r
                        $inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']);\r
                        \r
                        if ($inBrowser)\r
-                               print "<hr>\n($this->databaseType): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<hr>\n";\r
+                               print "<hr />\n($this->databaseType): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<hr />\n";\r
                        else\r
                                print "=----\n($this->databaseType): ".($sqlTxt)." \n-----\n";\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($this->ErrorMsg()) {\r
+                               if($emsg = $this->ErrorMsg()) {\r
                                        $err = $this->ErrorNo();\r
                                        if ($err) {\r
-                                               print $err.': '.$this->ErrorMsg().(($inBrowser) ? "<br>\n" : "\n");\r
+                                               print $err.': '.$emsg.(($inBrowser) ? "<br />\n" : "\n");\r
                                                flush();\r
                                        }\r
                                }\r
                        } else \r
                                if (!$this->_queryID) {\r
-                                       print $this->ErrorNo().': '.$this->ErrorMsg().(($inBrowser) ? "<br>\n" : "\n");\r
+                                       print $this->ErrorNo().': '.$this->ErrorMsg() .(($inBrowser) ? "<br />\n" : "\n");\r
                                        flush();\r
                                }\r
                } else \r
                else $rs->sql = $sql;\r
                \r
                global $ADODB_COUNTRECS;\r
-               if ($rs->_numOfRows <= 0 && !$rs->EOF && $ADODB_COUNTRECS) {\r
+               if ($rs->_numOfRows <= 0 && !$rs->EOF && $ADODB_COUNTRECS) { \r
                        $rs = &$this->_rs2rs($rs);\r
                        $rs->_queryID = $this->_queryID;\r
                }\r
                return $rs;\r
        }\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
         * @startID             if sequence does not exist, start at this ID\r
         * @return              0 if not supported, otherwise a sequence id\r
         */\r
-       \r
+\r
        function GenID($seqname='adodbseq',$startID=1)\r
        {\r
                if (!$this->hasGenID) {\r
                }\r
                if ($rs && !$rs->EOF) $this->genID = (integer) reset($rs->fields);\r
                else $this->genID = 0; // false\r
-               \r
+       \r
                if ($rs) $rs->Close();\r
-               \r
+\r
                return $this->genID;\r
        }       \r
-       \r
+\r
        /**\r
         * @return  the last inserted ID. Not all databases support this.\r
         */ \r
        */\r
        function &_rs2rs(&$rs,$nrows=-1,$offset=-1)\r
        {\r
+               if (! $rs) return false;\r
                $arr = &$rs->GetArrayLimit($nrows,$offset);\r
                $flds = array();\r
                for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)\r
                }\r
                return false;\r
        }\r
+       /**\r
+       * Insert or replace a single record\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
+       *\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)\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 and $this->Affected_Rows()>0) return 1;\r
+               }\r
+               $first = true;\r
+               foreach($fieldArray as $k => $v) {\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
                                                  // sql,    nrows, offset,inputarr,arg3\r
                        return $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$inputarr,$this->cacheSecs);\r
                }\r
-               if ($sql === false) echo "Warning: \$sql missing from CacheSelectLimit()<br>\n";\r
+               if ($sql === false) echo "Warning: \$sql missing from CacheSelectLimit()<br />\n";\r
                return $this->SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);\r
        }\r
        \r
                $md5file = $this->_gencachename($sql,true);\r
                $err = '';\r
                \r
-               if ($secs2cache > 0)$rs = &csv2rs($md5file,$err,$secs2cache);\r
-               else {\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
                \r
                if (!$rs) {\r
                        if ($rs) {\r
                                $eof = $rs->EOF;\r
                                $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately\r
-                               $txt = &rs2csv($rs,false,$sql); // serialize\r
-                               \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
                                        if ($this->debug) print " Cache write error<br>\n";\r
                                }\r
                                if ($rs->EOF && !$eof) {\r
-                                       $rs = &csv2rs($md5file,$err);           \r
+                                       $rs->MoveFirst();\r
+                                       //$rs = &csv2rs($md5file,$err);         \r
                                        $rs->connection = &$this; // Pablo suggestion\r
                                }  \r
                                \r
        function DBDate($d)\r
        {\r
        \r
-       // note that we are limited to 1970 to 2038\r
                if (empty($d) && $d !== 0) return 'null';\r
 \r
                if (is_string($d) && !is_numeric($d)) \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 1970, or false if invalid date format\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
+               if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|", \r
                        ($v), $rr)) return false;\r
-                       \r
-               if ($rr[1] <= 1970) return 0;\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
         * 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 1970, or false if invalid date format\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,2}))?$|", \r
                        ($v), $rr)) return false;\r
-               if ($rr[1] <= 1970 && $rr[2]<= 1) return 0;\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
-        * Converts a timestamp "ts" to a string that the database can understand.\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
                        return "'".str_replace("\\'",$this->replaceQuote,$s)."'";\r
                }\r
        }\r
-\r
+       \r
        \r
        /**\r
        * Will select the supplied $page number from a recordset, given that it is paginated in pages of \r
        function &PageExecute($sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2cache=0) \r
        {\r
                include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_pageexecute($this, $sql, $nrows, $page, $inputarr, $arg3, $secs2cache);\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
        * @return               the recordset ($rs->databaseType == 'array')\r
        */\r
        function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false, $arg3=false) {\r
-               include_once(ADODB_DIR.'/adodb-lib.inc.php');\r
-               return _adodb_pageexecute($this, $sql, $nrows, $page, $inputarr, $arg3,$secs2cache);\r
+               return $this->PageExecute($sql,$nrows,$page,$inputarr,$arg3,$secs2cache);\r
        }\r
 \r
 } // end class ADOConnection\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
-\r
-       \r
+       var $_lastPageNo = -1; \r
+       var $_maxRecordCount = 0;\r
        /**\r
         * Constructor\r
         *\r
        }\r
        \r
        \r
+       \r
        function Init()\r
        {\r
                if ($this->_inited) return;\r
        function UserTimeStamp($v,$fmt='Y-m-d H:i:s')\r
        {\r
                $tt = $this->UnixTimeStamp($v);\r
-               // $tt == -1 if pre 1970\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
        function UserDate($v,$fmt='Y-m-d')\r
        {\r
                $tt = $this->UnixDate($v);\r
-               // $tt == -1 if pre 1970\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-1970\r
+               else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR\r
                }\r
                return date($fmt,$tt);\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 1970, or false if invalid date format\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
+               if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|", \r
                        ($v), $rr)) return false;\r
                        \r
-               if ($rr[1] <= 1970) return 0;\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
         * @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 1970, or false if invalid date format\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,2}))?$|", \r
                        ($v), $rr)) return false;\r
-               if ($rr[1] <= 1970 && $rr[2]<= 1) return 0;\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
        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
                // 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
        * \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
                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
                                $ok = false;\r
                        }\r
                        if (!$ok) {\r
-                               if ($debug) print " Rename $tmpname ".($ok? 'ok' : 'failed')." <br>\n";\r
+                               if ($debug) print " Rename $tmpname ".($ok? 'ok' : 'failed')." <br />\n";\r
                        }\r
                        return $ok;\r
                }\r
index 7556cdf3e36745a0d66a1aa24048abebb6fb2187..7203fbc778d969a113dd824e387d19cd409ae964 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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. See License.txt. \r
index 9544ee1db74c2e6f9a1c30f5024d84e5f8bf534e..db596079557e16a2cf8bfbd30c6f12a4e6dc709f 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -25,6 +25,12 @@ class ADODB_ado extends ADOConnection {
        var $adoParameterType = 201; // 201 = long varchar, 203=long wide varchar, 205 = long varbinary\r
        var $_affectedRows = false;\r
        var $_thisTransactions;\r
+       var $_inTransaction = 0;\r
+       var $_cursor_type = 3; // 3=adOpenStatic,0=adOpenForwardOnly,1=adOpenKeyset,2=adOpenDynamic\r
+       var $_cursor_location = 3; // 2=adUseServer, 3 = adUseClient;\r
+       var $_lock_type = -1;\r
+       var $_execute_option = -1;\r
+                      \r
        \r
        function ADODB_ado() \r
        {       \r
@@ -35,7 +41,10 @@ class ADODB_ado extends ADOConnection {
     {\r
             return $this->_affectedRows;\r
     }\r
-         \r
+    \r
+       // you can also pass a connection string like this:\r
+       //\r
+       // $DB->Connect('USER ID=sa;PASSWORD=pwd;SERVER=mangrove;DATABASE=ai',false,false,'SQLOLEDB');\r
        function _connect($argHostname, $argUsername, $argPassword, $argProvider= 'MSDASQL')\r
        {\r
                $u = 'UID';\r
@@ -43,13 +52,22 @@ class ADODB_ado extends ADOConnection {
        \r
                $dbc = new COM('ADODB.Connection');\r
                if (! $dbc) return false;\r
-               /* // handle SQL server provider specially ? no need\r
-               if ($argProvider) {\r
-                       if ($argProvider == "SQLOLEDB") { // SQL Server Provider\r
-                       } \r
-               }*/\r
-               if ($argProvider) $dbc->Provider = $argProvider;\r
-               else $dbc->Provider ='MSDASQL';\r
+\r
+               /* special support if provider is mssql or access */\r
+               if ($argProvider=='mssql') {\r
+                       $u = 'User Id';  //User parameter name for OLEDB\r
+                       $p = 'Password'; \r
+                       $argProvider = "SQLOLEDB"; // SQL Server Provider\r
+                       \r
+                       // not yet\r
+                       //if ($argDatabasename) $argHostname .= ";Initial Catalog=$argDatabasename";\r
+                       \r
+                       //use trusted conection for SQL if username not specified\r
+                       if (!$argUsername) $argHostname .= ";Trusted_Connection=Yes";\r
+               } else if ($argProvider=='access')\r
+                       $argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider\r
+               \r
+               if ($argProvider) $dbc->Provider = $argProvider;        \r
                \r
                if ($argUsername) $argHostname .= ";$u=$argUsername";\r
                if ($argPassword)$argHostname .= ";$p=$argPassword";\r
@@ -57,28 +75,17 @@ class ADODB_ado extends ADOConnection {
                if ($this->debug) print "<p>Host=".$argHostname."<BR>version=$dbc->version</p>";\r
                // @ added below for php 4.0.1 and earlier\r
                @$dbc->Open((string) $argHostname);\r
-\r
+               \r
                $this->_connectionID = $dbc;\r
-               return  $dbc != false;\r
+               \r
+               $dbc->CursorLocation = $this->_cursor_location;\r
+               return  $dbc->State > 0;\r
        }\r
        \r
        // returns true or false\r
        function _pconnect($argHostname, $argUsername, $argPassword, $argProvider='MSDASQL')\r
        {\r
-               $dbc = new COM("ADODB.Connection");\r
-               if (! $dbc) return false;\r
-               \r
-               if ($argProvider) $dbc->Provider = $argProvider;\r
-               else $dbc->Provider ='MSDASQL';\r
-               \r
-               if ($argUsername) $argHostname .= ";UID=$argUsername";\r
-               if ($argPassword)$argHostname .= ";PWD=$argPassword";\r
-               \r
-               if ($this->debug) print "<p>Host=".$argHostname."<BR>version=$dbc->version</p>";\r
-               $dbc->Open((string) $argHostname);\r
-               \r
-               $this->_connectionID = $dbc;\r
-               return  $dbc != false;\r
+               return $this->_connect($argHostname,$argUsername,$argPassword,$argProvider);\r
        }       \r
        \r
 /*\r
@@ -202,8 +209,14 @@ class ADODB_ado extends ADOConnection {
                        if ($dbc->Errors->Count > 0) return false;\r
                        return $rs;\r
                }\r
-               $rs = @$dbc->Execute($sql,&$this->_affectedRows);\r
-                       \r
+               \r
+               $rs = @$dbc->Execute($sql,&$this->_affectedRows, $this->_execute_option);\r
+               /*\r
+                       $rs =  new COM('ADODB.Recordset');\r
+                       if ($rs) {\r
+                               $rs->Open ($sql, $dbc, $this->_cursor_type,$this->_lock_type, $this->_execute_option);                                          \r
+                       }\r
+               */\r
                if ($dbc->Errors->Count > 0) return false;\r
                if (! $rs) return false;\r
                \r
@@ -222,16 +235,19 @@ class ADODB_ado extends ADOConnection {
                        if (!$o) return false;\r
                }\r
                @$this->_connectionID->BeginTrans();\r
+               $this->_inTransaction += 1;\r
                return true;\r
        }\r
        function CommitTrans($ok=true) \r
        { \r
                if (!$ok) return $this->RollbackTrans();\r
                @$this->_connectionID->CommitTrans();\r
+               if ($this->_inTransaction) @$this->_inTransaction -= 1;\r
                return true;\r
        }\r
        function RollbackTrans() {\r
                @$this->_connectionID->RollbackTrans();\r
+               if ($this->_inTransaction) @$this->_inTransaction -= 1;\r
                return true;\r
        }\r
        \r
@@ -295,8 +311,10 @@ class ADORecordSet_ado extends ADORecordSet {
                $rs = $this->_queryID;\r
                $f = $rs->Fields($fieldOffset);\r
                $o->name = $f->Name;\r
-               $o->type = $this->MetaType($f->Type);\r
+               $t = $f->Type;\r
+               $o->type = $this->MetaType($t);\r
                $o->max_length = $f->DefinedSize;\r
+               $o->ado_type = $t;\r
                \r
 \r
                //print "off=$off name=$o->name type=$o->type len=$o->max_length<br>";\r
@@ -472,7 +490,7 @@ class ADORecordSet_ado extends ADORecordSet {
        function _fetch()\r
        {       \r
                $rs = $this->_queryID;\r
-               if ($rs->EOF) return false;\r
+               if (!$rs or $rs->EOF) return false;\r
                $this->fields = array();\r
        \r
                if (!$this->_tarr) {\r
@@ -494,6 +512,9 @@ class ADORecordSet_ado extends ADORecordSet {
                for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {\r
 \r
                        switch($t) {\r
+                       case 135: // timestamp\r
+                               $this->fields[] = date('Y-m-d H:i:s',(integer)$f->value);\r
+                               break;\r
                                \r
                        case 133:// A date value (yyyymmdd) \r
                                $val = $f->value;\r
index 37d3e8d8d7af9d15df981043996e7b375bf4d634..4175620e612cd426931cdde197c4989830f02784 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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. See License.txt. \r
@@ -20,7 +20,9 @@ class  ADODB_ado_access extends ADODB_ado {
        var $hasTop = 'top';            // support mssql SELECT TOP 10 * FROM TABLE\r
        var $fmtDate = "#Y-m-d#";\r
        var $fmtTimeStamp = "#Y-m-d h:i:sA#";// note no comma\r
-\r
+       var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";\r
+       var $sysTimeStamp = 'NOW';\r
+       \r
        function ADODB_ado_access()\r
        {\r
        }\r
index 32ba7791dcbf005b4dd134eae11fd616d0b3c4e2..7a9bb1c3ea642c84d269316a4fd730356c496e97 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -20,14 +20,26 @@ if (!defined('_ADODB_ADO_LAYER')) {
 }\r
 \r
 class  ADODB_ado_mssql extends ADODB_ado {     \r
-var $databaseType = 'ado_mssql';\r
-var $hasTop = 'top';\r
-var $sysDate = 'GetDate()';\r
-var $sysTimeStamp = 'GetDate()';\r
-\r
+       var $databaseType = 'ado_mssql';\r
+       var $hasTop = 'top';\r
+       var $sysDate = 'GetDate()';\r
+       var $sysTimeStamp = 'GetDate()';\r
+       //var $_inTransaction = 1; // always open recordsets, so no transaction problems.\r
+       \r
        function ADODB_ado_mssql()\r
        {\r
        }\r
+       \r
+    function _insertid()\r
+    {\r
+       return $this->GetOne('select @@identity');\r
+    }\r
+       \r
+    function _affectedrows()\r
+    {\r
+        return $this->GetOne('select @@rowcount');\r
+    }\r
+       \r
 }\r
  \r
 class  ADORecordSet_ado_mssql extends ADORecordSet_ado {       \r
index 370529b6d17ec3bfc69507db8637d0755e790ff5..3e63ffdb5d8ff6099aa9d19db571a49596557248 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 5949105195601c77ad9955d08e12d129df2c01d8..5230a54aa60b4f53aeb56b5c0fef01487aa55175 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index a1bb51b0c7906b2f0e22aa99014b5eb7adc5f5bc..a3f8d574f597dcef2680c56a46d8738b899229be 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 881158db68ba6fda31790594002668758231f2e2..c27383b2ba1483a65fb742aaac9a95f3589682d2 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
- @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ @version V2.12 12 June 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
index 6c3a27513b89137dfb83266c268033fa036271ab..2d3a8445a56278d27fa8d8afe720ba0d8fd6b4c4 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 24355dabc5c5ed5ec31e0bc187f35a4d66268bda..0e420914b1b404bf9b052274f439ec53ce019fac 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.  \r
+V2.12 12 June 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
@@ -39,7 +39,7 @@ class ADODB_ibase extends ADOConnection {
        var $dialect = 1;\r
        var $sysDate = "cast('TODAY' as date)";\r
        var $sysTimeStamp = "cast('NOW' as timestamp)";\r
-\r
+       \r
     function ADODB_ibase() \r
        {\r
         ibase_timefmt('%Y-%m-%d');\r
@@ -85,6 +85,12 @@ class ADODB_ibase extends ADOConnection {
                return 1;\r
        }\r
        \r
+       function Replace($table, $fieldArray, $keyCol,$autoQuote=false)\r
+       {\r
+               print "<p>ADOdb: Replace not supported because affected_rows does not work with Interbase</p>";\r
+               return 0;\r
+       }\r
+       \r
        function GenID($seqname='adodbseq',$startID=1)\r
        {\r
                $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE");\r
@@ -316,8 +322,9 @@ class ADORecordset_ibase extends ADORecordSet
         {\r
                  $fld = new ADOFieldObject;\r
                  $ibf = ibase_field_info($this->_queryID,$fieldOffset);\r
-                 $fld->name = strtolower($ibf['name']);\r
-                                if (empty($fld->name)) $fld->name = $ibf['alias'];\r
+                       \r
+                 $fld->name = strtolower($ibf['alias']);\r
+                                if (empty($fld->name)) $fld->name = strtolower($ibf['name']);\r
                  $fld->type = $ibf['type'];\r
                  $fld->max_length = $ibf['length'];\r
                  if ($this->debug) print_r($fld);\r
index 79c2a92cd2e8cebfebe8da093e6c474e4ce9fc62..c90a091d4cc4123fb297837e3c98784f21f7080c 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /**\r
-* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). \r
+* @version V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). \r
 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
index 078ef09a87719e4dd655c3f8b0e11eb91cd04ef5..e5b94ee19b9d2d3b485441a65d3affa27524db1b 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim. All rights reserved.\r
+V2.12 12 June 2002 (c) 2000-2002 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
@@ -123,10 +123,20 @@ class ADODB_informix72 extends ADOConnection {
                #if ($argDatabasename) return $this->SelectDB($argDatabasename);\r
                return true;\r
        }\r
-\r
+/*\r
+       // ifx_do does not accept bind parameters - wierd ???\r
+       function Prepare($sql)\r
+       {\r
+               $stmt = ifx_prepare($sql);\r
+               if (!$stmt) return $sql;\r
+               else return array($sql,$stmt);\r
+       }\r
+*/\r
        // returns query ID if successful, otherwise false\r
        function _query($sql,$inputarr)\r
        {\r
+       global $ADODB_COUNTRECS;\r
+       \r
       // String parameters have to be converted using ifx_create_char\r
       if ($inputarr) {\r
          foreach($inputarr as $v) {\r
@@ -141,7 +151,7 @@ class ADODB_informix72 extends ADOConnection {
 \r
       // In case of select statement, we use a scroll cursor in order\r
       // to be able to call "move", or "movefirst" statements\r
-      if (preg_match("/^[\\t\\n ]*select/i", $sql)) {\r
+      if ($ADODB_COUNTRECS && preg_match("/^[\\t\\n ]*select/i", $sql)) {\r
          if ($inputarr) {\r
             $this->lastQuery = ifx_query($sql,$this->_connectionID, IFX_SCROLL, $tab);\r
          }\r
index b1e3a0db1caedb3fca59a762c974d61199814b40..2c17345ccbc30085a6e27151aee63c1ff3ca9026 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -33,13 +33,19 @@ Set tabs to 4 for best viewing.
 //----------------------------------------------------------------\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
+       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
-$ADODB_mssql_date_order = 'mdy'; \r
-$ADODB_mssql_mths = array(\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
@@ -78,11 +84,11 @@ class ADODB_mssql extends ADOConnection {
        var $_has_mssql_init;\r
        var $maxParameterLen = 4000;\r
        var $arrayClass = 'ADORecordSet_array_mssql';\r
+       var $uniqueSort = true;\r
        \r
        function ADODB_mssql() \r
        {                       \r
-               $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0);\r
-       \r
+               $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0);   \r
        }\r
 \r
     // might require begintrans -- committrans\r
@@ -194,12 +200,17 @@ class ADODB_mssql extends ADOConnection {
                Note: This function is NOT available for Microsoft SQL Server.  */\r
        function ErrorMsg() \r
        {\r
-               $this->_errorMsg = mssql_get_last_message();\r
+               if (empty($this->_errorMsg)){\r
+                       $this->_errorMsg = mssql_get_last_message();\r
+               }\r
                return $this->_errorMsg;\r
        }\r
        \r
        function ErrorNo() \r
        {\r
+               if (empty($this->_errorMsg)) {\r
+                       $this->_errorMsg = mssql_get_last_message();    print " D E F $this->_errorMsg";\r
+               }\r
                $id = @mssql_query("select @@ERROR",$this->_connectionID);\r
                if (!$id) return false;\r
                $arr = mssql_fetch_array($id);\r
@@ -306,6 +317,7 @@ 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
        }\r
@@ -458,6 +470,9 @@ class ADORecordSet_array_mssql extends ADORecordSet_array {
                // 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
        global $ADODB_mssql_mths,$ADODB_mssql_date_order;\r
        \r
                //Dec 30 2000 12:00AM \r
@@ -465,7 +480,7 @@ class ADORecordSet_array_mssql extends ADORecordSet_array {
                        if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {\r
                                return parent::UnixDate($v);\r
                        }\r
-                       if ($rr[3] <= 1970) return 0;\r
+                       if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;\r
                        \r
                        $theday = $rr[1];\r
                        $themth =  substr(strtoupper($rr[2]),0,3);\r
@@ -473,7 +488,7 @@ class ADORecordSet_array_mssql extends ADORecordSet_array {
                        if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {\r
                                return parent::UnixDate($v);\r
                        }\r
-                       if ($rr[3] <= 1970) return 0;\r
+                       if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;\r
                        \r
                        $theday = $rr[2];\r
                        $themth = substr(strtoupper($rr[1]),0,3);\r
@@ -486,20 +501,23 @@ 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
        global $ADODB_mssql_mths,$ADODB_mssql_date_order;\r
        \r
                //Dec 30 2000 12:00AM\r
                 if ($ADODB_mssql_date_order == 'dmy') {\r
                         if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|"\r
                        ,$v, $rr)) return parent::UnixTimeStamp($v);\r
-                       if ($rr[3] <= 1970) return 0;\r
+                       if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;\r
                \r
                        $theday = $rr[1];\r
                        $themth =  substr(strtoupper($rr[2]),0,3);\r
                } else {\r
                        if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|"\r
                        ,$v, $rr)) return parent::UnixTimeStamp($v);\r
-                       if ($rr[3] <= 1970) return 0;\r
+                       if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;\r
                \r
                        $theday = $rr[2];\r
                        $themth = substr(strtoupper($rr[1]),0,3);\r
@@ -522,4 +540,5 @@ class ADORecordSet_array_mssql extends ADORecordSet_array {
                return  mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]);\r
        }\r
 }\r
+\r
 ?>
\ No newline at end of file
index 6595cb76556a340ba0845494cbc614794523aa56..3642fc4445b0919cbb0a63aecca81bf38966df35 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -29,6 +29,7 @@ class ADODB_mysql extends ADOConnection {
        var $isoDates = true; // accepts dates in ISO format\r
        var $sysDate = 'CURDATE()';\r
        var $sysTimeStamp = 'NOW()';\r
+       var $forceNewConnect = false;\r
        \r
        function ADODB_mysql() \r
        {                       \r
@@ -104,7 +105,10 @@ class ADODB_mysql extends ADOConnection {
        // returns true or false\r
        function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)\r
        {\r
-               $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);\r
+               if ($this->forceNewConnect && (strnatcmp(PHP_VERSION,'4.2.0')>=0))\r
+                       $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,true);\r
+               else\r
+                       $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);\r
                if ($this->_connectionID === false) return false;\r
                if ($argDatabasename) return $this->SelectDB($argDatabasename);\r
                return true;    \r
@@ -295,9 +299,11 @@ class ADORecordSet_mysql extends ADORecordSet{
                $this->_numOfFields = @mysql_num_fields($this->_queryID);\r
        }\r
        \r
-       function &FetchField($fieldOffset = -1) {\r
+       function &FetchField($fieldOffset = -1) \r
+       {       \r
+       \r
                if ($fieldOffset != -1) {\r
-                       $o =  @mysql_fetch_field($this->_queryID, $fieldOffset);\r
+                       $o =  mysql_fetch_field($this->_queryID, $fieldOffset);\r
                        $f = @mysql_field_flags($this->_queryID,$fieldOffset);\r
                        $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)\r
                        //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable\r
@@ -308,7 +314,7 @@ class ADORecordSet_mysql extends ADORecordSet{
                        $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)\r
                        //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable\r
                }\r
-               \r
+                       \r
                return $o;\r
        }\r
 \r
index ee50d7549958310b4e6c5decdc4b9a18e15f8786..d8d38217d12a0b9fb88d51818807560651cb8c2f 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 110c6fee601972f6e208c740f29f3d01dbc3c2ee..cbad55875a1f5ad05696d49c85940dd5c4a25c27 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim. All rights reserved.\r
+V2.12 12 June 2002 (c) 2000-2002 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
@@ -37,7 +37,7 @@ class ADODB_oci8 extends ADOConnection {
        var $dataProvider = 'oci8';\r
     var $replaceQuote = "''"; // string to use to replace quotes\r
     var $concat_operator='||';\r
-       var $sysDate = "TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD')";\r
+       var $sysDate = "TRUNC(SYSDATE)";\r
        var $sysTimeStamp = 'SYSDATE';\r
        \r
        var $_stmt;\r
@@ -594,6 +594,7 @@ NATSOFT.DOMAIN =
                        return "'".str_replace("\\'",$this->replaceQuote,$s)."'";\r
                }\r
        }\r
+       \r
 }\r
 \r
 /*--------------------------------------------------------------------------------------\r
@@ -631,22 +632,12 @@ class ADORecordset_oci8 extends ADORecordSet {
                $this->fields = array();\r
                \r
                if ($this->_queryID) {\r
-               /*\r
-                       if ($this->connection->_getarray) { \r
-                               if ($this->connection->_hasOCIFetchStatement) {\r
-                                       $arr = array();\r
-                                       if (OCIFetchStatement($this->_queryID,$arr,0,(integer)-1,OCI_FETCHSTATEMENT_BY_ROW|$this->fetchMode)) {\r
-                                               $this->_arr = $arr;\r
-                                       }\r
-                                       $this->EOF = false;\r
-                               }\r
-                       } else */\r
-                       {               \r
-                               $this->EOF = !$this->_fetch();                  \r
-                               $this->_currentRow = 0;\r
-                       }\r
-               \r
+                                               \r
+                       $this->_currentRow = 0;\r
+                       \r
                        @$this->_initrs();\r
+                       \r
+                       $this->EOF = !$this->_fetch();  \r
                \r
                } else {\r
                        $this->_numOfRows = 0;\r
@@ -815,4 +806,4 @@ class ADORecordset_oci8 extends ADORecordSet {
         }\r
     }\r
 }\r
-?>\r
+?>
\ No newline at end of file
index 45a365404a46da82e06446ba9979ae4e3e5883a2..fa248715afb3bfcc9972c57c4e6b3278ac59b55c 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V2.12 12 June 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
@@ -18,6 +18,11 @@ class ADODB_oci805 extends ADODB_oci8 {
        var $databaseType = "oci805";   \r
        var $connectSID = true;\r
        \r
+       function ADODB_oci805() \r
+       {\r
+               $this->ADODB_oci8();\r
+    }\r
+       \r
        function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$arg3=false,$secs2cache=0)\r
        {\r
                // seems that oracle only supports 1 hint comment in 8i\r
index 4bf4974a437e43382b012eb6da8ed293f8fcbe66..f0a0d4e56e90cdf5506de00e78ed7cbe2f32e705 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim. All rights reserved.\r
+V2.12 12 June 2002 (c) 2000-2002 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
index 47120b6af12037fa5058474fbf3c9e006366980f..5a40b213836e2ef02734d9502a98aa8bb1a6f891 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index bc48244fa48ffe83e6b675a8de0bd0dc22ef6c39..871055de689205c6ebe0ad188a6804a6f049ad24 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 2c50e88a2d69b4c7f3c8f2daa93329de4ebdddef..8620396f8ac82ea96cb4190edabf5180e3d351f7 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 8995af2fe9593c1a218a29e729cbc184b186ac56..beca349b5545cdda47f3f3088b99ee883e716679 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index fac10e777bda94766c96e30a19a9c123681bf3f1..e02fcd96ec693cb541900068ddde3387068729cc 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
- V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ V2.12 12 June 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
index 62507ee7adfd00d1498bb8821621fe5a9e725619..4708a4ac4c30e9acef5f10235cf030abf6f7d39e 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
- V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ V2.12 12 June 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
index f059f1637c7193fbe3e9955148e9f156bfd4bc2b..94e7077a36444288a78dff06a60e9007f1229c14 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
- V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ V2.12 12 June 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
index fb8d5d5d39c975605833bc915067ee2fd9792bbb..7cb3e34391a26f8acfc0398344eea5de16353376 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 58c79c4ed74188290525068211e6e07da3ecbb04..7dd733ec0261e1ff52a481a61fe92d469519b66b 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-version V2.00 13 May 2002 (c) 2000-2002  John Lim (jlim@natsoft.com.my). All rights\r
+version V2.12 12 June 2002 (c) 2000-2002  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
index 245c3ad5df13d97765364c4aabf124ccc0464750..d6b75f4dff0c1f0b63061408a81e363eca34be40 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim. All rights reserved.\r
+V2.12 12 June 2002 (c) 2000-2002 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
@@ -236,7 +236,7 @@ class ADORecordSet_array_sybase extends ADORecordSet_array {
                if (!ereg( "([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})"\r
                        ,$v, $rr)) return parent::UnixDate($v);\r
                        \r
-               if ($rr[3] <= 1970) return 0;\r
+               if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;\r
                \r
                $themth = substr(strtoupper($rr[1]),0,3);\r
                $themth = $ADODB_sybase_mths[$themth];\r
@@ -252,7 +252,7 @@ class ADORecordSet_array_sybase extends ADORecordSet_array {
                //Changed [0-9] to [0-9 ] in day conversion\r
                if (!ereg( "([A-Za-z]{3})[-/\. ]([0-9 ]{1,2})[-/\. ]([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})"\r
                        ,$v, $rr)) return parent::UnixTimeStamp($v);\r
-               if ($rr[3] <= 1970) return 0;\r
+               if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;\r
                \r
                $themth = substr(strtoupper($rr[1]),0,3);\r
                $themth = $ADODB_sybase_mths[$themth];\r
index 8329bcdf53452997d12952a546f88cb427c85bff..98f5417d69c0753a855a87190521cb527359271f 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -42,6 +42,7 @@ class ADODB_vfp extends ADODB_odbc {
                if (!$nofixquotes) return  "'".str_replace("\r\n","'+chr(13)+'",str_replace("'",$this->replaceQuote,$s))."'";\r
                return "'".$s."'";\r
        }\r
+\r
        \r
        // TOP requires ORDER BY for VFP\r
        function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$arg3=false,$secs2cache=0)\r
index c0fb98ef04abe9c326aae4b4b63842a6cddb2a63..3ad762d3ffcd306cfaf7e40d567c4aadcf5496e9 100644 (file)
@@ -12,7 +12,7 @@
 <body bgcolor="#FFFFFF">\r
 \r
 <h2>ADOdb Library for PHP</h2>\r
-<p>V2.00 13 May 2002 (c) 2000-2002 John Lim (<a href="mailto:jlim@natsoft.com.my">jlim@natsoft.com.my</a>)</p>\r
+<p>V2.12 12 June 2002 (c) 2000-2002 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
@@ -20,7 +20,7 @@ This means you can use it in proprietary and commercial products.</p>
  <a href="#features">Unique Features</a><br>\r
  <a href="#users">How People are using ADOdb</a><br>\r
  <a href="#bugs">Feature Requests and Bug Reports</a><br>\r
- </b><b><a href="#install">Installation<br>\r
+ </b><b><a href="#install">Installation<br>R\r
  </a><a href="#coding">Initializing Code</a></b> \r
  <font size="2"><a href=#adonewconnection>ADONewConnection</a></font>\r
   <font size="2"><a href=#adonewconnection>NewADOConnection</a></font><br>\r
@@ -45,8 +45,8 @@ This means you can use it in proprietary and commercial products.</p>
   Executing SQL: <a href="#execute">Execute</a> <a href="#cacheexecute">CacheExecute</a> \r
   <a href="#SelectLimit">SelectLimit</a> <a href="#cacheSelectLimit">CacheSelectLimit</a> \r
   <a href="#prepare">Prepare</a> <a href=#preparesp>PrepareSP</a> <a href="#parameter">Parameter</a> \r
-  <a href="#getone">GetOne</a> <a href="#getrow">GetRow</a><br>\r
-  Generate Updates/Inserts: <a href="#getupdatesql">GetUpdateSQL</a> <a href="#getinsertsql">GetInsertSQL</a></font><font size="2"><br>\r
+  <a href="#getone">GetOne</a> <a href="#getrow">GetRow</a> <a href="#replace">Replace</a> <br>\r
+  Generates SQL: <a href="#getupdatesql">GetUpdateSQL</a> <a href="#getinsertsql">GetInsertSQL</a></font><font size="2"><br>\r
   Blobs: <a href="#updateblob">UpdateBlob</a> <a href="#updateclob">UpdateClob</a> \r
   <a href="#updateblobfile">UpdateBlobFile</a> <br>\r
   Paging/Scrolling: <a href="#pageexecute">PageExecute</a> <a href="#cachepageexecute">CachePageExecute</a><br>\r
@@ -54,7 +54,7 @@ This means you can use it in proprietary and commercial products.</p>
   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">Concat</a> <a href="#qstr">qstr</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> <a href="#unixdate">UnixDate</a> \r
   <a href="#unixtimestamp">UnixTimeStamp</a><br>\r
   Rows Management: <a href="#affected_rows">Affected_Rows</a> <a href="#inserted_id">Insert_ID</a> \r
@@ -733,50 +733,85 @@ $conn->Close();
 ?>\r
 </pre>\r
 <h3>Example 8: Implementing Scrolling with Next and Previous<a name="ex8"></a></h3>\r
-<p>\r
-Code and idea by Iv&aacute;n Oliva ivan.oliva#amena.com. <p>\r
-We use the HTTP Get variable $next_page to keep track of what page to go next and\r
- store the current page in the session variable $curr_page.\r
-<p>\r
-We call the connection object's PageExecute() function to generate the appropriate recordset, \r
-then use the recordset's AtFirstPage() and AtLastPage() functions to determine \r
-whether to display the next and previous buttons. <p>\r
-\r
+<p> The following code creates a very simple recordset pager, where you can scroll \r
+  from page to page of a recordset.</p>\r
+  \r
 <pre>\r
-&lt;?php\r
-include_once('adodb.inc.php');\r
-include_once('tohtml.inc.php');\r
-<b>session_register('curr_page');</b>\r
+include_once('../adodb.inc.php');\r
+include_once('../adodb-pager.inc.php');\r
+session_start();\r
 \r
 $db = NewADOConnection('mysql');\r
+\r
 $db->Connect('localhost','root','','xphplens');\r
-<b>$num_of_rows_per_page = 10;\r
-$sql = 'select * from products';\r
 \r
-if (isset($HTTP_GET_VARS['next_page']))\r
-       $curr_page = $HTTP_GET_VARS['next_page'];\r
-if (empty($curr_page)) $curr_page = 1; ## at first page</b><b>\r
+$sql = "select * from adoxyz ";\r
 \r
-$rs = $db->PageExecute($sql, $num_of_rows_per_page, $curr_page);</b>\r
-if (!$rs) die('Query Failed');\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>\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
+         &nbsp; <a href="#scr"><code>>></code></a> &nbsp; <a href="#scr"><code>>|</code></a> \r
+         &nbsp; </td>\r
+  </tr><tr><td><TABLE COLS=4 width=100% border=1 bgcolor=white>\r
 \r
-if (!$rs->EOF && (!$rs-><b>AtFirstPage</b>() || !$rs-><b>AtLastPage</b>())) &#123;\r
-       if (!$rs-><b>AtFirstPage</b>()) &#123;\r
-?>\r
-&lt;a href="&lt;?php echo $PHPSELF,'?next_page=',$rs-><b>AbsolutePage</b>() - 1 ?>">Previous page&lt;/a>\r
-&lt;?php\r
-       &#125;\r
-       if (!$rs-><b>AtLastPage</b>()) &#123;\r
-?>\r
-&lt;a href="&lt;?php echo $PHPSELF,'?next_page=',$rs-><b>AbsolutePage</b>() + 1 ?>">Next page&lt;/a>\r
-&lt;?php\r
-       &#125;\r
-       rs2html($rs);\r
-&#125;\r
-?>\r
-</pre>\r
-The above code can be found in the <i>testpaging.php</i> example included with \r
-this release.\r
+<TH>ID</TH><TH>First Name</TH><TH>Last Name</TH><TH>Date Created</TH>\r
+\r
+<TR>\r
+       <TD align=right>36&nbsp;</TD>\r
+       <TD>Alan&nbsp;</TD>\r
+       <TD>Turing&nbsp;</TD>\r
+       <TD>Sat 06, Oct 2001&nbsp;</TD>\r
+</TR>\r
+\r
+<TR>\r
+       <TD align=right>37&nbsp;</TD>\r
+       <TD>Serena&nbsp;</TD>\r
+       <TD>Williams&nbsp;</TD>\r
+       <TD>Sat 06, Oct 2001&nbsp;</TD>\r
+</TR>\r
+\r
+<TR>\r
+       <TD align=right>38&nbsp;</TD>\r
+       <TD>Yat Sun&nbsp;</TD>\r
+       <TD>Sun&nbsp;</TD>\r
+       <TD>Sat 06, Oct 2001&nbsp;</TD>\r
+</TR>\r
+\r
+<TR>\r
+       <TD align=right>39&nbsp;</TD>\r
+       <TD>Wai Hun&nbsp;</TD>\r
+       <TD>See&nbsp;</TD>\r
+       <TD>Sat 06, Oct 2001&nbsp;</TD>\r
+</TR>\r
+\r
+<TR>\r
+       <TD align=right>40&nbsp;</TD>\r
+       <TD>Steven&nbsp;</TD>\r
+       <TD>Oey&nbsp;</TD>\r
+       <TD>Sat 06, Oct 2001&nbsp;</TD>\r
+</TR>\r
+\r
+</TABLE>\r
+\r
+</td></tr><tr><td><font size=-1>Page 8/10</font></td></tr></table>\r
+<p>The number of rows to display at one time is controled by the Render($rows) \r
+  method. If you do not pass any value to Render(), ADODB_Pager will default to \r
+  10 records per page. \r
+<p>You can control the column titles by modifying your SQL (supported by most \r
+  databases):\r
+<pre>$sql = 'select id as &quot;ID&quot;, firstname as &quot;First Name&quot;, \r
+          lastname as &quot;Last Name&quot;, created as &quot;Date Created&quot; <br>        from adoxyz';</pre>\r
+<p>The above code can be found in the <i>adodb/tests/testpaging.php</i> example \r
+  included with this release, and the class ADODB_Pager in <i>adodb/adodb-pager.inc.php</i>. \r
+  The ADODB_Pager code can be adapted by a programmer so that the text links can \r
+  be replaced by images, and the dull white background be replaced with more interesting \r
+  colors.\r
+<p>Some of the code used here was contributed by Iv&aacute;n Oliva and Cornel \r
+  G. </p>\r
+<p> \r
 <h2><a name="errorhandling"></a>Using Custom Error Handlers and PEAR_Error</h2>\r
 Apart from the old $con->debug = true; way of debugging, ADOdb 1.50 onwards provides \r
 another way of handling errors using ADOdb's custom error handlers. \r
@@ -915,7 +950,7 @@ CacheExecute(). If you leave it out, it will use the $connection->cacheSecs para
 to 60 minutes.\r
 <pre>\r
        $conn->Connect(...);\r
-       $conn->cacheSecs = 3600*24; // cache 24 hours\r
+       $conn->cacheSecs = 3600*24; # cache 24 hours\r
        $rs = $conn->CacheExecute('select * from table');\r
 </pre>\r
 <font color="#000000"> \r
@@ -1006,14 +1041,16 @@ to 60 minutes.
 <p><b>autoCommit</b>: indicates whether automatic commit is enabled. Default is \r
   true.</p>\r
 <p><b>charSet</b>: set the default charset to use. Currently only interbase supports \r
-  this. </p>\r
+  this.</p>\r
+<p><b>dialect</b>: set the default sql dialect to use. Currently only interbase supports\r
+this.</p>\r
 <p><b>metaTablesSQL</b>: SQL statement to return a list of available tables. Eg. \r
   <i>SHOW TABLES</i> in MySQL.</p>\r
 <p><b>genID</b>: The latest id generated by GenID() if supported by the database.</p>\r
 <p><b>cacheSecs</b>: The number of seconds to cache recordsets if CacheExecute() \r
   or CacheSelectLimit() do not define the $secs2cache parameter.</p>\r
-<p><b>sysDate</b>: The database function to call to get the current date and time \r
-  using the native date/timestamp type.</p>\r
+<p><b>sysDate</b>: String that holds the name of the database function to call to get the current date. Useful for inserts and updates.</p>\r
+<p><b>sysTimeStamp</b>: String that holds the name of the database function to call to get the current timestamp/datetime value.</p>\r
 <hr>\r
 <h3>ADOConnection Main Functions</h3>\r
 <p><b>ADOConnection( )</b></p>\r
@@ -1243,7 +1280,41 @@ Similar to UpdateBlob (see above), but for Character Large OBjects.
 <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
+<p>returns true if successful, false otherwise.\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 the MySQL replace which deletes\r
+the record and inserts a new record. This also means you cannot update the primary key.\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
+<pre>\r
+# single field primary key\r
+$ret = $db->Replace('atable', \r
+       array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'),\r
+       'id',\r
+       'firstname',$autoquote = true); \r
+# generates UPDATE atable SET firstname='Harun',lastname='Al-Rashid' WHERE id=1000\r
+# or INSERT INTO atable (id,firstname,lastname) VALUES (1000,'Harun','Al-Rashid')\r
+\r
+# compound key\r
+$ret = $db->Replace('atable2', \r
+       array('firstname'=>'Harun','lastname'=>'Al-Rashid', 'age' => 33, 'birthday' => 'null'),\r
+       array('lastname','firstname'),\r
+       'firstname',$autoquote = true);\r
+\r
+# no auto-quoting\r
+$ret = $db->Replace('atable2', \r
+       array('firstname'=>"'Harun'",'lastname'=>"'Al-Rashid'", 'age' => 'null'),\r
+       array('lastname','firstname'),\r
+       '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
@@ -1447,6 +1518,9 @@ for ($i = 0; $i &lt; $max; $i++) {
   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>Returns the number of rows affected by a update or delete statement. Returns \r
   false if function not supported.</p>\r
@@ -1829,9 +1903,42 @@ $<font color="#663300">rs</font>   = $<font color="#663300">conn</font>->Execute
 <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.</p>\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 info,\r
+  and read this article \r
+  on <a href=http://phplens.com/lens/php-book/optimizing-debugging-php.php>Optimizing PHP</a>.\r
+</p>\r
 </font>\r
 <h2>Change Log<a name="Changes"></a><a name=ChangeLog></a></h2>\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
index 687bd57d979c5b25f7cab0566e91ce801b3ea140..e906a1753e8d3368d22fa4645e070dea42e826b3 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /** \r
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V2.12 12 June 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
@@ -88,7 +88,7 @@ if (isset($HTTP_GET_VARS['nrows'])) {
        $rs = $conn->Execute($sql);\r
 if ($rs){ \r
        //$rs->timeToLive = 1;\r
-       echo rs2csv($rs,$conn,$sql);\r
+       echo _rs2serialize($rs,$conn,$sql);\r
        $rs->Close();\r
 } else\r
        err($conn->ErrorNo(). $sep .$conn->ErrorMsg());\r
index 32002ede0b734994ca8aa6b506cbb99e3236391f..bbf403bf81eac93e1cb79412367c3b7e63e90229 100644 (file)
@@ -8,7 +8,7 @@
 <body>\r
 <?php \r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index 55b39e821f0b9346b847ed6c01492d55fa1051f7..ffba20abf7c6d83b549f7989719accaaccb91818 100644 (file)
@@ -2,7 +2,7 @@
 <body bgcolor=white>\r
 <?php\r
 /** \r
- * (c)2001,2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * V2.12 12 June 2002 (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
index a0eb27bbc929506f64b02023549ba3decdde0690..ddafa71ad4084d991c02711e0c666a77076d568a 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -86,8 +86,8 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU
        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
        \r
-       \r
-       print "<i>date1</i> (1999-02-20) = ".$db->DBDate('1999-2-20');\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
        print "<i>ts1</i> (1999-02-20 3:40:50) = ".$db->DBTimeStamp('1999-2-20 3:40:50');\r
        print "<br><i>ts2</i> (1999-02-20) = ".$db->DBTimeStamp('1999-2-20');\r
@@ -140,12 +140,13 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU
        if ($rs) $rs->Close();\r
        \r
        \r
-       $db->debug=false;       \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
-               $rs = $db->Execute("insert into ADOXYZ values (99,'Should Not','Exist (Commit)',$time)");\r
+               \r
+               $rs = $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (99,'Should Not','Exist (Commit)',$time)");\r
                if ($rs && $db->CommitTrans()) {\r
                        $rs->Close();\r
                        $rs = &$db->Execute("select * from ADOXYZ where id=99");\r
@@ -156,13 +157,16 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU
                                die();\r
                        } else print 'OK</p>';\r
                        if ($rs) $rs->Close();\r
-               } else\r
-                       print "<b>Commit failed</b></p>";\r
-               \r
+               } else {\r
+                       if (!$rs) {\r
+                               print "<b>Insert failed</b></p>";\r
+                               $db->RollbackTrans();\r
+                       } else print "<b>Commit failed</b></p>";\r
+               }\r
                /* ROLLBACK */  \r
                if (!$db->BeginTrans()) print "<p><b>Error in BeginTrans</b>()</p>";\r
                print "<p>Testing Rollback: ";\r
-               $db->Execute("insert into ADOXYZ values (100,'Should Not','Exist (Rollback)',$time)");\r
+               $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (100,'Should Not','Exist (Rollback)',$time)");\r
                if ($db->RollbackTrans()) {\r
                        $rs = $db->Execute("select * from ADOXYZ where id=100");\r
                        if ($rs && !$rs->EOF) print '<b>Fail: Data should rollback</b></p>';\r
@@ -307,11 +311,10 @@ GO
        $db->debug = false;\r
 \r
        $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;\r
- ///////////////////////////////\r
-       \r
-       $rs = &$db->Execute("select * from ADOXYZ order by id");\r
+ //////////////////////////////////////////////////////////////////////////////////////////\r
+       \r
+       $rs = &$db->Execute("select id,firstname as TheFirstName,lastname,created from ADOXYZ order by id");\r
        if ($rs) {\r
-       //      print_r($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
@@ -586,7 +589,7 @@ GO
        if ($val == 0) echo " <p><b>GenID not supported</b>";\r
        echo "<p>";\r
        \r
-       if (substr($db->dataProvider,0,3) != 'ado') { // crashes ado\r
+       if (substr($db->dataProvider,0,3) != 'notused') { // used to crash ado\r
                $sql = "select firstnames from adoxyz";\r
                print "<p>Testing execution of illegal statement: <i>$sql</i></p>";\r
                if ($db->Execute($sql) === false) {\r
@@ -655,7 +658,9 @@ GO
                        print "<p><b>Invalid date {$rs->fields[0]}</b></p>";\r
                } else\r
                        print "<p>Passed \$sysDate test ({$rs->fields[0]})</p>";\r
-                       \r
+               \r
+               print_r($rs->FetchField(0));\r
+               print time();\r
                $db->debug=$saved;\r
        } else {\r
                print "<p><b>\$db->sysDate not defined</b></p>";\r
@@ -678,10 +683,44 @@ GO
                }\r
                $rs->Close();\r
        }\r
+       \r
+       print "<p>Test CSV</p>";\r
+       include_once('../toexport.inc.php');\r
+       $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;\r
+       $rs = $db->SelectLimit('select id,firstname,lastname,created,\'The      "young man", he said\' from adoxyz',10);        \r
+       \r
+       print "<pre>";\r
+       print rs2csv($rs);\r
+       print "</pre>";\r
+       \r
+       $rs = $db->SelectLimit('select id,firstname,lastname,created,\'The      "young man", he said\' from adoxyz',10);        \r
+       \r
+       print "<pre>";\r
+       tab2csvout($rs);\r
+       print "</pre>";\r
+       $db->debug=1;\r
+       \r
+       print "<p>Test Replace</p>";\r
+       \r
+       $ret = $db->Replace('adoxyz', \r
+               array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'),\r
+               array('id','firstname'),\r
+               $autoq = true);\r
+       if ($ret != 2) print "<b>Replace failed: </b>";\r
+       print "test A return value=$ret (2 expected) <p>";\r
+       \r
+       $ret = $db->Replace('adoxyz', \r
+               array('id'=>1000,'firstname'=>'Sherazade','lastname'=>'Al-Rashid'),\r
+               'id',\r
+               $autoq = true);\r
+       if ($ret != 1) print "<b>Replace failed: </b>";\r
+       print "test B return value=$ret (1 expected) <p>";\r
+       \r
+       /////////////////////////////////////////////////////////////\r
+\r
 \r
        \r
        include_once "PEAR.php";\r
-       $db->debug =true;\r
        if ($i != 50) {\r
                print "<p><b>PEAR DB emulation error 1.1 EOF ($i)</b></p>";\r
                $pear = false;\r
@@ -713,14 +752,21 @@ GO
        \r
 \r
        global $TESTERRS;\r
+       $debugerr = true;\r
+               \r
        $db->debug = false;\r
        $TESTERRS = 0;\r
        $db->raiseErrorFn = 'adodb_test_err';\r
        $db->Execute('select * from nowhere');\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
        $rs->Move(100);\r
        $rs->_queryID = false;\r
+       if ($debugerr) print " MoveNext";\r
        $rs->MoveNext();\r
+       \r
+       if ($debugerr) print " $rs=false";\r
        $rs = false;\r
        $conn = NewADOConnection($db->databaseType);\r
        $conn->raiseErrorFn = 'adodb_test_err';\r
index f620af3ab8db18390fb5eb0a8e66a96e0de6d8e9..007a57f5e48e31fed832544ae3a9f89bb0a5d96f 100644 (file)
@@ -8,7 +8,7 @@
 <body>\r
 <?php\r
 /*\r
-  V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  V2.12 12 June 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
@@ -23,30 +23,15 @@ include("../adodb.inc.php");
 \r
 ADOLoadCode('mysql');\r
 \r
-$c1 = ADONewConnection('mysql');\r
-$c2 = ADONewConnection('mysql');\r
+$c1 = ADONewConnection('oci8');\r
 \r
-if (!$c1->PConnect('flipper','','',"test")) \r
-       die("Cannot connect to flipper");\r
-if (!$c2->PConnect('mangrove','root','',"northwind")) \r
-       die("Cannot connect to mangrove");\r
-\r
-print "<h3>Flipper</h3>";\r
-$t = $c1->MetaTables(); # list all tables in DB\r
-print_r($t);\r
-# select * from last table in DB\r
-rs2html($c1->Execute("select * from ".$t[sizeof($t)-1])); \r
-\r
-print "<h3>Mangrove</h3>";\r
-$t = $c2->MetaTables();\r
-print_r($t);\r
-rs2html($c2->Execute("select * from ".$t[sizeof($t)-1] ));\r
-\r
-print "<h3>Flipper</h3>";\r
-$t = $c1->MetaTables();\r
-print_r($t);\r
-rs2html($c1->Execute("select * from ".$t[sizeof($t)-1]));\r
+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
+rs2html($rs);\r
 ?>\r
 \r
 \r
index 9bfafc7dc7f55af6cbd24d78f888667f58efe7ee..a544149473cd720226f9b2fa62a08e0ec4e3b9a1 100644 (file)
@@ -1,7 +1,7 @@
 <code>\r
 <?php\r
 /*\r
-  V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+  V2.12 12 June 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
index d20676bf6937ec0a86ebcd978f70f9ba63c3a32a..06f12da7638a401f1fe87da432ed462140637e4a 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 \r
 /** \r
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+ * @version V2.12 12 June 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
index a392bb7730c1442d9addb511ea7b60a78dd40359..64d45be3f8fb84f44c6ff6d790f7a7374db3bcb4 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index e55735a05cc80ea49015a2c9772ccc0a51f2c042..d98c2ca197b9cdc4d6508b6c8cb890df80f50e48 100644 (file)
@@ -2,7 +2,7 @@
 <body>\r
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index a64d6b2a8576716e4c183c735823f2c17cec4279..2357b76b2cbc9ca827f19371a1f1779ab7ce2550 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
   \r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -106,7 +106,7 @@ ADOLoadCode('oci805');
 ADOLoadCode("oci8po");\r
 if (!empty($testoracle)) { \r
        \r
-       $db = ADONewConnection();\r
+       $db = ADONewConnection('oci8po');\r
        print "<h1>Connecting $db->databaseType...</h1>";\r
        if ($db->Connect('', "scott", "tiger",'natsoft.ecosystem.natsoft.com.my'))\r
        //if ($db->PConnect("", "scott", "tiger", "juris.ecosystem.natsoft.com.my"))\r
@@ -127,7 +127,7 @@ if (false && !empty($testoracle)) {
 \r
 \r
 ADOLoadCode("odbc_mssql");\r
-if (!empty($testmssql) and false) { // MS SQL Server via ODBC\r
+if (!empty($testmssql) && false) { // MS SQL Server via ODBC\r
        \r
        $db = ADONewConnection();\r
        \r
@@ -143,10 +143,11 @@ ADOLoadCode("ado_mssql");
 if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC -- DSN-less\r
        \r
        $db = &ADONewConnection("ado_mssql");\r
+       $db->debug=1;\r
        print "<h1>Connecting DSN-less $db->databaseType...</h1>";\r
        \r
        $myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};"\r
-               . "SERVER=(local);DATABASE=NorthWind;UID=sa;PWD=natsoft;"  ;\r
+               . "SERVER=mangrove;DATABASE=NorthWind;UID=sa;PWD=natsoft;"  ;\r
 \r
                \r
        if (@$db->PConnect($myDSN, "", "", ""))\r
@@ -159,6 +160,7 @@ if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC
 ADOLoadCode("mssql");\r
 if (!empty($testmssql)) { // MS SQL Server -- the extension is buggy -- probably better to use ODBC\r
        $db = ADONewConnection();\r
+       $db->debug=1;\r
        print "<h1>Connecting $db->databaseType...</h1>";\r
        \r
        $db->Connect('(local)\NetSDK','','','northwind');\r
@@ -174,7 +176,7 @@ if (!empty($testmssql) && !empty($testado)) { // ADO ACCESS MSSQL with OLEDB pro
 \r
        $db = &ADONewConnection("ado_mssql");\r
        print "<h1>Connecting DSN-less OLEDB Provider $db->databaseType...</h1>";\r
-       \r
+       $db->debug=1;\r
        $myDSN="SERVER=mangrove;DATABASE=ai;";\r
        //$myDSN='SERVER=(local)\NetSDK;DATABASE=northwind;';\r
        if ($db->PConnect($myDSN, "sa", "natsoft", 'SQLOLEDB'))\r
index 51e3b0afbaade6a9e46ca4ed57f30df2966bc465..5d76d74ca8cf3221611f1499b35cc11561dbe43d 100644 (file)
@@ -1,5 +1,7 @@
 <?php\r
 /*\r
+       V2.12 12 June 2002\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
 */\r
diff --git a/lib/adodb/tests/testmssql.php b/lib/adodb/tests/testmssql.php
new file mode 100644 (file)
index 0000000..849b6ce
--- /dev/null
@@ -0,0 +1,50 @@
+<?php\r
+\r
+/** \r
+ * @version V2.12 12 June 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
+ * Test GetUpdateSQL and GetInsertSQL.\r
+ */\r
\r
+error_reporting(E_ALL);\r
+\r
+\r
+include('../adodb.inc.php');\r
+include('../tohtml.inc.php');\r
+\r
+//==========================\r
+// This code tests an insert\r
+\r
+\r
+\r
+$conn = &ADONewConnection("odbc_mssql");  // create a connection\r
+$conn->Connect('sqlserver','sa','natsoft');\r
+\r
+//$conn = &ADONewConnection("mssql");\r
+//$conn->Connect('mangrove','sa','natsoft','ai');\r
+\r
+//$conn->Connect('mangrove','sa','natsoft','ai');\r
+$conn->debug=1;\r
+$conn->Execute('delete from blobtest');\r
+\r
+$conn->Execute('insert into blobtest (id) values(1)');\r
+$conn->UpdateBlobFile('blobtest','b1','../cute_icons_for_site/adodb.gif','id=1');\r
+$rs = $conn->Execute('select b1 from blobtest where id=1');\r
+\r
+$output = "c:\\temp\\test_out-".date('H-i-s').".gif"; \r
+print "Saving file <b>$output</b>, size=".strlen($rs->fields[0])."<p>";\r
+$fd = fopen($output, "wb"); \r
+fwrite($fd, $rs->fields[0]); \r
+fclose($fd); \r
+\r
+print " <a href=file://$output>View Image</a>";\r
+//$rs = $conn->Execute('SELECT id,SUBSTRING(b1, 1, 10) FROM blobtest');\r
+//rs2html($rs);\r
+?>
\ No newline at end of file
index 735e93e2704618d4de7be8b9bdde495ae2b94972..b1088aed9904f7a4a75a561d041e3d30a9777758 100644 (file)
@@ -2,7 +2,7 @@
 <body>\r
 <?php\r
 /* \r
-V1.81 22 March 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index e3ac3c68e617978a93f14f7d1d0123b38b399e5d..badb83de508cd43f74e352a95e1ae6935be31cc0 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -11,44 +11,47 @@ V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reser
 \r
 error_reporting(E_ALL);\r
 \r
-$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];\r
 \r
-include_once('../adodb-pear.inc.php');\r
-include_once('../tohtml.inc.php');\r
-session_register('curr_page');\r
+include_once('../adodb.inc.php');\r
+include_once('../adodb-pager.inc.php');\r
 \r
-$db = NewADOConnection('mysql');\r
-$db->debug = true;\r
-//$db->Connect('localhost:4321','scott','tiger','natsoft.domain');\r
-$db->Connect('localhost','root','','xphplens');\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
 \r
-$num_of_rows_per_page = 7;\r
-$sql = "select * from adoxyz ";\r
+if ($driver == 'access') {\r
+       $db = NewADOConnection('access');\r
+       $db->PConnect("nwind", "", "", "");\r
+}\r
 \r
-if (isset($HTTP_GET_VARS['next_page']))\r
-       $curr_page = $HTTP_GET_VARS['next_page'];\r
-if (empty($curr_page)) $curr_page = 1; ## at first page\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
+}\r
+if ($driver == 'mssql') {\r
+       $db = NewADOConnection('mssql');\r
+       $db->Connect('(local)\NetSDK','','','northwind');\r
+}\r
+if ($driver == 'oci8') {\r
+       $db = NewADOConnection('oci8');\r
+       $db->Connect('','scott','tiger');\r
+}\r
 \r
-$rs = $db->PageExecute($sql, $num_of_rows_per_page, $curr_page);\r
-if (!$rs) die('Query Failed');\r
+if ($driver == 'access') {\r
+       $db = NewADOConnection('access');\r
+       $db->Connect('nwind');\r
+}\r
 \r
-if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) {\r
-       if (!$rs->AtFirstPage()) {\r
-?>\r
-<a href="<?php echo $PHP_SELF;?>?next_page=1">First page</a> &nbsp;\r
-<a href="<?php echo $PHP_SELF,'?next_page=',$rs->AbsolutePage() - 1 ?>">Previous page</a> &nbsp;\r
-<?php\r
-       } else {\r
-       echo " First Page &nbsp; Previous Page &nbsp; ";\r
-       }\r
-       if (!$rs->AtLastPage()) {\r
-?>\r
-<a href="<?php echo $PHP_SELF,'?next_page=',$rs->AbsolutePage() + 1 ?>">Next Page</a>\r
-<?php\r
-       } else\r
-               print "Next Page";\r
-       rs2html($rs);\r
+if (empty($driver) or $driver == 'mysql') {\r
+       $db = NewADOConnection('mysql');\r
+       $db->Connect('localhost','root','','xphplens');\r
 }\r
 \r
+//$db->pageExecuteCountRows = false;\r
+\r
+$db->debug = true;\r
 \r
-?>\r
+$pager = new ADODB_Pager($db,$sql);\r
+//$pager->cache = 60;\r
+$pager->Render($rows=7);\r
+?>
\ No newline at end of file
index c0e69b21672a45fdead8c704a1f3fc3d16ac6d08..1ae17c361375eabbc7f3a005a920eda1d74e009d 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
index e2727608cceabf725282280142cc45bbdbcd0671..4b359c90f6a59e470d13ca546913327cda9963b5 100644 (file)
@@ -1,6 +1,6 @@
 <?php\r
 /* \r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -11,14 +11,14 @@ V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reser
 \r
 GLOBAL $HTTP_SESSION_VARS;\r
 \r
+       error_reporting(E_ALL);\r
+       \r
        $ADODB_SESS_DEBUG = true;\r
-       include('adodb.inc.php');\r
-       include('adodb-session.php');\r
+       include('../adodb-session.php');\r
        session_start();\r
-       session_register('AVAR');\r
-       $HTTP_SESSION_VARS['AVAR'] += 1;\r
-       $AVAR += 1;\r
        \r
-       print "<p>\$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}</p>";\r
+       if (!isset($HTTP_GET_VARS['nochange'])) $HTTP_SESSION_VARS['AVAR'] += 1;\r
+       \r
+       print "<p><b>\$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}</b></p>";\r
        \r
 ?>
\ No newline at end of file
index 6c6cde133a3a3e23857560e0e8f4a096f57aec66..e2dbcafadac626965eef2ba9db2df5e22f17d101 100644 (file)
@@ -257,7 +257,8 @@ $rs = $db-&gt;Execute(sprintf($sqlSearchKeyWord,$db-&gt;qstr($word)));</pre>
 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
+  <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
diff --git a/lib/adodb/toexport.inc.php b/lib/adodb/toexport.inc.php
new file mode 100644 (file)
index 0000000..db45fe6
--- /dev/null
@@ -0,0 +1,130 @@
+<?php\r
+\r
+/** \r
+ * @version V2.12 12 June 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
+ * Code to export recordsets in several formats:\r
+ *\r
+ * AS VARIABLE\r
+ * $s = rs2csv($rs); # comma-separated values\r
+ * $s = rs2tab($rs); # tab delimited\r
+ * \r
+ * TO A FILE\r
+ * $f = fopen($path,'w');\r
+ * rs2csvfile($rs,$f);\r
+ * fclose($f);\r
+ *\r
+ * TO STDOUT\r
+ * rscsvout($rs);\r
+ */\r
\r
+// returns a recordset as a csv string\r
+function rs2csv(&$rs,$addtitles=true)\r
+{\r
+       return _adodb_export($rs,',',',',false,$addtitles);\r
+}\r
+\r
+// writes recordset to csv file \r
+function rs2csvfile(&$rs,$fp,$addtitles=true)\r
+{\r
+       _adodb_export($rs,',',',',$fp,$addtitles);\r
+}\r
+\r
+// write recordset as csv string to stdout\r
+function rs2csvout(&$rs,$addtitles=true)\r
+{\r
+       $fp = fopen('php://stdout','wb');\r
+       _adodb_export($rs,',',',',true,$addtitles);\r
+       fclose($fp);\r
+}\r
+\r
+function tab2csv(&$rs,$addtitles=true)\r
+{\r
+       return _adodb_export($rs,"\t",',',false,$addtitles);\r
+}\r
+\r
+// to file pointer\r
+function tab2csvfile(&$rs,$fp,$addtitles=true)\r
+{\r
+       _adodb_export($rs,"\t",',',$fp,$addtitles);\r
+}\r
+\r
+// to stdout\r
+function tab2csvout(&$rs,$addtitles=true)\r
+{\r
+       $fp = fopen('php://stdout','wb');\r
+       _adodb_export($rs,"\t",' ',true,$addtitles);\r
+       fclose($fp);\r
+}\r
+\r
+function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ')\r
+{\r
+       if (!$rs) return '';\r
+       //----------\r
+       // CONSTANTS\r
+       $NEWLINE = "\r\n";\r
+       $BUFLINES = 100;\r
+       $escquotequote = $escquote.$quote;\r
+       $s = '';\r
+       \r
+       if ($addtitles) {\r
+               $fieldTypes = $rs->FieldTypesArray();\r
+               foreach($fieldTypes as $o) {\r
+                       \r
+                       $v = $o->name;\r
+                       if ($escquote) $v = str_replace($quote,$escquotequote,$v);\r
+                       $v = strip_tags(str_replace("\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)));\r
+                       $elements[] = $v;\r
+                       \r
+               }\r
+               $s .= implode($sep, $elements).$NEWLINE;\r
+       }\r
+       $hasNumIndex = isset($rs->fields[0]);\r
+       \r
+       $line = 0;\r
+       $max = $rs->FieldCount();\r
+       \r
+       while (!$rs->EOF) {\r
+               $elements = array();\r
+               $i = 0;\r
+               \r
+               if ($hasNumIndex) {\r
+                       for ($j=0; $j < $max; $j++) {\r
+                               $v = $rs->fields[$j];\r
+                               if ($escquote) $v = str_replace($quote,$escquotequote,$v);\r
+                               $v = strip_tags(str_replace("\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)));\r
+                               \r
+                               if (strpos($v,$sep) || strpos($v,$quote))$elements[] = "$quote$v$quote";\r
+                               else $elements[] = $v;\r
+                       }\r
+               } else { // ASSOCIATIVE ARRAY\r
+                       foreach($rs->fields as $v) {\r
+                               if ($escquote) $v = str_replace($quote,$escquotequote,$v);\r
+                               $v = strip_tags(str_replace("\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)));\r
+                               \r
+                               if (strpos($v,$sep) || strpos($v,$quote))$elements[] = "$quote$v$quote";\r
+                               else $elements[] = $v;\r
+                       }\r
+               }\r
+               $s .= implode($sep, $elements).$NEWLINE;\r
+               $rs->MoveNext();\r
+               $line += 1;\r
+               if ($fp && ($line % $BUFLINES) == 0) {\r
+                       if ($fp === true) echo $s;\r
+                       else fwrite($fp,$s);\r
+                       $s = '';\r
+               }\r
+       }\r
+       \r
+       if ($fp) {\r
+               if ($fp === true) echo $s;\r
+               else fwrite($fp,$s);\r
+               $s = '';\r
+       }\r
+       \r
+       return $s;\r
+}\r
+?>
\ No newline at end of file
index 22c4857e8b46b8b0265508db4fa4c529c542df41..a82f19dee756a6e5f203bb4561109b0a7079fa74 100644 (file)
@@ -1,6 +1,6 @@
 <?php \r
 /*\r
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.\r
+V2.12 12 June 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
@@ -50,7 +50,6 @@ GLOBAL $gSQLMaxRows,$gSQLBlockRows;
        $typearr = array();\r
        $ncols = $rs->FieldCount();\r
     $hdr = "<TABLE COLS=$ncols $ztabhtml>\n\n";\r
-       \r
        for ($i=0; $i < $ncols; $i++) { \r
                $field = $rs->FetchField($i);\r
                if ($zheaderarray) $fname = $zheaderarray[$i];\r