From: martin Date: Thu, 13 Jun 2002 12:31:58 +0000 (+0000) Subject: Upgraded to ADOdb 2.12 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b1a1b00aa69041c70e1ae529f6643538cc7df591;p=moodle.git Upgraded to ADOdb 2.12 --- diff --git a/lib/adodb/adodb-cryptsession.php b/lib/adodb/adodb-cryptsession.php index 9aec4a26a1..f17eee1450 100644 --- a/lib/adodb/adodb-cryptsession.php +++ b/lib/adodb/adodb-cryptsession.php @@ -1,6 +1,6 @@ FieldCount() : 0; @@ -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 $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); diff --git a/lib/adodb/adodb-errorhandler.inc.php b/lib/adodb/adodb-errorhandler.inc.php index 9bf1c3632c..68c3480a80 100644 --- a/lib/adodb/adodb-errorhandler.inc.php +++ b/lib/adodb/adodb-errorhandler.inc.php @@ -1,6 +1,6 @@ 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,38 +22,43 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f if (!strpos($name,'[]')) $name .= '[]'; } else if ($size) $attr = " size=$size"; else $attr =''; - - + $s = "\n"; } -function &_adodb_pageexecute(&$zthis, $sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2cache=0) +/* + Code originally from "Cornel G" + + 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; diff --git a/lib/adodb/adodb-pager.inc.php b/lib/adodb/adodb-pager.inc.php new file mode 100644 index 0000000000..8b34d8f7bf --- /dev/null +++ b/lib/adodb/adodb-pager.inc.php @@ -0,0 +1,239 @@ +|<'; + var $prev = '<<'; + var $next = '>>'; + var $last = '>|'; + 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) { + ?> + first;?>   + first   "; + } + } + + //-------------------------- + // Display link to next page + function render_next($anchor=true) + { + global $PHP_SELF; + + if ($anchor) { + ?> + next;?>   + next   "; + } + } + + //------------------ + // 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) { + ?> + last;?>   + last   "; + } + } + + //---------------------- + // Link to previous page + function render_prev($anchor=true) + { + global $PHP_SELF; + if ($anchor) { + ?> + prev;?>   + prev   "; + } + } + + //-------------------------------------------------------- + // 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 "$this->page ".$this->curr_page."/".$this->rs->LastPageNo().""; + } + + //----------------------------------- + // 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 "

Query failed: $this->sql

"; + return; + } + + if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) + $header = $this->RenderNav(); + else + $header = " "; + + $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 "
", + $header, + "
", + $grid, + "
", + $footer, + "
"; + } +} + + +?> \ No newline at end of file diff --git a/lib/adodb/adodb-pear.inc.php b/lib/adodb/adodb-pear.inc.php index 474c30124d..df2714a60d 100644 --- a/lib/adodb/adodb-pear.inc.php +++ b/lib/adodb/adodb-pear.inc.php @@ -1,6 +1,6 @@ Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE"; + $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 "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; - $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 @@ GLOBAL $ADODB_SESSION_CONNECT, $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 "

Session: connection failed

"; } +/****************************************************************************************\ + Close the connection +\****************************************************************************************/ function adodb_sess_close() { global $ADODB_SESS_CONN; @@ -126,10 +140,14 @@ global $ADODB_SESS_CONN; 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 @@ global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL; $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 "

Session: No need to update - crc32 not changed

"; + 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(); diff --git a/lib/adodb/adodb.inc.php b/lib/adodb/adodb.inc.php index a33969a5fc..ccec7c8eb8 100644 --- a/lib/adodb/adodb.inc.php +++ b/lib/adodb/adodb.inc.php @@ -1,7 +1,7 @@ RecordCount() is used. @@ -134,7 +140,7 @@ 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 @@ 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 @@ } else if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true; - if ($this->debug) print $this->host.': '.$this->ErrorMsg()."
\n"; + if ($this->debug) print $this->host.': '.$this->ErrorMsg()."
\n"; return false; } @@ -245,7 +255,7 @@ } else if ($this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true; - if ($this->debug) print $this->host.': '.$this->ErrorMsg()."
\n"; + if ($this->debug) print $this->host.': '.$this->ErrorMsg()."
\n"; return false; } @@ -295,11 +305,11 @@ } /** - * 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 @@ $inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']); if ($inBrowser) - print "
\n($this->databaseType): ".htmlspecialchars($sqlTxt)."   $ss\n
\n"; + print "
\n($this->databaseType): ".htmlspecialchars($sqlTxt)."   $ss\n
\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) ? "
\n" : "\n"); + print $err.': '.$emsg.(($inBrowser) ? "
\n" : "\n"); flush(); } } } else if (!$this->_queryID) { - print $this->ErrorNo().': '.$this->ErrorMsg().(($inBrowser) ? "
\n" : "\n"); + print $this->ErrorNo().': '.$this->ErrorMsg() .(($inBrowser) ? "
\n" : "\n"); flush(); } } else @@ -506,14 +520,14 @@ 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 @@ * @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 @@ } 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 &_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 @@ } 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 @@ // sql, nrows, offset,inputarr,arg3 return $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$inputarr,$this->cacheSecs); } - if ($sql === false) echo "Warning: \$sql missing from CacheSelectLimit()
\n"; + if ($sql === false) echo "Warning: \$sql missing from CacheSelectLimit()
\n"; return $this->SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache); } @@ -849,10 +933,13 @@ $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,8 +949,8 @@ 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); @@ -871,7 +958,8 @@ if ($this->debug) print " Cache write error
\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 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 @@ * 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 @@ * 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 @@ 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 &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 @@ * @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 @@ 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 Init() { if ($this->_inited) return; @@ -1606,7 +1695,7 @@ 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 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 @@ /** * @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 @@ /** * @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 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 * @@ -1936,6 +2034,18 @@ // must be defined by child class } + /** + * 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. * @@ -2022,6 +2132,7 @@ 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 @@ 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 @@ $ok = false; } if (!$ok) { - if ($debug) print " Rename $tmpname ".($ok? 'ok' : 'failed')."
\n"; + if ($debug) print " Rename $tmpname ".($ok? 'ok' : 'failed')."
\n"; } return $ok; } diff --git a/lib/adodb/drivers/adodb-access.inc.php b/lib/adodb/drivers/adodb-access.inc.php index 7556cdf3e3..7203fbc778 100644 --- a/lib/adodb/drivers/adodb-access.inc.php +++ b/lib/adodb/drivers/adodb-access.inc.php @@ -1,6 +1,6 @@ _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'; @@ -43,13 +52,22 @@ class ADODB_ado extends ADOConnection { $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"; @@ -57,28 +75,17 @@ class ADODB_ado extends ADOConnection { if ($this->debug) print "

Host=".$argHostname."
version=$dbc->version

"; // @ 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 "

Host=".$argHostname."
version=$dbc->version

"; - $dbc->Open((string) $argHostname); - - $this->_connectionID = $dbc; - return $dbc != false; + return $this->_connect($argHostname,$argUsername,$argPassword,$argProvider); } /* @@ -202,8 +209,14 @@ class ADODB_ado extends ADOConnection { 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 @@ class ADODB_ado extends ADOConnection { 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 @@ class ADORecordSet_ado extends ADORecordSet { $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
"; @@ -472,7 +490,7 @@ class ADORecordSet_ado extends ADORecordSet { 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 @@ class ADORecordSet_ado extends ADORecordSet { 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; diff --git a/lib/adodb/drivers/adodb-ado_access.inc.php b/lib/adodb/drivers/adodb-ado_access.inc.php index 37d3e8d8d7..4175620e61 100644 --- a/lib/adodb/drivers/adodb-ado_access.inc.php +++ b/lib/adodb/drivers/adodb-ado_access.inc.php @@ -1,6 +1,6 @@ GetOne('select @@identity'); + } + + function _affectedrows() + { + return $this->GetOne('select @@rowcount'); + } + } class ADORecordSet_ado_mssql extends ADORecordSet_ado { diff --git a/lib/adodb/drivers/adodb-borland_ibase.inc.php b/lib/adodb/drivers/adodb-borland_ibase.inc.php index 370529b6d1..3e63ffdb5d 100644 --- a/lib/adodb/drivers/adodb-borland_ibase.inc.php +++ b/lib/adodb/drivers/adodb-borland_ibase.inc.php @@ -1,6 +1,6 @@ ADOdb: Replace not supported because affected_rows does not work with Interbase

"; + return 0; + } + function GenID($seqname='adodbseq',$startID=1) { $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE"); @@ -316,8 +322,9 @@ class ADORecordset_ibase extends ADORecordSet { $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); diff --git a/lib/adodb/drivers/adodb-informix.inc.php b/lib/adodb/drivers/adodb-informix.inc.php index 79c2a92cd2..c90a091d4c 100644 --- a/lib/adodb/drivers/adodb-informix.inc.php +++ b/lib/adodb/drivers/adodb-informix.inc.php @@ -1,6 +1,6 @@ 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 @@ class ADODB_informix72 extends ADOConnection { // 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); } diff --git a/lib/adodb/drivers/adodb-mssql.inc.php b/lib/adodb/drivers/adodb-mssql.inc.php index b1e3a0db1c..2c17345ccb 100644 --- a/lib/adodb/drivers/adodb-mssql.inc.php +++ b/lib/adodb/drivers/adodb-mssql.inc.php @@ -1,6 +1,6 @@ =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 @@ class ADODB_mssql extends ADOConnection { 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 @@ class ADODB_mssql extends ADOConnection { // 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,6 +470,9 @@ class ADORecordSet_array_mssql extends ADORecordSet_array { // 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 @@ -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)) { 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); @@ -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)) { 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 @@ class ADORecordSet_array_mssql extends ADORecordSet_array { 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})|" ,$v, $rr)) return parent::UnixTimeStamp($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); @@ -522,4 +540,5 @@ class ADORecordSet_array_mssql extends ADORecordSet_array { return mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]); } } + ?> \ No newline at end of file diff --git a/lib/adodb/drivers/adodb-mysql.inc.php b/lib/adodb/drivers/adodb-mysql.inc.php index 6595cb7655..3642fc4445 100644 --- a/lib/adodb/drivers/adodb-mysql.inc.php +++ b/lib/adodb/drivers/adodb-mysql.inc.php @@ -1,6 +1,6 @@ _connectionID = mysql_connect($argHostname,$argUsername,$argPassword); + if ($this->forceNewConnect && (strnatcmp(PHP_VERSION,'4.2.0')>=0)) + $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,true); + else + $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword); if ($this->_connectionID === false) return false; if ($argDatabasename) return $this->SelectDB($argDatabasename); return true; @@ -295,9 +299,11 @@ class ADORecordSet_mysql extends ADORecordSet{ $this->_numOfFields = @mysql_num_fields($this->_queryID); } - function &FetchField($fieldOffset = -1) { + function &FetchField($fieldOffset = -1) + { + if ($fieldOffset != -1) { - $o = @mysql_fetch_field($this->_queryID, $fieldOffset); + $o = mysql_fetch_field($this->_queryID, $fieldOffset); $f = @mysql_field_flags($this->_queryID,$fieldOffset); $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com) //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable @@ -308,7 +314,7 @@ class ADORecordSet_mysql extends ADORecordSet{ $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com) //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable } - + return $o; } diff --git a/lib/adodb/drivers/adodb-mysqlt.inc.php b/lib/adodb/drivers/adodb-mysqlt.inc.php index ee50d75499..d8d38217d1 100644 --- a/lib/adodb/drivers/adodb-mysqlt.inc.php +++ b/lib/adodb/drivers/adodb-mysqlt.inc.php @@ -1,7 +1,7 @@ replaceQuote,$s)."'"; } } + } /*-------------------------------------------------------------------------------------- @@ -631,22 +632,12 @@ class ADORecordset_oci8 extends ADORecordSet { $this->fields = array(); if ($this->_queryID) { - /* - if ($this->connection->_getarray) { - if ($this->connection->_hasOCIFetchStatement) { - $arr = array(); - if (OCIFetchStatement($this->_queryID,$arr,0,(integer)-1,OCI_FETCHSTATEMENT_BY_ROW|$this->fetchMode)) { - $this->_arr = $arr; - } - $this->EOF = false; - } - } else */ - { - $this->EOF = !$this->_fetch(); - $this->_currentRow = 0; - } - + + $this->_currentRow = 0; + @$this->_initrs(); + + $this->EOF = !$this->_fetch(); } else { $this->_numOfRows = 0; @@ -815,4 +806,4 @@ class ADORecordset_oci8 extends ADORecordSet { } } } -?> +?> \ No newline at end of file diff --git a/lib/adodb/drivers/adodb-oci805.inc.php b/lib/adodb/drivers/adodb-oci805.inc.php index 45a365404a..fa248715af 100644 --- a/lib/adodb/drivers/adodb-oci805.inc.php +++ b/lib/adodb/drivers/adodb-oci805.inc.php @@ -1,6 +1,6 @@ ADODB_oci8(); + } + function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$arg3=false,$secs2cache=0) { // seems that oracle only supports 1 hint comment in 8i diff --git a/lib/adodb/drivers/adodb-oci8po.inc.php b/lib/adodb/drivers/adodb-oci8po.inc.php index 4bf4974a43..f0a0d4e56e 100644 --- a/lib/adodb/drivers/adodb-oci8po.inc.php +++ b/lib/adodb/drivers/adodb-oci8po.inc.php @@ -1,6 +1,6 @@ replaceQuote,$s))."'"; return "'".$s."'"; } + // TOP requires ORDER BY for VFP function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$arg3=false,$secs2cache=0) diff --git a/lib/adodb/readme.htm b/lib/adodb/readme.htm index c0fb98ef04..3ad762d3ff 100644 --- a/lib/adodb/readme.htm +++ b/lib/adodb/readme.htm @@ -12,7 +12,7 @@

ADOdb Library for PHP

-

V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my)

