"TYPO3 4.0.1: typo3_src-4.0.1/typo3/sysext/adodb/adodb/tests/test.php Source File", "datetime" => "Sat Dec 2 19:22:26 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

test.php

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