Skip to content
Browse files

Upgraded to ADOdb 2.12

  • Loading branch information...
1 parent 22f4320 commit b1a1b00aa69041c70e1ae529f6643538cc7df591 martin committed Jun 13, 2002
Showing with 1,253 additions and 363 deletions.
  1. +1 −1 lib/adodb/adodb-cryptsession.php
  2. +7 −6 lib/adodb/adodb-csvlib.inc.php
  3. +1 −1 lib/adodb/adodb-errorhandler.inc.php
  4. +1 −1 lib/adodb/adodb-errorpear.inc.php
  5. +116 −20 lib/adodb/adodb-lib.inc.php
  6. +239 −0 lib/adodb/adodb-pager.inc.php
  7. +1 −1 lib/adodb/adodb-pear.inc.php
  8. +79 −41 lib/adodb/adodb-session.php
  9. +163 −46 lib/adodb/adodb.inc.php
  10. +1 −1 lib/adodb/drivers/adodb-access.inc.php
  11. +50 −29 lib/adodb/drivers/adodb-ado.inc.php
  12. +4 −2 lib/adodb/drivers/adodb-ado_access.inc.php
  13. +18 −6 lib/adodb/drivers/adodb-ado_mssql.inc.php
  14. +1 −1 lib/adodb/drivers/adodb-borland_ibase.inc.php
  15. +1 −1 lib/adodb/drivers/adodb-csv.inc.php
  16. +1 −1 lib/adodb/drivers/adodb-db2.inc.php
  17. +1 −1 lib/adodb/drivers/adodb-fbsql.inc.php
  18. +1 −1 lib/adodb/drivers/adodb-firebird.inc.php
  19. +11 −4 lib/adodb/drivers/adodb-ibase.inc.php
  20. +1 −1 lib/adodb/drivers/adodb-informix.inc.php
  21. +13 −3 lib/adodb/drivers/adodb-informix72.inc.php
  22. +30 −11 lib/adodb/drivers/adodb-mssql.inc.php
  23. +11 −5 lib/adodb/drivers/adodb-mysql.inc.php
  24. +1 −1 lib/adodb/drivers/adodb-mysqlt.inc.php
  25. +9 −18 lib/adodb/drivers/adodb-oci8.inc.php
  26. +6 −1 lib/adodb/drivers/adodb-oci805.inc.php
  27. +1 −1 lib/adodb/drivers/adodb-oci8po.inc.php
  28. +1 −1 lib/adodb/drivers/adodb-odbc.inc.php
  29. +1 −1 lib/adodb/drivers/adodb-odbc_mssql.inc.php
  30. +1 −1 lib/adodb/drivers/adodb-odbc_oracle.inc.php
  31. +1 −1 lib/adodb/drivers/adodb-oracle.inc.php
  32. +1 −1 lib/adodb/drivers/adodb-postgres.inc.php
  33. +1 −1 lib/adodb/drivers/adodb-postgres64.inc.php
  34. +1 −1 lib/adodb/drivers/adodb-postgres7.inc.php
  35. +1 −1 lib/adodb/drivers/adodb-proxy.inc.php
  36. +1 −1 lib/adodb/drivers/adodb-sqlanywhere.inc.php
  37. +3 −3 lib/adodb/drivers/adodb-sybase.inc.php
  38. +2 −1 lib/adodb/drivers/adodb-vfp.inc.php
  39. +155 −48 lib/adodb/readme.htm
  40. +2 −2 lib/adodb/server.php
  41. +1 −1 lib/adodb/tests/benchmark.php
  42. +1 −1 lib/adodb/tests/client.php
  43. +62 −16 lib/adodb/tests/test.php
  44. +8 −23 lib/adodb/tests/test2.php
  45. +1 −1 lib/adodb/tests/test3.php
  46. +1 −1 lib/adodb/tests/test4.php
  47. +1 −1 lib/adodb/tests/test5.php
  48. +1 −1 lib/adodb/tests/testcache.php
  49. +7 −5 lib/adodb/tests/testdatabases.inc.php
  50. +2 −0 lib/adodb/tests/testgenid.php
  51. +50 −0 lib/adodb/tests/testmssql.php
  52. +1 −1 lib/adodb/tests/testoci8.php
  53. +36 −33 lib/adodb/tests/testpaging.php
  54. +1 −1 lib/adodb/tests/testpear.php
  55. +7 −7 lib/adodb/tests/testsessions.php
  56. +2 −1 lib/adodb/tips_portable_sql.htm
  57. +130 −0 lib/adodb/toexport.inc.php
  58. +1 −2 lib/adodb/tohtml.inc.php