+

V2.12 12 June 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my)

This software is dual licensed using BSD-Style and LGPL. Where there is any discrepancy, the BSD-Style license will take precedence. This means you can use it in proprietary and commercial products.

@@ -20,7 +20,7 @@ This means you can use it in proprietary and commercial products.

Unique Features
How People are using ADOdb
Feature Requests and Bug Reports
- Installation
+
Installation
R
Initializing Code
ADONewConnection NewADOConnection
@@ -45,8 +45,8 @@ This means you can use it in proprietary and commercial products.

Executing SQL: Execute CacheExecute SelectLimit CacheSelectLimit Prepare PrepareSP Parameter - GetOne GetRow
- Generate Updates/Inserts: GetUpdateSQL GetInsertSQL
+ GetOne GetRow Replace
+ Generates SQL: GetUpdateSQL GetInsertSQL

Blobs: UpdateBlob UpdateClob UpdateBlobFile
Paging/Scrolling: PageExecute CachePageExecute
@@ -54,7 +54,7 @@ This means you can use it in proprietary and commercial products.

Transactions: BeginTrans CommitTrans RollbackTrans
Fetching Data: $ADODB_FETCH_MODE

- Strings: Concat qstr
+ Strings: concat qstr quote
Dates: DBDate DBTimeStamp UnixDate UnixTimeStamp
Rows Management: Affected_Rows Insert_ID @@ -733,50 +733,85 @@ $conn->Close(); ?>

