Changeset 8222 for sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/adodb.inc.php
- Timestamp:
- 09/26/13 15:41:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/adodb.inc.php
r34 r8222 3 3 * Set tabs to 4 for best viewing. 4 4 * 5 * Latest version is available at http://adodb.sourceforge.net /5 * Latest version is available at http://adodb.sourceforge.net 6 6 * 7 7 * This is the main include file for ADOdb. … … 13 13 14 14 /** 15 \mainpage 16 17 @version V 4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.15 \mainpage 16 17 @version V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. 18 18 19 19 Released under both BSD license and Lesser GPL library license. You can choose which license … … 55 55 $ADODB_COUNTRECS, // count number of records returned - slows down query 56 56 $ADODB_CACHE_DIR, // directory to cache recordsets 57 $ADODB_CACHE, 58 $ADODB_CACHE_CLASS, 57 59 $ADODB_EXTENSION, // ADODB extension installed 58 60 $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF 59 61 $ADODB_FETCH_MODE, // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default... 62 $ADODB_GETONE_EOF, 60 63 $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql. 61 64 … … 116 119 } else if ($_adodb_ver >= 5.0) { 117 120 define('ADODB_PHPVER',0x5000); 118 } else if ($_adodb_ver > 4.299999) { # 4.3 119 define('ADODB_PHPVER',0x4300); 120 } else if ($_adodb_ver > 4.199999) { # 4.2 121 define('ADODB_PHPVER',0x4200); 122 } else if (strnatcmp(PHP_VERSION,'4.0.5')>=0) { 123 define('ADODB_PHPVER',0x4050); 124 } else { 125 define('ADODB_PHPVER',0x4000); 126 } 127 } 121 } else 122 die("PHP5 or later required. You are running ".PHP_VERSION); 123 } 124 128 125 129 126 //if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2); … … 154 151 $ADODB_CACHE_DIR, // directory to cache recordsets 155 152 $ADODB_FETCH_MODE, 153 $ADODB_CACHE, 154 $ADODB_CACHE_CLASS, 156 155 $ADODB_FORCE_TYPE, 156 $ADODB_GETONE_EOF, 157 157 $ADODB_QUOTE_FIELDNAMES; 158 158 159 if (empty($ADODB_CACHE_CLASS)) $ADODB_CACHE_CLASS = 'ADODB_Cache_File' ; 159 160 $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT; 160 161 $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE; 161 162 $ADODB_GETONE_EOF = null; 162 163 163 164 if (!isset($ADODB_CACHE_DIR)) { … … 177 178 * ADODB version as a string. 178 179 */ 179 $ADODB_vers = 'V 4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';180 $ADODB_vers = 'V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. Released BSD & LGPL.'; 180 181 181 182 /** … … 216 217 } 217 218 218 219 220 function _adodb_safedate($s) 221 { 222 return str_replace(array("'", '\\'), '', $s); 223 } 224 225 // parse date string to prevent injection attack 226 // date string will have one quote at beginning e.g. '3434343' 227 function _adodb_safedateq($s) 228 { 229 $len = strlen($s); 230 if ($s[0] !== "'") $s2 = "'".$s[0]; 231 else $s2 = "'"; 232 for($i=1; $i<$len; $i++) { 233 $ch = $s[$i]; 234 if ($ch === '\\') { 235 $s2 .= "'"; 236 break; 237 } elseif ($ch === "'") { 238 $s2 .= $ch; 239 break; 240 } 241 242 $s2 .= $ch; 243 } 244 245 return strlen($s2) == 0 ? 'null' : $s2; 246 } 247 248 249 // for transaction handling 219 250 220 251 function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) … … 225 256 $fn = $thisConnection->_oldRaiseFn; 226 257 $fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection); 258 } 259 } 260 261 //------------------ 262 // class for caching 263 class ADODB_Cache_File { 264 265 var $createdir = true; // requires creation of temp dirs 266 267 function ADODB_Cache_File() 268 { 269 global $ADODB_INCLUDED_CSV; 270 if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); 271 } 272 273 // write serialised recordset to cache item/file 274 function writecache($filename, $contents, $debug, $secs2cache) 275 { 276 return adodb_write_file($filename, $contents,$debug); 277 } 278 279 // load serialised recordset and unserialise it 280 function &readcache($filename, &$err, $secs2cache, $rsClass) 281 { 282 $rs = csv2rs($filename,$err,$secs2cache,$rsClass); 283 return $rs; 284 } 285 286 // flush all items in cache 287 function flushall($debug=false) 288 { 289 global $ADODB_CACHE_DIR; 290 291 $rez = false; 292 293 if (strlen($ADODB_CACHE_DIR) > 1) { 294 $rez = $this->_dirFlush($ADODB_CACHE_DIR); 295 if ($debug) ADOConnection::outp( "flushall: $dir<br><pre>\n". $rez."</pre>"); 296 } 297 return $rez; 298 } 299 300 // flush one file in cache 301 function flushcache($f, $debug=false) 302 { 303 if (!@unlink($f)) { 304 if ($debug) ADOConnection::outp( "flushcache: failed for $f"); 305 } 306 } 307 308 function getdirname($hash) 309 { 310 global $ADODB_CACHE_DIR; 311 if (!isset($this->notSafeMode)) $this->notSafeMode = !ini_get('safe_mode'); 312 return ($this->notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($hash,0,2) : $ADODB_CACHE_DIR; 313 } 314 315 // create temp directories 316 function createdir($hash, $debug) 317 { 318 global $ADODB_CACHE_PERMS; 319 320 $dir = $this->getdirname($hash); 321 if ($this->notSafeMode && !file_exists($dir)) { 322 $oldu = umask(0); 323 if (!@mkdir($dir, empty($ADODB_CACHE_PERMS) ? 0771 : $ADODB_CACHE_PERMS)) if(!is_dir($dir) && $debug) ADOConnection::outp("Cannot create $dir"); 324 umask($oldu); 325 } 326 327 return $dir; 328 } 329 330 /** 331 * Private function to erase all of the files and subdirectories in a directory. 332 * 333 * Just specify the directory, and tell it if you want to delete the directory or just clear it out. 334 * Note: $kill_top_level is used internally in the function to flush subdirectories. 335 */ 336 function _dirFlush($dir, $kill_top_level = false) 337 { 338 if(!$dh = @opendir($dir)) return; 339 340 while (($obj = readdir($dh))) { 341 if($obj=='.' || $obj=='..') continue; 342 $f = $dir.'/'.$obj; 343 344 if (strpos($obj,'.cache')) @unlink($f); 345 if (is_dir($f)) $this->_dirFlush($f, true); 346 } 347 if ($kill_top_level === true) @rmdir($dir); 348 return true; 227 349 } 228 350 } … … 288 410 var $sysDate = false; /// name of function that returns the current date 289 411 var $sysTimeStamp = false; /// name of function that returns the current timestamp 412 var $sysUTimeStamp = false; // name of function that returns the current timestamp accurate to the microsecond or nearest fraction 290 413 var $arrayClass = 'ADORecordSet_array'; /// name of class used to generate array recordsets, which are pre-downloaded recordsets 291 414 … … 313 436 314 437 var $null2null = 'null'; // in autoexecute/getinsertsql/getupdatesql, this value will be converted to a null 438 var $bulkBind = false; // enable 2D Execute array 315 439 // 316 440 // PRIVATE VARS … … 341 465 } 342 466 343 function Version()467 static function Version() 344 468 { 345 469 global $ADODB_vers; 346 470 347 return (float) substr($ADODB_vers,1); 471 $ok = preg_match( '/^[Vv]([0-9\.]+)/', $ADODB_vers, $matches ); 472 if (!$ok) return (float) substr($ADODB_vers,1); 473 else return $matches[1]; 348 474 } 349 475 … … 374 500 * You can define your own handler by defining the function name in ADODB_OUTP. 375 501 */ 376 function outp($msg,$newline=true)502 static function outp($msg,$newline=true) 377 503 { 378 504 global $ADODB_FLUSH,$ADODB_OUTP; … … 400 526 function Time() 401 527 { 402 $rs = &$this->_Execute("select $this->sysTimeStamp");528 $rs = $this->_Execute("select $this->sysTimeStamp"); 403 529 if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields)); 404 530 … … 421 547 if ($argHostname != "") $this->host = $argHostname; 422 548 if ($argUsername != "") $this->user = $argUsername; 423 if ($argPassword != "") $this->password = $argPassword; // not stored for security reasons549 if ($argPassword != "") $this->password = 'not stored'; // not stored for security reasons 424 550 if ($argDatabaseName != "") $this->database = $argDatabaseName; 425 551 426 552 $this->_isPersistentConnection = false; 553 427 554 if ($forceNew) { 428 if ($rez=$this->_nconnect($this->host, $this->user, $ this->password, $this->database)) return true;555 if ($rez=$this->_nconnect($this->host, $this->user, $argPassword, $this->database)) return true; 429 556 } else { 430 if ($rez=$this->_connect($this->host, $this->user, $ this->password, $this->database)) return true;557 if ($rez=$this->_connect($this->host, $this->user, $argPassword, $this->database)) return true; 431 558 } 432 559 if (isset($rez)) { … … 480 607 function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") 481 608 { 609 482 610 if (defined('ADODB_NEVER_PERSIST')) 483 611 return $this->Connect($argHostname,$argUsername,$argPassword,$argDatabaseName); … … 485 613 if ($argHostname != "") $this->host = $argHostname; 486 614 if ($argUsername != "") $this->user = $argUsername; 487 if ($argPassword != "") $this->password = $argPassword;615 if ($argPassword != "") $this->password = 'not stored'; 488 616 if ($argDatabaseName != "") $this->database = $argDatabaseName; 489 617 490 618 $this->_isPersistentConnection = true; 491 if ($rez = $this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true; 619 620 if ($rez = $this->_pconnect($this->host, $this->user, $argPassword, $this->database)) return true; 492 621 if (isset($rez)) { 493 622 $err = $this->ErrorMsg(); … … 507 636 } 508 637 638 function outp_throw($msg,$src='WARN',$sql='') 639 { 640 if (defined('ADODB_ERROR_HANDLER') && ADODB_ERROR_HANDLER == 'adodb_throw') { 641 adodb_throw($this->databaseType,$src,-9999,$msg,$sql,false,$this); 642 return; 643 } 644 ADOConnection::outp($msg); 645 } 646 647 // create cache class. Code is backward compat with old memcache implementation 648 function _CreateCache() 649 { 650 global $ADODB_CACHE, $ADODB_CACHE_CLASS; 651 652 if ($this->memCache) { 653 global $ADODB_INCLUDED_MEMCACHE; 654 655 if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php'); 656 $ADODB_CACHE = new ADODB_Cache_MemCache($this); 657 } else 658 $ADODB_CACHE = new $ADODB_CACHE_CLASS($this); 659 660 } 661 509 662 // Format date column in sql string given an input format that understands Y M D 510 663 function SQLDate($fmt, $col=false) … … 533 686 return $sql; 534 687 } 535 688 536 689 /** 537 690 * Some databases, eg. mssql require a different function for preparing … … 552 705 return $this->Prepare($sql,$param); 553 706 } 554 707 555 708 /** 556 709 * PEAR DB Compat … … 599 752 * @param $where where clause to use, eg: "WHERE row=12". If left empty, will escalate to table lock 600 753 */ 601 function RowLock($table,$where )754 function RowLock($table,$where,$col='1 as adodbignore') 602 755 { 603 756 return false; … … 639 792 * PEAR DB Compat - do not use internally. 640 793 */ 641 function &Query($sql, $inputarr=false)642 { 643 $rs = &$this->Execute($sql, $inputarr);794 function Query($sql, $inputarr=false) 795 { 796 $rs = $this->Execute($sql, $inputarr); 644 797 if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error(); 645 798 return $rs; … … 650 803 * PEAR DB Compat - do not use internally 651 804 */ 652 function &LimitQuery($sql, $offset, $count, $params=false)653 { 654 $rs = &$this->SelectLimit($sql, $count, $offset, $params);805 function LimitQuery($sql, $offset, $count, $params=false) 806 { 807 $rs = $this->SelectLimit($sql, $count, $offset, $params); 655 808 if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error(); 656 809 return $rs; … … 744 897 if ($this->transOff > 0) { 745 898 $this->transOff += 1; 746 return ;899 return true; 747 900 } 748 901 … … 752 905 753 906 if ($this->debug && $this->transCnt > 0) ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans"); 754 $ this->BeginTrans();907 $ok = $this->BeginTrans(); 755 908 $this->transOff = 1; 909 return $ok; 756 910 } 757 911 … … 820 974 * @return RecordSet or false 821 975 */ 822 function &Execute($sql,$inputarr=false)976 function Execute($sql,$inputarr=false) 823 977 { 824 978 if ($this->fnExecute) { 825 979 $fn = $this->fnExecute; 826 $ret = &$fn($this,$sql,$inputarr);980 $ret = $fn($this,$sql,$inputarr); 827 981 if (isset($ret)) return $ret; 828 982 } … … 832 986 $element0 = reset($inputarr); 833 987 # is_object check because oci8 descriptors can be passed in 834 $array_2d = is_array($element0) && !is_object(reset($element0)); 988 $array_2d = $this->bulkBind && is_array($element0) && !is_object(reset($element0)); 989 835 990 //remove extra memory copy of input -mikefedyk 836 991 unset($element0); … … 838 993 if (!is_array($sql) && !$this->_bindInputArray) { 839 994 $sqlarr = explode('?',$sql); 840 995 $nparams = sizeof($sqlarr)-1; 841 996 if (!$array_2d) $inputarr = array($inputarr); 997 842 998 foreach($inputarr as $arr) { 843 999 $sql = ''; $i = 0; … … 863 1019 $sql .= $v; 864 1020 $i += 1; 865 } 1021 1022 if ($i == $nparams) break; 1023 } // while 866 1024 if (isset($sqlarr[$i])) { 867 1025 $sql .= $sqlarr[$i]; 868 if ($i+1 != sizeof($sqlarr)) ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql));1026 if ($i+1 != sizeof($sqlarr)) $this->outp_throw( "Input Array does not match ?: ".htmlspecialchars($sql),'Execute'); 869 1027 } else if ($i != sizeof($sqlarr)) 870 ADOConnection::outp( "Input array does not match ?: ".htmlspecialchars($sql));871 872 $ret = &$this->_Execute($sql);1028 $this->outp_throw( "Input array does not match ?: ".htmlspecialchars($sql),'Execute'); 1029 1030 $ret = $this->_Execute($sql); 873 1031 if (!$ret) return $ret; 874 1032 } … … 879 1037 else 880 1038 $stmt = $sql; 881 1039 882 1040 foreach($inputarr as $arr) { 883 $ret = &$this->_Execute($stmt,$arr);1041 $ret = $this->_Execute($stmt,$arr); 884 1042 if (!$ret) return $ret; 885 1043 } 886 1044 } else { 887 $ret = &$this->_Execute($sql,$inputarr);1045 $ret = $this->_Execute($sql,$inputarr); 888 1046 } 889 1047 } 890 1048 } else { 891 $ret = &$this->_Execute($sql,false);1049 $ret = $this->_Execute($sql,false); 892 1050 } 893 1051 … … 896 1054 897 1055 898 function &_Execute($sql,$inputarr=false)1056 function _Execute($sql,$inputarr=false) 899 1057 { 900 1058 if ($this->debug) { … … 921 1079 922 1080 if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead 923 $rs = new ADORecordSet_empty(); 1081 $rsclass = $this->rsPrefix.'empty'; 1082 $rs = (class_exists($rsclass)) ? new $rsclass(): new ADORecordSet_empty(); 1083 924 1084 return $rs; 925 1085 } … … 928 1088 $rsclass = $this->rsPrefix.$this->databaseType; 929 1089 $rs = new $rsclass($this->_queryID,$this->fetchMode); 930 $rs->connection = &$this; // Pablo suggestion1090 $rs->connection = $this; // Pablo suggestion 931 1091 $rs->Init(); 932 1092 if (is_array($sql)) $rs->sql = $sql[0]; … … 936 1096 if ($ADODB_COUNTRECS) { 937 1097 if (!$rs->EOF) { 938 $rs = &$this->_rs2rs($rs,-1,-1,!is_array($sql));1098 $rs = $this->_rs2rs($rs,-1,-1,!is_array($sql)); 939 1099 $rs->_queryID = $this->_queryID; 940 1100 } else … … 1081 1241 // owner not used in base class - see oci8 1082 1242 $p = array(); 1083 $objs = &$this->MetaColumns($table);1243 $objs = $this->MetaColumns($table); 1084 1244 if ($objs) { 1085 1245 foreach($objs as $v) { … … 1130 1290 * @return the recordset ($rs->databaseType == 'array') 1131 1291 */ 1132 function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)1292 function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) 1133 1293 { 1134 1294 if ($this->hasTop && $nrows > 0) { … … 1147 1307 1148 1308 if ($secs2cache != 0) { 1149 $ret = &$this->CacheExecute($secs2cache, $sql,$inputarr);1309 $ret = $this->CacheExecute($secs2cache, $sql,$inputarr); 1150 1310 } else { 1151 $ret = &$this->Execute($sql,$inputarr);1311 $ret = $this->Execute($sql,$inputarr); 1152 1312 } 1153 1313 return $ret; // PHP5 fix … … 1178 1338 $ADODB_COUNTRECS = false; 1179 1339 1180 if ($offset>0){ 1181 if ($secs2cache != 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 1182 else $rs = &$this->Execute($sql,$inputarr); 1183 } else { 1184 if ($secs2cache != 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 1185 else $rs = &$this->Execute($sql,$inputarr); 1186 } 1340 1341 if ($secs2cache != 0) $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); 1342 else $rs = $this->Execute($sql,$inputarr); 1343 1187 1344 $ADODB_COUNTRECS = $savec; 1188 1345 if ($rs && !$rs->EOF) { 1189 $rs = &$this->_rs2rs($rs,$nrows,$offset);1346 $rs = $this->_rs2rs($rs,$nrows,$offset); 1190 1347 } 1191 1348 //print_r($rs); … … 1198 1355 * @param rs the recordset to serialize 1199 1356 */ 1200 function &SerializableRS(&$rs)1201 { 1202 $rs2 = &$this->_rs2rs($rs);1357 function SerializableRS(&$rs) 1358 { 1359 $rs2 = $this->_rs2rs($rs); 1203 1360 $ignore = false; 1204 $rs2->connection = &$ignore;1361 $rs2->connection = $ignore; 1205 1362 1206 1363 return $rs2; … … 1225 1382 $dbtype = $rs->databaseType; 1226 1383 if (!$dbtype) { 1227 $rs = &$rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1 -- why ?1384 $rs = $rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1 -- why ? 1228 1385 return $rs; 1229 1386 } 1230 1387 if (($dbtype == 'array' || $dbtype == 'csv') && $nrows == -1 && $offset == -1) { 1231 1388 $rs->MoveFirst(); 1232 $rs = &$rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1-- why ?1389 $rs = $rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1-- why ? 1233 1390 return $rs; 1234 1391 } … … 1238 1395 } 1239 1396 1240 $arr = &$rs->GetArrayLimit($nrows,$offset);1397 $arr = $rs->GetArrayLimit($nrows,$offset); 1241 1398 //print_r($arr); 1242 1399 if ($close) $rs->Close(); … … 1245 1402 1246 1403 $rs2 = new $arrayClass(); 1247 $rs2->connection = &$this;1404 $rs2->connection = $this; 1248 1405 $rs2->sql = $rs->sql; 1249 1406 $rs2->dataProvider = $this->dataProvider; … … 1256 1413 * Return all rows. Compat with PEAR DB 1257 1414 */ 1258 function &GetAll($sql, $inputarr=false)1259 { 1260 $arr = &$this->GetArray($sql,$inputarr);1415 function GetAll($sql, $inputarr=false) 1416 { 1417 $arr = $this->GetArray($sql,$inputarr); 1261 1418 return $arr; 1262 1419 } 1263 1420 1264 function &GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false)1265 { 1266 $rs = &$this->Execute($sql, $inputarr);1421 function GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false) 1422 { 1423 $rs = $this->Execute($sql, $inputarr); 1267 1424 if (!$rs) { 1268 1425 $false = false; 1269 1426 return $false; 1270 1427 } 1271 $arr = &$rs->GetAssoc($force_array,$first2cols);1428 $arr = $rs->GetAssoc($force_array,$first2cols); 1272 1429 return $arr; 1273 1430 } 1274 1431 1275 function &CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false)1432 function CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false) 1276 1433 { 1277 1434 if (!is_numeric($secs2cache)) { … … 1279 1436 $force_array = $inputarr; 1280 1437 } 1281 $rs = &$this->CacheExecute($secs2cache, $sql, $inputarr);1438 $rs = $this->CacheExecute($secs2cache, $sql, $inputarr); 1282 1439 if (!$rs) { 1283 1440 $false = false; 1284 1441 return $false; 1285 1442 } 1286 $arr = &$rs->GetAssoc($force_array,$first2cols);1443 $arr = $rs->GetAssoc($force_array,$first2cols); 1287 1444 return $arr; 1288 1445 } … … 1297 1454 function GetOne($sql,$inputarr=false) 1298 1455 { 1299 global $ADODB_COUNTRECS ;1456 global $ADODB_COUNTRECS,$ADODB_GETONE_EOF; 1300 1457 $crecs = $ADODB_COUNTRECS; 1301 1458 $ADODB_COUNTRECS = false; 1302 1459 1303 1460 $ret = false; 1304 $rs = &$this->Execute($sql,$inputarr);1461 $rs = $this->Execute($sql,$inputarr); 1305 1462 if ($rs) { 1306 if (!$rs->EOF) $ret = reset($rs->fields); 1463 if ($rs->EOF) $ret = $ADODB_GETONE_EOF; 1464 else $ret = reset($rs->fields); 1465 1307 1466 $rs->Close(); 1308 1467 } … … 1311 1470 } 1312 1471 1472 // $where should include 'WHERE fld=value' 1473 function GetMedian($table, $field,$where = '') 1474 { 1475 $total = $this->GetOne("select count(*) from $table $where"); 1476 if (!$total) return false; 1477 1478 $midrow = (integer) ($total/2); 1479 $rs = $this->SelectLimit("select $field from $table $where order by 1",1,$midrow); 1480 if ($rs && !$rs->EOF) return reset($rs->fields); 1481 return false; 1482 } 1483 1484 1313 1485 function CacheGetOne($secs2cache,$sql=false,$inputarr=false) 1314 1486 { 1487 global $ADODB_GETONE_EOF; 1315 1488 $ret = false; 1316 $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 1317 if ($rs) { 1318 if (!$rs->EOF) $ret = reset($rs->fields); 1489 $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); 1490 if ($rs) { 1491 if ($rs->EOF) $ret = $ADODB_GETONE_EOF; 1492 else $ret = reset($rs->fields); 1319 1493 $rs->Close(); 1320 1494 } … … 1325 1499 function GetCol($sql, $inputarr = false, $trim = false) 1326 1500 { 1327 $rv = false;1328 $rs = &$this->Execute($sql, $inputarr);1501 1502 $rs = $this->Execute($sql, $inputarr); 1329 1503 if ($rs) { 1330 1504 $rv = array(); … … 1341 1515 } 1342 1516 $rs->Close(); 1343 } 1517 } else 1518 $rv = false; 1344 1519 return $rv; 1345 1520 } … … 1347 1522 function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false) 1348 1523 { 1349 $rv = false; 1350 $rs = &$this->CacheExecute($secs, $sql, $inputarr); 1524 $rs = $this->CacheExecute($secs, $sql, $inputarr); 1351 1525 if ($rs) { 1526 $rv = array(); 1352 1527 if ($trim) { 1353 1528 while (!$rs->EOF) { … … 1362 1537 } 1363 1538 $rs->Close(); 1364 } 1539 } else 1540 $rv = false; 1541 1365 1542 return $rv; 1366 1543 } 1367 1544 1368 function &Transpose(&$rs,$addfieldnames=true)1369 { 1370 $rs2 = &$this->_rs2rs($rs);1545 function Transpose(&$rs,$addfieldnames=true) 1546 { 1547 $rs2 = $this->_rs2rs($rs); 1371 1548 $false = false; 1372 1549 if (!$rs2) return $false; … … 1395 1572 * @param [inputarr] input bind array 1396 1573 */ 1397 function &GetArray($sql,$inputarr=false)1574 function GetArray($sql,$inputarr=false) 1398 1575 { 1399 1576 global $ADODB_COUNTRECS; … … 1401 1578 $savec = $ADODB_COUNTRECS; 1402 1579 $ADODB_COUNTRECS = false; 1403 $rs = &$this->Execute($sql,$inputarr);1580 $rs = $this->Execute($sql,$inputarr); 1404 1581 $ADODB_COUNTRECS = $savec; 1405 1582 if (!$rs) … … 1411 1588 return $false; 1412 1589 } 1413 $arr = &$rs->GetArray();1590 $arr = $rs->GetArray(); 1414 1591 $rs->Close(); 1415 1592 return $arr; 1416 1593 } 1417 1594 1418 function &CacheGetAll($secs2cache,$sql=false,$inputarr=false)1419 { 1420 $arr = &$this->CacheGetArray($secs2cache,$sql,$inputarr);1595 function CacheGetAll($secs2cache,$sql=false,$inputarr=false) 1596 { 1597 $arr = $this->CacheGetArray($secs2cache,$sql,$inputarr); 1421 1598 return $arr; 1422 1599 } 1423 1600 1424 function &CacheGetArray($secs2cache,$sql=false,$inputarr=false)1601 function CacheGetArray($secs2cache,$sql=false,$inputarr=false) 1425 1602 { 1426 1603 global $ADODB_COUNTRECS; … … 1428 1605 $savec = $ADODB_COUNTRECS; 1429 1606 $ADODB_COUNTRECS = false; 1430 $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);1607 $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); 1431 1608 $ADODB_COUNTRECS = $savec; 1432 1609 … … 1439 1616 return $false; 1440 1617 } 1441 $arr = &$rs->GetArray();1618 $arr = $rs->GetArray(); 1442 1619 $rs->Close(); 1443 1620 return $arr; 1444 1621 } 1445 1622 1446 1447 1448 /** 1449 * Return one row of sql statement. Recordset is disposed for you. 1623 function GetRandRow($sql, $arr= false) 1624 { 1625 $rezarr = $this->GetAll($sql, $arr); 1626 $sz = sizeof($rezarr); 1627 return $rezarr[abs(rand()) % $sz]; 1628 } 1629 1630 /** 1631 * Return one row of sql statement. Recordset is disposed for you. 1632 * Note that SelectLimit should not be called. 1450 1633 * 1451 1634 * @param sql SQL statement 1452 1635 * @param [inputarr] input bind array 1453 1636 */ 1454 function &GetRow($sql,$inputarr=false)1637 function GetRow($sql,$inputarr=false) 1455 1638 { 1456 1639 global $ADODB_COUNTRECS; … … 1458 1641 $ADODB_COUNTRECS = false; 1459 1642 1460 $rs = &$this->Execute($sql,$inputarr);1643 $rs = $this->Execute($sql,$inputarr); 1461 1644 1462 1645 $ADODB_COUNTRECS = $crecs; … … 1472 1655 } 1473 1656 1474 function &CacheGetRow($secs2cache,$sql=false,$inputarr=false)1475 { 1476 $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);1657 function CacheGetRow($secs2cache,$sql=false,$inputarr=false) 1658 { 1659 $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); 1477 1660 if ($rs) { 1478 $arr = false;1479 1661 if (!$rs->EOF) $arr = $rs->fields; 1662 else $arr = array(); 1663 1480 1664 $rs->Close(); 1481 1665 return $arr; … … 1532 1716 * @return the recordset ($rs->databaseType == 'array') 1533 1717 */ 1534 function &CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false)1718 function CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false) 1535 1719 { 1536 1720 if (!is_numeric($secs2cache)) { … … 1538 1722 if ($offset == -1) $offset = false; 1539 1723 // sql, nrows, offset,inputarr 1540 $rs = &$this->SelectLimit($secs2cache,$sql,$nrows,$offset,$this->cacheSecs);1724 $rs = $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$this->cacheSecs); 1541 1725 } else { 1542 if ($sql === false) ADOConnection::outp( "Warning: \$sql missing from CacheSelectLimit()");1543 $rs = &$this->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);1726 if ($sql === false) $this->outp_throw("Warning: \$sql missing from CacheSelectLimit()",'CacheSelectLimit'); 1727 $rs = $this->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 1544 1728 } 1545 1729 return $rs; … … 1558 1742 function CacheFlush($sql=false,$inputarr=false) 1559 1743 { 1560 global $ADODB_CACHE_DIR; 1561 1562 if ($this->memCache) { 1563 global $ADODB_INCLUDED_MEMCACHE; 1564 1565 $key = false; 1566 if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php'); 1567 if ($sql) $key = $this->_gencachename($sql.serialize($inputarr),false,true); 1568 FlushMemCache($key, $this->memCacheHost, $this->memCachePort, $this->debug); 1569 return; 1570 } 1571 1572 if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) { 1573 /*if (strncmp(PHP_OS,'WIN',3) === 0) 1574 $dir = str_replace('/', '\\', $ADODB_CACHE_DIR); 1575 else */ 1576 $dir = $ADODB_CACHE_DIR; 1577 1578 if ($this->debug) { 1579 ADOConnection::outp( "CacheFlush: $dir<br><pre>\n". $this->_dirFlush($dir)."</pre>"); 1580 } else { 1581 $this->_dirFlush($dir); 1582 } 1583 return; 1584 } 1585 1586 global $ADODB_INCLUDED_CSV; 1587 if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php'); 1588 1589 $f = $this->_gencachename($sql.serialize($inputarr),false); 1590 adodb_write_file($f,''); // is adodb_write_file needed? 1591 if (!@unlink($f)) { 1592 if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f"); 1593 } 1594 } 1744 global $ADODB_CACHE_DIR, $ADODB_CACHE; 1745 1746 if (empty($ADODB_CACHE)) return false; 1747 1748 if (!$sql) { 1749 $ADODB_CACHE->flushall($this->debug); 1750 return; 1751 } 1752 1753 $f = $this->_gencachename($sql.serialize($inputarr),false); 1754 return $ADODB_CACHE->flushcache($f, $this->debug); 1755 } 1595 1756 1596 /**1597 * Private function to erase all of the files and subdirectories in a directory.1598 *1599 * Just specify the directory, and tell it if you want to delete the directory or just clear it out.1600 * Note: $kill_top_level is used internally in the function to flush subdirectories.1601 */1602 function _dirFlush($dir, $kill_top_level = false)1603 {1604 if(!$dh = @opendir($dir)) return;1605 1606 while (($obj = readdir($dh))) {1607 if($obj=='.' || $obj=='..') continue;1608 $f = $dir.'/'.$obj;1609 1610 if (strpos($obj,'.cache')) @unlink($f);1611 if (is_dir($f)) $this->_dirFlush($f, true);1612 }1613 if ($kill_top_level === true) @rmdir($dir);1614 return true;1615 }1616 1617 1618 function xCacheFlush($sql=false,$inputarr=false)1619 {1620 global $ADODB_CACHE_DIR;1621 1622 if ($this->memCache) {1623 global $ADODB_INCLUDED_MEMCACHE;1624 $key = false;1625 if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php');1626 if ($sql) $key = $this->_gencachename($sql.serialize($inputarr),false,true);1627 flushmemCache($key, $this->memCacheHost, $this->memCachePort, $this->debug);1628 return;1629 }1630 1631 if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) {1632 if (strncmp(PHP_OS,'WIN',3) === 0) {1633 $cmd = 'del /s '.str_replace('/','\\',$ADODB_CACHE_DIR).'\adodb_*.cache';1634 } else {1635 //$cmd = 'find "'.$ADODB_CACHE_DIR.'" -type f -maxdepth 1 -print0 | xargs -0 rm -f';1636 $cmd = 'rm -rf '.$ADODB_CACHE_DIR.'/[0-9a-f][0-9a-f]/';1637 // old version 'rm -f `find '.$ADODB_CACHE_DIR.' -name adodb_*.cache`';1638 }1639 if ($this->debug) {1640 ADOConnection::outp( "CacheFlush: $cmd<br><pre>\n", system($cmd),"</pre>");1641 } else {1642 exec($cmd);1643 }1644 return;1645 }1646 1647 global $ADODB_INCLUDED_CSV;1648 if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');1649 1650 $f = $this->_gencachename($sql.serialize($inputarr),false);1651 adodb_write_file($f,''); // is adodb_write_file needed?1652 if (!@unlink($f)) {1653 if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f");1654 }1655 }1656 1757 1657 1758 /** … … 1669 1770 * then we can scale to 12.8 million unique cached recordsets. Wow! 1670 1771 */ 1671 function _gencachename($sql,$createdir,$memcache=false) 1672 { 1673 global $ADODB_CACHE_DIR; 1674 static $notSafeMode; 1772 function _gencachename($sql,$createdir) 1773 { 1774 global $ADODB_CACHE, $ADODB_CACHE_DIR; 1675 1775 1676 1776 if ($this->fetchMode === false) { … … 1681 1781 } 1682 1782 $m = md5($sql.$this->databaseType.$this->database.$this->user.$mode); 1683 if ($memcache) return $m; 1684 1685 if (!isset($notSafeMode)) $notSafeMode = !ini_get('safe_mode'); 1686 $dir = ($notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($m,0,2) : $ADODB_CACHE_DIR; 1687 1688 if ($createdir && $notSafeMode && !file_exists($dir)) { 1689 $oldu = umask(0); 1690 if (!mkdir($dir,0771)) 1691 if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql"); 1692 umask($oldu); 1693 } 1783 if (!$ADODB_CACHE->createdir) return $m; 1784 if (!$createdir) $dir = $ADODB_CACHE->getdirname($m); 1785 else $dir = $ADODB_CACHE->createdir($m, $this->debug); 1786 1694 1787 return $dir.'/adodb_'.$m.'.cache'; 1695 1788 } … … 1705 1798 * @return RecordSet or false 1706 1799 */ 1707 function &CacheExecute($secs2cache,$sql=false,$inputarr=false) 1708 { 1709 1710 1800 function CacheExecute($secs2cache,$sql=false,$inputarr=false) 1801 { 1802 global $ADODB_CACHE; 1803 1804 if (empty($ADODB_CACHE)) $this->_CreateCache(); 1805 1711 1806 if (!is_numeric($secs2cache)) { 1712 1807 $inputarr = $sql; … … 1721 1816 $sqlparam = $sql; 1722 1817 1723 if ($this->memCache) { 1724 global $ADODB_INCLUDED_MEMCACHE; 1725 if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php'); 1726 $md5file = $this->_gencachename($sql.serialize($inputarr),false,true); 1727 } else { 1728 global $ADODB_INCLUDED_CSV; 1729 if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php'); 1730 $md5file = $this->_gencachename($sql.serialize($inputarr),true); 1731 } 1732 1818 1819 $md5file = $this->_gencachename($sql.serialize($inputarr),true); 1733 1820 $err = ''; 1734 1821 1735 1822 if ($secs2cache > 0){ 1736 if ($this->memCache) 1737 $rs = &getmemCache($md5file,$err,$secs2cache, $this->memCacheHost, $this->memCachePort); 1738 else 1739 $rs = &csv2rs($md5file,$err,$secs2cache,$this->arrayClass); 1823 $rs = $ADODB_CACHE->readcache($md5file,$err,$secs2cache,$this->arrayClass); 1740 1824 $this->numCacheHits += 1; 1741 1825 } else { … … 1744 1828 $this->numCacheMisses += 1; 1745 1829 } 1830 1746 1831 if (!$rs) { 1747 1832 // no cached rs found … … 1750 1835 ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :("); 1751 1836 } 1752 if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (see sql below)"); 1753 } 1754 1755 $rs = &$this->Execute($sqlparam,$inputarr); 1756 1757 if ($rs && $this->memCache) { 1758 $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately 1759 if(!putmemCache($md5file, $rs, $this->memCacheHost, $this->memCachePort, $this->memCacheCompress, $this->debug)) { 1760 if ($fn = $this->raiseErrorFn) 1761 $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this); 1762 if ($this->debug) ADOConnection::outp( " Cache write error"); 1763 } 1764 } else 1837 if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (this is a notice and not an error)"); 1838 } 1839 1840 $rs = $this->Execute($sqlparam,$inputarr); 1841 1765 1842 if ($rs) { 1843 1766 1844 $eof = $rs->EOF; 1767 $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately 1845 $rs = $this->_rs2rs($rs); // read entire recordset into memory immediately 1846 $rs->timeCreated = time(); // used by caching 1768 1847 $txt = _rs2serialize($rs,false,$sql); // serialize 1769 1770 if (!adodb_write_file($md5file,$txt,$this->debug)) { 1771 if ($fn = $this->raiseErrorFn) { 1772 $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this); 1848 1849 $ok = $ADODB_CACHE->writecache($md5file,$txt,$this->debug, $secs2cache); 1850 if (!$ok) { 1851 if ($ok === false) { 1852 $em = 'Cache write error'; 1853 $en = -32000; 1854 1855 if ($fn = $this->raiseErrorFn) { 1856 $fn($this->databaseType,'CacheExecute', $en, $em, $md5file,$sql,$this); 1857 } 1858 } else { 1859 $em = 'Cache file locked warning'; 1860 $en = -32001; 1861 // do not call error handling for just a warning 1773 1862 } 1774 if ($this->debug) ADOConnection::outp( " Cache write error"); 1863 1864 if ($this->debug) ADOConnection::outp( " ".$em); 1775 1865 } 1776 1866 if ($rs->EOF && !$eof) { 1777 1867 $rs->MoveFirst(); 1778 //$rs = &csv2rs($md5file,$err);1779 $rs->connection = &$this; // Pablo suggestion1868 //$rs = csv2rs($md5file,$err); 1869 $rs->connection = $this; // Pablo suggestion 1780 1870 } 1781 1871 1782 } else 1783 if (!$this->memCache) 1784 @unlink($md5file); 1872 } else if (!$this->memCache) 1873 $ADODB_CACHE->flushcache($md5file); 1785 1874 } else { 1786 1875 $this->_errorMsg = ''; … … 1792 1881 } 1793 1882 // ok, set cached object found 1794 $rs->connection = &$this; // Pablo suggestion1795 if ($this->debug){ 1796 1883 $rs->connection = $this; // Pablo suggestion 1884 if ($this->debug){ 1885 if ($this->debug == 99) adodb_backtrace(); 1797 1886 $inBrowser = isset($_SERVER['HTTP_USER_AGENT']); 1798 1887 $ttl = $rs->timeCreated + $secs2cache - time(); … … 1814 1903 $forceUpdate means that even if the data has not changed, perform update. 1815 1904 */ 1816 function &AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false)1905 function AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false) 1817 1906 { 1818 1907 $false = false; … … 1820 1909 if ($where!==FALSE) $sql .= ' WHERE '.$where; 1821 1910 else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) { 1822 ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause');1911 $this->outp_throw('AutoExecute: Illegal mode=UPDATE with empty WHERE clause','AutoExecute'); 1823 1912 return $false; 1824 1913 } 1825 1914 1826 $rs = &$this->SelectLimit($sql,1);1915 $rs = $this->SelectLimit($sql,1); 1827 1916 if (!$rs) return $false; // table does not exist 1828 1917 $rs->tableName = $table; 1918 $rs->sql = $sql; 1829 1919 1830 1920 switch((string) $mode) { … … 1838 1928 break; 1839 1929 default: 1840 ADOConnection::outp("AutoExecute: Unknown mode=$mode");1930 $this->outp_throw("AutoExecute: Unknown mode=$mode",'AutoExecute'); 1841 1931 return $false; 1842 1932 } … … 1997 2087 $rsclass = $this->rsPrefix.$this->databaseType; 1998 2088 $this->_metars = new $rsclass(false,$this->fetchMode); 1999 $this->_metars->connection = &$this;2089 $this->_metars->connection = $this; 2000 2090 } 2001 2091 return $this->_metars->MetaType($t,$len,$fieldobj); … … 2043 2133 } 2044 2134 2045 function &GetActiveRecordsClass($class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false) 2135 /** 2136 * GetActiveRecordsClass Performs an 'ALL' query 2137 * 2138 * @param mixed $class This string represents the class of the current active record 2139 * @param mixed $table Table used by the active record object 2140 * @param mixed $whereOrderBy Where, order, by clauses 2141 * @param mixed $bindarr 2142 * @param mixed $primkeyArr 2143 * @param array $extra Query extras: limit, offset... 2144 * @param mixed $relations Associative array: table's foreign name, "hasMany", "belongsTo" 2145 * @access public 2146 * @return void 2147 */ 2148 function GetActiveRecordsClass( 2149 $class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false, 2150 $extra=array(), 2151 $relations=array()) 2046 2152 { 2047 2153 global $_ADODB_ACTIVE_DBS; 2048 2049 $save = $this->SetFetchMode(ADODB_FETCH_NUM); 2050 if (empty($whereOrderBy)) $whereOrderBy = '1=1'; 2051 $rows = $this->GetAll("select * from ".$table.' WHERE '.$whereOrderBy,$bindarr); 2052 $this->SetFetchMode($save); 2053 2054 $false = false; 2055 2056 if ($rows === false) { 2057 return $false; 2058 } 2059 2060 2061 if (!isset($_ADODB_ACTIVE_DBS)) { 2062 include(ADODB_DIR.'/adodb-active-record.inc.php'); 2063 } 2064 if (!class_exists($class)) { 2065 ADOConnection::outp("Unknown class $class in GetActiveRcordsClass()"); 2066 return $false; 2067 } 2068 $arr = array(); 2069 foreach($rows as $row) { 2070 2071 $obj = new $class($table,$primkeyArr,$this); 2072 if ($obj->ErrorMsg()){ 2073 $this->_errorMsg = $obj->ErrorMsg(); 2074 return $false; 2075 } 2076 $obj->Set($row); 2077 $arr[] = $obj; 2078 } 2079 return $arr; 2080 } 2081 2082 function &GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false) 2083 { 2084 $arr =& $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr); 2154 ## reduce overhead of adodb.inc.php -- moved to adodb-active-record.inc.php 2155 ## if adodb-active-recordx is loaded -- should be no issue as they will probably use Find() 2156 if (!isset($_ADODB_ACTIVE_DBS))include_once(ADODB_DIR.'/adodb-active-record.inc.php'); 2157 return adodb_GetActiveRecordsClass($this, $class, $table, $whereOrderBy, $bindarr, $primkeyArr, $extra, $relations); 2158 } 2159 2160 function GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false) 2161 { 2162 $arr = $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr); 2085 2163 return $arr; 2086 2164 } … … 2205 2283 } 2206 2284 2285 /** 2286 * List procedures or functions in an array. 2287 * @param procedureNamePattern a procedure name pattern; must match the procedure name as it is stored in the database 2288 * @param catalog a catalog name; must match the catalog name as it is stored in the database; 2289 * @param schemaPattern a schema name pattern; 2290 * 2291 * @return array of procedures on current database. 2292 2293 Array ( 2294 [name_of_procedure] => Array 2295 ( 2296 [type] => PROCEDURE or FUNCTION 2297 [catalog] => Catalog_name 2298 [schema] => Schema_name 2299 [remarks] => explanatory comment on the procedure 2300 ) 2301 ) 2302 */ 2303 function MetaProcedures($procedureNamePattern = null, $catalog = null, $schemaPattern = null) 2304 { 2305 return false; 2306 } 2307 2207 2308 2208 2309 /** … … 2216 2317 * @return array of tables for current database. 2217 2318 */ 2218 function &MetaTables($ttype=false,$showSchema=false,$mask=false)2319 function MetaTables($ttype=false,$showSchema=false,$mask=false) 2219 2320 { 2220 2321 global $ADODB_FETCH_MODE; … … 2236 2337 2237 2338 if ($rs === false) return $false; 2238 $arr = &$rs->GetArray();2339 $arr = $rs->GetArray(); 2239 2340 $arr2 = array(); 2240 2341 … … 2278 2379 * @return array of ADOFieldObjects for current table. 2279 2380 */ 2280 function &MetaColumns($table,$normalize=true)2381 function MetaColumns($table,$normalize=true) 2281 2382 { 2282 2383 global $ADODB_FETCH_MODE; … … 2337 2438 ) 2338 2439 */ 2339 function &MetaIndexes($table, $primary = false, $owner = false)2440 function MetaIndexes($table, $primary = false, $owner = false) 2340 2441 { 2341 2442 $false = false; … … 2349 2450 * @return array of column names for current table. 2350 2451 */ 2351 function &MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */)2352 { 2353 $objarr = &$this->MetaColumns($table);2452 function MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */) 2453 { 2454 $objarr = $this->MetaColumns($table); 2354 2455 if (!is_array($objarr)) { 2355 2456 $false = false; … … 2395 2496 * @return date string in database date format 2396 2497 */ 2397 function DBDate($d )2498 function DBDate($d, $isfld=false) 2398 2499 { 2399 2500 if (empty($d) && $d !== 0) return 'null'; 2400 2501 if ($isfld) return $d; 2502 2503 if (is_object($d)) return $d->format($this->fmtDate); 2504 2505 2401 2506 if (is_string($d) && !is_numeric($d)) { 2402 if ($d === 'null' || strncmp($d,"'",1) === 0) return $d; 2507 if ($d === 'null') return $d; 2508 if (strncmp($d,"'",1) === 0) { 2509 $d = _adodb_safedateq($d); 2510 return $d; 2511 } 2403 2512 if ($this->isoDates) return "'$d'"; 2404 2513 $d = ADOConnection::UnixDate($d); … … 2432 2541 * @return timestamp string in database timestamp format 2433 2542 */ 2434 function DBTimeStamp($ts )2543 function DBTimeStamp($ts,$isfld=false) 2435 2544 { 2436 2545 if (empty($ts) && $ts !== 0) return 'null'; 2437 2546 if ($isfld) return $ts; 2547 if (is_object($ts)) return $ts->format($this->fmtTimeStamp); 2548 2438 2549 # strlen(14) allows YYYYMMDDHHMMSS format 2439 2550 if (!is_string($ts) || (is_numeric($ts) && strlen($ts)<14)) … … 2441 2552 2442 2553 if ($ts === 'null') return $ts; 2443 if ($this->isoDates && strlen($ts) !== 14) return "'$ts'"; 2444 2554 if ($this->isoDates && strlen($ts) !== 14) { 2555 $ts = _adodb_safedate($ts); 2556 return "'$ts'"; 2557 } 2445 2558 $ts = ADOConnection::UnixTimeStamp($ts); 2446 2559 return adodb_date($this->fmtTimeStamp,$ts); … … 2453 2566 * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format 2454 2567 */ 2455 function UnixDate($v)2568 static function UnixDate($v) 2456 2569 { 2457 2570 if (is_object($v)) { … … 2477 2590 * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format 2478 2591 */ 2479 function UnixTimeStamp($v)2592 static function UnixTimeStamp($v) 2480 2593 { 2481 2594 if (is_object($v)) { … … 2563 2676 $s = str_replace('\\"','"',$s); 2564 2677 2565 if ($this->replaceQuote == "\\'" ) // ' already quoted, no need to change anything2678 if ($this->replaceQuote == "\\'" || ini_get('magic_quotes_sybase')) // ' already quoted, no need to change anything 2566 2679 return $s; 2567 2680 else {// change \' to '' for sybase/mssql … … 2597 2710 $s = str_replace('\\"','"',$s); 2598 2711 2599 if ($this->replaceQuote == "\\'" ) // ' already quoted, no need to change anything2712 if ($this->replaceQuote == "\\'" || ini_get('magic_quotes_sybase')) // ' already quoted, no need to change anything 2600 2713 return "'$s'"; 2601 2714 else {// change \' to '' for sybase/mssql … … 2623 2736 * 2624 2737 */ 2625 function &PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0)2738 function PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0) 2626 2739 { 2627 2740 global $ADODB_INCLUDED_LIB; 2628 2741 if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); 2629 if ($this->pageExecuteCountRows) $rs = &_adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache);2630 else $rs = &_adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache);2742 if ($this->pageExecuteCountRows) $rs = _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache); 2743 else $rs = _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache); 2631 2744 return $rs; 2632 2745 } … … 2645 2758 * @return the recordset ($rs->databaseType == 'array') 2646 2759 */ 2647 function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false)2760 function CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false) 2648 2761 { 2649 2762 /*switch($this->dataProvider) { … … 2653 2766 default: $secs2cache = 0; break; 2654 2767 }*/ 2655 $rs = &$this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache);2768 $rs = $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache); 2656 2769 return $rs; 2657 2770 } … … 2675 2788 //============================================================================================== 2676 2789 2790 class ADODB_Iterator_empty implements Iterator { 2791 2792 private $rs; 2793 2794 function __construct($rs) 2795 { 2796 $this->rs = $rs; 2797 } 2798 function rewind() 2799 { 2800 } 2801 2802 function valid() 2803 { 2804 return !$this->rs->EOF; 2805 } 2806 2807 function key() 2808 { 2809 return false; 2810 } 2811 2812 function current() 2813 { 2814 return false; 2815 } 2816 2817 function next() 2818 { 2819 } 2820 2821 function __call($func, $params) 2822 { 2823 return call_user_func_array(array($this->rs, $func), $params); 2824 } 2825 2826 function hasMore() 2827 { 2828 return false; 2829 } 2830 2831 } 2832 2833 2677 2834 /** 2678 2835 * Lightweight recordset when there are no records to be returned 2679 2836 */ 2680 class ADORecordSet_empty 2837 class ADORecordSet_empty implements IteratorAggregate 2681 2838 { 2682 2839 var $dataProvider = 'empty'; … … 2693 2850 function FieldCount(){ return 0;} 2694 2851 function Init() {} 2852 function getIterator() {return new ADODB_Iterator_empty($this);} 2853 function GetAssoc() {return array();} 2695 2854 } 2696 2855 … … 2704 2863 //============================================================================================== 2705 2864 2706 if (PHP_VERSION < 5) include_once(ADODB_DIR.'/adodb-php4.inc.php'); 2707 else include_once(ADODB_DIR.'/adodb-iterator.inc.php'); 2865 class ADODB_Iterator implements Iterator { 2866 2867 private $rs; 2868 2869 function __construct($rs) 2870 { 2871 $this->rs = $rs; 2872 } 2873 function rewind() 2874 { 2875 $this->rs->MoveFirst(); 2876 } 2877 2878 function valid() 2879 { 2880 return !$this->rs->EOF; 2881 } 2882 2883 function key() 2884 { 2885 return $this->rs->_currentRow; 2886 } 2887 2888 function current() 2889 { 2890 return $this->rs->fields; 2891 } 2892 2893 function next() 2894 { 2895 $this->rs->MoveNext(); 2896 } 2897 2898 function __call($func, $params) 2899 { 2900 return call_user_func_array(array($this->rs, $func), $params); 2901 } 2902 2903 2904 function hasMore() 2905 { 2906 return !$this->rs->EOF; 2907 } 2908 2909 } 2910 2911 2912 2708 2913 /** 2709 2914 * RecordSet class that represents the dataset returned by the database. … … 2712 2917 * means recordcount not known). 2713 2918 */ 2714 class ADORecordSet extends ADODB_BASE_RS{2919 class ADORecordSet implements IteratorAggregate { 2715 2920 /* 2716 2921 * public variables … … 2762 2967 } 2763 2968 2969 function getIterator() 2970 { 2971 return new ADODB_Iterator($this); 2972 } 2973 2974 /* this is experimental - i don't really know what to return... */ 2975 function __toString() 2976 { 2977 include_once(ADODB_DIR.'/toexport.inc.php'); 2978 return _adodb_export($this,',',',',false,true); 2979 } 2764 2980 2765 2981 … … 2848 3064 * @return an array indexed by the rows (0-based) from the recordset 2849 3065 */ 2850 function &GetArray($nRows = -1)3066 function GetArray($nRows = -1) 2851 3067 { 2852 3068 global $ADODB_EXTENSION; if ($ADODB_EXTENSION) { … … 2864 3080 } 2865 3081 2866 function &GetAll($nRows = -1)2867 { 2868 $arr = &$this->GetArray($nRows);3082 function GetAll($nRows = -1) 3083 { 3084 $arr = $this->GetArray($nRows); 2869 3085 return $arr; 2870 3086 } … … 2888 3104 * @return an array indexed by the rows (0-based) from the recordset 2889 3105 */ 2890 function &GetArrayLimit($nrows,$offset=-1)3106 function GetArrayLimit($nrows,$offset=-1) 2891 3107 { 2892 3108 if ($offset <= 0) { 2893 $arr = &$this->GetArray($nrows);3109 $arr = $this->GetArray($nrows); 2894 3110 return $arr; 2895 3111 } … … 2915 3131 * @return an array indexed by the rows (0-based) from the recordset 2916 3132 */ 2917 function &GetRows($nRows = -1)2918 { 2919 $arr = &$this->GetArray($nRows);3133 function GetRows($nRows = -1) 3134 { 3135 $arr = $this->GetArray($nRows); 2920 3136 return $arr; 2921 3137 } … … 2937 3153 * or false if the data has less than 2 cols. 2938 3154 */ 2939 function &GetAssoc($force_array = false, $first2cols = false)3155 function GetAssoc($force_array = false, $first2cols = false) 2940 3156 { 2941 3157 global $ADODB_EXTENSION; … … 2946 3162 return $false; 2947 3163 } 2948 $numIndex = isset($this->fields[0]) ;3164 $numIndex = isset($this->fields[0]) && isset($this->fields[1]); 2949 3165 $results = array(); 2950 3166 … … 3028 3244 } 3029 3245 3030 $ref = &$results; # workaround accelerator incompat with PHP 4.4 :(3246 $ref = $results; # workaround accelerator incompat with PHP 4.4 :( 3031 3247 return $ref; 3032 3248 } … … 3074 3290 * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format 3075 3291 */ 3076 function UnixDate($v)3292 static function UnixDate($v) 3077 3293 { 3078 3294 return ADOConnection::UnixDate($v); … … 3085 3301 * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format 3086 3302 */ 3087 function UnixTimeStamp($v)3303 static function UnixTimeStamp($v) 3088 3304 { 3089 3305 return ADOConnection::UnixTimeStamp($v); … … 3123 3339 * @return false or array containing the current record 3124 3340 */ 3125 function &FetchRow()3341 function FetchRow() 3126 3342 { 3127 3343 if ($this->EOF) { … … 3287 3503 * $upper 0 = lowercase, 1 = uppercase, 2 = whatever is returned by FetchField 3288 3504 */ 3289 function &GetRowAssoc($upper=1)3505 function GetRowAssoc($upper=1) 3290 3506 { 3291 3507 $record = array(); 3292 // if (!$this->fields) return $record; 3293 3294 if (!$this->bind) { 3508 if (!$this->bind) { 3295 3509 $this->GetAssocKeys($upper); 3296 3510 } 3297 3298 3511 foreach($this->bind as $k => $v) { 3299 $record[$k] = $this->fields[$v]; 3300 } 3301 3512 if( isset( $this->fields[$v] ) ) { 3513 $record[$k] = $this->fields[$v]; 3514 } else if (isset($this->fields[$k])) { 3515 $record[$k] = $this->fields[$k]; 3516 } else 3517 $record[$k] = $this->fields[$v]; 3518 } 3302 3519 return $record; 3303 3520 } 3304 3305 3521 3306 3522 /** … … 3361 3577 IF ($table) { 3362 3578 if ($condition) $condition = " WHERE " . $condition; 3363 $resultrows = &$this->connection->Execute("SELECT COUNT(*) FROM $table $condition");3579 $resultrows = $this->connection->Execute("SELECT COUNT(*) FROM $table $condition"); 3364 3580 if ($resultrows) $lnumrows = reset($resultrows->fields); 3365 3581 } … … 3395 3611 * @return the ADOFieldObject for that column, or false. 3396 3612 */ 3397 function &FetchField($fieldoffset = -1)3613 function FetchField($fieldoffset = -1) 3398 3614 { 3399 3615 // must be defined by child class … … 3407 3623 * 3408 3624 */ 3409 function &FieldTypesArray()3625 function FieldTypesArray() 3410 3626 { 3411 3627 $arr = array(); … … 3421 3637 * @return the object with the properties set to the fields of the current row 3422 3638 */ 3423 function &FetchObj()3424 { 3425 $o = &$this->FetchObject(false);3639 function FetchObj() 3640 { 3641 $o = $this->FetchObject(false); 3426 3642 return $o; 3427 3643 } … … 3435 3651 * @return the object with the properties set to the fields of the current row 3436 3652 */ 3437 function &FetchObject($isupper=true)3653 function FetchObject($isupper=true) 3438 3654 { 3439 3655 if (empty($this->_obj)) { … … 3468 3684 * Fixed bug reported by tim@orotech.net 3469 3685 */ 3470 function &FetchNextObj()3471 { 3472 $o = &$this->FetchNextObject(false);3686 function FetchNextObj() 3687 { 3688 $o = $this->FetchNextObject(false); 3473 3689 return $o; 3474 3690 } … … 3486 3702 * Fixed bug reported by tim@orotech.net 3487 3703 */ 3488 function &FetchNextObject($isupper=true)3704 function FetchNextObject($isupper=true) 3489 3705 { 3490 3706 $o = false; … … 3543 3759 'INTERVAL' => 'C', # Postgres 3544 3760 'MACADDR' => 'C', # postgres 3761 'VAR_STRING' => 'C', # mysql 3545 3762 ## 3546 3763 'LONGCHAR' => 'X', … … 3566 3783 'UNIQUEIDENTIFIER' => 'C', # MS SQL Server 3567 3784 ## 3785 'SMALLDATETIME' => 'T', 3568 3786 'TIME' => 'T', 3569 3787 'TIMESTAMP' => 'T', … … 3757 3975 3758 3976 $this->_skiprow1 = false; 3759 $this->_array = &$newarr;3977 $this->_array = $newarr; 3760 3978 $this->_colnames = $hdr; 3761 3979 … … 3811 4029 function InitArrayFields(&$array,&$fieldarr) 3812 4030 { 3813 $this->_array = &$array;4031 $this->_array = $array; 3814 4032 $this->_skiprow1= false; 3815 4033 if ($fieldarr) { 3816 $this->_fieldobjects = &$fieldarr;4034 $this->_fieldobjects = $fieldarr; 3817 4035 } 3818 4036 $this->Init(); 3819 4037 } 3820 4038 3821 function &GetArray($nRows=-1)4039 function GetArray($nRows=-1) 3822 4040 { 3823 4041 if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) { 3824 4042 return $this->_array; 3825 4043 } else { 3826 $arr = &ADORecordSet::GetArray($nRows);4044 $arr = ADORecordSet::GetArray($nRows); 3827 4045 return $arr; 3828 4046 } … … 3844 4062 3845 4063 if ($mode & ADODB_FETCH_ASSOC) { 3846 if (!isset($this->fields[$colname]) ) $colname = strtolower($colname);4064 if (!isset($this->fields[$colname]) && !is_null($this->fields[$colname])) $colname = strtolower($colname); 3847 4065 return $this->fields[$colname]; 3848 4066 } … … 3857 4075 } 3858 4076 3859 function &FetchField($fieldOffset = -1)4077 function FetchField($fieldOffset = -1) 3860 4078 { 3861 4079 if (isset($this->_fieldobjects)) { … … 3972 4190 * synonym for ADONewConnection for people like me who cannot remember the correct name 3973 4191 */ 3974 function &NewADOConnection($db='')3975 { 3976 $tmp = &ADONewConnection($db);4192 function NewADOConnection($db='') 4193 { 4194 $tmp = ADONewConnection($db); 3977 4195 return $tmp; 3978 4196 } … … 3986 4204 * @return the freshly created instance of the Connection class. 3987 4205 */ 3988 function &ADONewConnection($db='')4206 function ADONewConnection($db='') 3989 4207 { 3990 4208 GLOBAL $ADODB_NEWCONNECTION, $ADODB_LASTDB; … … 3993 4211 $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false; 3994 4212 $false = false; 3995 if ( $at = strpos($db,'://')) {4213 if (($at = strpos($db,'://')) !== FALSE) { 3996 4214 $origdsn = $db; 3997 if (PHP_VERSION < 5) $dsna = @parse_url($db); 3998 else { 3999 $fakedsn = 'fake'.substr($db,$at); 4215 $fakedsn = 'fake'.substr($origdsn,$at); 4216 if (($at2 = strpos($origdsn,'@/')) !== FALSE) { 4217 // special handling of oracle, which might not have host 4218 $fakedsn = str_replace('@/','@adodb-fakehost/',$fakedsn); 4219 } 4220 4221 if ((strpos($origdsn, 'sqlite')) !== FALSE && stripos($origdsn, '%2F') === FALSE) { 4222 // special handling for SQLite, it only might have the path to the database file. 4223 // If you try to connect to a SQLite database using a dsn like 'sqlite:///path/to/database', the 'parse_url' php function 4224 // will throw you an exception with a message such as "unable to parse url" 4225 list($scheme, $path) = explode('://', $origdsn); 4226 $dsna['scheme'] = $scheme; 4227 if ($qmark = strpos($path,'?')) { 4228 $dsn['query'] = substr($path,$qmark+1); 4229 $path = substr($path,0,$qmark); 4230 } 4231 $dsna['path'] = '/' . urlencode($path); 4232 } else 4000 4233 $dsna = @parse_url($fakedsn); 4001 $dsna['scheme'] = substr($db,0,$at); 4002 4003 if (strncmp($db,'pdo',3) == 0) { 4004 $sch = explode('_',$dsna['scheme']); 4005 if (sizeof($sch)>1) { 4006 $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : ''; 4234 4235 if (!$dsna) { 4236 return $false; 4237 } 4238 $dsna['scheme'] = substr($origdsn,0,$at); 4239 if ($at2 !== FALSE) { 4240 $dsna['host'] = ''; 4241 } 4242 4243 if (strncmp($origdsn,'pdo',3) == 0) { 4244 $sch = explode('_',$dsna['scheme']); 4245 if (sizeof($sch)>1) { 4246 4247 $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : ''; 4248 if ($sch[1] == 'sqlite') 4249 $dsna['host'] = rawurlencode($sch[1].':'.rawurldecode($dsna['host'])); 4250 else 4007 4251 $dsna['host'] = rawurlencode($sch[1].':host='.rawurldecode($dsna['host'])); 4008 $dsna['scheme'] = 'pdo'; 4009 } 4252 $dsna['scheme'] = 'pdo'; 4010 4253 } 4011 4254 } 4012 4255 4013 if (!$dsna) {4014 // special handling of oracle, which might not have host4015 $db = str_replace('@/','@adodb-fakehost/',$db);4016 $dsna = parse_url($db);4017 if (!$dsna) return $false;4018 $dsna['host'] = '';4019 }4020 4256 $db = @$dsna['scheme']; 4021 4257 if (!$db) return $false; … … 4045 4281 $obj = $ADODB_NEWCONNECTION($db); 4046 4282 4047 } else { 4283 } 4284 4285 if(empty($obj)) { 4048 4286 4049 4287 if (!isset($ADODB_LASTDB)) $ADODB_LASTDB = ''; … … 4103 4341 #oci8 4104 4342 case 'nls_date_format': $obj->NLS_DATE_FORMAT = $v; break; 4343 case 'cachesecs': $obj->cacheSecs = $v; break; 4344 case 'memcache': 4345 $varr = explode(':',$v); 4346 $vlen = sizeof($varr); 4347 if ($vlen == 0) break; 4348 $obj->memCache = true; 4349 $obj->memCacheHost = explode(',',$varr[0]); 4350 if ($vlen == 1) break; 4351 $obj->memCachePort = $varr[1]; 4352 if ($vlen == 2) break; 4353 $obj->memCacheCompress = $varr[2] ? true : false; 4354 break; 4105 4355 } 4106 4356 } … … 4153 4403 } 4154 4404 4155 function &NewPerfMonitor(&$conn)4405 function NewPerfMonitor(&$conn) 4156 4406 { 4157 4407 $false = false; … … 4167 4417 } 4168 4418 4169 function &NewDataDictionary(&$conn,$drivername=false)4419 function NewDataDictionary(&$conn,$drivername=false) 4170 4420 { 4171 4421 $false = false; … … 4184 4434 $dict = new $class(); 4185 4435 $dict->dataProvider = $conn->dataProvider; 4186 $dict->connection = &$conn;4436 $dict->connection = $conn; 4187 4437 $dict->upperName = strtoupper($drivername); 4188 4438 $dict->quote = $conn->nameQuote; … … 4220 4470 @param levels Number of levels to display 4221 4471 */ 4222 function adodb_backtrace($printOrArr=true,$levels=9999 )4472 function adodb_backtrace($printOrArr=true,$levels=9999,$ishtml=null) 4223 4473 { 4224 4474 global $ADODB_INCLUDED_LIB; 4225 4475 if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); 4226 return _adodb_backtrace($printOrArr,$levels );4476 return _adodb_backtrace($printOrArr,$levels,0,$ishtml); 4227 4477 } 4228 4478
Note: See TracChangeset
for help on using the changeset viewer.