Documentation TYPO3 par Ameos |
00001 <?php 00002 /* 00003 V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. 00004 Released under both BSD license and Lesser GPL library license. 00005 Whenever there is any discrepancy between the two licenses, 00006 the BSD license will take precedence. 00007 Set tabs to 4 for best viewing. 00008 00009 Latest version is available at http://adodb.sourceforge.net 00010 */ 00011 00012 error_reporting(E_ALL); 00013 00014 $ADODB_FLUSH = true; 00015 00016 define('ADODB_ASSOC_CASE',0); 00017 00018 00019 function getmicrotime() 00020 { 00021 $t = microtime(); 00022 $t = explode(' ',$t); 00023 return (float)$t[1]+ (float)$t[0]; 00024 } 00025 00026 00027 if (PHP_VERSION < 5) include_once('../adodb-pear.inc.php'); 00028 //-------------------------------------------------------------------------------------- 00029 //define('ADODB_ASSOC_CASE',1); 00030 // 00031 function Err($msg) 00032 { 00033 print "<b>$msg</b><br>"; 00034 flush(); 00035 } 00036 00037 function CheckWS($conn) 00038 { 00039 global $ADODB_EXTENSION; 00040 00041 include_once('../session/adodb-session.php'); 00042 if (defined('CHECKWSFAIL')){ echo " TESTING $conn ";flush();} 00043 $saved = $ADODB_EXTENSION; 00044 $db = ADONewConnection($conn); 00045 $ADODB_EXTENSION = $saved; 00046 if (headers_sent()) { 00047 print "<p><b>White space detected in adodb-$conn.inc.php or include file...</b></p>"; 00048 //die(); 00049 } 00050 } 00051 00052 function do_strtolower(&$arr) 00053 { 00054 foreach($arr as $k => $v) { 00055 if (is_object($v)) $arr[$k] = adodb_pr($v,true); 00056 else $arr[$k] = strtolower($v); 00057 } 00058 } 00059 00060 00061 function CountExecs($db, $sql, $inputarray) 00062 { 00063 global $EXECS; $EXECS++; 00064 } 00065 00066 function CountCachedExecs($db, $secs2cache, $sql, $inputarray) 00067 { 00068 global $CACHED; $CACHED++; 00069 } 00070 00071 // the table creation code is specific to the database, so we allow the user 00072 // to define their own table creation stuff 00073 00074 function testdb(&$db,$createtab="create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)") 00075 { 00076 GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE,$ADODB_COUNTRECS; 00077 00078 //adodb_pr($db); 00079 00080 ?> <form method=GET> 00081 </p> 00082 <table width=100% ><tr><td bgcolor=beige> </td></tr></table> 00083 </p> 00084 <?php 00085 $create =false; 00086 /*$ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00087 00088 $rs = $db->Execute('select lastname,firstname,lastname,id from adoxyz'); 00089 $arr = $rs->GetAssoc(); 00090 echo "<pre>";print_r($arr); 00091 die();*/ 00092 00093 if (!$db) die("testdb: database not inited"); 00094 GLOBAL $EXECS, $CACHED; 00095 00096 $EXECS = 0; 00097 $CACHED = 0; 00098 //$db->Execute("drop table adodb_logsql"); 00099 if ((rand()%3) == 0) @$db->Execute("delete from adodb_logsql"); 00100 $db->debug=1; 00101 00102 $db->fnExecute = 'CountExecs'; 00103 $db->fnCacheExecute = 'CountCachedExecs'; 00104 00105 if (empty($_GET['nolog'])) { 00106 echo "<h3>SQL Logging enabled</h3>"; 00107 $db->LogSQL();/* 00108 $sql = 00109 "SELECT t1.sid, t1.sid, t1.title, t1.hometext, t1.notes, t1.aid, t1.informant, 00110 t2.url, t2.email, t1.catid, t3.title, t1.topic, t4.topicname, t4.topicimage, 00111 t4.topictext, t1.score, t1.ratings, t1.counter, t1.comments, t1.acomm 00112 FROM `nuke_stories` `t1`, `nuke_authors` `t2`, `nuke_stories_cat` `t3`, `nuke_topics` `t4` 00113 WHERE ((t2.aid=t1.aid) AND (t3.catid=t1.catid) AND (t4.topicid=t1.topic) 00114 AND ((t1.alanguage='german') OR (t1.alanguage='')) AND (t1.ihome='0')) 00115 ORDER BY t1.time DESC"; 00116 $db->SelectLimit($sql); 00117 echo $db->ErrorMsg();*/ 00118 } 00119 $ADODB_CACHE_DIR = dirname(TempNam('/tmp','testadodb')); 00120 $db->debug = false; 00121 //print $db->UnixTimeStamp('2003-7-22 23:00:00'); 00122 00123 $phpv = phpversion(); 00124 if (defined('ADODB_EXTENSION')) $ext = ' Extension '.ADODB_EXTENSION.' installed'; 00125 else $ext = ''; 00126 print "<h3>ADODB Version: $ADODB_vers Host: <i>$db->host</i> Database: <i>$db->database</i> PHP: $phpv $ext</h3>"; 00127 flush(); 00128 00129 00130 $arr = $db->ServerInfo(); 00131 print_r($arr); 00132 echo "<br>"; 00133 $e = error_reporting(E_ALL-E_WARNING); 00134 flush(); 00135 #$db->debug=1; 00136 $tt = $db->Time(); 00137 if ($tt == 0) echo '<br><b>$db->Time failed</b>'; 00138 else echo "<br>db->Time: ".date('d-m-Y H:i:s',$tt); 00139 echo '<br>'; 00140 00141 echo "Date=",$db->UserDate('2002-04-07'),'<br>'; 00142 print "<i>date1</i> (1969-02-20) = ".$db->DBDate('1969-2-20'); 00143 print "<br><i>date1</i> (1999-02-20) = ".$db->DBDate('1999-2-20'); 00144 print "<br><i>date1.1</i> 1999 = ".$db->DBDate("'1999'"); 00145 print "<br><i>date2</i> (1970-1-2) = ".$db->DBDate(24*3600)."<p>"; 00146 print "<i>ts1</i> (1999-02-20 13:40:50) = ".$db->DBTimeStamp('1999-2-20 1:40:50 pm'); 00147 print "<br><i>ts1.1</i> (1999-02-20 13:40:00) = ".$db->DBTimeStamp('1999-2-20 13:40'); 00148 print "<br><i>ts2</i> (1999-02-20) = ".$db->DBTimeStamp('1999-2-20'); 00149 print "<br><i>ts3</i> (1970-1-2 +/- timezone) = ".$db->DBTimeStamp(24*3600); 00150 print "<br> Fractional TS (1999-2-20 13:40:50.91): ".$db->DBTimeStamp($db->UnixTimeStamp('1999-2-20 13:40:50.91+1')); 00151 $dd = $db->UnixDate('1999-02-20'); 00152 print "<br>unixdate</i> 1999-02-20 = ".date('Y-m-d',$dd)."<p>"; 00153 print "<br><i>ts4</i> =".($db->UnixTimeStamp("19700101000101")+8*3600); 00154 print "<br><i>ts5</i> =".$db->DBTimeStamp($db->UnixTimeStamp("20040110092123")); 00155 print "<br><i>ts6</i> =".$db->UserTimeStamp("20040110092123"); 00156 print "<br><i>ts7</i> =".$db->DBTimeStamp("20040110092123"); 00157 flush(); 00158 // mssql too slow in failing bad connection 00159 if (false && $db->databaseType != 'mssql') { 00160 print "<p>Testing bad connection. Ignore following error msgs:<br>"; 00161 $db2 = ADONewConnection(); 00162 $rez = $db2->Connect("bad connection"); 00163 $err = $db2->ErrorMsg(); 00164 print "<i>Error='$err'</i></p>"; 00165 if ($rez) print "<b>Cannot check if connection failed.</b> The Connect() function returned true.</p>"; 00166 } 00167 error_reporting($e); 00168 flush(); 00169 00170 //$ADODB_COUNTRECS=false; 00171 $rs=$db->Execute('select * from adoxyz order by id'); 00172 if($rs === false) $create = true; 00173 else $rs->Close(); 00174 00175 //if ($db->databaseType !='vfp') $db->Execute("drop table ADOXYZ"); 00176 00177 if ($create) { 00178 if (false && $db->databaseType == 'ibase') { 00179 print "<b>Please create the following table for testing:</b></p>$createtab</p>"; 00180 return; 00181 } else { 00182 $db->debug = 99; 00183 $e = error_reporting(E_ALL-E_WARNING); 00184 $db->Execute($createtab); 00185 error_reporting($e); 00186 } 00187 } 00188 error_reporting(E_ALL); 00189 echo "<p>Testing Metatypes</p>"; 00190 $t = $db->MetaType('varchar'); 00191 if ($t != 'C') Err("Bad Metatype for varchar"); 00192 00193 $rs = &$db->Execute("delete from ADOXYZ"); // some ODBC drivers will fail the drop so we delete 00194 if ($rs) { 00195 if(! $rs->EOF) print "<b>Error: </b>RecordSet returned by Execute('delete...') should show EOF</p>"; 00196 $rs->Close(); 00197 } else print "err=".$db->ErrorMsg(); 00198 00199 print "<p>Test select on empty table, FetchField when EOF, and GetInsertSQL</p>"; 00200 $rs = &$db->Execute("select id,firstname from ADOXYZ where id=9999"); 00201 if ($rs && !$rs->EOF) print "<b>Error: </b>RecordSet returned by Execute(select...') on empty table should show EOF</p>"; 00202 if ($rs->EOF && (($ox = $rs->FetchField(0)) && !empty($ox->name))) { 00203 $record['id'] = 99; 00204 $record['firstname'] = 'John'; 00205 $sql = $db->GetInsertSQL($rs, $record); 00206 if (strtoupper($sql) != strtoupper("INSERT INTO ADOXYZ ( id, firstname ) VALUES ( 99, 'John' )")) Err("GetInsertSQL does not work on empty table: $sql"); 00207 } else { 00208 Err("FetchField does not work on empty recordset, meaning GetInsertSQL will fail..."); 00209 } 00210 if ($rs) $rs->Close(); 00211 flush(); 00212 //$db->debug=true; 00213 print "<p>Testing Commit: "; 00214 $time = $db->DBDate(time()); 00215 if (!$db->BeginTrans()) { 00216 print '<b>Transactions not supported</b></p>'; 00217 if ($db->hasTransactions) Err("hasTransactions should be false"); 00218 } else { /* COMMIT */ 00219 if (!$db->hasTransactions) Err("hasTransactions should be true"); 00220 if ($db->transCnt != 1) Err("Invalid transCnt = $db->transCnt (should be 1)"); 00221 $rs = $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (99,'Should Not','Exist (Commit)',$time)"); 00222 if ($rs && $db->CommitTrans()) { 00223 $rs->Close(); 00224 $rs = &$db->Execute("select * from ADOXYZ where id=99"); 00225 if ($rs === false || $rs->EOF) { 00226 print '<b>Data not saved</b></p>'; 00227 $rs = &$db->Execute("select * from ADOXYZ where id=99"); 00228 print_r($rs); 00229 die(); 00230 } else print 'OK</p>'; 00231 if ($rs) $rs->Close(); 00232 } else { 00233 if (!$rs) { 00234 print "<b>Insert failed</b></p>"; 00235 $db->RollbackTrans(); 00236 } else print "<b>Commit failed</b></p>"; 00237 } 00238 if ($db->transCnt != 0) Err("Invalid transCnt = $db->transCnt (should be 0)"); 00239 00240 /* ROLLBACK */ 00241 if (!$db->BeginTrans()) print "<p><b>Error in BeginTrans</b>()</p>"; 00242 print "<p>Testing Rollback: "; 00243 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (100,'Should Not','Exist (Rollback)',$time)"); 00244 if ($db->RollbackTrans()) { 00245 $rs = $db->Execute("select * from ADOXYZ where id=100"); 00246 if ($rs && !$rs->EOF) print '<b>Fail: Data should rollback</b></p>'; 00247 else print 'OK</p>'; 00248 if ($rs) $rs->Close(); 00249 } else 00250 print "<b>Commit failed</b></p>"; 00251 00252 $rs = &$db->Execute('delete from ADOXYZ where id>50'); 00253 if ($rs) $rs->Close(); 00254 00255 if ($db->transCnt != 0) Err("Invalid transCnt = $db->transCnt (should be 0)"); 00256 } 00257 00258 if (1) { 00259 print "<p>Testing MetaDatabases()</p>"; 00260 print_r( $db->MetaDatabases()); 00261 00262 print "<p>Testing MetaTables() and MetaColumns()</p>"; 00263 $a = $db->MetaTables(); 00264 if ($a===false) print "<b>MetaTables not supported</b></p>"; 00265 else { 00266 print "Array of tables and views: "; 00267 foreach($a as $v) print " ($v) "; 00268 print '</p>'; 00269 } 00270 00271 $a = $db->MetaTables('VIEW'); 00272 if ($a===false) print "<b>MetaTables not supported (views)</b></p>"; 00273 else { 00274 print "Array of views: "; 00275 foreach($a as $v) print " ($v) "; 00276 print '</p>'; 00277 } 00278 00279 $a = $db->MetaTables(false,false,'aDo%'); 00280 if ($a===false) print "<b>MetaTables not supported (mask)</b></p>"; 00281 else { 00282 print "Array of ado%: "; 00283 foreach($a as $v) print " ($v) "; 00284 print '</p>'; 00285 } 00286 00287 $a = $db->MetaTables('TABLE'); 00288 if ($a===false) print "<b>MetaTables not supported</b></p>"; 00289 else { 00290 print "Array of tables: "; 00291 foreach($a as $v) print " ($v) "; 00292 print '</p>'; 00293 } 00294 00295 $db->debug=0; 00296 $rez = $db->MetaColumns("NOSUCHTABLEHERE"); 00297 if ($rez !== false) { 00298 Err("MetaColumns error handling failed"); 00299 var_dump($rez); 00300 } 00301 $db->debug=1; 00302 $a = $db->MetaColumns('ADOXYZ'); 00303 if ($a===false) print "<b>MetaColumns not supported</b></p>"; 00304 else { 00305 print "<p>Columns of ADOXYZ: <font size=1><br>"; 00306 foreach($a as $v) {print_r($v); echo "<br>";} 00307 echo "</font>"; 00308 } 00309 00310 print "<p>Testing MetaIndexes</p>"; 00311 00312 $a = $db->MetaIndexes(('ADOXYZ'),true); 00313 if ($a===false) print "<b>MetaIndexes not supported</b></p>"; 00314 else { 00315 print "<p>Indexes of ADOXYZ: <font size=1><br>"; 00316 adodb_pr($a); 00317 echo "</font>"; 00318 } 00319 print "<p>Testing MetaPrimaryKeys</p>"; 00320 $a = $db->MetaPrimaryKeys('ADOXYZ'); 00321 var_dump($a); 00322 } 00323 $rs = &$db->Execute('delete from ADOXYZ'); 00324 if ($rs) $rs->Close(); 00325 00326 $db->debug = false; 00327 00328 00329 switch ($db->databaseType) { 00330 case 'vfp': 00331 00332 if (0) { 00333 // memo test 00334 $rs = $db->Execute("select data from memo"); 00335 rs2html($rs); 00336 } 00337 break; 00338 00339 case 'postgres7': 00340 case 'postgres64': 00341 case 'postgres': 00342 case 'ibase': 00343 print "<p>Encode=".$db->BlobEncode("abc\0d\"' 00344 ef")."</p>";//' 00345 00346 print "<p>Testing Foreign Keys</p>"; 00347 $arr = $db->MetaForeignKeys('adoxyz',false,true); 00348 print_r($arr); 00349 if (!$arr) Err("No MetaForeignKeys"); 00350 break; 00351 00352 case 'odbc_mssql': 00353 case 'mssqlpo': 00354 print "<p>Testing Foreign Keys</p>"; 00355 $arr = $db->MetaForeignKeys('Orders',false,true); 00356 print_r($arr); 00357 if (!$arr) Err("Bad MetaForeignKeys"); 00358 if ($db->databaseType == 'odbc_mssql') break; 00359 00360 case 'mssql': 00361 00362 00363 /* 00364 ASSUME Northwind available... 00365 00366 CREATE PROCEDURE SalesByCategory 00367 @CategoryName nvarchar(15), @OrdYear nvarchar(4) = '1998' 00368 AS 00369 IF @OrdYear != '1996' AND @OrdYear != '1997' AND @OrdYear != '1998' 00370 BEGIN 00371 SELECT @OrdYear = '1998' 00372 END 00373 00374 SELECT ProductName, 00375 TotalPurchase=ROUND(SUM(CONVERT(decimal(14,2), OD.Quantity * (1-OD.Discount) * OD.UnitPrice)), 0) 00376 FROM [Order Details] OD, Orders O, Products P, Categories C 00377 WHERE OD.OrderID = O.OrderID 00378 AND OD.ProductID = P.ProductID 00379 AND P.CategoryID = C.CategoryID 00380 AND C.CategoryName = @CategoryName 00381 AND SUBSTRING(CONVERT(nvarchar(22), O.OrderDate, 111), 1, 4) = @OrdYear 00382 GROUP BY ProductName 00383 ORDER BY ProductName 00384 GO 00385 00386 00387 CREATE PROCEDURE ADODBTestSP 00388 @a nvarchar(25) 00389 AS 00390 SELECT GETDATE() AS T, @a AS A 00391 GO 00392 */ 00393 print "<h4>Testing Stored Procedures for mssql</h4>"; 00394 $saved = $db->debug; 00395 $db->debug=true; 00396 $assoc = $ADODB_FETCH_MODE; 00397 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 00398 $cmd = $db->PrepareSP('ADODBTestSP'); 00399 $ss = "You should see me in the output."; 00400 $db->InParameter($cmd,$ss,'a'); 00401 $rs = $db->Execute($cmd); 00402 #var_dump($rs->fields); 00403 echo $rs->fields['T']." --- ".$rs->fields['A']."---<br>"; 00404 00405 $cat = 'Dairy Products'; 00406 $yr = '1998'; 00407 00408 $stmt = $db->PrepareSP('SalesByCategory'); 00409 $db->InParameter($stmt,$cat,'CategoryName'); 00410 $db->InParameter($stmt,$yr,'OrdYear'); 00411 $rs = $db->Execute($stmt); 00412 rs2html($rs); 00413 00414 $cat = 'Grains/Cereals'; 00415 $yr = 1998; 00416 00417 $stmt = $db->PrepareSP('SalesByCategory'); 00418 $db->InParameter($stmt,$cat,'CategoryName'); 00419 $db->InParameter($stmt,$yr,'OrdYear'); 00420 $rs = $db->Execute($stmt); 00421 rs2html($rs); 00422 00423 $ADODB_FETCH_MODE = $assoc; 00424 00425 /* 00426 Test out params - works in PHP 4.2.3 and 4.3.3 and 4.3.8 but not 4.3.0: 00427 00428 CREATE PROCEDURE at_date_interval 00429 @days INTEGER, 00430 @start VARCHAR(20) OUT, 00431 @end VARCHAR(20) OUT 00432 AS 00433 BEGIN 00434 set @start = CONVERT(VARCHAR(20), getdate(), 101) 00435 set @end =CONVERT(VARCHAR(20), dateadd(day, @days, getdate()), 101 ) 00436 END 00437 GO 00438 */ 00439 $db->debug=1; 00440 $stmt = $db->PrepareSP('at_date_interval'); 00441 $days = 10; 00442 $begin_date = ''; 00443 $end_date = ''; 00444 $db->InParameter($stmt,$days,'days', 4, SQLINT4); 00445 $db->OutParameter($stmt,$begin_date,'start', 20, SQLVARCHAR ); 00446 $db->OutParameter($stmt,$end_date,'end', 20, SQLVARCHAR ); 00447 $db->Execute($stmt); 00448 if (empty($begin_date) or empty($end_date) or $begin_date == $end_date) { 00449 Err("MSSQL SP Test for OUT Failed"); 00450 print "begin=$begin_date end=$end_date<p>"; 00451 } else print "(Today +10days) = (begin=$begin_date end=$end_date)<p>"; 00452 00453 $db->debug = $saved; 00454 break; 00455 case 'oci8': 00456 case 'oci8po': 00457 00458 if (0) { 00459 $t = getmicrotime(); 00460 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00461 $arr = $db->GetArray('select * from abalone_tree'); 00462 $arr = $db->GetArray('select * from abalone_tree'); 00463 $arr = $db->GetArray('select * from abalone_tree'); 00464 echo "<p>t = ",getmicrotime() - $t,"</p>"; 00465 die(); 00466 } 00467 00468 # cleanup 00469 $db->Execute("delete from photos where id=99 or id=1"); 00470 $db->Execute("insert into photos (id) values(1)"); 00471 $db->Execute("update photos set photo=null,descclob=null where id=1"); 00472 00473 $saved = $db->debug; 00474 $db->debug=true; 00475 00476 00477 00478 /* 00479 CREATE TABLE PHOTOS 00480 ( 00481 ID NUMBER(16), 00482 PHOTO BLOB, 00483 DESCRIPTION VARCHAR2(4000 BYTE), 00484 DESCCLOB CLOB 00485 ); 00486 00487 INSERT INTO PHOTOS (ID) VALUES(1); 00488 */ 00489 $s = ''; 00490 for ($i = 0; $i <= 500; $i++) { 00491 $s .= '1234567890'; 00492 } 00493 00494 $sql = "INSERT INTO photos ( ID, photo) ". 00495 "VALUES ( :id, empty_blob() )". 00496 " RETURNING photo INTO :xx"; 00497 00498 00499 $blob_data = $s; 00500 $id = 99; 00501 00502 $stmt = $db->PrepareSP($sql); 00503 $db->InParameter($stmt, $id, 'id'); 00504 $blob = $db->InParameter($stmt, $s, 'xx',-1, OCI_B_BLOB); 00505 $db->StartTrans(); 00506 $result = $db->Execute($stmt); 00507 $db->CompleteTrans(); 00508 00509 $s2= $db->GetOne("select photo from photos where id=99"); 00510 echo "<br>---$s2"; 00511 if ($s !== $s2) Err("insert blob does not match"); 00512 00513 print "<h4>Testing Blob: size=".strlen($s)."</h4>"; 00514 $ok = $db->Updateblob('photos','photo',$s,'id=1'); 00515 if (!$ok) Err("Blob failed 1"); 00516 else { 00517 $s2= $db->GetOne("select photo from photos where id=1"); 00518 if ($s !== $s2) Err("updateblob does not match"); 00519 } 00520 00521 print "<h4>Testing Clob: size=".strlen($s)."</h4>"; 00522 $ok = $db->UpdateClob('photos','descclob',$s,'id=1'); 00523 if (!$ok) Err("Clob failed 1"); 00524 else { 00525 $s2= $db->GetOne("select descclob from photos where id=1"); 00526 if ($s !== $s2) Err("updateclob does not match"); 00527 } 00528 00529 00530 $s = ''; 00531 $s2 = ''; 00532 print "<h4>Testing Foreign Keys</h4>"; 00533 $arr = $db->MetaForeignKeys('emp','scott'); 00534 print_r($arr); 00535 if (!$arr) Err("Bad MetaForeignKeys"); 00536 /* 00537 -- TEST PACKAGE 00538 -- "Set scan off" turns off substitution variables. 00539 Set scan off; 00540 00541 CREATE OR REPLACE PACKAGE Adodb AS 00542 TYPE TabType IS REF CURSOR RETURN TAB%ROWTYPE; 00543 PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames IN VARCHAR); 00544 PROCEDURE open_tab2 (tabcursor IN OUT TabType,tablenames IN OUT VARCHAR) ; 00545 PROCEDURE data_out(input IN VARCHAR, output OUT VARCHAR); 00546 PROCEDURE data_in(input IN VARCHAR); 00547 PROCEDURE myproc (p1 IN NUMBER, p2 OUT NUMBER); 00548 END Adodb; 00549 / 00550 00551 00552 CREATE OR REPLACE PACKAGE BODY Adodb AS 00553 PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames IN VARCHAR) IS 00554 BEGIN 00555 OPEN tabcursor FOR SELECT * FROM TAB WHERE tname LIKE tablenames; 00556 END open_tab; 00557 00558 PROCEDURE open_tab2 (tabcursor IN OUT TabType,tablenames IN OUT VARCHAR) IS 00559 BEGIN 00560 OPEN tabcursor FOR SELECT * FROM TAB WHERE tname LIKE tablenames; 00561 tablenames := 'TEST'; 00562 END open_tab2; 00563 00564 PROCEDURE data_out(input IN VARCHAR, output OUT VARCHAR) IS 00565 BEGIN 00566 output := 'Cinta Hati '||input; 00567 END; 00568 00569 PROCEDURE data_in(input IN VARCHAR) IS 00570 ignore varchar(1000); 00571 BEGIN 00572 ignore := input; 00573 END; 00574 00575 PROCEDURE myproc (p1 IN NUMBER, p2 OUT NUMBER) AS 00576 BEGIN 00577 p2 := p1; 00578 END; 00579 END Adodb; 00580 / 00581 00582 */ 00583 00584 print "<h4>Testing Cursor Variables</h4>"; 00585 $rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:zz,'A%'); END;",'zz'); 00586 00587 if ($rs && !$rs->EOF) { 00588 $v = $db->GetOne("SELECT count(*) FROM tab where tname like 'A%'"); 00589 if ($v == $rs->RecordCount()) print "Test 1 RowCount: OK<p>"; 00590 else Err("Test 1 RowCount ".$rs->RecordCount().", actual = $v"); 00591 } else { 00592 print "<b>Error in using Cursor Variables 1</b><p>"; 00593 } 00594 $rs->Close(); 00595 00596 print "<h4>Testing Stored Procedures for oci8</h4>"; 00597 00598 $stmt = $db->PrepareSP("BEGIN adodb.data_out(:a1, :a2); END;"); 00599 $a1 = 'Malaysia'; 00600 //$a2 = ''; # a2 doesn't even need to be defined! 00601 $db->InParameter($stmt,$a1,'a1'); 00602 $db->OutParameter($stmt,$a2,'a2'); 00603 $rs = $db->Execute($stmt); 00604 if ($rs) { 00605 if ($a2 !== 'Cinta Hati Malaysia') print "<b>Stored Procedure Error: a2 = $a2</b><p>"; 00606 else echo "OK: a2=$a2<p>"; 00607 } else { 00608 print "<b>Error in using Stored Procedure IN/Out Variables</b><p>"; 00609 } 00610 00611 $tname = 'A%'; 00612 00613 $stmt = $db->PrepareSP('select * from tab where tname like :tablename'); 00614 $db->Parameter($stmt,$tname,'tablename'); 00615 $rs = $db->Execute($stmt); 00616 rs2html($rs); 00617 00618 $stmt = $db->PrepareSP("begin adodb.data_in(:a1); end;"); 00619 $db->InParameter($stmt,$a1,'a1'); 00620 $db->Execute($stmt); 00621 00622 $db->debug = $saved; 00623 break; 00624 00625 default: 00626 break; 00627 } 00628 $arr = array( 00629 array(1,'Caroline','Miranda'), 00630 array(2,'John','Lim'), 00631 array(3,'Wai Hun','See') 00632 ); 00633 //$db->debug=1; 00634 print "<p>Testing Bulk Insert of 3 rows</p>"; 00635 00636 $sql = "insert into ADOXYZ (id,firstname,lastname) values (".$db->Param('0').",".$db->Param('1').",".$db->Param('2').")"; 00637 $db->StartTrans(); 00638 $db->Execute($sql,$arr); 00639 $db->CompleteTrans(); 00640 $rs = $db->Execute('select * from ADOXYZ order by id'); 00641 if (!$rs || $rs->RecordCount() != 3) Err("Bad bulk insert"); 00642 00643 rs2html($rs); 00644 00645 $db->Execute('delete from ADOXYZ'); 00646 00647 print "<p>Inserting 50 rows</p>"; 00648 00649 for ($i = 0; $i < 5; $i++) { 00650 00651 $time = $db->DBDate(time()); 00652 if (empty($_GET['hide'])) $db->debug = true; 00653 switch($db->databaseType){ 00654 case 'mssqlpo': 00655 case 'mssql': 00656 $sqlt = "CREATE TABLE mytable ( 00657 row1 INT IDENTITY(1,1) NOT NULL, 00658 row2 varchar(16), 00659 PRIMARY KEY (row1))"; 00660 //$db->debug=1; 00661 if (!$db->Execute("delete from mytable")) 00662 $db->Execute($sqlt); 00663 00664 $ok = $db->Execute("insert into mytable (row2) values ('test')"); 00665 $ins_id=$db->Insert_ID(); 00666 echo "Insert ID=";var_dump($ins_id); 00667 if ($ins_id == 0) Err("Bad Insert_ID()"); 00668 $ins_id2 = $db->GetOne("select row1 from mytable"); 00669 if ($ins_id != $ins_id2) Err("Bad Insert_ID() 2"); 00670 00671 $arr = array(0=>'Caroline',1=>'Miranda'); 00672 $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,?,?,$time)"; 00673 break; 00674 case 'mysqli': 00675 case 'mysqlt': 00676 case 'mysql': 00677 $sqlt = "CREATE TABLE `mytable` ( 00678 `row1` int(11) NOT NULL auto_increment, 00679 `row2` varchar(16) NOT NULL default '', 00680 PRIMARY KEY (`row1`), 00681 KEY `myindex` (`row1`,`row2`) 00682 ) "; 00683 if (!$db->Execute("delete from mytable")) 00684 $db->Execute($sqlt); 00685 00686 $ok = $db->Execute("insert into mytable (row2) values ('test')"); 00687 $ins_id=$db->Insert_ID(); 00688 echo "Insert ID=";var_dump($ins_id); 00689 if ($ins_id == 0) Err("Bad Insert_ID()"); 00690 $ins_id2 = $db->GetOne("select row1 from mytable"); 00691 if ($ins_id != $ins_id2) Err("Bad Insert_ID() 2"); 00692 00693 default: 00694 $arr = array(0=>'Caroline',1=>'Miranda'); 00695 $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,?,?,$time)"; 00696 break; 00697 00698 case 'oci8': 00699 case 'oci805': 00700 $arr = array('first'=>'Caroline','last'=>'Miranda'); 00701 $amt = rand() % 100; 00702 $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,:first,:last,$time)"; 00703 break; 00704 } 00705 if ($i & 1) { 00706 $sql = $db->Prepare($sql); 00707 } 00708 $rs = $db->Execute($sql,$arr); 00709 00710 if ($rs === false) Err( 'Error inserting with parameters'); 00711 else $rs->Close(); 00712 $db->debug = false; 00713 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+1,'John','Lim',$time)"); 00714 /*$ins_id=$db->Insert_ID(); 00715 echo "Insert ID=";var_dump($ins_id);*/ 00716 if ($db->databaseType == 'mysql') if ($ins_id == 0) Err('Bad Insert_ID'); 00717 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+2,'Mary','Lamb',$time )"); 00718 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+3,'George','Washington',$time )"); 00719 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+4,'Mr. Alan','Tam',$time )"); 00720 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+5,'Alan',".$db->quote("Turing'ton").",$time )"); 00721 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created)values ($i*10+6,'Serena','Williams',$time )"); 00722 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+7,'Yat Sun','Sun',$time )"); 00723 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+8,'Wai Hun','See',$time )"); 00724 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+9,'Steven','Oey',$time )"); 00725 } // for 00726 if (1) { 00727 $db->debug=1; 00728 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 00729 $cnt = $db->GetOne("select count(*) from ADOXYZ"); 00730 $rs = $db->Execute('update ADOXYZ set id=id+1'); 00731 if (!is_object($rs)) { 00732 print_r($rs); 00733 err("Update should return object"); 00734 } 00735 if (!$rs) err("Update generated error"); 00736 00737 $nrows = $db->Affected_Rows(); 00738 if ($nrows === false) print "<p><b>Affected_Rows() not supported</b></p>"; 00739 else if ($nrows != $cnt) print "<p><b>Affected_Rows() Error: $nrows returned (should be 50) </b></p>"; 00740 else print "<p>Affected_Rows() passed</p>"; 00741 } 00742 00743 if ($db->dataProvider == 'oci8') $array = array('zid'=>1,'zdate'=>date('Y-m-d',time())); 00744 else $array=array(1,date('Y-m-d',time())); 00745 00746 00747 #$array = array(1,date('Y-m-d',time())); 00748 $id = $db->GetOne("select id from ADOXYZ 00749 where id=".$db->Param('zid')." and created>=".$db->Param('ZDATE')."", 00750 $array); 00751 if ($id != 1) Err("Bad bind; id=$id"); 00752 else echo "<br>Bind date/integer 1 passed"; 00753 00754 $array =array(1,$db->BindDate(time())); 00755 $id = $db->GetOne("select id from ADOXYZ 00756 where id=".$db->Param('0')." and created>=".$db->Param('1')."", 00757 $array); 00758 if ($id != 1) Err("Bad bind; id=$id"); 00759 else echo "<br>Bind date/integer 2 passed"; 00760 00761 $db->debug = false; 00762 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 00764 00765 $rs = $db->Execute("select * from ADOXYZ where firstname = 'not known'"); 00766 if (!$rs || !$rs->EOF) print "<p><b>Error on empty recordset</b></p>"; 00767 else if ($rs->RecordCount() != 0) { 00768 print "<p><b>Error on RecordCount. Should be 0. Was ".$rs->RecordCount()."</b></p>"; 00769 print_r($rs->fields); 00770 } 00771 if ($db->databaseType !== 'odbc') { 00772 $rs = &$db->Execute("select id,firstname,lastname,created,".$db->random." from ADOXYZ order by id"); 00773 if ($rs) { 00774 if ($rs->RecordCount() != 50) { 00775 print "<p><b>RecordCount returns ".$rs->RecordCount().", should be 50</b></p>"; 00776 adodb_pr($rs->GetArray()); 00777 $poc = $rs->PO_RecordCount('ADOXYZ'); 00778 if ($poc == 50) print "<p> PO_RecordCount passed</p>"; 00779 else print "<p><b>PO_RecordCount returns wrong value: $poc</b></p>"; 00780 } else print "<p>RecordCount() passed</p>"; 00781 if (isset($rs->fields['firstname'])) print '<p>The fields columns can be indexed by column name.</p>'; 00782 else { 00783 Err( '<p>The fields columns <i>cannot</i> be indexed by column name.</p>'); 00784 print_r($rs->fields); 00785 } 00786 if (empty($_GET['hide'])) rs2html($rs); 00787 } 00788 else print "<p><b>Error in Execute of SELECT with random</b></p>"; 00789 } 00790 $val = $db->GetOne("select count(*) from ADOXYZ"); 00791 if ($val == 50) print "<p>GetOne returns ok</p>"; 00792 else print "<p><b>Fail: GetOne returns $val</b></p>"; 00793 00794 echo "<b>GetRow Test</b>"; 00795 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00796 $val1 = $db->GetRow("select count(*) from ADOXYZ"); 00797 $val2 =& $db->GetRow("select count(*) from ADOXYZ"); 00798 if ($val1[0] == 50 and sizeof($val1) == 1 and $val2[0] == 50 and sizeof($val2) == 1) print "<p>GetRow returns ok</p>"; 00799 else { 00800 print_r($val); 00801 print "<p><b>Fail: GetRow returns {$val2[0]}</b></p>"; 00802 } 00803 00804 print "<p>FetchObject/FetchNextObject Test</p>"; 00805 $rs = $db->Execute('select * from ADOXYZ'); 00806 if ($rs) { 00807 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>"; 00808 00809 while ($o = $rs->FetchNextObject()) { // calls FetchObject internally 00810 if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) { 00811 print_r($o); 00812 print "<p><b>Firstname is not string</b></p>"; 00813 break; 00814 } 00815 } 00816 } else { 00817 print "<p><b>Failed rs</b></p>"; 00818 die("<p>ADOXYZ table cannot be read - die()"); 00819 } 00820 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 00821 print "<p>FetchObject/FetchNextObject Test 2</p>"; 00822 #$db->debug=99; 00823 $rs = $db->Execute('select * from ADOXYZ'); 00824 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>"; 00825 print_r($rs->fields); 00826 while ($o = $rs->FetchNextObject()) { // calls FetchObject internally 00827 if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) { 00828 print_r($o); 00829 print "<p><b>Firstname is not string</b></p>"; 00830 break; 00831 } 00832 } 00833 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00834 00835 $savefetch = $ADODB_FETCH_MODE; 00836 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 00837 00838 print "<p>CacheSelectLimit Test...</p>"; 00839 $db->debug=1; 00840 $rs = $db->CacheSelectLimit('select id, firstname from ADOXYZ order by id',2); 00841 00842 if ($rs && !$rs->EOF) { 00843 if (isset($rs->fields[0])) { 00844 Err("ASSOC has numeric fields"); 00845 print_r($rs->fields); 00846 } 00847 if ($rs->fields['id'] != 1) {Err("Error"); print_r($rs->fields);}; 00848 if (trim($rs->fields['firstname']) != 'Caroline') {print Err("Error 2"); print_r($rs->fields);}; 00849 00850 $rs->MoveNext(); 00851 if ($rs->fields['id'] != 2) {Err("Error 3"); print_r($rs->fields);}; 00852 $rs->MoveNext(); 00853 if (!$rs->EOF) { 00854 Err("Error EOF"); 00855 print_r($rs); 00856 } 00857 } 00858 00859 print "<p>FETCH_MODE = ASSOC: Should get 1, Caroline</p>"; 00860 $rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',2); 00861 if ($rs && !$rs->EOF) { 00862 if (ADODB_ASSOC_CASE == 2) { 00863 $id = 'ID'; 00864 $fname = 'FIRSTNAME'; 00865 }else { 00866 $id = 'id'; 00867 $fname = 'firstname'; 00868 } 00869 if ($rs->fields[$id] != 1) {Err("Error 1"); print_r($rs->fields);}; 00870 if (trim($rs->fields[$fname]) != 'Caroline') {Err("Error 2"); print_r($rs->fields);}; 00871 $rs->MoveNext(); 00872 if ($rs->fields[$id] != 2) {Err("Error 3"); print_r($rs->fields);}; 00873 $rs->MoveNext(); 00874 if (!$rs->EOF) Err("Error EOF"); 00875 else if (is_array($rs->fields) || $rs->fields) { 00876 Err("Error: ## fields should be set to false on EOF"); 00877 print_r($rs->fields); 00878 } 00879 } 00880 00881 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00882 print "<p>FETCH_MODE = NUM: Should get 1, Caroline</p>"; 00883 $rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1); 00884 if ($rs && !$rs->EOF) { 00885 if (isset($rs->fields['id'])) Err("FETCH_NUM has ASSOC fields"); 00886 if ($rs->fields[0] != 1) {Err("Error 1"); print_r($rs->fields);}; 00887 if (trim($rs->fields[1]) != 'Caroline') {Err("Error 2");print_r($rs->fields);}; 00888 $rs->MoveNext(); 00889 if (!$rs->EOF) Err("Error EOF"); 00890 00891 } 00892 $ADODB_FETCH_MODE = $savefetch; 00893 00894 $db->debug = false; 00895 print "<p>GetRowAssoc Upper: Should get 1, Caroline</p>"; 00896 $rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1); 00897 if ($rs && !$rs->EOF) { 00898 $arr = &$rs->GetRowAssoc(); 00899 if ($arr['ID'] != 1) {Err("Error 1");print_r($arr);}; 00900 if (trim($arr['FIRSTNAME']) != 'Caroline') {Err("Error 2"); print_r($arr);}; 00901 $rs->MoveNext(); 00902 if (!$rs->EOF) Err("Error EOF"); 00903 00904 } 00905 print "<p>GetRowAssoc Lower: Should get 1, Caroline</p>"; 00906 $rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1); 00907 if ($rs && !$rs->EOF) { 00908 $arr = &$rs->GetRowAssoc(false); 00909 if ($arr['id'] != 1) {Err("Error 1"); print_r($arr);}; 00910 if (trim($arr['firstname']) != 'Caroline') {Err("Error 2"); print_r($arr);}; 00911 00912 } 00913 00914 print "<p>GetCol Test</p>"; 00915 $col = $db->GetCol('select distinct firstname from adoxyz order by 1'); 00916 if (!is_array($col)) Err("Col size is wrong"); 00917 if (trim($col[0]) != 'Alan' or trim($col[9]) != 'Yat Sun') Err("Col elements wrong"); 00918 00919 $db->debug = true; 00920 00921 00922 echo "<p>Date Update Test</p>"; 00923 $zdate = date('Y-m-d',time()+3600*24); 00924 $zdate = $db->DBDate($zdate); 00925 $db->Execute("update ADOXYZ set created=$zdate where id=1"); 00926 $row = $db->GetRow("select created,firstname from ADOXYZ where id=1"); 00927 print_r($row); echo "<br>"; 00928 00929 00930 00931 print "<p>SelectLimit Distinct Test 1: Should see Caroline, John and Mary</p>"; 00932 $rs = &$db->SelectLimit('select distinct * from ADOXYZ order by id',3); 00933 00934 00935 if ($rs && !$rs->EOF) { 00936 if (trim($rs->fields[1]) != 'Caroline') Err("Error 1 (exp Caroline), ".$rs->fields[1]); 00937 $rs->MoveNext(); 00938 00939 if (trim($rs->fields[1]) != 'John') Err("Error 2 (exp John), ".$rs->fields[1]); 00940 $rs->MoveNext(); 00941 if (trim($rs->fields[1]) != 'Mary') Err("Error 3 (exp Mary),".$rs->fields[1]); 00942 $rs->MoveNext(); 00943 if (! $rs->EOF) Err("Error EOF"); 00944 //rs2html($rs); 00945 } else Err("Failed SelectLimit Test 1"); 00946 00947 print "<p>SelectLimit Test 2: Should see Mary, George and Mr. Alan</p>"; 00948 $rs = &$db->SelectLimit('select * from ADOXYZ order by id',3,2); 00949 if ($rs && !$rs->EOF) { 00950 if (trim($rs->fields[1]) != 'Mary') Err("Error 1 - No Mary, instead: ".$rs->fields[1]); 00951 $rs->MoveNext(); 00952 if (trim($rs->fields[1]) != 'George')Err("Error 2 - No George, instead: ".$rs->fields[1]); 00953 $rs->MoveNext(); 00954 if (trim($rs->fields[1]) != 'Mr. Alan') Err("Error 3 - No Mr. Alan, instead: ".$rs->fields[1]); 00955 $rs->MoveNext(); 00956 if (! $rs->EOF) Err("Error EOF"); 00957 // rs2html($rs); 00958 } 00959 else Err("Failed SelectLimit Test 2 ". ($rs ? 'EOF':'no RS')); 00960 00961 print "<p>SelectLimit Test 3: Should see Wai Hun and Steven</p>"; 00962 $db->debug=1; 00963 global $A; $A=1; 00964 $rs = &$db->SelectLimit('select * from ADOXYZ order by id',-1,48); 00965 $A=0; 00966 if ($rs && !$rs->EOF) { 00967 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>"; 00968 if (trim($rs->fields[1]) != 'Wai Hun') Err("Error 1 ".$rs->fields[1]); 00969 $rs->MoveNext(); 00970 if (trim($rs->fields[1]) != 'Steven') Err("Error 2 ".$rs->fields[1]); 00971 $rs->MoveNext(); 00972 if (! $rs->EOF) { 00973 Err("Error EOF"); 00974 } 00975 //rs2html($rs); 00976 } 00977 else Err("Failed SelectLimit Test 3"); 00978 $db->debug = false; 00979 00980 00981 $rs = &$db->Execute("select * from ADOXYZ order by id"); 00982 print "<p>Testing Move()</p>"; 00983 if (!$rs)Err( "Failed Move SELECT"); 00984 else { 00985 if (!$rs->Move(2)) { 00986 if (!$rs->canSeek) print "<p>$db->databaseType: <b>Move(), MoveFirst() nor MoveLast() not supported.</b></p>"; 00987 else print '<p><b>RecordSet->canSeek property should be set to false</b></p>'; 00988 } else { 00989 $rs->MoveFirst(); 00990 if (trim($rs->Fields("firstname")) != 'Caroline') { 00991 print "<p><b>$db->databaseType: MoveFirst failed -- probably cannot scroll backwards</b></p>"; 00992 } 00993 else print "MoveFirst() OK<BR>"; 00994 00995 // Move(3) tests error handling -- MoveFirst should not move cursor 00996 $rs->Move(3); 00997 if (trim($rs->Fields("firstname")) != 'George') { 00998 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) failed</b></p>"; 00999 } else print "Move(3) OK<BR>"; 01000 01001 $rs->Move(7); 01002 if (trim($rs->Fields("firstname")) != 'Yat Sun') { 01003 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(7) failed</b></p>"; 01004 print_r($rs); 01005 } else print "Move(7) OK<BR>"; 01006 if ($rs->EOF) Err("Move(7) is EOF already"); 01007 $rs->MoveLast(); 01008 if (trim($rs->Fields("firstname")) != 'Steven'){ 01009 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: MoveLast() failed</b></p>"; 01010 print_r($rs); 01011 }else print "MoveLast() OK<BR>"; 01012 $rs->MoveNext(); 01013 if (!$rs->EOF) err("Bad MoveNext"); 01014 if ($rs->canSeek) { 01015 $rs->Move(3); 01016 if (trim($rs->Fields("firstname")) != 'George') { 01017 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) after MoveLast failed</b></p>"; 01018 01019 } else print "Move(3) after MoveLast() OK<BR>"; 01020 } 01021 01022 print "<p>Empty Move Test"; 01023 $rs = $db->Execute("select * from ADOXYZ where id > 0 and id < 0"); 01024 $rs->MoveFirst(); 01025 if (!$rs->EOF || $rs->fields) Err("Error in empty move first"); 01026 } 01027 } 01028 01029 $rs = $db->Execute('select * from ADOXYZ where id = 2'); 01030 if ($rs->EOF || !is_array($rs->fields)) Err("Error in select"); 01031 $rs->MoveNext(); 01032 if (!$rs->EOF) Err("Error in EOF (xx) "); 01033 // $db->debug=true; 01034 print "<p>Testing ADODB_FETCH_ASSOC and concat: concat firstname and lastname</p>"; 01035 01036 $save = $ADODB_FETCH_MODE; 01037 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 01038 if ($db->dataProvider == 'postgres') { 01039 $sql = "select ".$db->Concat('cast(firstname as varchar)',$db->qstr(' '),'lastname')." as fullname,id,".$db->sysTimeStamp." as d from ADOXYZ"; 01040 $rs = &$db->Execute($sql); 01041 } else { 01042 $sql = "select distinct ".$db->Concat('firstname',$db->qstr(' '),'lastname')." as fullname,id,".$db->sysTimeStamp." as d from ADOXYZ"; 01043 $rs = &$db->Execute($sql); 01044 } 01045 if ($rs) { 01046 if (empty($_GET['hide'])) rs2html($rs); 01047 } else { 01048 Err( "Failed Concat:".$sql); 01049 } 01050 $ADODB_FETCH_MODE = $save; 01051 print "<hr />Testing GetArray() "; 01052 //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 01053 01054 $rs = &$db->Execute("select * from ADOXYZ order by id"); 01055 if ($rs) { 01056 $arr = &$rs->GetArray(10); 01057 if (sizeof($arr) != 10 || trim($arr[1][1]) != 'John' || trim($arr[1][2]) != 'Lim') print $arr[1][1].' '.$arr[1][2]."<b> ERROR</b><br>"; 01058 else print " OK<BR>"; 01059 } 01060 01061 $arr = $db->GetArray("select x from ADOXYZ"); 01062 $e = $db->ErrorMsg(); $e2 = $db->ErrorNo(); 01063 echo "Testing error handling, should see illegal column 'x' error=<i>$e ($e2) </i><br>"; 01064 if (!$e || !$e2) Err("Error handling did not work"); 01065 print "Testing FetchNextObject for 1 object "; 01066 $rs = &$db->Execute("select distinct lastname,firstname from ADOXYZ where firstname='Caroline'"); 01067 $fcnt = 0; 01068 if ($rs) 01069 while ($o = $rs->FetchNextObject()) { 01070 $fcnt += 1; 01071 } 01072 if ($fcnt == 1) print " OK<BR>"; 01073 else print "<b>FAILED</b><BR>"; 01074 01075 $stmt = $db->Prepare("select * from ADOXYZ where id < 3"); 01076 $rs = $db->Execute($stmt); 01077 if (!$rs) Err("Prepare failed"); 01078 else { 01079 $arr = $rs->GetArray(); 01080 if (!$arr) Err("Prepare failed 2"); 01081 if (sizeof($arr) != 2) Err("Prepare failed 3"); 01082 } 01083 print "Testing GetAssoc() "; 01084 $savecrecs = $ADODB_COUNTRECS; 01085 $ADODB_COUNTRECS = false; 01086 //$arr = $db->GetArray("select lastname,firstname from ADOXYZ"); 01087 //print_r($arr); 01088 print "<hr />"; 01089 $rs =& $db->Execute("select distinct lastname,firstname,created from ADOXYZ"); 01090 01091 if ($rs) { 01092 $arr = $rs->GetAssoc(); 01093 //print_r($arr); 01094 if (empty($arr['See']) || trim(reset($arr['See'])) != 'Wai Hun') print $arr['See']." <b>ERROR</b><br>"; 01095 else print " OK 1"; 01096 } 01097 01098 $arr = &$db->GetAssoc("select distinct lastname,firstname from ADOXYZ"); 01099 if ($arr) { 01100 //print_r($arr); 01101 if (empty($arr['See']) || trim($arr['See']) != 'Wai Hun') print $arr['See']." <b>ERROR</b><br>"; 01102 else print " OK 2<BR>"; 01103 } 01104 // Comment this out to test countrecs = false 01105 $ADODB_COUNTRECS = $savecrecs; 01106 $db->debug=1; 01107 $query = $db->Prepare("select count(*) from ADOXYZ"); 01108 $rs = $db->CacheExecute(10,$query); 01109 if (reset($rs->fields) != 50) echo Err("$cnt wrong for Prepare/CacheGetOne"); 01110 01111 for ($loop=0; $loop < 1; $loop++) { 01112 print "Testing GetMenu() and CacheExecute<BR>"; 01113 $db->debug = true; 01114 $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); 01115 01116 01117 01118 01119 if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu('menu','Steven').'<BR>'; 01120 else print " Fail<BR>"; 01121 $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); 01122 01123 if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu('menu','Steven',false).'<BR>'; 01124 else print " Fail<BR>"; 01125 01126 $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); 01127 01128 if ($rs) print ' 1st line set to **** , Steven selected: '. $rs->GetMenu('menu','Steven','1st:****').'<BR>'; 01129 else print " Fail<BR>"; 01130 01131 01132 01133 $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); 01134 if ($rs) print ' Multiple, Alan selected: '. $rs->GetMenu('menu','Alan',false,true).'<BR>'; 01135 else print " Fail<BR>"; 01136 print '</p><hr />'; 01137 01138 $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); 01139 if ($rs) { 01140 print ' Multiple, Alan and George selected: '. $rs->GetMenu('menu',array('Alan','George'),false,true); 01141 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>"; 01142 } else print " Fail<BR>"; 01143 print '</p><hr />'; 01144 01145 print "Testing GetMenu3()<br>"; 01146 $rs = $db->Execute("select ".$db->Concat('firstname',"'-'",'id').",id, lastname from ADOXYZ order by lastname,id"); 01147 if ($rs) print "Grouped Menu: ".$rs->GetMenu3('name'); 01148 else Err('Grouped Menu GetMenu3()'); 01149 print "<hr />"; 01150 01151 print "Testing GetMenu2() <BR>"; 01152 $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); 01153 if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu2('menu',('Oey')).'<BR>'; 01154 else print " Fail<BR>"; 01155 $rs = &$db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ"); 01156 if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu2('menu',('Oey'),false).'<BR>'; 01157 else print " Fail<BR>"; 01158 } 01159 echo "<h3>CacheEXecute</h3>"; 01160 01161 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 01162 $rs = &$db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ"); 01163 print_r($rs->fields); echo $rs->fetchMode;echo "<br>"; 01164 echo $rs->Fields('firstname'); 01165 01166 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 01167 $rs = &$db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ"); 01168 print_r($rs->fields);echo "<br>"; 01169 echo $rs->Fields('firstname'); 01170 $db->debug = false; 01171 01172 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 01173 // phplens 01174 01175 $sql = 'select * from ADOXYZ where 0=1'; 01176 echo "<p>**Testing '$sql' (phplens compat 1)</p>"; 01177 $rs = &$db->Execute($sql); 01178 if (!$rs) err( "<b>No recordset returned for '$sql'</b>"); 01179 if (!$rs->FieldCount()) err( "<b>No fields returned for $sql</b>"); 01180 if (!$rs->FetchField(1)) err( "<b>FetchField failed for $sql</b>"); 01181 01182 $sql = 'select * from ADOXYZ order by 1'; 01183 echo "<p>**Testing '$sql' (phplens compat 2)</p>"; 01184 $rs = &$db->Execute($sql); 01185 if (!$rs) err( "<b>No recordset returned for '$sql'<br>".$db->ErrorMsg()."</b>"); 01186 01187 01188 $sql = 'select * from ADOXYZ order by 1,1'; 01189 echo "<p>**Testing '$sql' (phplens compat 3)</p>"; 01190 $rs = &$db->Execute($sql); 01191 if (!$rs) err( "<b>No recordset returned for '$sql'<br>".$db->ErrorMsg()."</b>"); 01192 01193 01194 // Move 01195 $rs1 = &$db->Execute("select id from ADOXYZ where id <= 2 order by 1"); 01196 $rs2 = &$db->Execute("select id from ADOXYZ where id = 3 or id = 4 order by 1"); 01197 01198 if ($rs1) $rs1->MoveLast(); 01199 if ($rs2) $rs2->MoveLast(); 01200 01201 if (empty($rs1) || empty($rs2) || $rs1->fields[0] != 2 || $rs2->fields[0] != 4) { 01202 $a = $rs1->fields[0]; 01203 $b = $rs2->fields[0]; 01204 print "<p><b>Error in multiple recordset test rs1=$a rs2=$b (should be rs1=2 rs2=4)</b></p>"; 01205 } else 01206 print "<p>Testing multiple recordsets OK</p>"; 01207 01208 01209 echo "<p> GenID test: "; 01210 for ($i=1; $i <= 10; $i++) 01211 echo "($i: ",$val = $db->GenID($db->databaseType.'abcseq6' ,5), ") "; 01212 if ($val == 0) Err("GenID not supported"); 01213 01214 if ($val) { 01215 $db->DropSequence('abc_seq2'); 01216 $db->CreateSequence('abc_seq2'); 01217 $val = $db->GenID('abc_seq2'); 01218 $db->DropSequence('abc_seq2'); 01219 $db->CreateSequence('abc_seq2'); 01220 $val = $db->GenID('abc_seq2'); 01221 if ($val != 1) Err("Drop and Create Sequence not supported ($val)"); 01222 } 01223 echo "<p>"; 01224 01225 if (substr($db->dataProvider,0,3) != 'notused') { // used to crash ado 01226 $sql = "select firstnames from adoxyz"; 01227 print "<p>Testing execution of illegal statement: <i>$sql</i></p>"; 01228 if ($db->Execute($sql) === false) { 01229 print "<p>This returns the following ErrorMsg(): <i>".$db->ErrorMsg()."</i> and ErrorNo(): ".$db->ErrorNo().'</p>'; 01230 } else 01231 print "<p><b>Error in error handling -- Execute() should return false</b></p>"; 01232 } else 01233 print "<p><b>ADO skipped error handling of bad select statement</b></p>"; 01234 01235 print "<p>ASSOC TEST 2<br>"; 01236 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 01237 $rs = $db->query('select * from adoxyz order by id'); 01238 if ($ee = $db->ErrorMsg()) { 01239 Err("Error message=$ee"); 01240 } 01241 if ($ee = $db->ErrorNo()) { 01242 Err("Error No = $ee"); 01243 } 01244 print_r($rs->fields); 01245 for($i=0;$i<$rs->FieldCount();$i++) 01246 { 01247 $fld=$rs->FetchField($i); 01248 print "<br> Field name is ".$fld->name; 01249 print " ".$rs->Fields($fld->name); 01250 } 01251 01252 01253 print "<p>BOTH TEST 2<br>"; 01254 if ($db->dataProvider == 'ado') { 01255 print "<b>ADODB_FETCH_BOTH not supported</b> for dataProvider=".$db->dataProvider."<br>"; 01256 } else { 01257 $ADODB_FETCH_MODE = ADODB_FETCH_BOTH; 01258 $rs = $db->query('select * from adoxyz order by id'); 01259 for($i=0;$i<$rs->FieldCount();$i++) 01260 { 01261 $fld=$rs->FetchField($i); 01262 print "<br> Field name is ".$fld->name; 01263 print " ".$rs->Fields($fld->name); 01264 } 01265 } 01266 01267 print "<p>NUM TEST 2<br>"; 01268 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 01269 $rs = $db->query('select * from adoxyz order by id'); 01270 for($i=0;$i<$rs->FieldCount();$i++) 01271 { 01272 $fld=$rs->FetchField($i); 01273 print "<br> Field name is ".$fld->name; 01274 print " ".$rs->Fields($fld->name); 01275 } 01276 01277 print "<p>ASSOC Test of SelectLimit<br>"; 01278 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 01279 $rs = $db->selectlimit('select * from adoxyz order by id',3,4); 01280 $cnt = 0; 01281 while ($rs && !$rs->EOF) { 01282 $cnt += 1; 01283 if (!isset($rs->fields['firstname'])) { 01284 print "<br><b>ASSOC returned numeric field</b></p>"; 01285 break; 01286 } 01287 $rs->MoveNext(); 01288 } 01289 if ($cnt != 3) print "<br><b>Count should be 3, instead it was $cnt</b></p>"; 01290 01291 01292 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 01293 if ($db->sysDate) { 01294 $saved = $db->debug; 01295 $db->debug = 1; 01296 $rs = $db->Execute("select {$db->sysDate} from adoxyz where id=1"); 01297 if (ADORecordSet::UnixDate(date('Y-m-d')) != $rs->UnixDate($rs->fields[0])) { 01298 print "<p><b>Invalid date {$rs->fields[0]}</b></p>"; 01299 } else 01300 print "<p>Passed \$sysDate test ({$rs->fields[0]})</p>"; 01301 01302 print_r($rs->FetchField(0)); 01303 print time(); 01304 $db->debug=$saved; 01305 } else { 01306 print "<p><b>\$db->sysDate not defined</b></p>"; 01307 } 01308 01309 print "<p>Test CSV</p>"; 01310 include_once('../toexport.inc.php'); 01311 //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 01312 $rs = $db->SelectLimit('select id,firstname,lastname,created,\'He, he\' he,\'"\' q from adoxyz',10); 01313 01314 print "<pre>"; 01315 print rs2csv($rs); 01316 print "</pre>"; 01317 01318 $rs = $db->SelectLimit('select id,firstname,lastname,created,\'The "young man", he said\' from adoxyz',10); 01319 01320 if (PHP_VERSION < 5) { 01321 print "<pre>"; 01322 rs2tabout($rs); 01323 print "</pre>"; 01324 } 01325 print " CacheFlush "; 01326 $db->CacheFlush(); 01327 01328 $date = $db->SQLDate('d-m-M-Y-\QQ h:i:s A'); 01329 $sql = "SELECT $date from ADOXYZ"; 01330 print "<p>Test SQLDate: ".htmlspecialchars($sql)."</p>"; 01331 $rs = $db->SelectLimit($sql,1); 01332 $d = date('d-m-M-Y-').'Q'.(ceil(date('m')/3.0)).date(' h:i:s A'); 01333 if (!$rs) Err("SQLDate query returned no recordset"); 01334 else if ($d != $rs->fields[0]) Err("SQLDate 1 failed expected: <br>act:$d <br>sql:".$rs->fields[0]); 01335 01336 $date = $db->SQLDate('d-m-M-Y-\QQ h:i:s A',$db->DBDate("1974-02-25")); 01337 $sql = "SELECT $date from ADOXYZ"; 01338 print "<p>Test SQLDate: ".htmlspecialchars($sql)."</p>"; 01339 $db->debug=1; 01340 $rs = $db->SelectLimit($sql,1); 01341 $ts = ADOConnection::UnixDate('1974-02-25'); 01342 $d = date('d-m-M-Y-',$ts).'Q'.(ceil(date('m',$ts)/3.0)).date(' h:i:s A',$ts); 01343 if (!$rs) { 01344 Err("SQLDate query returned no recordset"); 01345 echo $db->ErrorMsg(),'<br>'; 01346 } else if ($d != reset($rs->fields)) { 01347 Err("SQLDate 2 failed expected: <br>act:$d <br>sql:".$rs->fields[0].' <br>'.$db->ErrorMsg()); 01348 } 01349 01350 01351 print "<p>Test Filter</p>"; 01352 $db->debug = 1; 01353 01354 $rs = $db->SelectLimit('select * from ADOXYZ where id < 3 order by id'); 01355 01356 $rs = RSFilter($rs,'do_strtolower'); 01357 if (trim($rs->fields[1]) != 'caroline' && trim($rs->fields[2]) != 'miranda') { 01358 err('**** RSFilter failed'); 01359 print_r($rs->fields); 01360 } 01361 01362 rs2html($rs); 01363 01364 $db->debug=1; 01365 01366 01367 print "<p>Test Replace</p>"; 01368 01369 $ret = $db->Replace('adoxyz', 01370 array('id'=>1,'firstname'=>'Caroline','lastname'=>'Miranda'), 01371 array('id'), 01372 $autoq = true); 01373 if (!$ret) echo "<p>Error in replacing existing record</p>"; 01374 else { 01375 $saved = $db->debug; 01376 $db->debug = 0; 01377 $savec = $ADODB_COUNTRECS; 01378 $ADODB_COUNTRECS = true; 01379 $rs = $db->Execute('select * FROM ADOXYZ where id=1'); 01380 $db->debug = $saved; 01381 if ($rs->RecordCount() != 1) { 01382 $cnt = $rs->RecordCount(); 01383 rs2html($rs); 01384 print "<b>Error - Replace failed, count=$cnt</b><p>"; 01385 } 01386 $ADODB_COUNTRECS = $savec; 01387 } 01388 $ret = $db->Replace('adoxyz', 01389 array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'), 01390 array('id','firstname'), 01391 $autoq = true); 01392 if ($ret != 2) print "<b>Replace failed: </b>"; 01393 print "test A return value=$ret (2 expected) <p>"; 01394 01395 $ret = $db->Replace('adoxyz', 01396 array('id'=>1000,'firstname'=>'Sherazade','lastname'=>'Al-Rashid'), 01397 'id', 01398 $autoq = true); 01399 if ($ret != 1) 01400 if ($db->dataProvider == 'ibase' && $ret == 2); 01401 else print "<b>Replace failed: </b>"; 01402 print "test B return value=$ret (1 or if ibase then 2 expected) <p>"; 01403 01404 print "<h3>rs2rs Test</h3>"; 01405 01406 $rs = $db->Execute('select * from adoxyz where id>= 1 order by id'); 01407 $rs = $db->_rs2rs($rs); 01408 $rs->valueX = 'X'; 01409 $rs->MoveNext(); 01410 $rs = $db->_rs2rs($rs); 01411 if (!isset($rs->valueX)) err("rs2rs does not preserve array recordsets"); 01412 if (reset($rs->fields) != 1) err("rs2rs does not move to first row: id=".reset($rs->fields)); 01413 01415 include_once('../pivottable.inc.php'); 01416 print "<h3>Pivot Test</h3>"; 01417 $db->debug=true; 01418 $sql = PivotTableSQL( 01419 $db, # adodb connection 01420 'adoxyz', # tables 01421 'firstname', # row fields 01422 'lastname', # column fields 01423 false, # join 01424 'ID', # sum 01425 'Sum ', # label for sum 01426 'sum', # aggregate function 01427 true 01428 ); 01429 $rs = $db->Execute($sql); 01430 if ($rs) rs2html($rs); 01431 else Err("Pivot sql error"); 01432 01433 $pear = true; //true; 01434 $db->debug=false; 01435 01436 if ($pear) { 01437 // PEAR TESTS BELOW 01438 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 01439 01440 include_once "PEAR.php"; 01441 $rs = $db->query('select * from adoxyz where id>0 and id<10 order by id'); 01442 01443 $i = 0; 01444 if ($rs && !$rs->EOF) { 01445 while ($arr = $rs->fetchRow()) { 01446 $i++; 01447 //print "$i "; 01448 if ($arr[0] != $i) { 01449 print_r($arr); 01450 print "<p><b>PEAR DB emulation error 1.</b></p>"; 01451 $pear = false; 01452 break; 01453 } 01454 } 01455 $rs->Close(); 01456 } 01457 01458 01459 if ($i != $db->GetOne('select count(*) from adoxyz where id>0 and id<10')) { 01460 print "<p><b>PEAR DB emulation error 1.1 EOF ($i)</b></p>"; 01461 $pear = false; 01462 } 01463 01464 $rs = $db->limitQuery('select * from adoxyz where id>0 order by id',$i=3,$top=3); 01465 $i2 = $i; 01466 if ($rs && !$rs->EOF) { 01467 01468 while (!is_object($rs->fetchInto($arr))) { 01469 $i2++; 01470 01471 // print_r($arr); 01472 // print "$i ";print_r($arr); 01473 if ($arr[0] != $i2) { 01474 print "<p><b>PEAR DB emulation error 2.</b></p>"; 01475 $pear = false; 01476 break; 01477 } 01478 } 01479 $rs->Close(); 01480 } 01481 if ($i2 != $i+$top) { 01482 print "<p><b>PEAR DB emulation error 2.1 EOF (correct=$i+$top, actual=$i2)</b></p>"; 01483 $pear = false; 01484 } 01485 } 01486 if ($pear) print "<p>PEAR DB emulation passed.</p>"; 01487 flush(); 01488 01489 01490 $rs = $db->SelectLimit("select ".$db->sysDate." from adoxyz",1); 01491 $date = $rs->fields[0]; 01492 if (!$date) Err("Bad sysDate"); 01493 else { 01494 $ds = $db->UserDate($date,"d m Y"); 01495 if ($ds != date("d m Y")) Err("Bad UserDate: ".$ds.' expected='.date("d m Y")); 01496 else echo "Passed UserDate: $ds<p>"; 01497 } 01498 $db->debug=1; 01499 if ($db->dataProvider == 'oci8') 01500 $rs = $db->SelectLimit("select to_char(".$db->sysTimeStamp.",'YYYY-MM-DD HH24:MI:SS') from adoxyz",1); 01501 else 01502 $rs = $db->SelectLimit("select ".$db->sysTimeStamp." from adoxyz",1); 01503 $date = $rs->fields[0]; 01504 if (!$date) Err("Bad sysTimeStamp"); 01505 else { 01506 $ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y"); 01507 if ($ds != date("H \\h\\r\\s-d m Y")) Err("Bad UserTimeStamp: ".$ds.", correct is ".date("H \\h\\r\\s-d m Y")); 01508 else echo "Passed UserTimeStamp: $ds<p>"; 01509 01510 $date = 100; 01511 $ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y"); 01512 $ds2 = date("H \\h\\r\\s-d m Y",$date); 01513 if ($ds != $ds2) Err("Bad UserTimeStamp 2: $ds: $ds2"); 01514 else echo "Passed UserTimeStamp 2: $ds<p>"; 01515 } 01516 flush(); 01517 01518 if ($db->hasTransactions) { 01519 $db->debug=1; 01520 echo "<p>Testing StartTrans CompleteTrans</p>"; 01521 $db->raiseErrorFn = false; 01522 01523 $db->SetTransactionMode('SERIALIZABLE'); 01524 $db->StartTrans(); 01525 $rs = $db->Execute('select * from notable'); 01526 $db->StartTrans(); 01527 $db->BeginTrans(); 01528 $db->Execute("update ADOXYZ set firstname='Carolx' where id=1"); 01529 $db->CommitTrans(); 01530 $db->CompleteTrans(); 01531 $rez = $db->CompleteTrans(); 01532 $db->SetTransactionMode(''); 01533 $db->debug=0; 01534 if ($rez !== false) { 01535 if (is_null($rez)) Err("Error: _transOK not modified"); 01536 else Err("Error: CompleteTrans (1) should have failed"); 01537 } else { 01538 $name = $db->GetOne("Select firstname from ADOXYZ where id=1"); 01539 if ($name == "Carolx") Err("Error: CompleteTrans (2) should have failed"); 01540 else echo "<p> -- Passed StartTrans test1 - rolling back</p>"; 01541 } 01542 01543 $db->StartTrans(); 01544 $db->BeginTrans(); 01545 $db->Execute("update ADOXYZ set firstname='Carolx' where id=1"); 01546 $db->RollbackTrans(); 01547 $rez = $db->CompleteTrans(); 01548 if ($rez !== true) Err("Error: CompleteTrans (1) should have succeeded"); 01549 else { 01550 $name = $db->GetOne("Select firstname from ADOXYZ where id=1"); 01551 if (trim($name) != "Carolx") Err("Error: CompleteTrans (2) should have succeeded, returned name=$name"); 01552 else echo "<p> -- Passed StartTrans test2 - commiting</p>"; 01553 } 01554 } 01555 flush(); 01556 $saved = $db->debug; 01557 $db->debug=1; 01558 $cnt = _adodb_getcount($db, 'select * from ADOXYZ where firstname in (select firstname from ADOXYZ)'); 01559 echo "<b>Count=</b> $cnt"; 01560 $db->debug=$saved; 01561 01562 global $TESTERRS; 01563 $debugerr = true; 01564 01565 global $ADODB_LANG;$ADODB_LANG = 'fr'; 01566 $db->debug = false; 01567 $TESTERRS = 0; 01568 $db->raiseErrorFn = 'adodb_test_err'; 01569 global $ERRNO; // from adodb_test_err 01570 $db->Execute('select * from nowhere'); 01571 $metae = $db->MetaError($ERRNO); 01572 if ($metae !== DB_ERROR_NOSUCHTABLE) print "<p><b>MetaError=".$metae." wrong</b>, should be ".DB_ERROR_NOSUCHTABLE."</p>"; 01573 else print "<p>MetaError ok (".DB_ERROR_NOSUCHTABLE."): ".$db->MetaErrorMsg($metae)."</p>"; 01574 if ($TESTERRS != 1) print "<b>raiseErrorFn select nowhere failed</b><br>"; 01575 $rs = $db->Execute('select * from adoxyz'); 01576 if ($debugerr) print " Move"; 01577 $rs->Move(100); 01578 $rs->_queryID = false; 01579 if ($debugerr) print " MoveNext"; 01580 $rs->MoveNext(); 01581 if ($debugerr) print " $rs=false"; 01582 $rs = false; 01583 01584 flush(); 01585 01586 print "<p>SetFetchMode() tests</p>"; 01587 $db->SetFetchMode(ADODB_FETCH_ASSOC); 01588 $rs = $db->SelectLimit('select firstname from adoxyz',1); 01589 if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC"); 01590 01591 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 01592 $rs = $db->SelectLimit('select firstname from adoxyz',1); 01593 //var_dump($rs->fields); 01594 if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC"); 01595 01596 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 01597 $db->SetFetchMode(ADODB_FETCH_NUM); 01598 $rs = $db->SelectLimit('select firstname from adoxyz',1); 01599 if (!isset($rs->fields[0])) Err("BAD FETCH NUM"); 01600 01601 flush(); 01602 01603 print "<p>Test MetaTables again with SetFetchMode()</p>"; 01604 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; 01605 $db->SetFetchMode(ADODB_FETCH_ASSOC); 01606 print_r($db->MetaTables()); 01607 print "<p>"; 01608 01610 01611 print "<p>Testing Bad Connection</p>"; 01612 flush(); 01613 01614 if (true || PHP_VERSION < 5) { 01615 if ($db->dataProvider == 'odbtp') $db->databaseType = 'odbtp'; 01616 $conn = NewADOConnection($db->databaseType); 01617 $conn->raiseErrorFn = 'adodb_test_err'; 01618 if (1) $conn->PConnect('abc','baduser','badpassword'); 01619 if ($TESTERRS == 2) print "raiseErrorFn tests passed<br>"; 01620 else print "<b>raiseErrorFn tests failed ($TESTERRS)</b><br>"; 01621 01622 flush(); 01623 } 01625 01626 global $nocountrecs; 01627 01628 if (isset($nocountrecs) && $ADODB_COUNTRECS) err("Error: \$ADODB_COUNTRECS is set"); 01629 if (empty($nocountrecs) && $ADODB_COUNTRECS==false) err("Error: \$ADODB_COUNTRECS is not set"); 01630 01631 flush(); 01632 ?> 01633 </p> 01634 <table width=100% ><tr><td bgcolor=beige> </td></tr></table> 01635 </p></form> 01636 <?php 01637 01638 if ($rs1) $rs1->Close(); 01639 if ($rs2) $rs2->Close(); 01640 if ($rs) $rs->Close(); 01641 $db->Close(); 01642 01643 if ($db->transCnt != 0) Err("Error in transCnt=$db->transCnt (should be 0)"); 01644 01645 01646 printf("<p>Total queries=%d; total cached=%d</p>",$EXECS+$CACHED, $CACHED); 01647 flush(); 01648 } 01649 01650 function adodb_test_err($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) 01651 { 01652 global $TESTERRS,$ERRNO; 01653 01654 $ERRNO = $errno; 01655 $TESTERRS += 1; 01656 print "<i>** $dbms ($fn): errno=$errno errmsg=$errmsg ($p1,$p2)</i><br>"; 01657 } 01658 01659 //-------------------------------------------------------------------------------------- 01660 01661 01662 @set_time_limit(240); // increase timeout 01663 01664 include("../tohtml.inc.php"); 01665 include("../adodb.inc.php"); 01666 include("../rsfilter.inc.php"); 01667 01668 /* White Space Check */ 01669 01670 if (isset($_SERVER['argv'][1])) { 01671 //print_r($_SERVER['argv']); 01672 $_GET[$_SERVER['argv'][1]] = 1; 01673 } 01674 01675 if (@$_SERVER['COMPUTERNAME'] == 'TIGRESS') { 01676 CheckWS('mysqlt'); 01677 CheckWS('postgres'); 01678 CheckWS('oci8po'); 01679 01680 CheckWS('firebird'); 01681 CheckWS('sybase'); 01682 if (!ini_get('safe_mode')) CheckWS('informix'); 01683 01684 CheckWS('ado_mssql'); 01685 CheckWS('ado_access'); 01686 CheckWS('mssql'); 01687 01688 CheckWS('vfp'); 01689 CheckWS('sqlanywhere'); 01690 CheckWS('db2'); 01691 CheckWS('access'); 01692 CheckWS('odbc_mssql'); 01693 CheckWS('firebird15'); 01694 // 01695 CheckWS('oracle'); 01696 CheckWS('proxy'); 01697 CheckWS('fbsql'); 01698 print "White Space Check complete<p>"; 01699 } 01700 if (sizeof($_GET) == 0) $testmysql = true; 01701 01702 01703 foreach($_GET as $k=>$v) { 01704 //global $$k; 01705 $$k = $v; 01706 } 01707 if (strpos(PHP_VERSION,'5') === 0) { 01708 //$testaccess=1; 01709 //$testmssql = 1; 01710 //$testsqlite=1; 01711 } 01712 ?> 01713 <html> 01714 <title>ADODB Testing</title> 01715 <body bgcolor=white> 01716 <H1>ADODB Test</H1> 01717 01718 This script tests the following databases: Interbase, Oracle, Visual FoxPro, Microsoft Access (ODBC and ADO), MySQL, MSSQL (ODBC, native, ADO). 01719 There is also support for Sybase, PostgreSQL.</p> 01720 For the latest version of ADODB, visit <a href=http://adodb.sourceforge.net/>adodb.sourceforge.net</a>.</p> 01721 01722 Test <a href=test4.php>GetInsertSQL/GetUpdateSQL</a> 01723 <a href=testsessions.php>Sessions</a> 01724 <a href=testpaging.php>Paging</a> 01725 <a href=test-perf.php>Perf Monitor</a><p> 01726 <?php 01727 include('./testdatabases.inc.php'); 01728 01729 echo "<br>vers=",ADOConnection::Version(); 01730 01731 01732 include_once('../adodb-time.inc.php'); 01733 if (isset($_GET['time'])) adodb_date_test(); 01734 01735 ?> 01736 <p><i>ADODB Database Library (c) 2000-2006 John Lim. All rights reserved. Released under BSD and LGPL, PHP <?php echo PHP_VERSION ?>.</i></p> 01737 </body> 01738 </html>