Example 8: Implementing Scrolling with Next and Previous

-

-Code and idea by Iván Oliva ivan.oliva#amena.com.

-We use the HTTP Get variable $next_page to keep track of what page to go next and - store the current page in the session variable $curr_page. -

-We call the connection object's PageExecute() function to generate the appropriate recordset, -then use the recordset's AtFirstPage() and AtLastPage() functions to determine -whether to display the next and previous buttons.

- +

The following code creates a very simple recordset pager, where you can scroll + from page to page of a recordset.

+
-<?php
-include_once('adodb.inc.php');
-include_once('tohtml.inc.php');
-session_register('curr_page');
+include_once('../adodb.inc.php');
+include_once('../adodb-pager.inc.php');
+session_start();
 
 $db = NewADOConnection('mysql');
+
 $db->Connect('localhost','root','','xphplens');
-$num_of_rows_per_page = 10;
-$sql = 'select * from products';
 
-if (isset($HTTP_GET_VARS['next_page']))
-	$curr_page = $HTTP_GET_VARS['next_page'];
-if (empty($curr_page)) $curr_page = 1; ## at first page
+$sql = "select * from adoxyz ";
 
-$rs = $db->PageExecute($sql, $num_of_rows_per_page, $curr_page);
-if (!$rs) die('Query Failed');
+$pager = new ADODB_Pager($db,$sql);
+$pager->Render($rows_per_page=5);
+