View
2 lib/adodb/adodb-cryptsession.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
View
13 lib/adodb/adodb-csvlib.inc.php
@@ -1,7 +1,7 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
@@ -18,13 +18,13 @@
*/
/**
- * convert a recordset into CSV format
+ * convert a recordset into special format
*
* @param rs the recordset
*
* @return the CSV formated data
*/
- function &rs2csv(&$rs,$conn=false,$sql='')
+ function _rs2serialize(&$rs,$conn=false,$sql='')
{
$max = ($rs) ? $rs->FieldCount() : 0;
@@ -196,12 +196,13 @@ function &csv2rs($url,&$err,$timeout=0)
// slurp in the data
$MAXSIZE = 128000;
$text = fread($fp,$MAXSIZE);
- if (strlen($text) == $MAXSIZE) {
- $text .= fread($fp,filesize($url)-$MAXSIZE);
+ $cnt = 1;
+ while (strlen($text) == $MAXSIZE*$cnt) {
+ $text .= fread($fp,$MAXSIZE);
+ $cnt += 1;
}
fclose($fp);
- //$text = substr($text,0,44);
$arr = @unserialize($text);
//var_dump($arr);
View
2 lib/adodb/adodb-errorhandler.inc.php
@@ -1,6 +1,6 @@
<?php
/**
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+ * @version V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
View
2 lib/adodb/adodb-errorpear.inc.php
@@ -1,6 +1,6 @@
<?php
/**
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+ * @version V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
View
136 lib/adodb/adodb-lib.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
@@ -9,14 +9,6 @@
Less commonly used functions are placed here to reduce size of adodb.inc.php.
*/
-function _adodb_totalpages(&$rs)
-{
- if ($rs->rowsPerPage) {
- $rows = ($rs->RecordCount()+$rs->rowsPerPage-1) / $rs->rowsPerPage;
- if ($rows < 0) return -1;
- else return $rows;
- } else return -1;
-}
// Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM
function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false,
@@ -30,46 +22,150 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
if (!strpos($name,'[]')) $name .= '[]';
} else if ($size) $attr = " size=$size";
else $attr ='';
-
-
+
$s = "<select name=\"$name\"$attr $selectAttr>";
if ($blank1stItem) $s .= "\n<option></option>";
if ($zthis->FieldCount() > 1) $hasvalue=true;
else $compareFields0 = true;
+ $value = '';
while(!$zthis->EOF) {
- $zval = trim($zthis->fields[0]);
- $selected = trim($zthis->fields[$compareFields0 ? 0 : 1]);
+ $zval = trim(reset($zthis->fields));
+ if (sizeof($zthis->fields) > 1) {
+ if (isset($zthis->fields[1]))
+ $zval2 = trim($zthis->fields[1]);
+ else
+ $zval2 = trim(next($zthis->fields));
+ }
+ $selected = ($compareFields0) ? $zval : $zval2;
if ($blank1stItem && $zval=="") {
$zthis->MoveNext();
continue;
}
if ($hasvalue)
- $value = 'value="'.htmlspecialchars(trim($zthis->fields[1])).'"';
-
+ $value = ' value="'.htmlspecialchars($zval2).'"';
if (is_array($defstr)) {
if (in_array($selected,$defstr))
- $s .= "<option selected $value>".htmlspecialchars($zval).'</option>';
+ $s .= "<option selected$value>".htmlspecialchars($zval).'</option>';
else
- $s .= "\n<option ".$value.'>'.htmlspecialchars($zval).'</option>';
+ $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';
}
else {
if (strcasecmp($selected,$defstr)==0)
- $s .= "<option selected $value>".htmlspecialchars($zval).'</option>';
+ $s .= "<option selected$value>".htmlspecialchars($zval).'</option>';
else
- $s .= "\n<option ".$value.'>'.htmlspecialchars($zval).'</option>';
+ $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';
}
$zthis->MoveNext();
} // while
return $s ."\n</select>\n";
}
-function &_adodb_pageexecute(&$zthis, $sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2cache=0)
+/*
+ Code originally from "Cornel G" <conyg@fx.ro>
+
+ This code will not work with SQL that has UNION in it
+
+ Also if you are using CachePageExecute(), there is a strong possibility that
+ data will get out of synch. use CachePageExecute() only with tables that
+ rarely change.
+*/
+function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
+ $inputarr=false, $arg3=false, $secs2cache=0)
+{
+ $atfirstpage = false;
+ $atlastpage = false;
+ $lastpageno=1;
+
+ // If an invalid nrows is supplied,
+ // we assume a default value of 10 rows per page
+ if (!isset($nrows) || $nrows <= 0) $nrows = 10;
+
+ $qryRecs = false; //count records for no offset
+
+ // jlim - attempt query rewrite first
+ $rewritesql = preg_replace(
+ '/^\s*SELECT\s.*\sFROM\s/is','SELECT COUNT(*) FROM ',$sql);
+
+ if ($rewritesql != $sql){
+
+ // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails
+ // with mssql, access and postgresql
+ $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql);
+
+ if ($secs2cache) {
+ // we only use half the time of secs2cache because the count can quickly
+ // become inaccurate if new records are added
+ $rs = $zthis->CacheExecute($secs2cache/2,$rewritesql);
+ if ($rs) {
+ if (!$rs->EOF) $qryRecs = reset($rs->fields);
+ $rs->Close();
+ }
+ } else $qryRecs = $zthis->GetOne($rewritesql);
+ if ($qryRecs !== false)
+ $lastpageno = (int) ceil($qryRecs / $nrows);
+ }
+
+ // query rewrite failed - so try slower way...
+ if ($qryRecs === false) {
+ $rstest = &$zthis->Execute($sql);
+ if ($rstest) {
+ //save total records
+ $qryRecs = $rstest->RecordCount();
+ if ($qryRecs == -1)
+ if (!$rstest->EOF) {
+ $rstest->MoveLast();
+ $qryRecs = $zthis->_currentRow;
+ } else
+ $qryRecs = 0;
+
+ $lastpageno = (int) ceil($qryRecs / $nrows);
+ }
+ if ($rstest) $rstest->Close();
+ }
+
+ $zthis->_maxRecordCount = $qryRecs;
+
+ // If page number <= 1, then we are at the first page
+ if (!isset($page) || $page <= 1) {
+ $page = 1;
+ $atfirstpage = true;
+ }
+
+ // ***** Here we check whether $page is the last page or
+ // whether we are trying to retrieve
+ // a page number greater than the last page number.
+ if ($page >= $lastpageno) {
+ $page = $lastpageno;
+ $atlastpage = true;
+ }
+
+ // We get the data we want
+ $offset = $nrows * ($page-1);
+ if ($secs2cache > 0)
+ $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr, $arg3);
+ else
+ $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $arg3, $secs2cache);
+
+
+ // Before returning the RecordSet, we set the pagination properties we need
+ if ($rsreturn) {
+ $rsreturn->rowsPerPage = $nrows;
+ $rsreturn->AbsolutePage($page);
+ $rsreturn->AtFirstPage($atfirstpage);
+ $rsreturn->AtLastPage($atlastpage);
+ $rsreturn->LastPageNo($lastpageno);
+ }
+ return $rsreturn;
+}
+
+// Iván Oliva version
+function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2cache=0)
{
$atfirstpage = false;
View
239 lib/adodb/adodb-pager.inc.php
@@ -0,0 +1,239 @@
+<?php
+/*
+ V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+ Released under both BSD license and Lesser GPL library license.
+ Whenever there is any discrepancy between the two licenses,
+ the BSD license will take precedence.
+ Set tabs to 4 for best viewing.
+
+ This class provides recordset pagination with
+ First/Prev/Next/Last links.
+
+ Feel free to modify this class for your own use as
+ it is very basic. To learn how to use it, see the
+ example in adodb/tests/testpaging.php.
+
+ Please note, this class is entirely unsupported,
+ and no free support requests except for bug reports
+ will be entertained by the author.
+
+ My company also sells a commercial pagination
+ object at http://phplens.com/ with much more
+ functionality, including search, create, edit,
+ delete records.
+*/
+class ADODB_Pager {
+ var $id; // unique id for pager (defaults to 'adodb')
+ var $db; // ADODB connection object
+ var $sql; // sql used
+ var $rs; // recordset generated
+ var $curr_page; // current page number before Render() called, calculated in constructor
+ var $rows; // number of rows per page
+
+ var $gridAttributes = 'width=100% border=1 bgcolor=white';
+
+ // Localize text strings here
+ var $first = '<code>|&lt;</code>';
+ var $prev = '<code>&lt;&lt;</code>';
+ var $next = '<code>>></code>';
+ var $last = '<code>>|</code>';
+ var $page = 'Page';
+ var $cache = 0; #secs to cache with CachePageExecute()
+
+ //----------------------------------------------
+ // constructor
+ //
+ // $db adodb connection object
+ // $sql sql statement
+ // $id optional id to identify which pager,
+ // if you have multiple on 1 page.
+ // $id should be only be [a-z0-9]*
+ //
+ function ADODB_Pager(&$db,$sql,$id = 'adodb')
+ {
+ global $HTTP_SERVER_VARS,$PHP_SELF,$HTTP_SESSION_VARS,$HTTP_GET_VARS;
+
+ $curr_page = $id.'_curr_page';
+ if (empty($PHP_SELF)) $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
+
+ $this->sql = $sql;
+ $this->id = $id;
+ $this->db = $db;
+
+ $next_page = $id.'_next_page';
+
+ if (isset($HTTP_GET_VARS[$next_page])) {
+ $HTTP_SESSION_VARS[$curr_page] = $HTTP_GET_VARS[$next_page];
+ }
+ if (empty($HTTP_SESSION_VARS[$curr_page])) $HTTP_SESSION_VARS[$curr_page] = 1; ## at first page
+
+ $this->curr_page = $HTTP_SESSION_VARS[$curr_page];
+
+ }
+
+ //---------------------------
+ // Display link to first page
+ function Render_First($anchor=true)
+ {
+ global $PHP_SELF;
+ if ($anchor) {
+ ?>
+ <a href="<?php echo $PHP_SELF,'?',$this->id;?>_next_page=1"><?php echo $this->first;?></a> &nbsp;
+ <?php
+ } else {
+ print "$this->first &nbsp; ";
+ }
+ }
+
+ //--------------------------
+ // Display link to next page
+ function render_next($anchor=true)
+ {
+ global $PHP_SELF;
+
+ if ($anchor) {
+ ?>
+ <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() + 1 ?>"><?php echo $this->next;?></a> &nbsp;
+ <?php
+ } else {
+ print "$this->next &nbsp; ";
+ }
+ }
+
+ //------------------
+ // Link to last page
+ //
+ // for better performance with large recordsets, you can set
+ // $this->db->pageExecuteCountRows = false, which disables
+ // last page counting.
+ function render_last($anchor=true)
+ {
+ global $PHP_SELF;
+
+ if (!$this->db->pageExecuteCountRows) return;
+
+ if ($anchor) {
+ ?>
+ <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->LastPageNo() ?>"><?php echo $this->last;?></a> &nbsp;
+ <?php
+ } else {
+ print "$this->last &nbsp; ";
+ }
+ }
+
+ //----------------------
+ // Link to previous page
+ function render_prev($anchor=true)
+ {
+ global $PHP_SELF;
+ if ($anchor) {
+ ?>
+ <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() - 1 ?>"><?php echo $this->prev;?></a> &nbsp;
+ <?php
+ } else {
+ print "$this->prev &nbsp; ";
+ }
+ }
+
+ //--------------------------------------------------------
+ // Simply rendering of grid. You should override this for
+ // better control over the format of the grid
+ //
+ // We use output buffering to keep code clean and readable.
+ function RenderGrid()
+ {
+ global $gSQLBlockRows; // used by rs2html to indicate how many rows to display
+ include_once(ADODB_DIR.'/tohtml.inc.php');
+ ob_start();
+ $gSQLBlockRows = $this->rows;
+ rs2html($this->rs,$this->gridAttributes);
+ $s = ob_get_contents();
+ ob_end_clean();
+ return $s;
+ }
+
+ //-------------------------------------------------------
+ // Navigation bar
+ //
+ // we use output buffering to keep the code easy to read.
+ function RenderNav()
+ {
+ ob_start();
+ if (!$this->rs->AtFirstPage()) {
+ $this->Render_First();
+ $this->Render_Prev();
+ } else {
+ $this->Render_First(false);
+ $this->Render_Prev(false);
+ }
+ if (!$this->rs->AtLastPage()) {
+ $this->Render_Next();
+ $this->Render_Last();
+ } else {
+ $this->Render_Next(false);
+ $this->Render_Last(false);
+ }
+ $s = ob_get_contents();
+ ob_end_clean();
+ return $s;
+ }
+
+ //-------------------
+ // This is the footer
+ function RenderPageCount()
+ {
+ if (!$this->db->pageExecuteCountRows) return '';
+ return "<font size=-1>$this->page ".$this->curr_page."/".$this->rs->LastPageNo()."</font>";
+ }
+
+ //-----------------------------------
+ // Call this class to draw everything.
+ function Render($rows=10)
+ {
+ global $ADODB_COUNTRECS;
+
+ $this->rows = $rows;
+
+ $savec = $ADODB_COUNTRECS;
+ if ($this->db->pageExecuteCountRows) $ADODB_COUNTRECS = true;
+ if ($this->cache)
+ $rs = &$this->db->CachePageExecute($this->cache,$this->sql,$rows,$this->curr_page);
+ else
+ $rs = &$this->db->PageExecute($this->sql,$rows,$this->curr_page);
+ $ADODB_COUNTRECS = $savec;
+
+ $this->rs = &$rs;
+ if (!$rs) {
+ print "<h3>Query failed: $this->sql</h3>";
+ return;
+ }
+
+ if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage()))
+ $header = $this->RenderNav();
+ else
+ $header = "&nbsp;";
+
+ $grid = $this->RenderGrid();
+ $footer = $this->RenderPageCount();
+ $rs->Close();
+ $this->rs = false;
+
+ $this->RenderLayout($header,$grid,$footer);
+ }
+
+ //------------------------------------------------------
+ // override this to control overall layout and formating
+ function RenderLayout($header,$grid,$footer)
+ {
+ echo "<table border=1 bgcolor=beige><tr><td>",
+ $header,
+ "</td></tr><tr><td>",
+ $grid,
+ "</td></tr><tr><td>",
+ $footer,
+ "</td></tr></table>";
+ }
+}
+
+
+?>
View
2 lib/adodb/adodb-pear.inc.php
@@ -1,6 +1,6 @@
<?php
/**
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+ * @version V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
View
120 lib/adodb/adodb-session.php
@@ -1,12 +1,10 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
- Made table name configurable - by David Johnson djohnson@inpro.net
-
- Set tabs to 4 for best viewing.
+ Set tabs to 4 for best viewing.
Latest version of ADODB is available at http://php.weblogs.com/adodb
======================================================================
@@ -28,16 +26,16 @@
Installation
============
- 1. Create a new database in MySQL or Access "sessions" like
-so:
+ 1. Create this table in your database (syntax might vary depending on your db):
create table sessions (
SESSKEY char(32) not null,
EXPIRY int(11) unsigned not null,
DATA text not null,
primary key (sesskey)
);
-
+
+
2. Then define the following parameters in this file:
$ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';
$ADODB_SESSION_CONNECT='server to connect to';
@@ -46,22 +44,22 @@
$ADODB_SESSION_DB ='database';
$ADODB_SESSION_TBL = 'sessions'
- 3. Recommended is PHP 4.0.2 or later. There are documented
-session bugs in
- earlier versions of PHP.
+ 3. Recommended is PHP 4.0.6 or later. There are documented
+ session bugs in earlier versions of PHP.
*/
if (!defined('_ADODB_LAYER')) {
- include ('adodb.inc.php');
+ include (dirname(__FILE__).'/adodb.inc.php');
}
-
-
if (!defined('ADODB_SESSION')) {
define('ADODB_SESSION',1);
-
+
+/****************************************************************************************\
+ Global definitions
+\****************************************************************************************/
GLOBAL $ADODB_SESSION_CONNECT,
$ADODB_SESSION_DRIVER,
$ADODB_SESSION_USER,
@@ -70,29 +68,40 @@
$ADODB_SESS_CONN,
$ADODB_SESS_LIFE,
$ADODB_SESS_DEBUG,
- $ADODB_SESS_INSERT;
-
+ $ADODB_SESS_INSERT,
+ $ADODB_SESSION_CRC;
+
+ $ADODB_SESS_LIFE = get_cfg_var('session.gc_maxlifetime');
+ if ($ADODB_SESS_LIFE <= 1) {
+ // bug in PHP 4.0.3 pl 1 -- how about other versions?
+ //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";
+ $ADODB_SESS_LIFE=1440;
+ }
+ $ADODB_SESSION_CRC = false;
//$ADODB_SESS_DEBUG = true;
+ //////////////////////////////////
/* SET THE FOLLOWING PARAMETERS */
-if (empty($ADODB_SESSION_DRIVER)) {
- $ADODB_SESSION_DRIVER='mysql';
- $ADODB_SESSION_CONNECT='localhost';
- $ADODB_SESSION_USER ='root';
- $ADODB_SESSION_PWD ='';
- $ADODB_SESSION_DB ='xphplens_2';
-}
-if (empty($ADODB_SESSION_TBL)){
- $ADODB_SESSION_TBL = 'sessions';
-}
-
-$ADODB_SESS_LIFE = get_cfg_var('session.gc_maxlifetime');
-if ($ADODB_SESS_LIFE <= 1) {
- // bug in PHP 4.0.3 pl 1 -- how about other versions?
- //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";
- $ADODB_SESS_LIFE=1440;
-}
+ //////////////////////////////////
+
+ if (empty($ADODB_SESSION_DRIVER)) {
+ $ADODB_SESSION_DRIVER='mysql';
+ $ADODB_SESSION_CONNECT='localhost';
+ $ADODB_SESSION_USER ='root';
+ $ADODB_SESSION_PWD ='';
+ $ADODB_SESSION_DB ='xphplens_2';
+ }
+
+ // Made table name configurable - by David Johnson djohnson@inpro.net
+ if (empty($ADODB_SESSION_TBL)){
+ $ADODB_SESSION_TBL = 'sessions';
+ }
+/****************************************************************************************\
+ Create the connection to the database.
+
+ If $ADODB_SESS_CONN already exists, reuse that connection
+\****************************************************************************************/
function adodb_sess_open($save_path, $session_name,$persist=true)
{
GLOBAL $ADODB_SESS_CONN;
@@ -106,18 +115,23 @@ function adodb_sess_open($save_path, $session_name,$persist=true)
$ADODB_SESSION_DB,
$ADODB_SESS_DEBUG;
+ // cannot use & below - do not know why...
$ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);
if (!empty($ADODB_SESS_DEBUG)) {
$ADODB_SESS_CONN->debug = true;
- print" conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ";
+ print " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ";
}
- if ($persist) $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,
+ if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,
$ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
- else $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,
+ else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,
$ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
+ if (!$ok) print "<p>Session: connection failed</p>";
}
+/****************************************************************************************\
+ Close the connection
+\****************************************************************************************/
function adodb_sess_close()
{
global $ADODB_SESS_CONN;
@@ -126,10 +140,14 @@ function adodb_sess_close()
return true;
}
+/****************************************************************************************\
+ Slurp in the session variables and return the serialized string
+\****************************************************************************************/
function adodb_sess_read($key)
{
-global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL;
- $ADODB_SESS_INSERT = false;
+global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;
+
+ $ADODB_SESS_INSERT = false;
$rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());
if ($rs) {
if ($rs->EOF) {
@@ -139,19 +157,38 @@ function adodb_sess_read($key)
$v = rawurldecode(reset($rs->fields));
$rs->Close();
+
+ // new optimization adodb 2.1
+ $ADODB_SESSION_CRC = crc32($v);
+
return $v;
}
else $ADODB_SESS_INSERT = true;
- return false;
+ return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com
}
+/****************************************************************************************\
+ Write the serialized data to a database.
+
+ If the data has not been modified since adodb_sess_read(), we do not write.
+\****************************************************************************************/
function adodb_sess_write($key, $val)
{
- global $ADODB_SESS_INSERT,$ADODB_SESS_CONN, $ADODB_SESS_LIFE, $ADODB_SESSION_TBL;
+ global $ADODB_SESS_INSERT,
+ $ADODB_SESS_CONN,
+ $ADODB_SESS_LIFE,
+ $ADODB_SESSION_TBL,
+ $ADODB_SESS_DEBUG,
+ $ADODB_SESSION_CRC;
$expiry = time() + $ADODB_SESS_LIFE;
+ // new optimization adodb 2.1
+ if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == crc32($val)) {
+ if ($ADODB_SESS_DEBUG) echo "<p>Session: No need to update - crc32 not changed</p>";
+ return true;
+ }
$val = rawurlencode($val);
$qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry,data='$val' WHERE sesskey='$key'";
$rs = $ADODB_SESS_CONN->Execute($qry);
@@ -180,7 +217,8 @@ function adodb_sess_destroy($key)
return $rs ? true : false;
}
-function adodb_sess_gc($maxlifetime) {
+function adodb_sess_gc($maxlifetime)
+{
global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_DRIVER;
$qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();
View
209 lib/adodb/adodb.inc.php
@@ -1,7 +1,7 @@
<?php
/**
- * @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+ * @version V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
@@ -43,6 +43,12 @@
*/
if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));
+ if (strpos(strtoupper(PHP_OS),'WIN') !== false) {
+ // windows, negative timestamps are illegal as of php 4.2.0
+ define('TIMESTAMP_FIRST_YEAR',1970);
+ } else
+ define('TIMESTAMP_FIRST_YEAR',1904);
+
//==============================================================================================
// GLOBAL VARIABLES
//==============================================================================================
@@ -84,7 +90,7 @@
/**
* ADODB version as a string.
*/
- $ADODB_vers = 'V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved. Released BSD & LGPL.';
+ $ADODB_vers = 'V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved. Released BSD & LGPL.';
/**
* Determines whether recordset->RecordCount() is used.
@@ -134,7 +140,7 @@ class ADOConnection {
var $user = ''; // The username which is used to connect to the database server.
var $password = ''; // Password for the username
var $debug = false; // if set to true will output sql statements
- var $maxblobsize = 8000; // maximum size of blobs or large text fields -- some databases die otherwise like foxpro
+ var $maxblobsize = 64000; // maximum size of blobs or large text fields -- some databases die otherwise like foxpro
var $concat_operator = '+'; // default concat operator -- change to || for Oracle/Interbase
var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database
var $fmtTimeStamp = "'Y-m-d, h:i:s A'"; // used by DBTimeStamp as the default timestamp fmt.
@@ -160,6 +166,10 @@ class ADOConnection {
var $arrayClass = 'ADORecordSet_array';
// oracle specific stuff
var $noNullStrings = false;
+ var $numCacheHits = 0;
+ var $numCacheMisses = 0;
+ var $pageExecuteCountRows = true;
+ var $uniqueSort = false; // indicates that all fields in order by must be unique
/*
* PRIVATE VARS
@@ -212,7 +222,7 @@ function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDa
} else
if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true;
- if ($this->debug) print $this->host.': '.$this->ErrorMsg()."<br>\n";
+ if ($this->debug) print $this->host.': '.$this->ErrorMsg()."<br />\n";
return false;
}
@@ -245,7 +255,7 @@ function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argD
} else
if ($this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true;
- if ($this->debug) print $this->host.': '.$this->ErrorMsg()."<br>\n";
+ if ($this->debug) print $this->host.': '.$this->ErrorMsg()."<br />\n";
return false;
}
@@ -295,11 +305,11 @@ function PrepareSP($sql)
}
/**
- * PEAR DB Compat - do not use internally.
+ * PEAR DB Compat - Quote with auto-checking of magic-quotes-gpc.
*/
function Quote($s)
{
- return $this->qstr($s);
+ return $this->qstr($s,get_magic_quotes_gpc());
}
@@ -458,26 +468,30 @@ function &Execute($sql,$inputarr=false,$arg3=false)
$inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']);
if ($inBrowser)
- print "<hr>\n($this->databaseType): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<hr>\n";
+ print "<hr />\n($this->databaseType): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<hr />\n";
else
print "=----\n($this->databaseType): ".($sqlTxt)." \n-----\n";
flush();
$this->_queryID = $this->_query($sql,$inputarr,$arg3);
+ /*
+ Alexios Fakios notes that ErrorMsg() must be called before ErrorNo() for mssql
+ because ErrorNo() calls Execute('SELECT @ERROR'), causing recure
+ */
if ($this->databaseType == 'mssql') {
// ErrorNo is a slow function call in mssql, and not reliable
// in PHP 4.0.6
- if($this->ErrorMsg()) {
+ if($emsg = $this->ErrorMsg()) {
$err = $this->ErrorNo();
if ($err) {
- print $err.': '.$this->ErrorMsg().(($inBrowser) ? "<br>\n" : "\n");
+ print $err.': '.$emsg.(($inBrowser) ? "<br />\n" : "\n");
flush();
}
}
} else
if (!$this->_queryID) {
- print $this->ErrorNo().': '.$this->ErrorMsg().(($inBrowser) ? "<br>\n" : "\n");
+ print $this->ErrorNo().': '.$this->ErrorMsg() .(($inBrowser) ? "<br />\n" : "\n");
flush();
}
} else
@@ -506,14 +520,14 @@ function &Execute($sql,$inputarr=false,$arg3=false)
else $rs->sql = $sql;
global $ADODB_COUNTRECS;
- if ($rs->_numOfRows <= 0 && !$rs->EOF && $ADODB_COUNTRECS) {
+ if ($rs->_numOfRows <= 0 && !$rs->EOF && $ADODB_COUNTRECS) {
$rs = &$this->_rs2rs($rs);
$rs->_queryID = $this->_queryID;
}
return $rs;
}
-
+
/**
* Generates a sequence id and stores it in $this->genID;
* GenID is only available if $this->hasGenID = true;
@@ -522,7 +536,7 @@ function &Execute($sql,$inputarr=false,$arg3=false)
* @startID if sequence does not exist, start at this ID
* @return 0 if not supported, otherwise a sequence id
*/
-
+
function GenID($seqname='adodbseq',$startID=1)
{
if (!$this->hasGenID) {
@@ -538,12 +552,12 @@ function GenID($seqname='adodbseq',$startID=1)
}
if ($rs && !$rs->EOF) $this->genID = (integer) reset($rs->fields);
else $this->genID = 0; // false
-
+
if ($rs) $rs->Close();
-
+
return $this->genID;
}
-
+
/**
* @return the last inserted ID. Not all databases support this.
*/
@@ -699,6 +713,7 @@ function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$arg3=false,$se
*/
function &_rs2rs(&$rs,$nrows=-1,$offset=-1)
{
+ if (! $rs) return false;
$arr = &$rs->GetArrayLimit($nrows,$offset);
$flds = array();
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
@@ -768,7 +783,76 @@ function GetRow($sql,$inputarr=false)
}
return false;
}
+ /**
+ * Insert or replace a single record
+ *
+ * $this->Replace('products', array('prodname' =>"'Nails'","price" => 3.99), 'prodname');
+ *
+ * $table table name
+ * $fieldArray associative array of data (you must quote strings yourself).
+ * $keyCol the primary key field name or if compound key, array of field names
+ * autoQuote set to true to use a hueristic to quote strings. Works with nulls and numbers
+ * but does not work with dates nor SQL functions.
+ *
+ * Currently blob replace not supported
+ *
+ * returns 0 = fail, 1 = update, 2 = insert
+ */
+ function Replace($table, $fieldArray, $keyCol,$autoQuote=false)
+ {
+ if (count($fieldArray) == 0) return 0;
+ $first = true;
+ $uSet = '';
+
+ if (!is_array($keyCol)) {
+ $keyCol = array($keyCol);
+ }
+ foreach($fieldArray as $k => $v) {
+ if ($autoQuote && !is_numeric($v) and $v[0] != "'" and strcasecmp($v,'null')!=0) {
+ $v = $this->qstr($v);
+ $fieldArray[$k] = $v;
+ }
+ if (in_array($k,$keyCol)) continue; // skip UPDATE if is key
+
+ if ($first) {
+ $first = false;
+ $uSet = "$k=$v";
+ } else
+ $uSet .= ",$k=$v";
+ }
+
+ $first = true;
+ foreach ($keyCol as $v) {
+ if ($first) {
+ $first = false;
+ $where = "$v=$fieldArray[$v]";
+ } else {
+ $where .= " and $v=$fieldArray[$v]";
+ }
+ }
+
+ if ($uSet) {
+ $update = "UPDATE $table SET $uSet WHERE $where";
+
+ $rs = $this->Execute($update);
+ if ($rs and $this->Affected_Rows()>0) return 1;
+ }
+ $first = true;
+ foreach($fieldArray as $k => $v) {
+ if ($first) {
+ $first = false;
+ $iCols = "$k";
+ $iVals = "$v";
+ } else {
+ $iCols .= ",$k";
+ $iVals .= ",$v";
+ }
+ }
+ $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)";
+ $rs = $this->Execute($insert);
+ return ($rs) ? 2 : 0;
+ }
/**
@@ -798,7 +882,7 @@ function &CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false
// sql, nrows, offset,inputarr,arg3
return $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$inputarr,$this->cacheSecs);
}
- if ($sql === false) echo "Warning: \$sql missing from CacheSelectLimit()<br>\n";
+ if ($sql === false) echo "Warning: \$sql missing from CacheSelectLimit()<br />\n";
return $this->SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);
}
@@ -849,10 +933,13 @@ function &CacheExecute($secs2cache,$sql=false,$inputarr=false,$arg3=false)
$md5file = $this->_gencachename($sql,true);
$err = '';
- if ($secs2cache > 0)$rs = &csv2rs($md5file,$err,$secs2cache);
- else {
+ if ($secs2cache > 0){
+ $rs = &csv2rs($md5file,$err,$secs2cache);
+ $this->numCacheHits += 1;
+ } else {
$err='Timeout 1';
$rs = false;
+ $this->numCacheMisses += 1;
}
if (!$rs) {
@@ -862,16 +949,17 @@ function &CacheExecute($secs2cache,$sql=false,$inputarr=false,$arg3=false)
if ($rs) {
$eof = $rs->EOF;
$rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately
- $txt = &rs2csv($rs,false,$sql); // serialize
-
+ $txt = _rs2serialize($rs,false,$sql); // serialize
+
if (!adodb_write_file($md5file,$txt,$this->debug)) {
if ($fn = $this->raiseErrorFn) {
$fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql);
}
if ($this->debug) print " Cache write error<br>\n";
}
if ($rs->EOF && !$eof) {
- $rs = &csv2rs($md5file,$err);
+ $rs->MoveFirst();
+ //$rs = &csv2rs($md5file,$err);
$rs->connection = &$this; // Pablo suggestion
}
@@ -1182,7 +1270,6 @@ function Concat()
function DBDate($d)
{
- // note that we are limited to 1970 to 2038
if (empty($d) && $d !== 0) return 'null';
if (is_string($d) && !is_numeric($d))
@@ -1214,14 +1301,14 @@ function DBTimeStamp($ts)
* Also in ADORecordSet.
* @param $v is a date string in YYYY-MM-DD format
*
- * @return date in unix timestamp format, or 0 if before 1970, or false if invalid date format
+ * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
*/
function UnixDate($v)
{
- if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})$|",
+ if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|",
($v), $rr)) return false;
-
- if ($rr[1] <= 1970) return 0;
+
+ if ($rr[1] <= TIMESTAMP_FIRST_YEAR) return 0;
// h-m-s-MM-DD-YY
return mktime(0,0,0,$rr[2],$rr[3],$rr[1]);
}
@@ -1231,21 +1318,22 @@ function UnixDate($v)
* Also in ADORecordSet.
* @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format
*
- * @return date in unix timestamp format, or 0 if before 1970, or false if invalid date format
+ * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
*/
function UnixTimeStamp($v)
{
if (!preg_match(
"|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9]{1,2}))?$|",
($v), $rr)) return false;
- if ($rr[1] <= 1970 && $rr[2]<= 1) return 0;
+ if ($rr[1] <= TIMESTAMP_FIRST_YEAR && $rr[2]<= 1) return 0;
// h-m-s-MM-DD-YY
return @mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]);
}
/**
- * Converts a timestamp "ts" to a string that the database can understand.
+ * Correctly quotes a string so that all strings are escaped. We prefix and append
+ * to the string single-quotes.
* An example is $db->qstr("Don't bother",magic_quotes_runtime());
*
* @param s the string to quote
@@ -1275,7 +1363,7 @@ function qstr($s,$magic_quotes=false)
return "'".str_replace("\\'",$this->replaceQuote,$s)."'";
}
}
-
+
/**
* Will select the supplied $page number from a recordset, given that it is paginated in pages of
@@ -1298,7 +1386,8 @@ function qstr($s,$magic_quotes=false)
function &PageExecute($sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2cache=0)
{
include_once(ADODB_DIR.'/adodb-lib.inc.php');
- return _adodb_pageexecute($this, $sql, $nrows, $page, $inputarr, $arg3, $secs2cache);
+ if ($this->pageExecuteCountRows) return _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $arg3, $secs2cache);
+ return _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $arg3, $secs2cache);
}
@@ -1317,8 +1406,7 @@ function &PageExecute($sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2c
* @return the recordset ($rs->databaseType == 'array')
*/
function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false, $arg3=false) {
- include_once(ADODB_DIR.'/adodb-lib.inc.php');
- return _adodb_pageexecute($this, $sql, $nrows, $page, $inputarr, $arg3,$secs2cache);
+ return $this->PageExecute($sql,$nrows,$page,$inputarr,$arg3,$secs2cache);
}
} // end class ADOConnection
@@ -1402,8 +1490,8 @@ class ADORecordSet {
var $_currentPage = -1; /* Added by Iván Oliva to implement recordset pagination */
var $_atFirstPage = false; /* Added by Iván Oliva to implement recordset pagination */
var $_atLastPage = false; /* Added by Iván Oliva to implement recordset pagination */
-
-
+ var $_lastPageNo = -1;
+ var $_maxRecordCount = 0;
/**
* Constructor
*
@@ -1416,6 +1504,7 @@ function ADORecordSet($queryID)
}
+
function Init()
{
if ($this->_inited) return;
@@ -1606,7 +1695,7 @@ function GetAssoc($force_array = false) {
function UserTimeStamp($v,$fmt='Y-m-d H:i:s')
{
$tt = $this->UnixTimeStamp($v);
- // $tt == -1 if pre 1970
+ // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
if (($tt === false || $tt == -1) && $v != false) return $v;
if ($tt == 0) return $this->emptyTimeStamp;
@@ -1623,10 +1712,10 @@ function UserTimeStamp($v,$fmt='Y-m-d H:i:s')
function UserDate($v,$fmt='Y-m-d')
{
$tt = $this->UnixDate($v);
- // $tt == -1 if pre 1970
+ // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
if (($tt === false || $tt == -1) && $v != false) return $v;
else if ($tt == 0) return $this->emptyDate;
- else if ($tt == -1) { // pre-1970
+ else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR
}
return date($fmt,$tt);
@@ -1636,14 +1725,14 @@ function UserDate($v,$fmt='Y-m-d')
/**
* @param $v is a date string in YYYY-MM-DD format
*
- * @return date in unix timestamp format, or 0 if before 1970, or false if invalid date format
+ * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
*/
function UnixDate($v)
{
- if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})$|",
+ if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|",
($v), $rr)) return false;
- if ($rr[1] <= 1970) return 0;
+ if ($rr[1] <= 1903) return 0;
// h-m-s-MM-DD-YY
return mktime(0,0,0,$rr[2],$rr[3],$rr[1]);
}
@@ -1652,14 +1741,14 @@ function UnixDate($v)
/**
* @param $v is a timestamp string in YYYY-MM-DD HH-NN-SS format
*
- * @return date in unix timestamp format, or 0 if before 1970, or false if invalid date format
+ * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
*/
function UnixTimeStamp($v)
{
if (!preg_match(
"|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9]{1,2}))?$|",
($v), $rr)) return false;
- if ($rr[1] <= 1970 && $rr[2]<= 1) return 0;
+ if ($rr[1] <= 1903 && $rr[2]<= 1) return 0;
// h-m-s-MM-DD-YY
return @mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]);
@@ -1875,6 +1964,15 @@ function Close()
function RecordCount() {return $this->_numOfRows;}
+ /*
+ * If we are using PageExecute(), this will return the maximum possible rows
+ * that can be returned when paging a recordset.
+ */
+ function MaxRecordCount()
+ {
+ return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount();
+ }
+
/**
* synonyms RecordCount and RowCount
*
@@ -1937,6 +2035,18 @@ function &FetchField($fieldoffset)
}
/**
+ * Get the ADOFieldObjects of all columns in an array.
+ *
+ */
+ function FieldTypesArray()
+ {
+ $arr = array();
+ for ($i=0, $max=$this->_numOfFields; $i < $max; $i++)
+ $arr[] = $this->FetchField($i);
+ return $arr;
+ }
+
+ /**
* Return the fields array of the current row as an object for convenience.
*
* @param $isupper to set the object property names to uppercase
@@ -2022,6 +2132,7 @@ function MetaType($t,$len=-1,$fieldobj=false)
case 'NVARCHAR':
case 'VARYING':
case 'BPCHAR':
+ case 'CHARACTER':
if (!empty($this)) if ($len <= $this->blobSize) return 'C';
else if ($len <= 250) return 'C';
@@ -2096,6 +2207,12 @@ function AtFirstPage($status=false)
return $this->_atFirstPage;
}
+ function LastPageNo($page = false)
+ {
+ if ($page != false) $this->_lastPageNo = $page;
+ return $this->_lastPageNo;
+ }
+
/**
* set/returns the status of the atLastPage flag when paginating
*/
@@ -2347,7 +2464,7 @@ function adodb_write_file($filename, $contents,$debug=false)
$ok = false;
}
if (!$ok) {
- if ($debug) print " Rename $tmpname ".($ok? 'ok' : 'failed')." <br>\n";
+ if ($debug) print " Rename $tmpname ".($ok? 'ok' : 'failed')." <br />\n";
}
return $ok;
}
View
2 lib/adodb/drivers/adodb-access.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
View
79 lib/adodb/drivers/adodb-ado.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -25,6 +25,12 @@ class ADODB_ado extends ADOConnection {
var $adoParameterType = 201; // 201 = long varchar, 203=long wide varchar, 205 = long varbinary
var $_affectedRows = false;
var $_thisTransactions;
+ var $_inTransaction = 0;
+ var $_cursor_type = 3; // 3=adOpenStatic,0=adOpenForwardOnly,1=adOpenKeyset,2=adOpenDynamic
+ var $_cursor_location = 3; // 2=adUseServer, 3 = adUseClient;
+ var $_lock_type = -1;
+ var $_execute_option = -1;
+
function ADODB_ado()
{
@@ -35,50 +41,51 @@ function _affectedrows()
{
return $this->_affectedRows;
}
-
+
+ // you can also pass a connection string like this:
+ //
+ // $DB->Connect('USER ID=sa;PASSWORD=pwd;SERVER=mangrove;DATABASE=ai',false,false,'SQLOLEDB');
function _connect($argHostname, $argUsername, $argPassword, $argProvider= 'MSDASQL')
{
$u = 'UID';
$p = 'PWD';
$dbc = new COM('ADODB.Connection');
if (! $dbc) return false;
- /* // handle SQL server provider specially ? no need
- if ($argProvider) {
- if ($argProvider == "SQLOLEDB") { // SQL Server Provider
- }
- }*/
- if ($argProvider) $dbc->Provider = $argProvider;
- else $dbc->Provider ='MSDASQL';
+
+ /* special support if provider is mssql or access */
+ if ($argProvider=='mssql') {
+ $u = 'User Id'; //User parameter name for OLEDB
+ $p = 'Password';
+ $argProvider = "SQLOLEDB"; // SQL Server Provider
+
+ // not yet
+ //if ($argDatabasename) $argHostname .= ";Initial Catalog=$argDatabasename";
+
+ //use trusted conection for SQL if username not specified
+ if (!$argUsername) $argHostname .= ";Trusted_Connection=Yes";
+ } else if ($argProvider=='access')
+ $argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider
+
+ if ($argProvider) $dbc->Provider = $argProvider;
if ($argUsername) $argHostname .= ";$u=$argUsername";
if ($argPassword)$argHostname .= ";$p=$argPassword";
if ($this->debug) print "<p>Host=".$argHostname."<BR>version=$dbc->version</p>";
// @ added below for php 4.0.1 and earlier
@$dbc->Open((string) $argHostname);
-
+
$this->_connectionID = $dbc;
- return $dbc != false;
+
+ $dbc->CursorLocation = $this->_cursor_location;
+ return $dbc->State > 0;
}
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argProvider='MSDASQL')
{
- $dbc = new COM("ADODB.Connection");
- if (! $dbc) return false;
-
- if ($argProvider) $dbc->Provider = $argProvider;
- else $dbc->Provider ='MSDASQL';
-
- if ($argUsername) $argHostname .= ";UID=$argUsername";
- if ($argPassword)$argHostname .= ";PWD=$argPassword";
-
- if ($this->debug) print "<p>Host=".$argHostname."<BR>version=$dbc->version</p>";
- $dbc->Open((string) $argHostname);
-
- $this->_connectionID = $dbc;
- return $dbc != false;
+ return $this->_connect($argHostname,$argUsername,$argPassword,$argProvider);
}
/*
@@ -202,8 +209,14 @@ function &_query($sql,$inputarr=false)
if ($dbc->Errors->Count > 0) return false;
return $rs;
}
- $rs = @$dbc->Execute($sql,&$this->_affectedRows);
-
+
+ $rs = @$dbc->Execute($sql,&$this->_affectedRows, $this->_execute_option);
+ /*
+ $rs = new COM('ADODB.Recordset');
+ if ($rs) {
+ $rs->Open ($sql, $dbc, $this->_cursor_type,$this->_lock_type, $this->_execute_option);
+ }
+ */
if ($dbc->Errors->Count > 0) return false;
if (! $rs) return false;
@@ -222,16 +235,19 @@ function BeginTrans()
if (!$o) return false;
}
@$this->_connectionID->BeginTrans();
+ $this->_inTransaction += 1;
return true;
}
function CommitTrans($ok=true)
{
if (!$ok) return $this->RollbackTrans();
@$this->_connectionID->CommitTrans();
+ if ($this->_inTransaction) @$this->_inTransaction -= 1;
return true;
}
function RollbackTrans() {
@$this->_connectionID->RollbackTrans();
+ if ($this->_inTransaction) @$this->_inTransaction -= 1;
return true;
}
@@ -295,8 +311,10 @@ function FetchField($fieldOffset = -1) {
$rs = $this->_queryID;
$f = $rs->Fields($fieldOffset);
$o->name = $f->Name;
- $o->type = $this->MetaType($f->Type);
+ $t = $f->Type;
+ $o->type = $this->MetaType($t);
$o->max_length = $f->DefinedSize;
+ $o->ado_type = $t;
//print "off=$off name=$o->name type=$o->type len=$o->max_length<br>";
@@ -472,7 +490,7 @@ function MetaType($t,$len=-1)
function _fetch()
{
$rs = $this->_queryID;
- if ($rs->EOF) return false;
+ if (!$rs or $rs->EOF) return false;
$this->fields = array();
if (!$this->_tarr) {
@@ -494,6 +512,9 @@ function _fetch()
for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
switch($t) {
+ case 135: // timestamp
+ $this->fields[] = date('Y-m-d H:i:s',(integer)$f->value);
+ break;
case 133:// A date value (yyyymmdd)
$val = $f->value;
View
6 lib/adodb/drivers/adodb-ado_access.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
@@ -20,7 +20,9 @@ class ADODB_ado_access extends ADODB_ado {
var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE
var $fmtDate = "#Y-m-d#";
var $fmtTimeStamp = "#Y-m-d h:i:sA#";// note no comma
-
+ var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
+ var $sysTimeStamp = 'NOW';
+
function ADODB_ado_access()
{
}
View
24 lib/adodb/drivers/adodb-ado_mssql.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -20,14 +20,26 @@
}
class ADODB_ado_mssql extends ADODB_ado {
-var $databaseType = 'ado_mssql';
-var $hasTop = 'top';
-var $sysDate = 'GetDate()';
-var $sysTimeStamp = 'GetDate()';
-
+ var $databaseType = 'ado_mssql';
+ var $hasTop = 'top';
+ var $sysDate = 'GetDate()';
+ var $sysTimeStamp = 'GetDate()';
+ //var $_inTransaction = 1; // always open recordsets, so no transaction problems.
+
function ADODB_ado_mssql()
{
}
+
+ function _insertid()
+ {
+ return $this->GetOne('select @@identity');
+ }
+
+ function _affectedrows()
+ {
+ return $this->GetOne('select @@rowcount');
+ }
+
}
class ADORecordSet_ado_mssql extends ADORecordSet_ado {
View
2 lib/adodb/drivers/adodb-borland_ibase.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
View
2 lib/adodb/drivers/adodb-csv.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
View
2 lib/adodb/drivers/adodb-db2.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
View
2 lib/adodb/drivers/adodb-fbsql.inc.php
@@ -1,6 +1,6 @@
<?php
/*
- @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+ @version V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
View
2 lib/adodb/drivers/adodb-firebird.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
View
15 lib/adodb/drivers/adodb-ibase.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -39,7 +39,7 @@ class ADODB_ibase extends ADOConnection {
var $dialect = 1;
var $sysDate = "cast('TODAY' as date)";
var $sysTimeStamp = "cast('NOW' as timestamp)";
-
+
function ADODB_ibase()
{
ibase_timefmt('%Y-%m-%d');
@@ -85,6 +85,12 @@ function RowLock($tables,$where,$col)
return 1;
}
+ function Replace($table, $fieldArray, $keyCol,$autoQuote=false)
+ {
+ print "<p>ADOdb: Replace not supported because affected_rows does not work with Interbase</p>";
+ return 0;
+ }
+
function GenID($seqname='adodbseq',$startID=1)
{
$getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE");
@@ -316,8 +322,9 @@ function &FetchField($fieldOffset = -1)
{
$fld = new ADOFieldObject;
$ibf = ibase_field_info($this->_queryID,$fieldOffset);
- $fld->name = strtolower($ibf['name']);
- if (empty($fld->name)) $fld->name = $ibf['alias'];
+
+ $fld->name = strtolower($ibf['alias']);
+ if (empty($fld->name)) $fld->name = strtolower($ibf['name']);
$fld->type = $ibf['type'];
$fld->max_length = $ibf['length'];
if ($this->debug) print_r($fld);
View
2 lib/adodb/drivers/adodb-informix.inc.php
@@ -1,6 +1,6 @@
<?php
/**
-* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my).
+* @version V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my).
All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
View
16 lib/adodb/drivers/adodb-informix72.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim. All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim. All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -123,10 +123,20 @@ function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
#if ($argDatabasename) return $this->SelectDB($argDatabasename);
return true;
}
-
+/*
+ // ifx_do does not accept bind parameters - wierd ???
+ function Prepare($sql)
+ {
+ $stmt = ifx_prepare($sql);
+ if (!$stmt) return $sql;
+ else return array($sql,$stmt);
+ }
+*/
// returns query ID if successful, otherwise false
function _query($sql,$inputarr)
{
+ global $ADODB_COUNTRECS;
+
// String parameters have to be converted using ifx_create_char
if ($inputarr) {
foreach($inputarr as $v) {
@@ -141,7 +151,7 @@ function _query($sql,$inputarr)
// In case of select statement, we use a scroll cursor in order
// to be able to call "move", or "movefirst" statements
- if (preg_match("/^[\\t\\n ]*select/i", $sql)) {
+ if ($ADODB_COUNTRECS && preg_match("/^[\\t\\n ]*select/i", $sql)) {
if ($inputarr) {
$this->lastQuery = ifx_query($sql,$this->_connectionID, IFX_SCROLL, $tab);
}
View
41 lib/adodb/drivers/adodb-mssql.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
+V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -33,13 +33,19 @@
//----------------------------------------------------------------
global $ADODB_mssql_date_order; // 'dmy' and 'mdy' supported
+
+$ADODB_mssql_has_datetimeconvert = (strnatcmp(PHP_VERSION,'4.2.0')>=0);
+if ($ADODB_mssql_has_datetimeconvert) {
+ ini_set('mssql.datetimeconvert',0);
+} else {
global $ADODB_mssql_mths; // array, months must be upper-case
+global $ADODB_mssql_has_datetimeconvert;
-$ADODB_mssql_date_order = 'mdy';
-$ADODB_mssql_mths = array(
+ $ADODB_mssql_date_order = 'mdy';
+ $ADODB_mssql_mths = array(
'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,
'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12);
-
+}
//---------------------------------------------------------------------------
// Call this to autoset $ADODB_mssql_date_order at the beginning of your code,
// just after you connect to the database. Supports mdy and dmy only
@@ -78,11 +84,11 @@ class ADODB_mssql extends ADOConnection {
var $_has_mssql_init;
var $maxParameterLen = 4000;
var $arrayClass = 'ADORecordSet_array_mssql';
+ var $uniqueSort = true;
function ADODB_mssql()
{
- $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0);
-
+ $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0);
}
// might require begintrans -- committrans
@@ -194,12 +200,17 @@ function SelectDB($dbName)
Note: This function is NOT available for Microsoft SQL Server. */
function ErrorMsg()
{
- $this->_errorMsg = mssql_get_last_message();
+ if (empty($this->_errorMsg)){
+ $this->_errorMsg = mssql_get_last_message();
+ }
return $this->_errorMsg;
}
function ErrorNo()
{
+ if (empty($this->_errorMsg)) {
+ $this->_errorMsg = mssql_get_last_message(); print " D E F $this->_errorMsg";
+ }
$id = @mssql_query("select @@ERROR",$this->_connectionID);
if (!$id) return false;
$arr = mssql_fetch_array($id);
@@ -306,6 +317,7 @@ function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
// returns query ID if successful, otherwise false
function _query($sql,$inputarr)
{
+ $this->_errorMsg = false;
if (is_array($sql)) return mssql_execute($sql[1]);
return mssql_query($sql,$this->_connectionID);
}
@@ -458,22 +470,25 @@ function ADORecordSet_array_mssql($id=-1)
// mssql uses a default date like Dec 30 2000 12:00AM
function UnixDate($v)
{
+ global $ADODB_mssql_has_datetimeconvert;
+ if ($ADODB_mssql_has_datetimeconvert) return parent::UnixDate($v);
+
global $ADODB_mssql_mths,$ADODB_mssql_date_order;
//Dec 30 2000 12:00AM
if ($ADODB_mssql_date_order == 'dmy') {
if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {
return parent::UnixDate($v);
}
- if ($rr[3] <= 1970) return 0;
+ if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
$theday = $rr[1];
$themth = substr(strtoupper($rr[2]),0,3);
} else {
if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {
return parent::UnixDate($v);
}
- if ($rr[3] <= 1970) return 0;
+ if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
$theday = $rr[2];
$themth = substr(strtoupper($rr[1]),0,3);
@@ -486,20 +501,23 @@ function UnixDate($v)
function UnixTimeStamp($v)
{
+ global $ADODB_mssql_has_datetimeconvert;
+ if ($ADODB_mssql_has_datetimeconvert) return parent::UnixTimeStamp($v);
+
global $ADODB_mssql_mths,$ADODB_mssql_date_order;
//Dec 30 2000 12:00AM
if ($ADODB_mssql_date_order == 'dmy') {
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})|"
,$v, $rr)) return parent::UnixTimeStamp($v);
- if ($rr[3] <= 1970) return 0;
+ if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
$theday = $rr[1];
$themth = substr(strtoupper($rr[2]),0,3);
} else {
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})|"