Documentation TYPO3 par Ameos |
00001 <?php 00002 /* 00003 * Set tabs to 4 for best viewing. 00004 * 00005 * Latest version is available at http://adodb.sourceforge.net 00006 * 00007 * This is the main include file for ADOdb. 00008 * Database specific drivers are stored in the adodb/drivers/adodb-*.inc.php 00009 * 00010 * The ADOdb files are formatted so that doxygen can be used to generate documentation. 00011 * Doxygen is a documentation generation tool and can be downloaded from http://doxygen.org/ 00012 */ 00013 00035 if (!defined('_ADODB_LAYER')) { 00036 define('_ADODB_LAYER',1); 00037 00038 //============================================================================================== 00039 // CONSTANT DEFINITIONS 00040 //============================================================================================== 00041 00042 00047 if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__)); 00048 00049 //============================================================================================== 00050 // GLOBAL VARIABLES 00051 //============================================================================================== 00052 00053 GLOBAL 00054 $ADODB_vers, // database version 00055 $ADODB_COUNTRECS, // count number of records returned - slows down query 00056 $ADODB_CACHE_DIR, // directory to cache recordsets 00057 $ADODB_EXTENSION, // ADODB extension installed 00058 $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF 00059 $ADODB_FETCH_MODE; // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default... 00060 00061 //============================================================================================== 00062 // GLOBAL SETUP 00063 //============================================================================================== 00064 00065 $ADODB_EXTENSION = defined('ADODB_EXTENSION'); 00066 00067 //********************************************************// 00068 /* 00069 Controls $ADODB_FORCE_TYPE mode. Default is ADODB_FORCE_VALUE (3). 00070 Used in GetUpdateSql and GetInsertSql functions. Thx to Niko, nuko#mbnet.fi 00071 00072 0 = ignore empty fields. All empty fields in array are ignored. 00073 1 = force null. All empty, php null and string 'null' fields are changed to sql NULL values. 00074 2 = force empty. All empty, php null and string 'null' fields are changed to sql empty '' or 0 values. 00075 3 = force value. Value is left as it is. Php null and string 'null' are set to sql NULL values and empty fields '' are set to empty '' sql values. 00076 */ 00077 define('ADODB_FORCE_IGNORE',0); 00078 define('ADODB_FORCE_NULL',1); 00079 define('ADODB_FORCE_EMPTY',2); 00080 define('ADODB_FORCE_VALUE',3); 00081 //********************************************************// 00082 00083 00084 if (!$ADODB_EXTENSION || ADODB_EXTENSION < 4.0) { 00085 00086 define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>'); 00087 00088 // allow [ ] @ ` " and . in table names 00089 define('ADODB_TABLE_REGEX','([]0-9a-z_\:\"\`\.\@\[-]*)'); 00090 00091 // prefetching used by oracle 00092 if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10); 00093 00094 00095 /* 00096 Controls ADODB_FETCH_ASSOC field-name case. Default is 2, use native case-names. 00097 This currently works only with mssql, odbc, oci8po and ibase derived drivers. 00098 00099 0 = assoc lowercase field names. $rs->fields['orderid'] 00100 1 = assoc uppercase field names. $rs->fields['ORDERID'] 00101 2 = use native-case field names. $rs->fields['OrderID'] 00102 */ 00103 00104 define('ADODB_FETCH_DEFAULT',0); 00105 define('ADODB_FETCH_NUM',1); 00106 define('ADODB_FETCH_ASSOC',2); 00107 define('ADODB_FETCH_BOTH',3); 00108 00109 if (!defined('TIMESTAMP_FIRST_YEAR')) define('TIMESTAMP_FIRST_YEAR',100); 00110 00111 // PHP's version scheme makes converting to numbers difficult - workaround 00112 $_adodb_ver = (float) PHP_VERSION; 00113 if ($_adodb_ver >= 5.0) { 00114 define('ADODB_PHPVER',0x5000); 00115 } else if ($_adodb_ver > 4.299999) { # 4.3 00116 define('ADODB_PHPVER',0x4300); 00117 } else if ($_adodb_ver > 4.199999) { # 4.2 00118 define('ADODB_PHPVER',0x4200); 00119 } else if (strnatcmp(PHP_VERSION,'4.0.5')>=0) { 00120 define('ADODB_PHPVER',0x4050); 00121 } else { 00122 define('ADODB_PHPVER',0x4000); 00123 } 00124 } 00125 00126 //if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2); 00127 00128 00132 function ADODB_str_replace($src, $dest, $data) 00133 { 00134 if (ADODB_PHPVER >= 0x4050) return str_replace($src,$dest,$data); 00135 00136 $s = reset($src); 00137 $d = reset($dest); 00138 while ($s !== false) { 00139 $data = str_replace($s,$d,$data); 00140 $s = next($src); 00141 $d = next($dest); 00142 } 00143 return $data; 00144 } 00145 00146 function ADODB_Setup() 00147 { 00148 GLOBAL 00149 $ADODB_vers, // database version 00150 $ADODB_COUNTRECS, // count number of records returned - slows down query 00151 $ADODB_CACHE_DIR, // directory to cache recordsets 00152 $ADODB_FETCH_MODE, 00153 $ADODB_FORCE_TYPE; 00154 00155 $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT; 00156 $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE; 00157 00158 00159 if (!isset($ADODB_CACHE_DIR)) { 00160 $ADODB_CACHE_DIR = '/tmp'; //(isset($_ENV['TMP'])) ? $_ENV['TMP'] : '/tmp'; 00161 } else { 00162 // do not accept url based paths, eg. http:/ or ftp:/ 00163 if (strpos($ADODB_CACHE_DIR,'://') !== false) 00164 die("Illegal path http:// or ftp://"); 00165 } 00166 00167 00168 // Initialize random number generator for randomizing cache flushes 00169 srand(((double)microtime())*1000000); 00170 00174 $ADODB_vers = 'V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.'; 00175 00181 if (!isset($ADODB_COUNTRECS)) $ADODB_COUNTRECS = true; 00182 } 00183 00184 00185 //============================================================================================== 00186 // CHANGE NOTHING BELOW UNLESS YOU ARE DESIGNING ADODB 00187 //============================================================================================== 00188 00189 ADODB_Setup(); 00190 00191 //============================================================================================== 00192 // CLASS ADOFieldObject 00193 //============================================================================================== 00197 class ADOFieldObject { 00198 var $name = ''; 00199 var $max_length=0; 00200 var $type=""; 00201 /* 00202 // additional fields by dannym... (danny_milo@yahoo.com) 00203 var $not_null = false; 00204 // actually, this has already been built-in in the postgres, fbsql AND mysql module? ^-^ 00205 // so we can as well make not_null standard (leaving it at "false" does not harm anyways) 00206 00207 var $has_default = false; // this one I have done only in mysql and postgres for now ... 00208 // others to come (dannym) 00209 var $default_value; // default, if any, and supported. Check has_default first. 00210 */ 00211 } 00212 00213 00214 00215 function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) 00216 { 00217 //print "Errorno ($fn errno=$errno m=$errmsg) "; 00218 $thisConnection->_transOK = false; 00219 if ($thisConnection->_oldRaiseFn) { 00220 $fn = $thisConnection->_oldRaiseFn; 00221 $fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection); 00222 } 00223 } 00224 00225 //============================================================================================== 00226 // CLASS ADOConnection 00227 //============================================================================================== 00228 00232 class ADOConnection { 00233 // 00234 // PUBLIC VARS 00235 // 00236 var $dataProvider = 'native'; 00237 var $databaseType = ''; 00238 var $database = ''; 00239 var $host = ''; 00240 var $user = ''; 00241 var $password = ''; 00242 var $debug = false; 00243 var $maxblobsize = 262144; 00244 var $concat_operator = '+'; 00245 var $substr = 'substr'; 00246 var $length = 'length'; 00247 var $random = 'rand()'; 00248 var $upperCase = 'upper'; 00249 var $fmtDate = "'Y-m-d'"; 00250 var $fmtTimeStamp = "'Y-m-d, h:i:s A'"; 00251 var $true = '1'; 00252 var $false = '0'; 00253 var $replaceQuote = "\\'"; 00254 var $nameQuote = '"'; 00255 var $charSet=false; 00256 var $metaDatabasesSQL = ''; 00257 var $metaTablesSQL = ''; 00258 var $uniqueOrderBy = false; 00259 var $emptyDate = ' '; 00260 var $emptyTimeStamp = ' '; 00261 var $lastInsID = false; 00262 //-- 00263 var $hasInsertID = false; 00264 var $hasAffectedRows = false; 00265 var $hasTop = false; 00266 var $hasLimit = false; 00267 var $readOnly = false; 00268 var $hasMoveFirst = false; 00269 var $hasGenID = false; 00270 var $hasTransactions = true; 00271 //-- 00272 var $genID = 0; 00273 var $raiseErrorFn = false; 00274 var $isoDates = false; 00275 var $cacheSecs = 3600; 00276 var $sysDate = false; 00277 var $sysTimeStamp = false; 00278 var $arrayClass = 'ADORecordSet_array'; 00279 00280 var $noNullStrings = false; 00281 var $numCacheHits = 0; 00282 var $numCacheMisses = 0; 00283 var $pageExecuteCountRows = true; 00284 var $uniqueSort = false; 00285 var $leftOuter = false; 00286 var $rightOuter = false; 00287 var $ansiOuter = false; 00288 var $autoRollback = false; // autoRollback on PConnect(). 00289 var $poorAffectedRows = false; // affectedRows not working or unreliable 00290 00291 var $fnExecute = false; 00292 var $fnCacheExecute = false; 00293 var $blobEncodeType = false; // false=not required, 'I'=encode to integer, 'C'=encode to char 00294 var $rsPrefix = "ADORecordSet_"; 00295 00296 var $autoCommit = true; 00297 var $transOff = 0; 00298 var $transCnt = 0; 00299 00300 var $fetchMode=false; 00301 // 00302 // PRIVATE VARS 00303 // 00304 var $_oldRaiseFn = false; 00305 var $_transOK = null; 00306 var $_connectionID = false; 00307 var $_errorMsg = false; 00308 00309 var $_errorCode = false; 00310 var $_queryID = false; 00311 00312 var $_isPersistentConnection = false; 00313 var $_bindInputArray = false; 00314 var $_evalAll = false; 00315 var $_affected = false; 00316 var $_logsql = false; 00317 00321 function ADOConnection() 00322 { 00323 die('Virtual Class -- cannot instantiate'); 00324 } 00325 00326 function Version() 00327 { 00328 global $ADODB_vers; 00329 00330 return (float) substr($ADODB_vers,1); 00331 } 00332 00339 function ServerInfo() 00340 { 00341 return array('description' => '', 'version' => ''); 00342 } 00343 00344 function IsConnected() 00345 { 00346 return !empty($this->_connectionID); 00347 } 00348 00349 function _findvers($str) 00350 { 00351 if (preg_match('/([0-9]+\.([0-9\.])+)/',$str, $arr)) return $arr[1]; 00352 else return ''; 00353 } 00354 00359 function outp($msg,$newline=true) 00360 { 00361 global $ADODB_FLUSH,$ADODB_OUTP; 00362 00363 if (defined('ADODB_OUTP')) { 00364 $fn = ADODB_OUTP; 00365 $fn($msg,$newline); 00366 return; 00367 } else if (isset($ADODB_OUTP)) { 00368 $fn = $ADODB_OUTP; 00369 $fn($msg,$newline); 00370 return; 00371 } 00372 00373 if ($newline) $msg .= "<br>\n"; 00374 00375 if (isset($_SERVER['HTTP_USER_AGENT']) || !$newline) echo $msg; 00376 else echo strip_tags($msg); 00377 00378 00379 if (!empty($ADODB_FLUSH) && ob_get_length() !== false) flush(); // do not flush if output buffering enabled - useless - thx to Jesse Mullan 00380 00381 } 00382 00383 function Time() 00384 { 00385 $rs =& $this->_Execute("select $this->sysTimeStamp"); 00386 if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields)); 00387 00388 return false; 00389 } 00390 00402 function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "", $forceNew = false) 00403 { 00404 if ($argHostname != "") $this->host = $argHostname; 00405 if ($argUsername != "") $this->user = $argUsername; 00406 if ($argPassword != "") $this->password = $argPassword; // not stored for security reasons 00407 if ($argDatabaseName != "") $this->database = $argDatabaseName; 00408 00409 $this->_isPersistentConnection = false; 00410 if ($forceNew) { 00411 if ($rez=$this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true; 00412 } else { 00413 if ($rez=$this->_connect($this->host, $this->user, $this->password, $this->database)) return true; 00414 } 00415 if (isset($rez)) { 00416 $err = $this->ErrorMsg(); 00417 if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'"; 00418 $ret = false; 00419 } else { 00420 $err = "Missing extension for ".$this->dataProvider; 00421 $ret = 0; 00422 } 00423 if ($fn = $this->raiseErrorFn) 00424 $fn($this->databaseType,'CONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this); 00425 00426 00427 $this->_connectionID = false; 00428 if ($this->debug) ADOConnection::outp( $this->host.': '.$err); 00429 return $ret; 00430 } 00431 00432 function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName) 00433 { 00434 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName); 00435 } 00436 00437 00448 function NConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") 00449 { 00450 return $this->Connect($argHostname, $argUsername, $argPassword, $argDatabaseName, true); 00451 } 00452 00463 function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") 00464 { 00465 if (defined('ADODB_NEVER_PERSIST')) 00466 return $this->Connect($argHostname,$argUsername,$argPassword,$argDatabaseName); 00467 00468 if ($argHostname != "") $this->host = $argHostname; 00469 if ($argUsername != "") $this->user = $argUsername; 00470 if ($argPassword != "") $this->password = $argPassword; 00471 if ($argDatabaseName != "") $this->database = $argDatabaseName; 00472 00473 $this->_isPersistentConnection = true; 00474 if ($rez = $this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true; 00475 if (isset($rez)) { 00476 $err = $this->ErrorMsg(); 00477 if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'"; 00478 $ret = false; 00479 } else { 00480 $err = "Missing extension for ".$this->dataProvider; 00481 $ret = 0; 00482 } 00483 if ($fn = $this->raiseErrorFn) { 00484 $fn($this->databaseType,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this); 00485 } 00486 00487 $this->_connectionID = false; 00488 if ($this->debug) ADOConnection::outp( $this->host.': '.$err); 00489 return $ret; 00490 } 00491 00492 // Format date column in sql string given an input format that understands Y M D 00493 function SQLDate($fmt, $col=false) 00494 { 00495 if (!$col) $col = $this->sysDate; 00496 return $col; // child class implement 00497 } 00498 00514 function Prepare($sql) 00515 { 00516 return $sql; 00517 } 00518 00533 function PrepareSP($sql,$param=true) 00534 { 00535 return $this->Prepare($sql,$param); 00536 } 00537 00541 function Quote($s) 00542 { 00543 return $this->qstr($s,false); 00544 } 00545 00549 function QMagic($s) 00550 { 00551 return $this->qstr($s,get_magic_quotes_gpc()); 00552 } 00553 00554 function q(&$s) 00555 { 00556 $s = $this->qstr($s,false); 00557 } 00558 00562 function ErrorNative() 00563 { 00564 return $this->ErrorNo(); 00565 } 00566 00567 00571 function nextId($seq_name) 00572 { 00573 return $this->GenID($seq_name); 00574 } 00575 00583 function RowLock($table,$where) 00584 { 00585 return false; 00586 } 00587 00588 function CommitLock($table) 00589 { 00590 return $this->CommitTrans(); 00591 } 00592 00593 function RollbackLock($table) 00594 { 00595 return $this->RollbackTrans(); 00596 } 00597 00607 function SetFetchMode($mode) 00608 { 00609 $old = $this->fetchMode; 00610 $this->fetchMode = $mode; 00611 00612 if ($old === false) { 00613 global $ADODB_FETCH_MODE; 00614 return $ADODB_FETCH_MODE; 00615 } 00616 return $old; 00617 } 00618 00619 00623 function &Query($sql, $inputarr=false) 00624 { 00625 $rs = &$this->Execute($sql, $inputarr); 00626 if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error(); 00627 return $rs; 00628 } 00629 00630 00634 function &LimitQuery($sql, $offset, $count, $params=false) 00635 { 00636 $rs = &$this->SelectLimit($sql, $count, $offset, $params); 00637 if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error(); 00638 return $rs; 00639 } 00640 00641 00645 function Disconnect() 00646 { 00647 return $this->Close(); 00648 } 00649 00650 /* 00651 Returns placeholder for parameter, eg. 00652 $DB->Param('a') 00653 00654 will return ':a' for Oracle, and '?' for most other databases... 00655 00656 For databases that require positioned params, eg $1, $2, $3 for postgresql, 00657 pass in Param(false) before setting the first parameter. 00658 */ 00659 function Param($name,$type='C') 00660 { 00661 return '?'; 00662 } 00663 00664 /* 00665 InParameter and OutParameter are self-documenting versions of Parameter(). 00666 */ 00667 function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false) 00668 { 00669 return $this->Parameter($stmt,$var,$name,false,$maxLen,$type); 00670 } 00671 00672 /* 00673 */ 00674 function OutParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false) 00675 { 00676 return $this->Parameter($stmt,$var,$name,true,$maxLen,$type); 00677 00678 } 00679 00680 /* 00681 Usage in oracle 00682 $stmt = $db->Prepare('select * from table where id =:myid and group=:group'); 00683 $db->Parameter($stmt,$id,'myid'); 00684 $db->Parameter($stmt,$group,'group',64); 00685 $db->Execute(); 00686 00687 @param $stmt Statement returned by Prepare() or PrepareSP(). 00688 @param $var PHP variable to bind to 00689 @param $name Name of stored procedure variable name to bind to. 00690 @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8. 00691 @param [$maxLen] Holds an maximum length of the variable. 00692 @param [$type] The data type of $var. Legal values depend on driver. 00693 00694 */ 00695 function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false) 00696 { 00697 return false; 00698 } 00699 00710 function StartTrans($errfn = 'ADODB_TransMonitor') 00711 { 00712 if ($this->transOff > 0) { 00713 $this->transOff += 1; 00714 return; 00715 } 00716 00717 $this->_oldRaiseFn = $this->raiseErrorFn; 00718 $this->raiseErrorFn = $errfn; 00719 $this->_transOK = true; 00720 00721 if ($this->debug && $this->transCnt > 0) ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans"); 00722 $this->BeginTrans(); 00723 $this->transOff = 1; 00724 } 00725 00726 00735 function CompleteTrans($autoComplete = true) 00736 { 00737 if ($this->transOff > 1) { 00738 $this->transOff -= 1; 00739 return true; 00740 } 00741 $this->raiseErrorFn = $this->_oldRaiseFn; 00742 00743 $this->transOff = 0; 00744 if ($this->_transOK && $autoComplete) { 00745 if (!$this->CommitTrans()) { 00746 $this->_transOK = false; 00747 if ($this->debug) ADOConnection::outp("Smart Commit failed"); 00748 } else 00749 if ($this->debug) ADOConnection::outp("Smart Commit occurred"); 00750 } else { 00751 $this->_transOK = false; 00752 $this->RollbackTrans(); 00753 if ($this->debug) ADOCOnnection::outp("Smart Rollback occurred"); 00754 } 00755 00756 return $this->_transOK; 00757 } 00758 00759 /* 00760 At the end of a StartTrans/CompleteTrans block, perform a rollback. 00761 */ 00762 function FailTrans() 00763 { 00764 if ($this->debug) 00765 if ($this->transOff == 0) { 00766 ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans"); 00767 } else { 00768 ADOConnection::outp("FailTrans was called"); 00769 adodb_backtrace(); 00770 } 00771 $this->_transOK = false; 00772 } 00773 00777 function HasFailedTrans() 00778 { 00779 if ($this->transOff > 0) return $this->_transOK == false; 00780 return false; 00781 } 00782 00790 function &Execute($sql,$inputarr=false) 00791 { 00792 if ($this->fnExecute) { 00793 $fn = $this->fnExecute; 00794 $ret =& $fn($this,$sql,$inputarr); 00795 if (isset($ret)) return $ret; 00796 } 00797 if ($inputarr) { 00798 if (!is_array($inputarr)) $inputarr = array($inputarr); 00799 00800 $element0 = reset($inputarr); 00801 # is_object check because oci8 descriptors can be passed in 00802 $array_2d = is_array($element0) && !is_object(reset($element0)); 00803 //remove extra memory copy of input -mikefedyk 00804 unset($element0); 00805 00806 if (!is_array($sql) && !$this->_bindInputArray) { 00807 $sqlarr = explode('?',$sql); 00808 00809 if (!$array_2d) $inputarr = array($inputarr); 00810 foreach($inputarr as $arr) { 00811 $sql = ''; $i = 0; 00812 //Use each() instead of foreach to reduce memory usage -mikefedyk 00813 while(list(, $v) = each($arr)) { 00814 $sql .= $sqlarr[$i]; 00815 // from Ron Baldwin <ron.baldwin#sourceprose.com> 00816 // Only quote string types 00817 $typ = gettype($v); 00818 if ($typ == 'string') 00819 //New memory copy of input created here -mikefedyk 00820 $sql .= $this->qstr($v); 00821 else if ($typ == 'double') 00822 $sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1 00823 else if ($typ == 'boolean') 00824 $sql .= $v ? $this->true : $this->false; 00825 else if ($v === null) 00826 $sql .= 'NULL'; 00827 else 00828 $sql .= $v; 00829 $i += 1; 00830 } 00831 if (isset($sqlarr[$i])) { 00832 $sql .= $sqlarr[$i]; 00833 if ($i+1 != sizeof($sqlarr)) ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql)); 00834 } else if ($i != sizeof($sqlarr)) 00835 ADOConnection::outp( "Input array does not match ?: ".htmlspecialchars($sql)); 00836 00837 $ret =& $this->_Execute($sql); 00838 if (!$ret) return $ret; 00839 } 00840 } else { 00841 if ($array_2d) { 00842 if (is_string($sql)) 00843 $stmt = $this->Prepare($sql); 00844 else 00845 $stmt = $sql; 00846 00847 foreach($inputarr as $arr) { 00848 $ret =& $this->_Execute($stmt,$arr); 00849 if (!$ret) return $ret; 00850 } 00851 } else { 00852 $ret =& $this->_Execute($sql,$inputarr); 00853 } 00854 } 00855 } else { 00856 $ret =& $this->_Execute($sql,false); 00857 } 00858 00859 return $ret; 00860 } 00861 00862 00863 function &_Execute($sql,$inputarr=false) 00864 { 00865 if ($this->debug) { 00866 global $ADODB_INCLUDED_LIB; 00867 if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); 00868 $this->_queryID = _adodb_debug_execute($this, $sql,$inputarr); 00869 } else { 00870 $this->_queryID = @$this->_query($sql,$inputarr); 00871 } 00872 00873 /************************ 00874 // OK, query executed 00875 *************************/ 00876 00877 if ($this->_queryID === false) { // error handling if query fails 00878 if ($this->debug == 99) adodb_backtrace(true,5); 00879 $fn = $this->raiseErrorFn; 00880 if ($fn) { 00881 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr,$this); 00882 } 00883 $false = false; 00884 return $false; 00885 } 00886 00887 if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead 00888 $rs =& new ADORecordSet_empty(); 00889 return $rs; 00890 } 00891 00892 // return real recordset from select statement 00893 $rsclass = $this->rsPrefix.$this->databaseType; 00894 $rs = new $rsclass($this->_queryID,$this->fetchMode); 00895 $rs->connection = &$this; // Pablo suggestion 00896 $rs->Init(); 00897 if (is_array($sql)) $rs->sql = $sql[0]; 00898 else $rs->sql = $sql; 00899 if ($rs->_numOfRows <= 0) { 00900 global $ADODB_COUNTRECS; 00901 if ($ADODB_COUNTRECS) { 00902 if (!$rs->EOF) { 00903 $rs = &$this->_rs2rs($rs,-1,-1,!is_array($sql)); 00904 $rs->_queryID = $this->_queryID; 00905 } else 00906 $rs->_numOfRows = 0; 00907 } 00908 } 00909 return $rs; 00910 } 00911 00912 function CreateSequence($seqname='adodbseq',$startID=1) 00913 { 00914 if (empty($this->_genSeqSQL)) return false; 00915 return $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID)); 00916 } 00917 00918 function DropSequence($seqname='adodbseq') 00919 { 00920 if (empty($this->_dropSeqSQL)) return false; 00921 return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); 00922 } 00923 00932 function GenID($seqname='adodbseq',$startID=1) 00933 { 00934 if (!$this->hasGenID) { 00935 return 0; // formerly returns false pre 1.60 00936 } 00937 00938 $getnext = sprintf($this->_genIDSQL,$seqname); 00939 00940 $holdtransOK = $this->_transOK; 00941 00942 $save_handler = $this->raiseErrorFn; 00943 $this->raiseErrorFn = ''; 00944 @($rs = $this->Execute($getnext)); 00945 $this->raiseErrorFn = $save_handler; 00946 00947 if (!$rs) { 00948 $this->_transOK = $holdtransOK; //if the status was ok before reset 00949 $createseq = $this->Execute(sprintf($this->_genSeqSQL,$seqname,$startID)); 00950 $rs = $this->Execute($getnext); 00951 } 00952 if ($rs && !$rs->EOF) $this->genID = reset($rs->fields); 00953 else $this->genID = 0; // false 00954 00955 if ($rs) $rs->Close(); 00956 00957 return $this->genID; 00958 } 00959 00965 function Insert_ID($table='',$column='') 00966 { 00967 if ($this->_logsql && $this->lastInsID) return $this->lastInsID; 00968 if ($this->hasInsertID) return $this->_insertid($table,$column); 00969 if ($this->debug) { 00970 ADOConnection::outp( '<p>Insert_ID error</p>'); 00971 adodb_backtrace(); 00972 } 00973 return false; 00974 } 00975 00976 00983 function PO_Insert_ID($table="", $id="") 00984 { 00985 if ($this->hasInsertID){ 00986 return $this->Insert_ID($table,$id); 00987 } else { 00988 return $this->GetOne("SELECT MAX($id) FROM $table"); 00989 } 00990 } 00991 00995 function Affected_Rows() 00996 { 00997 if ($this->hasAffectedRows) { 00998 if ($this->fnExecute === 'adodb_log_sql') { 00999 if ($this->_logsql && $this->_affected !== false) return $this->_affected; 01000 } 01001 $val = $this->_affectedrows(); 01002 return ($val < 0) ? false : $val; 01003 } 01004 01005 if ($this->debug) ADOConnection::outp( '<p>Affected_Rows error</p>',false); 01006 return false; 01007 } 01008 01009 01013 function ErrorMsg() 01014 { 01015 if ($this->_errorMsg) return '!! '.strtoupper($this->dataProvider.' '.$this->databaseType).': '.$this->_errorMsg; 01016 else return ''; 01017 } 01018 01019 01023 function ErrorNo() 01024 { 01025 return ($this->_errorMsg) ? -1 : 0; 01026 } 01027 01028 function MetaError($err=false) 01029 { 01030 include_once(ADODB_DIR."/adodb-error.inc.php"); 01031 if ($err === false) $err = $this->ErrorNo(); 01032 return adodb_error($this->dataProvider,$this->databaseType,$err); 01033 } 01034 01035 function MetaErrorMsg($errno) 01036 { 01037 include_once(ADODB_DIR."/adodb-error.inc.php"); 01038 return adodb_errormsg($errno); 01039 } 01040 01044 function MetaPrimaryKeys($table, $owner=false) 01045 { 01046 // owner not used in base class - see oci8 01047 $p = array(); 01048 $objs =& $this->MetaColumns($table); 01049 if ($objs) { 01050 foreach($objs as $v) { 01051 if (!empty($v->primary_key)) 01052 $p[] = $v->name; 01053 } 01054 } 01055 if (sizeof($p)) return $p; 01056 if (function_exists('ADODB_VIEW_PRIMARYKEYS')) 01057 return ADODB_VIEW_PRIMARYKEYS($this->databaseType, $this->database, $table, $owner); 01058 return false; 01059 } 01060 01064 function MetaForeignKeys($table, $owner=false, $upper=false) 01065 { 01066 return false; 01067 } 01074 function SelectDB($dbName) 01075 {return false;} 01076 01077 01097 function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) 01098 { 01099 if ($this->hasTop && $nrows > 0) { 01100 // suggested by Reinhard Balling. Access requires top after distinct 01101 // Informix requires first before distinct - F Riosa 01102 $ismssql = (strpos($this->databaseType,'mssql') !== false); 01103 if ($ismssql) $isaccess = false; 01104 else $isaccess = (strpos($this->databaseType,'access') !== false); 01105 01106 if ($offset <= 0) { 01107 01108 // access includes ties in result 01109 if ($isaccess) { 01110 $sql = preg_replace( 01111 '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql); 01112 01113 if ($secs2cache>0) { 01114 $ret =& $this->CacheExecute($secs2cache, $sql,$inputarr); 01115 } else { 01116 $ret =& $this->Execute($sql,$inputarr); 01117 } 01118 return $ret; // PHP5 fix 01119 } else if ($ismssql){ 01120 $sql = preg_replace( 01121 '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql); 01122 } else { 01123 $sql = preg_replace( 01124 '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql); 01125 } 01126 } else { 01127 $nn = $nrows + $offset; 01128 if ($isaccess || $ismssql) { 01129 $sql = preg_replace( 01130 '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql); 01131 } else { 01132 $sql = preg_replace( 01133 '/(^\s*select\s)/i','\\1 '.$this->hasTop.' '.$nn.' ',$sql); 01134 } 01135 } 01136 } 01137 01138 // if $offset>0, we want to skip rows, and $ADODB_COUNTRECS is set, we buffer rows 01139 // 0 to offset-1 which will be discarded anyway. So we disable $ADODB_COUNTRECS. 01140 global $ADODB_COUNTRECS; 01141 01142 $savec = $ADODB_COUNTRECS; 01143 $ADODB_COUNTRECS = false; 01144 01145 if ($offset>0){ 01146 if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 01147 else $rs = &$this->Execute($sql,$inputarr); 01148 } else { 01149 if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 01150 else $rs = &$this->Execute($sql,$inputarr); 01151 } 01152 $ADODB_COUNTRECS = $savec; 01153 if ($rs && !$rs->EOF) { 01154 $rs =& $this->_rs2rs($rs,$nrows,$offset); 01155 } 01156 //print_r($rs); 01157 return $rs; 01158 } 01159 01165 function &SerializableRS(&$rs) 01166 { 01167 $rs2 =& $this->_rs2rs($rs); 01168 $ignore = false; 01169 $rs2->connection =& $ignore; 01170 01171 return $rs2; 01172 } 01173 01184 function &_rs2rs(&$rs,$nrows=-1,$offset=-1,$close=true) 01185 { 01186 if (! $rs) { 01187 $false = false; 01188 return $false; 01189 } 01190 $dbtype = $rs->databaseType; 01191 if (!$dbtype) { 01192 $rs = &$rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1 -- why ? 01193 return $rs; 01194 } 01195 if (($dbtype == 'array' || $dbtype == 'csv') && $nrows == -1 && $offset == -1) { 01196 $rs->MoveFirst(); 01197 $rs = &$rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1-- why ? 01198 return $rs; 01199 } 01200 $flds = array(); 01201 for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) { 01202 $flds[] = $rs->FetchField($i); 01203 } 01204 01205 $arr =& $rs->GetArrayLimit($nrows,$offset); 01206 //print_r($arr); 01207 if ($close) $rs->Close(); 01208 01209 $arrayClass = $this->arrayClass; 01210 01211 $rs2 = new $arrayClass(); 01212 $rs2->connection = &$this; 01213 $rs2->sql = $rs->sql; 01214 $rs2->dataProvider = $this->dataProvider; 01215 $rs2->InitArrayFields($arr,$flds); 01216 $rs2->fetchMode = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode; 01217 return $rs2; 01218 } 01219 01220 /* 01221 * Return all rows. Compat with PEAR DB 01222 */ 01223 function &GetAll($sql, $inputarr=false) 01224 { 01225 $arr =& $this->GetArray($sql,$inputarr); 01226 return $arr; 01227 } 01228 01229 function &GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false) 01230 { 01231 $rs =& $this->Execute($sql, $inputarr); 01232 if (!$rs) { 01233 $false = false; 01234 return $false; 01235 } 01236 $arr =& $rs->GetAssoc($force_array,$first2cols); 01237 return $arr; 01238 } 01239 01240 function &CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false) 01241 { 01242 if (!is_numeric($secs2cache)) { 01243 $first2cols = $force_array; 01244 $force_array = $inputarr; 01245 } 01246 $rs =& $this->CacheExecute($secs2cache, $sql, $inputarr); 01247 if (!$rs) { 01248 $false = false; 01249 return $false; 01250 } 01251 $arr =& $rs->GetAssoc($force_array,$first2cols); 01252 return $arr; 01253 } 01254 01262 function GetOne($sql,$inputarr=false) 01263 { 01264 global $ADODB_COUNTRECS; 01265 $crecs = $ADODB_COUNTRECS; 01266 $ADODB_COUNTRECS = false; 01267 01268 $ret = false; 01269 $rs = &$this->Execute($sql,$inputarr); 01270 if ($rs) { 01271 if (!$rs->EOF) $ret = reset($rs->fields); 01272 $rs->Close(); 01273 } 01274 $ADODB_COUNTRECS = $crecs; 01275 return $ret; 01276 } 01277 01278 function CacheGetOne($secs2cache,$sql=false,$inputarr=false) 01279 { 01280 $ret = false; 01281 $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 01282 if ($rs) { 01283 if (!$rs->EOF) $ret = reset($rs->fields); 01284 $rs->Close(); 01285 } 01286 01287 return $ret; 01288 } 01289 01290 function GetCol($sql, $inputarr = false, $trim = false) 01291 { 01292 $rv = false; 01293 $rs = &$this->Execute($sql, $inputarr); 01294 if ($rs) { 01295 $rv = array(); 01296 if ($trim) { 01297 while (!$rs->EOF) { 01298 $rv[] = trim(reset($rs->fields)); 01299 $rs->MoveNext(); 01300 } 01301 } else { 01302 while (!$rs->EOF) { 01303 $rv[] = reset($rs->fields); 01304 $rs->MoveNext(); 01305 } 01306 } 01307 $rs->Close(); 01308 } 01309 return $rv; 01310 } 01311 01312 function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false) 01313 { 01314 $rv = false; 01315 $rs = &$this->CacheExecute($secs, $sql, $inputarr); 01316 if ($rs) { 01317 if ($trim) { 01318 while (!$rs->EOF) { 01319 $rv[] = trim(reset($rs->fields)); 01320 $rs->MoveNext(); 01321 } 01322 } else { 01323 while (!$rs->EOF) { 01324 $rv[] = reset($rs->fields); 01325 $rs->MoveNext(); 01326 } 01327 } 01328 $rs->Close(); 01329 } 01330 return $rv; 01331 } 01332 01333 /* 01334 Calculate the offset of a date for a particular database and generate 01335 appropriate SQL. Useful for calculating future/past dates and storing 01336 in a database. 01337 01338 If dayFraction=1.5 means 1.5 days from now, 1.0/24 for 1 hour. 01339 */ 01340 function OffsetDate($dayFraction,$date=false) 01341 { 01342 if (!$date) $date = $this->sysDate; 01343 return '('.$date.'+'.$dayFraction.')'; 01344 } 01345 01346 01352 function &GetArray($sql,$inputarr=false) 01353 { 01354 global $ADODB_COUNTRECS; 01355 01356 $savec = $ADODB_COUNTRECS; 01357 $ADODB_COUNTRECS = false; 01358 $rs =& $this->Execute($sql,$inputarr); 01359 $ADODB_COUNTRECS = $savec; 01360 if (!$rs) 01361 if (defined('ADODB_PEAR')) { 01362 $cls = ADODB_PEAR_Error(); 01363 return $cls; 01364 } else { 01365 $false = false; 01366 return $false; 01367 } 01368 $arr =& $rs->GetArray(); 01369 $rs->Close(); 01370 return $arr; 01371 } 01372 01373 function &CacheGetAll($secs2cache,$sql=false,$inputarr=false) 01374 { 01375 return $this->CacheGetArray($secs2cache,$sql,$inputarr); 01376 } 01377 01378 function &CacheGetArray($secs2cache,$sql=false,$inputarr=false) 01379 { 01380 global $ADODB_COUNTRECS; 01381 01382 $savec = $ADODB_COUNTRECS; 01383 $ADODB_COUNTRECS = false; 01384 $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr); 01385 $ADODB_COUNTRECS = $savec; 01386 01387 if (!$rs) 01388 if (defined('ADODB_PEAR')) { 01389 $cls = ADODB_PEAR_Error(); 01390 return $cls; 01391 } else { 01392 $false = false; 01393 return $false; 01394 } 01395 $arr =& $rs->GetArray(); 01396 $rs->Close(); 01397 return $arr; 01398 } 01399 01400 01401 01408 function &GetRow($sql,$inputarr=false) 01409 { 01410 global $ADODB_COUNTRECS; 01411 $crecs = $ADODB_COUNTRECS; 01412 $ADODB_COUNTRECS = false; 01413 01414 $rs =& $this->Execute($sql,$inputarr); 01415 01416 $ADODB_COUNTRECS = $crecs; 01417 if ($rs) { 01418 if (!$rs->EOF) $arr = $rs->fields; 01419 else $arr = array(); 01420 $rs->Close(); 01421 return $arr; 01422 } 01423 01424 $false = false; 01425 return $false; 01426 } 01427 01428 function &CacheGetRow($secs2cache,$sql=false,$inputarr=false) 01429 { 01430 $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr); 01431 if ($rs) { 01432 $arr = false; 01433 if (!$rs->EOF) $arr = $rs->fields; 01434 $rs->Close(); 01435 return $arr; 01436 } 01437 $false = false; 01438 return $false; 01439 } 01440 01461 function Replace($table, $fieldArray, $keyCol, $autoQuote=false, $has_autoinc=false) 01462 { 01463 global $ADODB_INCLUDED_LIB; 01464 if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); 01465 01466 return _adodb_replace($this, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc); 01467 } 01468 01469 01488 function &CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false) 01489 { 01490 if (!is_numeric($secs2cache)) { 01491 if ($sql === false) $sql = -1; 01492 if ($offset == -1) $offset = false; 01493 // sql, nrows, offset,inputarr 01494 $rs =& $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$this->cacheSecs); 01495 } else { 01496 if ($sql === false) ADOConnection::outp( "Warning: \$sql missing from CacheSelectLimit()"); 01497 $rs =& $this->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 01498 } 01499 return $rs; 01500 } 01501 01502 01512 function CacheFlush($sql=false,$inputarr=false) 01513 { 01514 global $ADODB_CACHE_DIR; 01515 01516 if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) { 01517 /*if (strncmp(PHP_OS,'WIN',3) === 0) 01518 $dir = str_replace('/', '\\', $ADODB_CACHE_DIR); 01519 else */ 01520 $dir = $ADODB_CACHE_DIR; 01521 01522 if ($this->debug) { 01523 ADOConnection::outp( "CacheFlush: $dir<br><pre>\n", $this->_dirFlush($dir),"</pre>"); 01524 } else { 01525 $this->_dirFlush($dir); 01526 } 01527 return; 01528 } 01529 01530 global $ADODB_INCLUDED_CSV; 01531 if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); 01532 01533 $f = $this->_gencachename($sql.serialize($inputarr),false); 01534 adodb_write_file($f,''); // is adodb_write_file needed? 01535 if (!@unlink($f)) { 01536 if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f"); 01537 } 01538 } 01539 01546 function _dirFlush($dir, $kill_top_level = false) { 01547 if(!$dh = @opendir($dir)) return; 01548 01549 while (($obj = readdir($dh))) { 01550 if($obj=='.' || $obj=='..') 01551 continue; 01552 01553 if (!@unlink($dir.'/'.$obj)) 01554 $this->_dirFlush($dir.'/'.$obj, true); 01555 } 01556 if ($kill_top_level === true) 01557 @rmdir($dir); 01558 return true; 01559 } 01560 01561 01562 function xCacheFlush($sql=false,$inputarr=false) 01563 { 01564 global $ADODB_CACHE_DIR; 01565 01566 if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) { 01567 if (strncmp(PHP_OS,'WIN',3) === 0) { 01568 $cmd = 'del /s '.str_replace('/','\\',$ADODB_CACHE_DIR).'\adodb_*.cache'; 01569 } else { 01570 //$cmd = 'find "'.$ADODB_CACHE_DIR.'" -type f -maxdepth 1 -print0 | xargs -0 rm -f'; 01571 $cmd = 'rm -rf '.$ADODB_CACHE_DIR.'/[0-9a-f][0-9a-f]/'; 01572 // old version 'rm -f `find '.$ADODB_CACHE_DIR.' -name adodb_*.cache`'; 01573 } 01574 if ($this->debug) { 01575 ADOConnection::outp( "CacheFlush: $cmd<br><pre>\n", system($cmd),"</pre>"); 01576 } else { 01577 exec($cmd); 01578 } 01579 return; 01580 } 01581 01582 global $ADODB_INCLUDED_CSV; 01583 if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); 01584 01585 $f = $this->_gencachename($sql.serialize($inputarr),false); 01586 adodb_write_file($f,''); // is adodb_write_file needed? 01587 if (!@unlink($f)) { 01588 if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f"); 01589 } 01590 } 01591 01606 function _gencachename($sql,$createdir) 01607 { 01608 global $ADODB_CACHE_DIR; 01609 static $notSafeMode; 01610 01611 if ($this->fetchMode === false) { 01612 global $ADODB_FETCH_MODE; 01613 $mode = $ADODB_FETCH_MODE; 01614 } else { 01615 $mode = $this->fetchMode; 01616 } 01617 $m = md5($sql.$this->databaseType.$this->database.$this->user.$mode); 01618 01619 if (!isset($notSafeMode)) $notSafeMode = !ini_get('safe_mode'); 01620 $dir = ($notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($m,0,2) : $ADODB_CACHE_DIR; 01621 01622 if ($createdir && $notSafeMode && !file_exists($dir)) { 01623 $oldu = umask(0); 01624 if (!mkdir($dir,0771)) 01625 if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql"); 01626 umask($oldu); 01627 } 01628 return $dir.'/adodb_'.$m.'.cache'; 01629 } 01630 01631 01641 function &CacheExecute($secs2cache,$sql=false,$inputarr=false) 01642 { 01643 01644 01645 if (!is_numeric($secs2cache)) { 01646 $inputarr = $sql; 01647 $sql = $secs2cache; 01648 $secs2cache = $this->cacheSecs; 01649 } 01650 01651 if (is_array($sql)) { 01652 $sqlparam = $sql; 01653 $sql = $sql[0]; 01654 } else 01655 $sqlparam = $sql; 01656 01657 global $ADODB_INCLUDED_CSV; 01658 if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); 01659 01660 $md5file = $this->_gencachename($sql.serialize($inputarr),true); 01661 $err = ''; 01662 01663 if ($secs2cache > 0){ 01664 $rs = &csv2rs($md5file,$err,$secs2cache,$this->arrayClass); 01665 $this->numCacheHits += 1; 01666 } else { 01667 $err='Timeout 1'; 01668 $rs = false; 01669 $this->numCacheMisses += 1; 01670 } 01671 if (!$rs) { 01672 // no cached rs found 01673 if ($this->debug) { 01674 if (get_magic_quotes_runtime()) { 01675 ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :("); 01676 } 01677 if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (see sql below)"); 01678 } 01679 01680 $rs = &$this->Execute($sqlparam,$inputarr); 01681 01682 if ($rs) { 01683 $eof = $rs->EOF; 01684 $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately 01685 $txt = _rs2serialize($rs,false,$sql); // serialize 01686 01687 if (!adodb_write_file($md5file,$txt,$this->debug)) { 01688 if ($fn = $this->raiseErrorFn) { 01689 $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this); 01690 } 01691 if ($this->debug) ADOConnection::outp( " Cache write error"); 01692 } 01693 if ($rs->EOF && !$eof) { 01694 $rs->MoveFirst(); 01695 //$rs = &csv2rs($md5file,$err); 01696 $rs->connection = &$this; // Pablo suggestion 01697 } 01698 01699 } else 01700 @unlink($md5file); 01701 } else { 01702 $this->_errorMsg = ''; 01703 $this->_errorCode = 0; 01704 01705 if ($this->fnCacheExecute) { 01706 $fn = $this->fnCacheExecute; 01707 $fn($this, $secs2cache, $sql, $inputarr); 01708 } 01709 // ok, set cached object found 01710 $rs->connection = &$this; // Pablo suggestion 01711 if ($this->debug){ 01712 01713 $inBrowser = isset($_SERVER['HTTP_USER_AGENT']); 01714 $ttl = $rs->timeCreated + $secs2cache - time(); 01715 $s = is_array($sql) ? $sql[0] : $sql; 01716 if ($inBrowser) $s = '<i>'.htmlspecialchars($s).'</i>'; 01717 01718 ADOConnection::outp( " $md5file reloaded, ttl=$ttl [ $s ]"); 01719 } 01720 } 01721 return $rs; 01722 } 01723 01724 01725 /* 01726 Similar to PEAR DB's autoExecute(), except that 01727 $mode can be 'INSERT' or 'UPDATE' or DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE 01728 If $mode == 'UPDATE', then $where is compulsory as a safety measure. 01729 01730 $forceUpdate means that even if the data has not changed, perform update. 01731 */ 01732 function& AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false) 01733 { 01734 $sql = 'SELECT * FROM '.$table; 01735 if ($where!==FALSE) $sql .= ' WHERE '.$where; 01736 else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) { 01737 ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause'); 01738 return false; 01739 } 01740 01741 $rs =& $this->SelectLimit($sql,1); 01742 if (!$rs) return false; // table does not exist 01743 $rs->tableName = $table; 01744 01745 switch((string) $mode) { 01746 case 'UPDATE': 01747 case '2': 01748 $sql = $this->GetUpdateSQL($rs, $fields_values, $forceUpdate, $magicq); 01749 break; 01750 case 'INSERT': 01751 case '1': 01752 $sql = $this->GetInsertSQL($rs, $fields_values, $magicq); 01753 break; 01754 default: 01755 ADOConnection::outp("AutoExecute: Unknown mode=$mode"); 01756 return false; 01757 } 01758 $ret = false; 01759 if ($sql) $ret = $this->Execute($sql); 01760 if ($ret) $ret = true; 01761 return $ret; 01762 } 01763 01764 01776 function GetUpdateSQL(&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=null) 01777 { 01778 global $ADODB_INCLUDED_LIB; 01779 01780 //********************************************************// 01781 //This is here to maintain compatibility 01782 //with older adodb versions. Sets force type to force nulls if $forcenulls is set. 01783 if (!isset($force)) { 01784 global $ADODB_FORCE_TYPE; 01785 $force = $ADODB_FORCE_TYPE; 01786 } 01787 //********************************************************// 01788 01789 if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); 01790 return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq,$force); 01791 } 01792 01801 function GetInsertSQL(&$rs, $arrFields,$magicq=false,$force=null) 01802 { 01803 global $ADODB_INCLUDED_LIB; 01804 if (!isset($force)) { 01805 global $ADODB_FORCE_TYPE; 01806 $force = $ADODB_FORCE_TYPE; 01807 01808 } 01809 if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); 01810 return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force); 01811 } 01812 01813 01833 function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') 01834 { 01835 return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false; 01836 } 01837 01847 function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') 01848 { 01849 $fd = fopen($path,'rb'); 01850 if ($fd === false) return false; 01851 $val = fread($fd,filesize($path)); 01852 fclose($fd); 01853 return $this->UpdateBlob($table,$column,$val,$where,$blobtype); 01854 } 01855 01856 function BlobDecode($blob) 01857 { 01858 return $blob; 01859 } 01860 01861 function BlobEncode($blob) 01862 { 01863 return $blob; 01864 } 01865 01866 function SetCharSet($charset) 01867 { 01868 return false; 01869 } 01870 01871 function IfNull( $field, $ifNull ) 01872 { 01873 return " CASE WHEN $field is null THEN $ifNull ELSE $field END "; 01874 } 01875 01876 function LogSQL($enable=true) 01877 { 01878 include_once(ADODB_DIR.'/adodb-perf.inc.php'); 01879 01880 if ($enable) $this->fnExecute = 'adodb_log_sql'; 01881 else $this->fnExecute = false; 01882 01883 $old = $this->_logsql; 01884 $this->_logsql = $enable; 01885 if ($enable && !$old) $this->_affected = false; 01886 return $old; 01887 } 01888 01889 function GetCharSet() 01890 { 01891 return false; 01892 } 01893 01901 function UpdateClob($table,$column,$val,$where) 01902 { 01903 return $this->UpdateBlob($table,$column,$val,$where,'CLOB'); 01904 } 01905 01906 // not the fastest implementation - quick and dirty - jlim 01907 // for best performance, use the actual $rs->MetaType(). 01908 function MetaType($t,$len=-1,$fieldobj=false) 01909 { 01910 01911 if (empty($this->_metars)) { 01912 $rsclass = $this->rsPrefix.$this->databaseType; 01913 $this->_metars =& new $rsclass(false,$this->fetchMode); 01914 $this->_metars->connection =& $this; 01915 } 01916 return $this->_metars->MetaType($t,$len,$fieldobj); 01917 } 01918 01919 01924 function SetDateLocale($locale = 'En') 01925 { 01926 $this->locale = $locale; 01927 switch (strtoupper($locale)) 01928 { 01929 case 'EN': 01930 $this->fmtDate="'Y-m-d'"; 01931 $this->fmtTimeStamp = "'Y-m-d H:i:s'"; 01932 break; 01933 01934 case 'US': 01935 $this->fmtDate = "'m-d-Y'"; 01936 $this->fmtTimeStamp = "'m-d-Y H:i:s'"; 01937 break; 01938 01939 case 'NL': 01940 case 'FR': 01941 case 'RO': 01942 case 'IT': 01943 $this->fmtDate="'d-m-Y'"; 01944 $this->fmtTimeStamp = "'d-m-Y H:i:s'"; 01945 break; 01946 01947 case 'GE': 01948 $this->fmtDate="'d.m.Y'"; 01949 $this->fmtTimeStamp = "'d.m.Y H:i:s'"; 01950 break; 01951 01952 default: 01953 $this->fmtDate="'Y-m-d'"; 01954 $this->fmtTimeStamp = "'Y-m-d H:i:s'"; 01955 break; 01956 } 01957 } 01958 01959 function &GetActiveRecordsClass($class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false) 01960 { 01961 global $_ADODB_ACTIVE_DBS; 01962 01963 $save = $this->SetFetchMode(ADODB_FETCH_NUM); 01964 if (empty($whereOrderBy)) $whereOrderBy = '1=1'; 01965 $rows = $this->GetAll("select * from ".$table.' WHERE '.$whereOrderBy,$bindarr); 01966 $this->SetFetchMode($save); 01967 01968 $false = false; 01969 01970 if ($rows === false) { 01971 return $false; 01972 } 01973 01974 01975 if (!isset($_ADODB_ACTIVE_DBS)) { 01976 include_once(ADODB_DIR.'/adodb-active-record.inc.php'); 01977 } 01978 if (!class_exists($class)) { 01979 ADOConnection::outp("Unknown class $class in GetActiveRcordsClass()"); 01980 return $false; 01981 } 01982 $arr = array(); 01983 foreach($rows as $row) { 01984 01985 $obj =& new $class($table,$primkeyArr,$this); 01986 if ($obj->ErrorMsg()){ 01987 $this->_errorMsg = $obj->ErrorMsg(); 01988 return $false; 01989 } 01990 $obj->Set($row); 01991 $arr[] =& $obj; 01992 } 01993 return $arr; 01994 } 01995 01996 function &GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false) 01997 { 01998 $arr =& $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr); 01999 return $arr; 02000 } 02001 02005 function Close() 02006 { 02007 $rez = $this->_close(); 02008 $this->_connectionID = false; 02009 return $rez; 02010 } 02011 02017 function BeginTrans() {return false;} 02018 02019 02027 function CommitTrans($ok=true) 02028 { return true;} 02029 02030 02036 function RollbackTrans() 02037 { return false;} 02038 02039 02046 function MetaDatabases() 02047 { 02048 global $ADODB_FETCH_MODE; 02049 02050 if ($this->metaDatabasesSQL) { 02051 $save = $ADODB_FETCH_MODE; 02052 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 02053 02054 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); 02055 02056 $arr = $this->GetCol($this->metaDatabasesSQL); 02057 if (isset($savem)) $this->SetFetchMode($savem); 02058 $ADODB_FETCH_MODE = $save; 02059 02060 return $arr; 02061 } 02062 02063 return false; 02064 } 02065 02066 02077 function &MetaTables($ttype=false,$showSchema=false,$mask=false) 02078 { 02079 global $ADODB_FETCH_MODE; 02080 02081 02082 $false = false; 02083 if ($mask) { 02084 return $false; 02085 } 02086 if ($this->metaTablesSQL) { 02087 $save = $ADODB_FETCH_MODE; 02088 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 02089 02090 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); 02091 02092 $rs = $this->Execute($this->metaTablesSQL); 02093 if (isset($savem)) $this->SetFetchMode($savem); 02094 $ADODB_FETCH_MODE = $save; 02095 02096 if ($rs === false) return $false; 02097 $arr =& $rs->GetArray(); 02098 $arr2 = array(); 02099 02100 if ($hast = ($ttype && isset($arr[0][1]))) { 02101 $showt = strncmp($ttype,'T',1); 02102 } 02103 02104 for ($i=0; $i < sizeof($arr); $i++) { 02105 if ($hast) { 02106 if ($showt == 0) { 02107 if (strncmp($arr[$i][1],'T',1) == 0) $arr2[] = trim($arr[$i][0]); 02108 } else { 02109 if (strncmp($arr[$i][1],'V',1) == 0) $arr2[] = trim($arr[$i][0]); 02110 } 02111 } else 02112 $arr2[] = trim($arr[$i][0]); 02113 } 02114 $rs->Close(); 02115 return $arr2; 02116 } 02117 return $false; 02118 } 02119 02120 02121 function _findschema(&$table,&$schema) 02122 { 02123 if (!$schema && ($at = strpos($table,'.')) !== false) { 02124 $schema = substr($table,0,$at); 02125 $table = substr($table,$at+1); 02126 } 02127 } 02128 02139 function &MetaColumns($table,$normalize=true) 02140 { 02141 global $ADODB_FETCH_MODE; 02142 02143 $false = false; 02144 02145 if (!empty($this->metaColumnsSQL)) { 02146 02147 $schema = false; 02148 $this->_findschema($table,$schema); 02149 02150 $save = $ADODB_FETCH_MODE; 02151 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 02152 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); 02153 $rs = $this->Execute(sprintf($this->metaColumnsSQL,($normalize)?strtoupper($table):$table)); 02154 if (isset($savem)) $this->SetFetchMode($savem); 02155 $ADODB_FETCH_MODE = $save; 02156 if ($rs === false || $rs->EOF) return $false; 02157 02158 $retarr = array(); 02159 while (!$rs->EOF) { //print_r($rs->fields); 02160 $fld = new ADOFieldObject(); 02161 $fld->name = $rs->fields[0]; 02162 $fld->type = $rs->fields[1]; 02163 if (isset($rs->fields[3]) && $rs->fields[3]) { 02164 if ($rs->fields[3]>0) $fld->max_length = $rs->fields[3]; 02165 $fld->scale = $rs->fields[4]; 02166 if ($fld->scale>0) $fld->max_length += 1; 02167 } else 02168 $fld->max_length = $rs->fields[2]; 02169 02170 if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; 02171 else $retarr[strtoupper($fld->name)] = $fld; 02172 $rs->MoveNext(); 02173 } 02174 $rs->Close(); 02175 return $retarr; 02176 } 02177 return $false; 02178 } 02179 02198 function &MetaIndexes($table, $primary = false, $owner = false) 02199 { 02200 $false = false; 02201 return $false; 02202 } 02203 02210 function &MetaColumnNames($table, $numIndexes=false) 02211 { 02212 $objarr =& $this->MetaColumns($table); 02213 if (!is_array($objarr)) { 02214 $false = false; 02215 return $false; 02216 } 02217 $arr = array(); 02218 if ($numIndexes) { 02219 $i = 0; 02220 foreach($objarr as $v) $arr[$i++] = $v->name; 02221 } else 02222 foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name; 02223 02224 return $arr; 02225 } 02226 02237 function Concat() 02238 { 02239 $arr = func_get_args(); 02240 return implode($this->concat_operator, $arr); 02241 } 02242 02243 02251 function DBDate($d) 02252 { 02253 if (empty($d) && $d !== 0) return 'null'; 02254 02255 if (is_string($d) && !is_numeric($d)) { 02256 if ($d === 'null' || strncmp($d,"'",1) === 0) return $d; 02257 if ($this->isoDates) return "'$d'"; 02258 $d = ADOConnection::UnixDate($d); 02259 } 02260 02261 return adodb_date($this->fmtDate,$d); 02262 } 02263 02264 02272 function DBTimeStamp($ts) 02273 { 02274 if (empty($ts) && $ts !== 0) return 'null'; 02275 02276 # strlen(14) allows YYYYMMDDHHMMSS format 02277 if (!is_string($ts) || (is_numeric($ts) && strlen($ts)<14)) 02278 return adodb_date($this->fmtTimeStamp,$ts); 02279 02280 if ($ts === 'null') return $ts; 02281 if ($this->isoDates && strlen($ts) !== 14) return "'$ts'"; 02282 02283 $ts = ADOConnection::UnixTimeStamp($ts); 02284 return adodb_date($this->fmtTimeStamp,$ts); 02285 } 02286 02293 function UnixDate($v) 02294 { 02295 if (is_object($v)) { 02296 // odbtp support 02297 //( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 ) 02298 return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year); 02299 } 02300 02301 if (is_numeric($v) && strlen($v) !== 8) return $v; 02302 if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|", 02303 ($v), $rr)) return false; 02304 02305 if ($rr[1] <= TIMESTAMP_FIRST_YEAR) return 0; 02306 // h-m-s-MM-DD-YY 02307 return @adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); 02308 } 02309 02310 02317 function UnixTimeStamp($v) 02318 { 02319 if (is_object($v)) { 02320 // odbtp support 02321 //( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 ) 02322 return adodb_mktime($v->hour,$v->minute,$v->second,$v->month,$v->day, $v->year); 02323 } 02324 02325 if (!preg_match( 02326 "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ ,-]*(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", 02327 ($v), $rr)) return false; 02328 02329 if ($rr[1] <= TIMESTAMP_FIRST_YEAR && $rr[2]<= 1) return 0; 02330 02331 // h-m-s-MM-DD-YY 02332 if (!isset($rr[5])) return adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); 02333 return @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]); 02334 } 02335 02347 function UserDate($v,$fmt='Y-m-d',$gmt=false) 02348 { 02349 $tt = $this->UnixDate($v); 02350 02351 // $tt == -1 if pre TIMESTAMP_FIRST_YEAR 02352 if (($tt === false || $tt == -1) && $v != false) return $v; 02353 else if ($tt == 0) return $this->emptyDate; 02354 else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR 02355 } 02356 02357 return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt); 02358 02359 } 02360 02368 function UserTimeStamp($v,$fmt='Y-m-d H:i:s',$gmt=false) 02369 { 02370 if (!isset($v)) return $this->emptyTimeStamp; 02371 # strlen(14) allows YYYYMMDDHHMMSS format 02372 if (is_numeric($v) && strlen($v)<14) return ($gmt) ? adodb_gmdate($fmt,$v) : adodb_date($fmt,$v); 02373 $tt = $this->UnixTimeStamp($v); 02374 // $tt == -1 if pre TIMESTAMP_FIRST_YEAR 02375 if (($tt === false || $tt == -1) && $v != false) return $v; 02376 if ($tt == 0) return $this->emptyTimeStamp; 02377 return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt); 02378 } 02379 02380 function escape($s,$magic_quotes=false) 02381 { 02382 return $this->addq($s,$magic_quotes); 02383 } 02384 02388 function addq($s,$magic_quotes=false) 02389 { 02390 if (!$magic_quotes) { 02391 02392 if ($this->replaceQuote[0] == '\\'){ 02393 // only since php 4.0.5 02394 $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); 02395 //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s)); 02396 } 02397 return str_replace("'",$this->replaceQuote,$s); 02398 } 02399 02400 // undo magic quotes for " 02401 $s = str_replace('\\"','"',$s); 02402 02403 if ($this->replaceQuote == "\\'") // ' already quoted, no need to change anything 02404 return $s; 02405 else {// change \' to '' for sybase/mssql 02406 $s = str_replace('\\\\','\\',$s); 02407 return str_replace("\\'",$this->replaceQuote,$s); 02408 } 02409 } 02410 02422 function qstr($s,$magic_quotes=false) 02423 { 02424 if (!$magic_quotes) { 02425 02426 if ($this->replaceQuote[0] == '\\'){ 02427 // only since php 4.0.5 02428 $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); 02429 //$s = str_replace("\0","\\\0", str_replace('\\','\\\\',$s)); 02430 } 02431 return "'".str_replace("'",$this->replaceQuote,$s)."'"; 02432 } 02433 02434 // undo magic quotes for " 02435 $s = str_replace('\\"','"',$s); 02436 02437 if ($this->replaceQuote == "\\'") // ' already quoted, no need to change anything 02438 return "'$s'"; 02439 else {// change \' to '' for sybase/mssql 02440 $s = str_replace('\\\\','\\',$s); 02441 return "'".str_replace("\\'",$this->replaceQuote,$s)."'"; 02442 } 02443 } 02444 02445 02463 function &PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0) 02464 { 02465 global $ADODB_INCLUDED_LIB; 02466 if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); 02467 if ($this->pageExecuteCountRows) $rs =& _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache); 02468 else $rs =& _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache); 02469 return $rs; 02470 } 02471 02472 02485 function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false) 02486 { 02487 /*switch($this->dataProvider) { 02488 case 'postgres': 02489 case 'mysql': 02490 break; 02491 default: $secs2cache = 0; break; 02492 }*/ 02493 $rs =& $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache); 02494 return $rs; 02495 } 02496 02497 } // end class ADOConnection 02498 02499 02500 02501 //============================================================================================== 02502 // CLASS ADOFetchObj 02503 //============================================================================================== 02504 02508 class ADOFetchObj { 02509 }; 02510 02511 //============================================================================================== 02512 // CLASS ADORecordSet_empty 02513 //============================================================================================== 02514 02518 class ADORecordSet_empty 02519 { 02520 var $dataProvider = 'empty'; 02521 var $databaseType = false; 02522 var $EOF = true; 02523 var $_numOfRows = 0; 02524 var $fields = false; 02525 var $connection = false; 02526 function RowCount() {return 0;} 02527 function RecordCount() {return 0;} 02528 function PO_RecordCount(){return 0;} 02529 function Close(){return true;} 02530 function FetchRow() {return false;} 02531 function FieldCount(){ return 0;} 02532 function Init() {} 02533 } 02534 02535 //============================================================================================== 02536 // DATE AND TIME FUNCTIONS 02537 //============================================================================================== 02538 include_once(ADODB_DIR.'/adodb-time.inc.php'); 02539 02540 //============================================================================================== 02541 // CLASS ADORecordSet 02542 //============================================================================================== 02543 02544 if (PHP_VERSION < 5) include_once(ADODB_DIR.'/adodb-php4.inc.php'); 02545 else include_once(ADODB_DIR.'/adodb-iterator.inc.php'); 02552 class ADORecordSet extends ADODB_BASE_RS { 02553 /* 02554 * public variables 02555 */ 02556 var $dataProvider = "native"; 02557 var $fields = false; 02558 var $blobSize = 100; 02559 02560 var $canSeek = false; 02561 var $sql; 02562 var $EOF = false; 02563 02564 var $emptyTimeStamp = ' '; 02565 var $emptyDate = ' '; 02566 var $debug = false; 02567 var $timeCreated=0; 02568 02569 var $bind = false; 02570 var $fetchMode; 02571 var $connection = false; 02572 /* 02573 * private variables 02574 */ 02575 var $_numOfRows = -1; 02576 var $_numOfFields = -1; 02577 var $_queryID = -1; 02578 var $_currentRow = -1; 02579 var $_closed = false; 02580 var $_inited = false; 02581 var $_obj; 02582 var $_names; 02584 var $_currentPage = -1; 02585 var $_atFirstPage = false; 02586 var $_atLastPage = false; 02587 var $_lastPageNo = -1; 02588 var $_maxRecordCount = 0; 02589 var $datetime = false; 02590 02597 function ADORecordSet($queryID) 02598 { 02599 $this->_queryID = $queryID; 02600 } 02601 02602 02603 02604 function Init() 02605 { 02606 if ($this->_inited) return; 02607 $this->_inited = true; 02608 if ($this->_queryID) @$this->_initrs(); 02609 else { 02610 $this->_numOfRows = 0; 02611 $this->_numOfFields = 0; 02612 } 02613 if ($this->_numOfRows != 0 && $this->_numOfFields && $this->_currentRow == -1) { 02614 02615 $this->_currentRow = 0; 02616 if ($this->EOF = ($this->_fetch() === false)) { 02617 $this->_numOfRows = 0; // _numOfRows could be -1 02618 } 02619 } else { 02620 $this->EOF = true; 02621 } 02622 } 02623 02624 02645 function GetMenu($name,$defstr='',$blank1stItem=true,$multiple=false, 02646 $size=0, $selectAttr='',$compareFields0=true) 02647 { 02648 global $ADODB_INCLUDED_LIB; 02649 if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); 02650 return _adodb_getmenu($this, $name,$defstr,$blank1stItem,$multiple, 02651 $size, $selectAttr,$compareFields0); 02652 } 02653 02654 02655 02663 function GetMenu2($name,$defstr='',$blank1stItem=true,$multiple=false,$size=0, $selectAttr='') 02664 { 02665 return $this->GetMenu($name,$defstr,$blank1stItem,$multiple, 02666 $size, $selectAttr,false); 02667 } 02668 02669 /* 02670 Grouped Menu 02671 */ 02672 function GetMenu3($name,$defstr='',$blank1stItem=true,$multiple=false, 02673 $size=0, $selectAttr='') 02674 { 02675 global $ADODB_INCLUDED_LIB; 02676 if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); 02677 return _adodb_getmenu_gp($this, $name,$defstr,$blank1stItem,$multiple, 02678 $size, $selectAttr,false); 02679 } 02680 02688 function &GetArray($nRows = -1) 02689 { 02690 global $ADODB_EXTENSION; if ($ADODB_EXTENSION) { 02691 $results = adodb_getall($this,$nRows); 02692 return $results; 02693 } 02694 $results = array(); 02695 $cnt = 0; 02696 while (!$this->EOF && $nRows != $cnt) { 02697 $results[] = $this->fields; 02698 $this->MoveNext(); 02699 $cnt++; 02700 } 02701 return $results; 02702 } 02703 02704 function &GetAll($nRows = -1) 02705 { 02706 $arr =& $this->GetArray($nRows); 02707 return $arr; 02708 } 02709 02710 /* 02711 * Some databases allow multiple recordsets to be returned. This function 02712 * will return true if there is a next recordset, or false if no more. 02713 */ 02714 function NextRecordSet() 02715 { 02716 return false; 02717 } 02718 02728 function &GetArrayLimit($nrows,$offset=-1) 02729 { 02730 if ($offset <= 0) { 02731 $arr =& $this->GetArray($nrows); 02732 return $arr; 02733 } 02734 02735 $this->Move($offset); 02736 02737 $results = array(); 02738 $cnt = 0; 02739 while (!$this->EOF && $nrows != $cnt) { 02740 $results[$cnt++] = $this->fields; 02741 $this->MoveNext(); 02742 } 02743 02744 return $results; 02745 } 02746 02747 02755 function &GetRows($nRows = -1) 02756 { 02757 $arr =& $this->GetArray($nRows); 02758 return $arr; 02759 } 02760 02777 function &GetAssoc($force_array = false, $first2cols = false) 02778 { 02779 global $ADODB_EXTENSION; 02780 02781 $cols = $this->_numOfFields; 02782 if ($cols < 2) { 02783 $false = false; 02784 return $false; 02785 } 02786 $numIndex = isset($this->fields[0]); 02787 $results = array(); 02788 02789 if (!$first2cols && ($cols > 2 || $force_array)) { 02790 if ($ADODB_EXTENSION) { 02791 if ($numIndex) { 02792 while (!$this->EOF) { 02793 $results[trim($this->fields[0])] = array_slice($this->fields, 1); 02794 adodb_movenext($this); 02795 } 02796 } else { 02797 while (!$this->EOF) { 02798 $results[trim(reset($this->fields))] = array_slice($this->fields, 1); 02799 adodb_movenext($this); 02800 } 02801 } 02802 } else { 02803 if ($numIndex) { 02804 while (!$this->EOF) { 02805 $results[trim($this->fields[0])] = array_slice($this->fields, 1); 02806 $this->MoveNext(); 02807 } 02808 } else { 02809 while (!$this->EOF) { 02810 $results[trim(reset($this->fields))] = array_slice($this->fields, 1); 02811 $this->MoveNext(); 02812 } 02813 } 02814 } 02815 } else { 02816 if ($ADODB_EXTENSION) { 02817 // return scalar values 02818 if ($numIndex) { 02819 while (!$this->EOF) { 02820 // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string 02821 $results[trim(($this->fields[0]))] = $this->fields[1]; 02822 adodb_movenext($this); 02823 } 02824 } else { 02825 while (!$this->EOF) { 02826 // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string 02827 $v1 = trim(reset($this->fields)); 02828 $v2 = ''.next($this->fields); 02829 $results[$v1] = $v2; 02830 adodb_movenext($this); 02831 } 02832 } 02833 } else { 02834 if ($numIndex) { 02835 while (!$this->EOF) { 02836 // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string 02837 $results[trim(($this->fields[0]))] = $this->fields[1]; 02838 $this->MoveNext(); 02839 } 02840 } else { 02841 while (!$this->EOF) { 02842 // some bug in mssql PHP 4.02 -- doesn't handle references properly so we FORCE creating a new string 02843 $v1 = trim(reset($this->fields)); 02844 $v2 = ''.next($this->fields); 02845 $results[$v1] = $v2; 02846 $this->MoveNext(); 02847 } 02848 } 02849 } 02850 } 02851 02852 $ref =& $results; # workaround accelerator incompat with PHP 4.4 :( 02853 return $ref; 02854 } 02855 02856 02864 function UserTimeStamp($v,$fmt='Y-m-d H:i:s') 02865 { 02866 if (is_numeric($v) && strlen($v)<14) return adodb_date($fmt,$v); 02867 $tt = $this->UnixTimeStamp($v); 02868 // $tt == -1 if pre TIMESTAMP_FIRST_YEAR 02869 if (($tt === false || $tt == -1) && $v != false) return $v; 02870 if ($tt === 0) return $this->emptyTimeStamp; 02871 return adodb_date($fmt,$tt); 02872 } 02873 02874 02881 function UserDate($v,$fmt='Y-m-d') 02882 { 02883 $tt = $this->UnixDate($v); 02884 // $tt == -1 if pre TIMESTAMP_FIRST_YEAR 02885 if (($tt === false || $tt == -1) && $v != false) return $v; 02886 else if ($tt == 0) return $this->emptyDate; 02887 else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR 02888 } 02889 return adodb_date($fmt,$tt); 02890 } 02891 02892 02898 function UnixDate($v) 02899 { 02900 return ADOConnection::UnixDate($v); 02901 } 02902 02903 02909 function UnixTimeStamp($v) 02910 { 02911 return ADOConnection::UnixTimeStamp($v); 02912 } 02913 02914 02918 function Free() 02919 { 02920 return $this->Close(); 02921 } 02922 02923 02927 function NumRows() 02928 { 02929 return $this->_numOfRows; 02930 } 02931 02932 02936 function NumCols() 02937 { 02938 return $this->_numOfFields; 02939 } 02940 02947 function &FetchRow() 02948 { 02949 if ($this->EOF) { 02950 $false = false; 02951 return $false; 02952 } 02953 $arr = $this->fields; 02954 $this->_currentRow++; 02955 if (!$this->_fetch()) $this->EOF = true; 02956 return $arr; 02957 } 02958 02959 02966 function FetchInto(&$arr) 02967 { 02968 if ($this->EOF) return (defined('PEAR_ERROR_RETURN')) ? new PEAR_Error('EOF',-1): false; 02969 $arr = $this->fields; 02970 $this->MoveNext(); 02971 return 1; // DB_OK 02972 } 02973 02974 02980 function MoveFirst() 02981 { 02982 if ($this->_currentRow == 0) return true; 02983 return $this->Move(0); 02984 } 02985 02986 02992 function MoveLast() 02993 { 02994 if ($this->_numOfRows >= 0) return $this->Move($this->_numOfRows-1); 02995 if ($this->EOF) return false; 02996 while (!$this->EOF) { 02997 $f = $this->fields; 02998 $this->MoveNext(); 02999 } 03000 $this->fields = $f; 03001 $this->EOF = false; 03002 return true; 03003 } 03004 03005 03011 function MoveNext() 03012 { 03013 if (!$this->EOF) { 03014 $this->_currentRow++; 03015 if ($this->_fetch()) return true; 03016 } 03017 $this->EOF = true; 03018 /* -- tested error handling when scrolling cursor -- seems useless. 03019 $conn = $this->connection; 03020 if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) { 03021 $fn = $conn->raiseErrorFn; 03022 $fn($conn->databaseType,'MOVENEXT',$errno,$conn->ErrorMsg().' ('.$this->sql.')',$conn->host,$conn->database); 03023 } 03024 */ 03025 return false; 03026 } 03027 03028 03037 function Move($rowNumber = 0) 03038 { 03039 $this->EOF = false; 03040 if ($rowNumber == $this->_currentRow) return true; 03041 if ($rowNumber >= $this->_numOfRows) 03042 if ($this->_numOfRows != -1) $rowNumber = $this->_numOfRows-2; 03043 03044 if ($this->canSeek) { 03045 03046 if ($this->_seek($rowNumber)) { 03047 $this->_currentRow = $rowNumber; 03048 if ($this->_fetch()) { 03049 return true; 03050 } 03051 } else { 03052 $this->EOF = true; 03053 return false; 03054 } 03055 } else { 03056 if ($rowNumber < $this->_currentRow) return false; 03057 global $ADODB_EXTENSION; 03058 if ($ADODB_EXTENSION) { 03059 while (!$this->EOF && $this->_currentRow < $rowNumber) { 03060 adodb_movenext($this); 03061 } 03062 } else { 03063 03064 while (! $this->EOF && $this->_currentRow < $rowNumber) { 03065 $this->_currentRow++; 03066 03067 if (!$this->_fetch()) $this->EOF = true; 03068 } 03069 } 03070 return !($this->EOF); 03071 } 03072 03073 $this->fields = false; 03074 $this->EOF = true; 03075 return false; 03076 } 03077 03078 03087 function Fields($colname) 03088 { 03089 return $this->fields[$colname]; 03090 } 03091 03092 function GetAssocKeys($upper=true) 03093 { 03094 $this->bind = array(); 03095 for ($i=0; $i < $this->_numOfFields; $i++) { 03096 $o = $this->FetchField($i); 03097 if ($upper === 2) $this->bind[$o->name] = $i; 03098 else $this->bind[($upper) ? strtoupper($o->name) : strtolower($o->name)] = $i; 03099 } 03100 } 03101 03111 function &GetRowAssoc($upper=1) 03112 { 03113 $record = array(); 03114 // if (!$this->fields) return $record; 03115 03116 if (!$this->bind) { 03117 $this->GetAssocKeys($upper); 03118 } 03119 03120 foreach($this->bind as $k => $v) { 03121 $record[$k] = $this->fields[$v]; 03122 } 03123 03124 return $record; 03125 } 03126 03127 03133 function Close() 03134 { 03135 // free connection object - this seems to globally free the object 03136 // and not merely the reference, so don't do this... 03137 // $this->connection = false; 03138 if (!$this->_closed) { 03139 $this->_closed = true; 03140 return $this->_close(); 03141 } else 03142 return true; 03143 } 03144 03150 function RecordCount() {return $this->_numOfRows;} 03151 03152 03153 /* 03154 * If we are using PageExecute(), this will return the maximum possible rows 03155 * that can be returned when paging a recordset. 03156 */ 03157 function MaxRecordCount() 03158 { 03159 return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount(); 03160 } 03161 03167 function RowCount() {return $this->_numOfRows;} 03168 03169 03178 function PO_RecordCount($table="", $condition="") { 03179 03180 $lnumrows = $this->_numOfRows; 03181 // the database doesn't support native recordcount, so we do a workaround 03182 if ($lnumrows == -1 && $this->connection) { 03183 IF ($table) { 03184 if ($condition) $condition = " WHERE " . $condition; 03185 $resultrows = &$this->connection->Execute("SELECT COUNT(*) FROM $table $condition"); 03186 if ($resultrows) $lnumrows = reset($resultrows->fields); 03187 } 03188 } 03189 return $lnumrows; 03190 } 03191 03192 03196 function CurrentRow() {return $this->_currentRow;} 03197 03203 function AbsolutePosition() {return $this->_currentRow;} 03204 03209 function FieldCount() {return $this->_numOfFields;} 03210 03211 03219 function &FetchField($fieldoffset) 03220 { 03221 // must be defined by child class 03222 } 03223 03228 function& FieldTypesArray() 03229 { 03230 $arr = array(); 03231 for ($i=0, $max=$this->_numOfFields; $i < $max; $i++) 03232 $arr[] = $this->FetchField($i); 03233 return $arr; 03234 } 03235 03242 function &FetchObj() 03243 { 03244 $o =& $this->FetchObject(false); 03245 return $o; 03246 } 03247 03256 function &FetchObject($isupper=true) 03257 { 03258 if (empty($this->_obj)) { 03259 $this->_obj = new ADOFetchObj(); 03260 $this->_names = array(); 03261 for ($i=0; $i <$this->_numOfFields; $i++) { 03262 $f = $this->FetchField($i); 03263 $this->_names[] = $f->name; 03264 } 03265 } 03266 $i = 0; 03267 if (PHP_VERSION >= 5) $o = clone($this->_obj); 03268 else $o = $this->_obj; 03269 03270 for ($i=0; $i <$this->_numOfFields; $i++) { 03271 $name = $this->_names[$i]; 03272 if ($isupper) $n = strtoupper($name); 03273 else $n = $name; 03274 03275 $o->$n = $this->Fields($name); 03276 } 03277 return $o; 03278 } 03279 03289 function &FetchNextObj() 03290 { 03291 $o =& $this->FetchNextObject(false); 03292 return $o; 03293 } 03294 03295 03307 function &FetchNextObject($isupper=true) 03308 { 03309 $o = false; 03310 if ($this->_numOfRows != 0 && !$this->EOF) { 03311 $o = $this->FetchObject($isupper); 03312 $this->_currentRow++; 03313 if ($this->_fetch()) return $o; 03314 } 03315 $this->EOF = true; 03316 return $o; 03317 } 03318 03343 function MetaType($t,$len=-1,$fieldobj=false) 03344 { 03345 if (is_object($t)) { 03346 $fieldobj = $t; 03347 $t = $fieldobj->type; 03348 $len = $fieldobj->max_length; 03349 } 03350 // changed in 2.32 to hashing instead of switch stmt for speed... 03351 static $typeMap = array( 03352 'VARCHAR' => 'C', 03353 'VARCHAR2' => 'C', 03354 'CHAR' => 'C', 03355 'C' => 'C', 03356 'STRING' => 'C', 03357 'NCHAR' => 'C', 03358 'NVARCHAR' => 'C', 03359 'VARYING' => 'C', 03360 'BPCHAR' => 'C', 03361 'CHARACTER' => 'C', 03362 'INTERVAL' => 'C', # Postgres 03363 ## 03364 'LONGCHAR' => 'X', 03365 'TEXT' => 'X', 03366 'NTEXT' => 'X', 03367 'M' => 'X', 03368 'X' => 'X', 03369 'CLOB' => 'X', 03370 'NCLOB' => 'X', 03371 'LVARCHAR' => 'X', 03372 ## 03373 'BLOB' => 'B', 03374 'IMAGE' => 'B', 03375 'BINARY' => 'B', 03376 'VARBINARY' => 'B', 03377 'LONGBINARY' => 'B', 03378 'B' => 'B', 03379 ## 03380 'YEAR' => 'D', // mysql 03381 'DATE' => 'D', 03382 'D' => 'D', 03383 ## 03384 'TIME' => 'T', 03385 'TIMESTAMP' => 'T', 03386 'DATETIME' => 'T', 03387 'TIMESTAMPTZ' => 'T', 03388 'T' => 'T', 03389 ## 03390 'BOOL' => 'L', 03391 'BOOLEAN' => 'L', 03392 'BIT' => 'L', 03393 'L' => 'L', 03394 ## 03395 'COUNTER' => 'R', 03396 'R' => 'R', 03397 'SERIAL' => 'R', // ifx 03398 'INT IDENTITY' => 'R', 03399 ## 03400 'INT' => 'I', 03401 'INT2' => 'I', 03402 'INT4' => 'I', 03403 'INT8' => 'I', 03404 'INTEGER' => 'I', 03405 'INTEGER UNSIGNED' => 'I', 03406 'SHORT' => 'I', 03407 'TINYINT' => 'I', 03408 'SMALLINT' => 'I', 03409 'I' => 'I', 03410 ## 03411 'LONG' => 'N', // interbase is numeric, oci8 is blob 03412 'BIGINT' => 'N', // this is bigger than PHP 32-bit integers 03413 'DECIMAL' => 'N', 03414 'DEC' => 'N', 03415 'REAL' => 'N', 03416 'DOUBLE' => 'N', 03417 'DOUBLE PRECISION' => 'N', 03418 'SMALLFLOAT' => 'N', 03419 'FLOAT' => 'N', 03420 'NUMBER' => 'N', 03421 'NUM' => 'N', 03422 'NUMERIC' => 'N', 03423 'MONEY' => 'N', 03424 03425 ## informix 9.2 03426 'SQLINT' => 'I', 03427 'SQLSERIAL' => 'I', 03428 'SQLSMINT' => 'I', 03429 'SQLSMFLOAT' => 'N', 03430 'SQLFLOAT' => 'N', 03431 'SQLMONEY' => 'N', 03432 'SQLDECIMAL' => 'N', 03433 'SQLDATE' => 'D', 03434 'SQLVCHAR' => 'C', 03435 'SQLCHAR' => 'C', 03436 'SQLDTIME' => 'T', 03437 'SQLINTERVAL' => 'N', 03438 'SQLBYTES' => 'B', 03439 'SQLTEXT' => 'X' 03440 ); 03441 03442 $tmap = false; 03443 $t = strtoupper($t); 03444 $tmap = (isset($typeMap[$t])) ? $typeMap[$t] : 'N'; 03445 switch ($tmap) { 03446 case 'C': 03447 03448 // is the char field is too long, return as text field... 03449 if ($this->blobSize >= 0) { 03450 if ($len > $this->blobSize) return 'X'; 03451 } else if ($len > 250) { 03452 return 'X'; 03453 } 03454 return 'C'; 03455 03456 case 'I': 03457 if (!empty($fieldobj->primary_key)) return 'R'; 03458 return 'I'; 03459 03460 case false: 03461 return 'N'; 03462 03463 case 'B': 03464 if (isset($fieldobj->binary)) 03465 return ($fieldobj->binary) ? 'B' : 'X'; 03466 return 'B'; 03467 03468 case 'D': 03469 if (!empty($this->connection) && !empty($this->connection->datetime)) return 'T'; 03470 return 'D'; 03471 03472 default: 03473 if ($t == 'LONG' && $this->dataProvider == 'oci8') return 'B'; 03474 return $tmap; 03475 } 03476 } 03477 03478 function _close() {} 03479 03483 function AbsolutePage($page=-1) 03484 { 03485 if ($page != -1) $this->_currentPage = $page; 03486 return $this->_currentPage; 03487 } 03488 03492 function AtFirstPage($status=false) 03493 { 03494 if ($status != false) $this->_atFirstPage = $status; 03495 return $this->_atFirstPage; 03496 } 03497 03498 function LastPageNo($page = false) 03499 { 03500 if ($page != false) $this->_lastPageNo = $page; 03501 return $this->_lastPageNo; 03502 } 03503 03507 function AtLastPage($status=false) 03508 { 03509 if ($status != false) $this->_atLastPage = $status; 03510 return $this->_atLastPage; 03511 } 03512 03513 } // end class ADORecordSet 03514 03515 //============================================================================================== 03516 // CLASS ADORecordSet_array 03517 //============================================================================================== 03518 03526 class ADORecordSet_array extends ADORecordSet 03527 { 03528 var $databaseType = 'array'; 03529 03530 var $_array; // holds the 2-dimensional data array 03531 var $_types; // the array of types of each column (C B I L M) 03532 var $_colnames; // names of each column in array 03533 var $_skiprow1; // skip 1st row because it holds column names 03534 var $_fieldarr; // holds array of field objects 03535 var $canSeek = true; 03536 var $affectedrows = false; 03537 var $insertid = false; 03538 var $sql = ''; 03539 var $compat = false; 03544 function ADORecordSet_array($fakeid=1) 03545 { 03546 global $ADODB_FETCH_MODE,$ADODB_COMPAT_FETCH; 03547 03548 // fetch() on EOF does not delete $this->fields 03549 $this->compat = !empty($ADODB_COMPAT_FETCH); 03550 $this->ADORecordSet($fakeid); // fake queryID 03551 $this->fetchMode = $ADODB_FETCH_MODE; 03552 } 03553 03554 03566 function InitArray($array,$typearr,$colnames=false) 03567 { 03568 $this->_array = $array; 03569 $this->_types = $typearr; 03570 if ($colnames) { 03571 $this->_skiprow1 = false; 03572 $this->_colnames = $colnames; 03573 } else { 03574 $this->_skiprow1 = true; 03575 $this->_colnames = $array[0]; 03576 } 03577 $this->Init(); 03578 } 03587 function InitArrayFields(&$array,&$fieldarr) 03588 { 03589 $this->_array =& $array; 03590 $this->_skiprow1= false; 03591 if ($fieldarr) { 03592 $this->_fieldobjects =& $fieldarr; 03593 } 03594 $this->Init(); 03595 } 03596 03597 function &GetArray($nRows=-1) 03598 { 03599 if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) { 03600 return $this->_array; 03601 } else { 03602 $arr =& ADORecordSet::GetArray($nRows); 03603 return $arr; 03604 } 03605 } 03606 03607 function _initrs() 03608 { 03609 $this->_numOfRows = sizeof($this->_array); 03610 if ($this->_skiprow1) $this->_numOfRows -= 1; 03611 03612 $this->_numOfFields =(isset($this->_fieldobjects)) ? 03613 sizeof($this->_fieldobjects):sizeof($this->_types); 03614 } 03615 03616 /* Use associative array to get fields array */ 03617 function Fields($colname) 03618 { 03619 $mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode; 03620 03621 if ($mode & ADODB_FETCH_ASSOC) { 03622 if (!isset($this->fields[$colname])) $colname = strtolower($colname); 03623 return $this->fields[$colname]; 03624 } 03625 if (!$this->bind) { 03626 $this->bind = array(); 03627 for ($i=0; $i < $this->_numOfFields; $i++) { 03628 $o = $this->FetchField($i); 03629 $this->bind[strtoupper($o->name)] = $i; 03630 } 03631 } 03632 return $this->fields[$this->bind[strtoupper($colname)]]; 03633 } 03634 03635 function &FetchField($fieldOffset = -1) 03636 { 03637 if (isset($this->_fieldobjects)) { 03638 return $this->_fieldobjects[$fieldOffset]; 03639 } 03640 $o = new ADOFieldObject(); 03641 $o->name = $this->_colnames[$fieldOffset]; 03642 $o->type = $this->_types[$fieldOffset]; 03643 $o->max_length = -1; // length not known 03644 03645 return $o; 03646 } 03647 03648 function _seek($row) 03649 { 03650 if (sizeof($this->_array) && 0 <= $row && $row < $this->_numOfRows) { 03651 $this->_currentRow = $row; 03652 if ($this->_skiprow1) $row += 1; 03653 $this->fields = $this->_array[$row]; 03654 return true; 03655 } 03656 return false; 03657 } 03658 03659 function MoveNext() 03660 { 03661 if (!$this->EOF) { 03662 $this->_currentRow++; 03663 03664 $pos = $this->_currentRow; 03665 03666 if ($this->_numOfRows <= $pos) { 03667 if (!$this->compat) $this->fields = false; 03668 } else { 03669 if ($this->_skiprow1) $pos += 1; 03670 $this->fields = $this->_array[$pos]; 03671 return true; 03672 } 03673 $this->EOF = true; 03674 } 03675 03676 return false; 03677 } 03678 03679 function _fetch() 03680 { 03681 $pos = $this->_currentRow; 03682 03683 if ($this->_numOfRows <= $pos) { 03684 if (!$this->compat) $this->fields = false; 03685 return false; 03686 } 03687 if ($this->_skiprow1) $pos += 1; 03688 $this->fields = $this->_array[$pos]; 03689 return true; 03690 } 03691 03692 function _close() 03693 { 03694 return true; 03695 } 03696 03697 } // ADORecordSet_array 03698 03699 //============================================================================================== 03700 // HELPER FUNCTIONS 03701 //============================================================================================== 03702 03708 function ADOLoadDB($dbType) 03709 { 03710 return ADOLoadCode($dbType); 03711 } 03712 03716 function ADOLoadCode($dbType) 03717 { 03718 global $ADODB_LASTDB; 03719 03720 if (!$dbType) return false; 03721 $db = strtolower($dbType); 03722 switch ($db) { 03723 case 'ado': 03724 if (PHP_VERSION >= 5) $db = 'ado5'; 03725 $class = 'ado'; 03726 break; 03727 case 'ifx': 03728 case 'maxsql': $class = $db = 'mysqlt'; break; 03729 case 'postgres': 03730 case 'postgres8': 03731 case 'pgsql': $class = $db = 'postgres7'; break; 03732 default: 03733 $class = $db; break; 03734 } 03735 03736 $file = ADODB_DIR."/drivers/adodb-".$db.".inc.php"; 03737 @include_once($file); 03738 $ADODB_LASTDB = $class; 03739 if (class_exists("ADODB_" . $class)) return $class; 03740 03741 //ADOConnection::outp(adodb_pr(get_declared_classes(),true)); 03742 if (!file_exists($file)) ADOConnection::outp("Missing file: $file"); 03743 else ADOConnection::outp("Syntax error in file: $file"); 03744 return false; 03745 } 03746 03750 function &NewADOConnection($db='') 03751 { 03752 $tmp =& ADONewConnection($db); 03753 return $tmp; 03754 } 03755 03764 function &ADONewConnection($db='') 03765 { 03766 GLOBAL $ADODB_NEWCONNECTION, $ADODB_LASTDB; 03767 03768 if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2); 03769 $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false; 03770 $false = false; 03771 if ($at = strpos($db,'://')) { 03772 $origdsn = $db; 03773 if (PHP_VERSION < 5) $dsna = @parse_url($db); 03774 else { 03775 $fakedsn = 'fake'.substr($db,$at); 03776 $dsna = @parse_url($fakedsn); 03777 $dsna['scheme'] = substr($db,0,$at); 03778 03779 if (strncmp($db,'pdo',3) == 0) { 03780 $sch = explode('_',$dsna['scheme']); 03781 if (sizeof($sch)>1) { 03782 $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : ''; 03783 $dsna['host'] = rawurlencode($sch[1].':host='.rawurldecode($dsna['host'])); 03784 $dsna['scheme'] = 'pdo'; 03785 } 03786 } 03787 } 03788 03789 if (!$dsna) { 03790 // special handling of oracle, which might not have host 03791 $db = str_replace('@/','@adodb-fakehost/',$db); 03792 $dsna = parse_url($db); 03793 if (!$dsna) return $false; 03794 $dsna['host'] = ''; 03795 } 03796 $db = @$dsna['scheme']; 03797 if (!$db) return $false; 03798 $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : ''; 03799 $dsna['user'] = isset($dsna['user']) ? rawurldecode($dsna['user']) : ''; 03800 $dsna['pass'] = isset($dsna['pass']) ? rawurldecode($dsna['pass']) : ''; 03801 $dsna['path'] = isset($dsna['path']) ? rawurldecode(substr($dsna['path'],1)) : ''; # strip off initial / 03802 03803 if (isset($dsna['query'])) { 03804 $opt1 = explode('&',$dsna['query']); 03805 foreach($opt1 as $k => $v) { 03806 $arr = explode('=',$v); 03807 $opt[$arr[0]] = isset($arr[1]) ? rawurldecode($arr[1]) : 1; 03808 } 03809 } else $opt = array(); 03810 } 03811 /* 03812 * phptype: Database backend used in PHP (mysql, odbc etc.) 03813 * dbsyntax: Database used with regards to SQL syntax etc. 03814 * protocol: Communication protocol to use (tcp, unix etc.) 03815 * hostspec: Host specification (hostname[:port]) 03816 * database: Database to use on the DBMS server 03817 * username: User name for login 03818 * password: Password for login 03819 */ 03820 if (!empty($ADODB_NEWCONNECTION)) { 03821 $obj = $ADODB_NEWCONNECTION($db); 03822 03823 } else { 03824 03825 if (!isset($ADODB_LASTDB)) $ADODB_LASTDB = ''; 03826 if (empty($db)) $db = $ADODB_LASTDB; 03827 03828 if ($db != $ADODB_LASTDB) $db = ADOLoadCode($db); 03829 03830 if (!$db) { 03831 if (isset($origdsn)) $db = $origdsn; 03832 if ($errorfn) { 03833 // raise an error 03834 $ignore = false; 03835 $errorfn('ADONewConnection', 'ADONewConnection', -998, 03836 "could not load the database driver for '$db'", 03837 $db,false,$ignore); 03838 } else 03839 ADOConnection::outp( "<p>ADONewConnection: Unable to load database driver '$db'</p>",false); 03840 03841 return $false; 03842 } 03843 03844 $cls = 'ADODB_'.$db; 03845 if (!class_exists($cls)) { 03846 adodb_backtrace(); 03847 return $false; 03848 } 03849 03850 $obj = new $cls(); 03851 } 03852 03853 # constructor should not fail 03854 if ($obj) { 03855 if ($errorfn) $obj->raiseErrorFn = $errorfn; 03856 if (isset($dsna)) { 03857 if (isset($dsna['port'])) $obj->port = $dsna['port']; 03858 foreach($opt as $k => $v) { 03859 switch(strtolower($k)) { 03860 case 'new': 03861 $nconnect = true; $persist = true; break; 03862 case 'persist': 03863 case 'persistent': $persist = $v; break; 03864 case 'debug': $obj->debug = (integer) $v; break; 03865 #ibase 03866 case 'role': $obj->role = $v; break; 03867 case 'dialect': $obj->dialect = (integer) $v; break; 03868 case 'charset': $obj->charset = $v; $obj->charSet=$v; break; 03869 case 'buffers': $obj->buffers = $v; break; 03870 case 'fetchmode': $obj->SetFetchMode($v); break; 03871 #ado 03872 case 'charpage': $obj->charPage = $v; break; 03873 #mysql, mysqli 03874 case 'clientflags': $obj->clientFlags = $v; break; 03875 #mysql, mysqli, postgres 03876 case 'port': $obj->port = $v; break; 03877 #mysqli 03878 case 'socket': $obj->socket = $v; break; 03879 #oci8 03880 case 'nls_date_format': $obj->NLS_DATE_FORMAT = $v; break; 03881 } 03882 } 03883 if (empty($persist)) 03884 $ok = $obj->Connect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']); 03885 else if (empty($nconnect)) 03886 $ok = $obj->PConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']); 03887 else 03888 $ok = $obj->NConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']); 03889 03890 if (!$ok) return $false; 03891 } 03892 } 03893 return $obj; 03894 } 03895 03896 03897 03898 // $perf == true means called by NewPerfMonitor(), otherwise for data dictionary 03899 function _adodb_getdriver($provider,$drivername,$perf=false) 03900 { 03901 switch ($provider) { 03902 case 'odbtp': if (strncmp('odbtp_',$drivername,6)==0) return substr($drivername,6); 03903 case 'odbc' : if (strncmp('odbc_',$drivername,5)==0) return substr($drivername,5); 03904 case 'ado' : if (strncmp('ado_',$drivername,4)==0) return substr($drivername,4); 03905 case 'native': break; 03906 default: 03907 return $provider; 03908 } 03909 03910 switch($drivername) { 03911 case 'mysqlt': 03912 case 'mysqli': 03913 $drivername='mysql'; 03914 break; 03915 case 'postgres7': 03916 case 'postgres8': 03917 $drivername = 'postgres'; 03918 break; 03919 case 'firebird15': $drivername = 'firebird'; break; 03920 case 'oracle': $drivername = 'oci8'; break; 03921 case 'access': if ($perf) $drivername = ''; break; 03922 case 'db2' : break; 03923 case 'sapdb' : break; 03924 default: 03925 $drivername = 'generic'; 03926 break; 03927 } 03928 return $drivername; 03929 } 03930 03931 function &NewPerfMonitor(&$conn) 03932 { 03933 $false = false; 03934 $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType,true); 03935 if (!$drivername || $drivername == 'generic') return $false; 03936 include_once(ADODB_DIR.'/adodb-perf.inc.php'); 03937 @include_once(ADODB_DIR."/perf/perf-$drivername.inc.php"); 03938 $class = "Perf_$drivername"; 03939 if (!class_exists($class)) return $false; 03940 $perf = new $class($conn); 03941 03942 return $perf; 03943 } 03944 03945 function &NewDataDictionary(&$conn,$drivername=false) 03946 { 03947 $false = false; 03948 if (!$drivername) $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType); 03949 03950 include_once(ADODB_DIR.'/adodb-lib.inc.php'); 03951 include_once(ADODB_DIR.'/adodb-datadict.inc.php'); 03952 $path = ADODB_DIR."/datadict/datadict-$drivername.inc.php"; 03953 03954 if (!file_exists($path)) { 03955 ADOConnection::outp("Database driver '$path' not available"); 03956 return $false; 03957 } 03958 include_once($path); 03959 $class = "ADODB2_$drivername"; 03960 $dict = new $class(); 03961 $dict->dataProvider = $conn->dataProvider; 03962 $dict->connection = &$conn; 03963 $dict->upperName = strtoupper($drivername); 03964 $dict->quote = $conn->nameQuote; 03965 if (!empty($conn->_connectionID)) 03966 $dict->serverInfo = $conn->ServerInfo(); 03967 03968 return $dict; 03969 } 03970 03971 03972 03973 /* 03974 Perform a print_r, with pre tags for better formatting. 03975 */ 03976 function adodb_pr($var,$as_string=false) 03977 { 03978 if ($as_string) ob_start(); 03979 03980 if (isset($_SERVER['HTTP_USER_AGENT'])) { 03981 echo " <pre>\n";print_r($var);echo "</pre>\n"; 03982 } else 03983 print_r($var); 03984 03985 if ($as_string) { 03986 $s = ob_get_contents(); 03987 ob_end_clean(); 03988 return $s; 03989 } 03990 } 03991 03992 /* 03993 Perform a stack-crawl and pretty print it. 03994 03995 @param printOrArr Pass in a boolean to indicate print, or an $exception->trace array (assumes that print is true then). 03996 @param levels Number of levels to display 03997 */ 03998 function adodb_backtrace($printOrArr=true,$levels=9999) 03999 { 04000 global $ADODB_INCLUDED_LIB; 04001 if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); 04002 return _adodb_backtrace($printOrArr,$levels); 04003 } 04004 04005 04006 } 04007 ?>