This will create a basic record pager that looks like this: +

+ + +
|<   << +   >>   >| +  
-if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) { - if (!$rs->AtFirstPage()) { -?> -<a href="<?php echo $PHPSELF,'?next_page=',$rs->AbsolutePage() - 1 ?>">Previous page</a> -<?php - } - if (!$rs->AtLastPage()) { -?> -<a href="<?php echo $PHPSELF,'?next_page=',$rs->AbsolutePage() + 1 ?>">Next page</a> -<?php - } - rs2html($rs); -} -?> - -The above code can be found in the testpaging.php example included with -this release. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDFirst NameLast NameDate Created
36 Alan Turing Sat 06, Oct 2001 
37 Serena Williams Sat 06, Oct 2001 
38 Yat Sun Sun Sat 06, Oct 2001 
39 Wai Hun See Sat 06, Oct 2001 
40 Steven Oey Sat 06, Oct 2001 
+ +
Page 8/10
+

The number of rows to display at one time is controled by the Render($rows) + method. If you do not pass any value to Render(), ADODB_Pager will default to + 10 records per page. +

You can control the column titles by modifying your SQL (supported by most + databases): +

$sql = 'select id as "ID", firstname as "First Name", 
+          lastname as "Last Name", created as "Date Created" 
from adoxyz';
+

The above code can be found in the adodb/tests/testpaging.php example + included with this release, and the class ADODB_Pager in adodb/adodb-pager.inc.php. + The ADODB_Pager code can be adapted by a programmer so that the text links can + be replaced by images, and the dull white background be replaced with more interesting + colors. +

Some of the code used here was contributed by Iván Oliva and Cornel + G.

+

Using Custom Error Handlers and PEAR_Error

Apart from the old $con->debug = true; way of debugging, ADOdb 1.50 onwards provides another way of handling errors using ADOdb's custom error handlers. @@ -915,7 +950,7 @@ CacheExecute(). If you leave it out, it will use the $connection->cacheSecs para to 60 minutes.
 	$conn->Connect(...);
-	$conn->cacheSecs = 3600*24; // cache 24 hours
+	$conn->cacheSecs = 3600*24; # cache 24 hours
 	$rs = $conn->CacheExecute('select * from table');
 
@@ -1006,14 +1041,16 @@ to 60 minutes.

autoCommit: indicates whether automatic commit is enabled. Default is true.

charSet: set the default charset to use. Currently only interbase supports - this.

+ this.

+

dialect: set the default sql dialect to use. Currently only interbase supports +this.

metaTablesSQL: SQL statement to return a list of available tables. Eg. SHOW TABLES in MySQL.

genID: The latest id generated by GenID() if supported by the database.

cacheSecs: The number of seconds to cache recordsets if CacheExecute() or CacheSelectLimit() do not define the $secs2cache parameter.

-

sysDate: The database function to call to get the current date and time - using the native date/timestamp type.

+

sysDate: String that holds the name of the database function to call to get the current date. Useful for inserts and updates.

+

sysTimeStamp: String that holds the name of the database function to call to get the current timestamp/datetime value.


ADOConnection Main Functions

ADOConnection( )

@@ -1243,7 +1280,41 @@ Similar to UpdateBlob (see above), but for Character Large OBjects.

UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB')

Similar to UpdateBlob, except that we pass in a file path to where the blob resides. -

returns true if successful, false otherwise. +

returns true if successful, false otherwise. +

Replace($table, $arrFields, $keyCols,$autoQuote=false)

+

Try to update a record, and if the record is not found, +an insert statement is generated and executed. +Returns 0 on failure, 1 if update statement worked, 2 if no record +was found and the insert was executed successfully. This differs from the MySQL replace which deletes +the record and inserts a new record. This also means you cannot update the primary key. +

The parameters are $table which is the table name, the $keyCols which is an associative array where +the keys are the field names, and keyCols is the name of the primary key, or an array of field names if +it is a compound key. If $autoQuote is set to true, then Replace() will quote all values that are non-numeric; +auto-quoting will not quote nulls. Note that auto-quoting will not work if you use SQL functions or operators. +

Examples: +

+# single field primary key
+$ret = $db->Replace('atable', 
+	array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'),
+	'id',
+	'firstname',$autoquote = true);	
+# generates UPDATE atable SET firstname='Harun',lastname='Al-Rashid' WHERE id=1000
+# or INSERT INTO atable (id,firstname,lastname) VALUES (1000,'Harun','Al-Rashid')
+
+# compound key
+$ret = $db->Replace('atable2', 
+	array('firstname'=>'Harun','lastname'=>'Al-Rashid', 'age' => 33, 'birthday' => 'null'),
+	array('lastname','firstname'),
+	'firstname',$autoquote = true);
+
+# no auto-quoting
+$ret = $db->Replace('atable2', 
+	array('firstname'=>"'Harun'",'lastname'=>"'Al-Rashid'", 'age' => 'null'),
+	array('lastname','firstname'),
+	'firstname');	
+
+
+

GetUpdateSQL(&$rs, $arrFields, $forceUpdate=false,$magicq=false)

Generate SQL to update a table given a recordset $rs, and the modified fields of the array $arrFields (which must be an associative array holding the column @@ -1447,6 +1518,9 @@ for ($i = 0; $i < $max; $i++) { and once by the magic_quotes_gpc.

Eg. $s = $db->qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc());

Returns the quoted string.

+

Quote($s)

+

Quotes the string, automatically checking get_magic_quotes_gpc() first. +If get_magic_quotes_gpc() is set, then we do not quote the string.

Affected_Rows( )

Returns the number of rows affected by a update or delete statement. Returns false if function not supported.

@@ -1829,9 +1903,42 @@ $rs = $conn->Execute

ToDo:

See the RoadMap article.

Also see the ADOdb proxy article - for bridging Windows and Unix databases using http remote procedure calls.

+ for bridging Windows and Unix databases using http remote procedure calls. For + your education, visit palslib.com for database info, + and read this article + on Optimizing PHP. +

Change Log

+

2.12 12 June 2002

+

Added toexport.inc.php to export recordsets in CSV and tab-delimited format. +

CachePageExecute() does not work - fixed - thx John Huong. +

Interbase aliases not set properly in FetchField() - fixed. Thx Stefan Goethals. +

Added cache property to adodb pager class. The number of secs to cache recordsets. +

SQL rewriting bug in pageexecute() due to skipping of newlines due to missing /s modifier. Fixed. +

Max size of cached recordset due to a bug was 256000 bytes. Fixed. +

Speedup of 1st invocation of CacheExecute() by tuning code. +

We compare $rewritesql with $sql in pageexecute code in case of rewrite failure. +

2.11 7 June 2002

+

Fixed PageExecute() rewrite sql problem - COUNT(*) and ORDER BY don't go together with + mssql, access and postgres. Thx to Alexander Zhukov alex#unipack.ru +

DB2 support for CHARACTER type added - thx John Huong huongch#bigfoot.com +

For ado, $argProvider not properly checked. Fixed - kalimero#ngi.it +

Added $conn->Replace() function for update with automatic insert if the record does not exist. + Supported by all databases except interbase. +

2.10 4 June 2002

+

Added uniqueSort property to indicate mssql ORDER BY cols must be unique. +

Optimized session handler by crc32 the data. We only write if session data has changed. +

adodb_sess_read in adodb-session.php now returns ''correctly - thanks to Jorma Tuomainen, webmaster#wizactive.com +

Mssql driver did not throw EXECUTE errors correctly because ErrorMsg() and ErrorNo() called in wrong order. +Pointed out by Alexios Fakos. Fixed. +

Changed ado to use client cursors. This fixes BeginTran() problems with ado. +

Added handling of timestamp type in ado. +

Added to ado_mssql support for insert_id() and affected_rows(). +

Added support for mssql.datetimeconvert=0, available since php 4.2.0. +

Made UnixDate() less strict, so that the time is ignored if present. +

Changed quote() so that it checks for magic_quotes_gpc. +

Changed maxblobsize for odbc to default to 64000.

2.00 13 May 2002

Added drivers informix72 for pre-7.3 versions, and oci805 for oracle 8.0.5, and postgres64 for postgresql 6.4 and earlier. The postgres and postgres7 drivers diff --git a/lib/adodb/server.php b/lib/adodb/server.php index 687bd57d97..e906a1753e 100644 --- a/lib/adodb/server.php +++ b/lib/adodb/server.php @@ -1,6 +1,6 @@ Execute($sql); if ($rs){ //$rs->timeToLive = 1; - echo rs2csv($rs,$conn,$sql); + echo _rs2serialize($rs,$conn,$sql); $rs->Close(); } else err($conn->ErrorNo(). $sep .$conn->ErrorMsg()); diff --git a/lib/adodb/tests/benchmark.php b/lib/adodb/tests/benchmark.php index 32002ede0b..bbf403bf81 100644 --- a/lib/adodb/tests/benchmark.php +++ b/lib/adodb/tests/benchmark.php @@ -8,7 +8,7 @@ ADODB Version: $ADODB_vers Host: $db->host   Database: $db->database   PHP: $phpv"; $e = error_reporting(E_ALL-E_WARNING); - - print "date1 (1999-02-20) = ".$db->DBDate('1999-2-20'); + print "date1 (1969-02-20) = ".$db->DBDate('1969-2-20'); + print "
date1 (1999-02-20) = ".$db->DBDate('1999-2-20'); print "
date2 (1970-1-2) = ".$db->DBDate(24*3600)."

"; print "ts1 (1999-02-20 3:40:50) = ".$db->DBTimeStamp('1999-2-20 3:40:50'); print "
ts2 (1999-02-20) = ".$db->DBTimeStamp('1999-2-20'); @@ -140,12 +140,13 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU if ($rs) $rs->Close(); - $db->debug=false; + //$db->debug=true; print "

Testing Commit: "; $time = $db->DBDate(time()); if (!$db->BeginTrans()) print 'Transactions not supported

'; else { /* COMMIT */ - $rs = $db->Execute("insert into ADOXYZ values (99,'Should Not','Exist (Commit)',$time)"); + + $rs = $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (99,'Should Not','Exist (Commit)',$time)"); if ($rs && $db->CommitTrans()) { $rs->Close(); $rs = &$db->Execute("select * from ADOXYZ where id=99"); @@ -156,13 +157,16 @@ GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COU die(); } else print 'OK

'; if ($rs) $rs->Close(); - } else - print "Commit failed

"; - + } else { + if (!$rs) { + print "Insert failed

"; + $db->RollbackTrans(); + } else print "Commit failed

"; + } /* ROLLBACK */ if (!$db->BeginTrans()) print "

Error in BeginTrans()

"; print "

Testing Rollback: "; - $db->Execute("insert into ADOXYZ values (100,'Should Not','Exist (Rollback)',$time)"); + $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (100,'Should Not','Exist (Rollback)',$time)"); if ($db->RollbackTrans()) { $rs = $db->Execute("select * from ADOXYZ where id=100"); if ($rs && !$rs->EOF) print 'Fail: Data should rollback

'; @@ -307,11 +311,10 @@ GO $db->debug = false; $ADODB_FETCH_MODE = ADODB_FETCH_BOTH; - /////////////////////////////// - - $rs = &$db->Execute("select * from ADOXYZ order by id"); + ////////////////////////////////////////////////////////////////////////////////////////// + + $rs = &$db->Execute("select id,firstname as TheFirstName,lastname,created from ADOXYZ order by id"); if ($rs) { - // print_r($rs); if ($rs->RecordCount() != 50) { print "

RecordCount returns -1

"; if ($rs->PO_RecordCount('ADOXYZ') == 50) print "

    PO_RecordCount passed

"; @@ -586,7 +589,7 @@ GO if ($val == 0) echo "

GenID not supported"; echo "

"; - if (substr($db->dataProvider,0,3) != 'ado') { // crashes ado + if (substr($db->dataProvider,0,3) != 'notused') { // used to crash ado $sql = "select firstnames from adoxyz"; print "

Testing execution of illegal statement: $sql

"; if ($db->Execute($sql) === false) { @@ -655,7 +658,9 @@ GO print "

Invalid date {$rs->fields[0]}

"; } else print "

Passed \$sysDate test ({$rs->fields[0]})

"; - + + print_r($rs->FetchField(0)); + print time(); $db->debug=$saved; } else { print "

\$db->sysDate not defined

"; @@ -678,10 +683,44 @@ GO } $rs->Close(); } + + print "

Test CSV

"; + include_once('../toexport.inc.php'); + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; + $rs = $db->SelectLimit('select id,firstname,lastname,created,\'The "young man", he said\' from adoxyz',10); + + print "
";
+	print rs2csv($rs);
+	print "
"; + + $rs = $db->SelectLimit('select id,firstname,lastname,created,\'The "young man", he said\' from adoxyz',10); + + print "
";
+	tab2csvout($rs);
+	print "
"; + $db->debug=1; + + print "

Test Replace

"; + + $ret = $db->Replace('adoxyz', + array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'), + array('id','firstname'), + $autoq = true); + if ($ret != 2) print "Replace failed: "; + print "test A return value=$ret (2 expected)

"; + + $ret = $db->Replace('adoxyz', + array('id'=>1000,'firstname'=>'Sherazade','lastname'=>'Al-Rashid'), + 'id', + $autoq = true); + if ($ret != 1) print "Replace failed: "; + print "test B return value=$ret (1 expected)

"; + + ///////////////////////////////////////////////////////////// + include_once "PEAR.php"; - $db->debug =true; if ($i != 50) { print "

PEAR DB emulation error 1.1 EOF ($i)

"; $pear = false; @@ -713,14 +752,21 @@ GO global $TESTERRS; + $debugerr = true; + $db->debug = false; $TESTERRS = 0; $db->raiseErrorFn = 'adodb_test_err'; $db->Execute('select * from nowhere'); + if ($TESTERRS != 1) print "raiseErrorFn select nowhere failed
"; $rs = $db->Execute('select * from adoxyz'); + if ($debugerr) print " Move"; $rs->Move(100); $rs->_queryID = false; + if ($debugerr) print " MoveNext"; $rs->MoveNext(); + + if ($debugerr) print " $rs=false"; $rs = false; $conn = NewADOConnection($db->databaseType); $conn->raiseErrorFn = 'adodb_test_err'; diff --git a/lib/adodb/tests/test2.php b/lib/adodb/tests/test2.php index f620af3ab8..007a57f5e4 100644 --- a/lib/adodb/tests/test2.php +++ b/lib/adodb/tests/test2.php @@ -8,7 +8,7 @@ PConnect('flipper','','',"test")) - die("Cannot connect to flipper"); -if (!$c2->PConnect('mangrove','root','',"northwind")) - die("Cannot connect to mangrove"); - -print "

Flipper

"; -$t = $c1->MetaTables(); # list all tables in DB -print_r($t); -# select * from last table in DB -rs2html($c1->Execute("select * from ".$t[sizeof($t)-1])); - -print "

Mangrove

"; -$t = $c2->MetaTables(); -print_r($t); -rs2html($c2->Execute("select * from ".$t[sizeof($t)-1] )); - -print "

Flipper

"; -$t = $c1->MetaTables(); -print_r($t); -rs2html($c1->Execute("select * from ".$t[sizeof($t)-1])); +if (!$c1->PConnect('','scott','tiger')) + die("Cannot connect to server"); +$c1->debug=1; +$rs = $c1->CacheExecute(1200,'select rownum, p1.firstname,p2.lastname,p2.firstname,p1.lastname from adoxyz p1, adoxyz p2'); +print "Records=".$rs->RecordCount()."
"; +rs2html($rs); ?> diff --git a/lib/adodb/tests/test3.php b/lib/adodb/tests/test3.php index 9bfafc7dc7..a544149473 100644 --- a/lib/adodb/tests/test3.php +++ b/lib/adodb/tests/test3.php @@ -1,7 +1,7 @@ Connecting $db->databaseType..."; if ($db->Connect('', "scott", "tiger",'natsoft.ecosystem.natsoft.com.my')) //if ($db->PConnect("", "scott", "tiger", "juris.ecosystem.natsoft.com.my")) @@ -127,7 +127,7 @@ if (false && !empty($testoracle)) { ADOLoadCode("odbc_mssql"); -if (!empty($testmssql) and false) { // MS SQL Server via ODBC +if (!empty($testmssql) && false) { // MS SQL Server via ODBC $db = ADONewConnection(); @@ -143,10 +143,11 @@ ADOLoadCode("ado_mssql"); if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC -- DSN-less $db = &ADONewConnection("ado_mssql"); + $db->debug=1; print "

Connecting DSN-less $db->databaseType...

"; $myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};" - . "SERVER=(local);DATABASE=NorthWind;UID=sa;PWD=natsoft;" ; + . "SERVER=mangrove;DATABASE=NorthWind;UID=sa;PWD=natsoft;" ; if (@$db->PConnect($myDSN, "", "", "")) @@ -159,6 +160,7 @@ if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC ADOLoadCode("mssql"); if (!empty($testmssql)) { // MS SQL Server -- the extension is buggy -- probably better to use ODBC $db = ADONewConnection(); + $db->debug=1; print "

Connecting $db->databaseType...

"; $db->Connect('(local)\NetSDK','','','northwind'); @@ -174,7 +176,7 @@ if (!empty($testmssql) && !empty($testado)) { // ADO ACCESS MSSQL with OLEDB pro $db = &ADONewConnection("ado_mssql"); print "

Connecting DSN-less OLEDB Provider $db->databaseType...

"; - + $db->debug=1; $myDSN="SERVER=mangrove;DATABASE=ai;"; //$myDSN='SERVER=(local)\NetSDK;DATABASE=northwind;'; if ($db->PConnect($myDSN, "sa", "natsoft", 'SQLOLEDB')) diff --git a/lib/adodb/tests/testgenid.php b/lib/adodb/tests/testgenid.php index 51e3b0afba..5d76d74ca8 100644 --- a/lib/adodb/tests/testgenid.php +++ b/lib/adodb/tests/testgenid.php @@ -1,5 +1,7 @@ Connect('sqlserver','sa','natsoft'); + +//$conn = &ADONewConnection("mssql"); +//$conn->Connect('mangrove','sa','natsoft','ai'); + +//$conn->Connect('mangrove','sa','natsoft','ai'); +$conn->debug=1; +$conn->Execute('delete from blobtest'); + +$conn->Execute('insert into blobtest (id) values(1)'); +$conn->UpdateBlobFile('blobtest','b1','../cute_icons_for_site/adodb.gif','id=1'); +$rs = $conn->Execute('select b1 from blobtest where id=1'); + +$output = "c:\\temp\\test_out-".date('H-i-s').".gif"; +print "Saving file $output, size=".strlen($rs->fields[0])."

"; +$fd = fopen($output, "wb"); +fwrite($fd, $rs->fields[0]); +fclose($fd); + +print " View Image"; +//$rs = $conn->Execute('SELECT id,SUBSTRING(b1, 1, 10) FROM blobtest'); +//rs2html($rs); +?> \ No newline at end of file diff --git a/lib/adodb/tests/testoci8.php b/lib/adodb/tests/testoci8.php index 735e93e270..b1088aed99 100644 --- a/lib/adodb/tests/testoci8.php +++ b/lib/adodb/tests/testoci8.php @@ -2,7 +2,7 @@ debug = true; -//$db->Connect('localhost:4321','scott','tiger','natsoft.domain'); -$db->Connect('localhost','root','','xphplens'); +$driver = 'mysql'; +$sql = 'select ID, firstname as "First Name", lastname as "Last Name", created as "Date Created" from adoxyz order by id'; -$num_of_rows_per_page = 7; -$sql = "select * from adoxyz "; +if ($driver == 'access') { + $db = NewADOConnection('access'); + $db->PConnect("nwind", "", "", ""); +} -if (isset($HTTP_GET_VARS['next_page'])) - $curr_page = $HTTP_GET_VARS['next_page']; -if (empty($curr_page)) $curr_page = 1; ## at first page +if ($driver == 'ibase') { + $db = NewADOConnection('ibase'); + $db->PConnect("localhost:e:\\interbase\\examples\\database\\employee.gdb", "sysdba", "masterkey", ""); + $sql = 'select ID, firstname , lastname , created from adoxyz order by id'; +} +if ($driver == 'mssql') { + $db = NewADOConnection('mssql'); + $db->Connect('(local)\NetSDK','','','northwind'); +} +if ($driver == 'oci8') { + $db = NewADOConnection('oci8'); + $db->Connect('','scott','tiger'); +} -$rs = $db->PageExecute($sql, $num_of_rows_per_page, $curr_page); -if (!$rs) die('Query Failed'); +if ($driver == 'access') { + $db = NewADOConnection('access'); + $db->Connect('nwind'); +} -if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) { - if (!$rs->AtFirstPage()) { -?> -First page   -Previous page   -AtLastPage()) { -?> -Next Page -Connect('localhost','root','','xphplens'); } +//$db->pageExecuteCountRows = false; + +$db->debug = true; -?> +$pager = new ADODB_Pager($db,$sql); +//$pager->cache = 60; +$pager->Render($rows=7); +?> \ No newline at end of file diff --git a/lib/adodb/tests/testpear.php b/lib/adodb/tests/testpear.php index c0e69b2167..1ae17c3613 100644 --- a/lib/adodb/tests/testpear.php +++ b/lib/adodb/tests/testpear.php @@ -1,6 +1,6 @@ \$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}

"; + if (!isset($HTTP_GET_VARS['nochange'])) $HTTP_SESSION_VARS['AVAR'] += 1; + + print "

\$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}

"; ?> \ No newline at end of file diff --git a/lib/adodb/tips_portable_sql.htm b/lib/adodb/tips_portable_sql.htm index 6c6cde133a..e2dbcafada 100644 --- a/lib/adodb/tips_portable_sql.htm +++ b/lib/adodb/tips_portable_sql.htm @@ -257,7 +257,8 @@ $rs = $db->Execute(sprintf($sqlSearchKeyWord,$db->qstr($word))); sound principles. Learn the theory of normalization and entity-relationship diagrams and model your data carefully. Understand how joins and indexes work and how they are used to tune performance.

Visit the following page for more references on database theory and vendors: - http://php.weblogs.com/sql_tutorial + http://php.weblogs.com/sql_tutorial. + Also read this article on Optimizing PHP.

(c) 2002 John Lim. diff --git a/lib/adodb/toexport.inc.php b/lib/adodb/toexport.inc.php new file mode 100644 index 0000000000..db45fe6c73 --- /dev/null +++ b/lib/adodb/toexport.inc.php @@ -0,0 +1,130 @@ +FieldTypesArray(); + foreach($fieldTypes as $o) { + + $v = $o->name; + if ($escquote) $v = str_replace($quote,$escquotequote,$v); + $v = strip_tags(str_replace("\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))); + $elements[] = $v; + + } + $s .= implode($sep, $elements).$NEWLINE; + } + $hasNumIndex = isset($rs->fields[0]); + + $line = 0; + $max = $rs->FieldCount(); + + while (!$rs->EOF) { + $elements = array(); + $i = 0; + + if ($hasNumIndex) { + for ($j=0; $j < $max; $j++) { + $v = $rs->fields[$j]; + if ($escquote) $v = str_replace($quote,$escquotequote,$v); + $v = strip_tags(str_replace("\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))); + + if (strpos($v,$sep) || strpos($v,$quote))$elements[] = "$quote$v$quote"; + else $elements[] = $v; + } + } else { // ASSOCIATIVE ARRAY + foreach($rs->fields as $v) { + if ($escquote) $v = str_replace($quote,$escquotequote,$v); + $v = strip_tags(str_replace("\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))); + + if (strpos($v,$sep) || strpos($v,$quote))$elements[] = "$quote$v$quote"; + else $elements[] = $v; + } + } + $s .= implode($sep, $elements).$NEWLINE; + $rs->MoveNext(); + $line += 1; + if ($fp && ($line % $BUFLINES) == 0) { + if ($fp === true) echo $s; + else fwrite($fp,$s); + $s = ''; + } + } + + if ($fp) { + if ($fp === true) echo $s; + else fwrite($fp,$s); + $s = ''; + } + + return $s; +} +?> \ No newline at end of file diff --git a/lib/adodb/tohtml.inc.php b/lib/adodb/tohtml.inc.php index 22c4857e8b..a82f19dee7 100644 --- a/lib/adodb/tohtml.inc.php +++ b/lib/adodb/tohtml.inc.php @@ -1,6 +1,6 @@ FieldCount(); $hdr = "\n\n"; - for ($i=0; $i < $ncols; $i++) { $field = $rs->FetchField($i); if ($zheaderarray) $fname = $zheaderarray[$i];