Documentation TYPO3 par Ameos

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 passed";
00751         
00752         $db->debug = false;
00753         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
00755         
00756         $rs = $db->Execute("select * from ADOXYZ where firstname = 'not known'");
00757         if (!$rs ||  !$rs->EOF) print "<p><b>Error on empty recordset</b></p>";
00758         else if ($rs->RecordCount() != 0) {
00759                 print "<p><b>Error on RecordCount. Should be 0. Was ".$rs->RecordCount()."</b></p>"; 
00760                 print_r($rs->fields);
00761         }
00762         if ($db->databaseType !== 'odbc') {
00763                 $rs = &$db->Execute("select id,firstname,lastname,created,".$db->random." from ADOXYZ order by id");
00764                 if ($rs) {
00765                         if ($rs->RecordCount() != 50) {
00766                                 print "<p><b>RecordCount returns ".$rs->RecordCount().", should be 50</b></p>";
00767                                 adodb_pr($rs->GetArray());
00768                                 $poc = $rs->PO_RecordCount('ADOXYZ');
00769                                 if ($poc == 50) print "<p> &nbsp; &nbsp; PO_RecordCount passed</p>";
00770                                 else print "<p><b>PO_RecordCount returns wrong value: $poc</b></p>";
00771                         } else print "<p>RecordCount() passed</p>";
00772                         if (isset($rs->fields['firstname'])) print '<p>The fields columns can be indexed by column name.</p>';
00773                         else {
00774                                 Err( '<p>The fields columns <i>cannot</i> be indexed by column name.</p>');
00775                                 print_r($rs->fields);
00776                         }
00777                         if (empty($_GET['hide'])) rs2html($rs);
00778                 }
00779                 else print "<p><b>Error in Execute of SELECT with random</b></p>";
00780         }
00781         $val = $db->GetOne("select count(*) from ADOXYZ");
00782          if ($val == 50) print "<p>GetOne returns ok</p>";
00783          else print "<p><b>Fail: GetOne returns $val</b></p>";
00784 
00785          echo "<b>GetRow Test</b>";
00786         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00787         $val1 = $db->GetRow("select count(*) from ADOXYZ");
00788         $val2 =& $db->GetRow("select count(*) from ADOXYZ");
00789          if ($val1[0] == 50 and sizeof($val1) == 1 and $val2[0] == 50 and sizeof($val2) == 1) print "<p>GetRow returns ok</p>";
00790          else {
00791                 print_r($val);
00792                 print "<p><b>Fail: GetRow returns {$val2[0]}</b></p>";
00793         }
00794 
00795         print "<p>FetchObject/FetchNextObject Test</p>";
00796         $rs = $db->Execute('select * from ADOXYZ');
00797         if ($rs) {
00798                 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
00799                 
00800                 while ($o = $rs->FetchNextObject()) { // calls FetchObject internally
00801                         if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) {
00802                                 print_r($o);
00803                                 print "<p><b>Firstname is not string</b></p>";
00804                                 break;
00805                         }
00806                 }
00807         } else {
00808                 print "<p><b>Failed rs</b></p>";
00809                 die("<p>ADOXYZ table cannot be read - die()");
00810         }
00811         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
00812         print "<p>FetchObject/FetchNextObject Test 2</p>";
00813         #$db->debug=99;
00814         $rs = $db->Execute('select * from ADOXYZ');
00815         if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
00816         print_r($rs->fields);
00817         while ($o = $rs->FetchNextObject()) { // calls FetchObject internally
00818                 if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) {
00819                         print_r($o);
00820                         print "<p><b>Firstname is not string</b></p>";
00821                         break;
00822                 }
00823         }
00824         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00825         
00826         $savefetch = $ADODB_FETCH_MODE;
00827         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
00828         
00829         print "<p>CacheSelectLimit  Test...</p>";
00830         $db->debug=1;
00831         $rs = $db->CacheSelectLimit('select  id, firstname from  ADOXYZ order by id',2);
00832         
00833         if ($rs && !$rs->EOF) {
00834                 if (isset($rs->fields[0])) {
00835                         Err("ASSOC has numeric fields");
00836                         print_r($rs->fields);
00837                 }
00838                 if ($rs->fields['id'] != 1)  {Err("Error"); print_r($rs->fields);};
00839                 if (trim($rs->fields['firstname']) != 'Caroline')  {print Err("Error 2"); print_r($rs->fields);};
00840                 
00841                 $rs->MoveNext();
00842                 if ($rs->fields['id'] != 2)  {Err("Error 3"); print_r($rs->fields);};
00843                 $rs->MoveNext();
00844                 if (!$rs->EOF) {
00845                         Err("Error EOF");
00846                         print_r($rs);
00847                 }
00848         }
00849         
00850         print "<p>FETCH_MODE = ASSOC: Should get 1, Caroline</p>";
00851         $rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',2);
00852         if ($rs && !$rs->EOF) {
00853                 if (ADODB_ASSOC_CASE == 2) {
00854                         $id = 'ID';
00855                         $fname = 'FIRSTNAME';
00856                 }else {
00857                         $id = 'id';
00858                         $fname = 'firstname';
00859                 }
00860                 if ($rs->fields[$id] != 1)  {Err("Error 1"); print_r($rs->fields);};
00861                 if (trim($rs->fields[$fname]) != 'Caroline')  {Err("Error 2"); print_r($rs->fields);};
00862                 $rs->MoveNext();
00863                 if ($rs->fields[$id] != 2)  {Err("Error 3"); print_r($rs->fields);};
00864                 $rs->MoveNext();
00865                 if (!$rs->EOF) Err("Error EOF");
00866                 else if (is_array($rs->fields) || $rs->fields) {
00867                         Err("Error: ## fields should be set to false on EOF");
00868                         print_r($rs->fields);
00869                 }
00870         }
00871         
00872         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00873         print "<p>FETCH_MODE = NUM: Should get 1, Caroline</p>";
00874         $rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
00875         if ($rs && !$rs->EOF) {
00876                 if (isset($rs->fields['id'])) Err("FETCH_NUM has ASSOC fields");
00877                 if ($rs->fields[0] != 1)  {Err("Error 1"); print_r($rs->fields);};
00878                 if (trim($rs->fields[1]) != 'Caroline')  {Err("Error 2");print_r($rs->fields);};
00879                 $rs->MoveNext();
00880                 if (!$rs->EOF) Err("Error EOF");
00881 
00882         }
00883         $ADODB_FETCH_MODE = $savefetch;
00884         
00885         $db->debug = false;
00886         print "<p>GetRowAssoc Upper: Should get 1, Caroline</p>";
00887         $rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
00888         if ($rs && !$rs->EOF) {
00889                 $arr = &$rs->GetRowAssoc();
00890                 if ($arr['ID'] != 1) {Err("Error 1");print_r($arr);};
00891                 if (trim($arr['FIRSTNAME']) != 'Caroline') {Err("Error 2"); print_r($arr);};
00892                 $rs->MoveNext();
00893                 if (!$rs->EOF) Err("Error EOF");
00894 
00895         }
00896         print "<p>GetRowAssoc Lower: Should get 1, Caroline</p>";
00897         $rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
00898         if ($rs && !$rs->EOF) {
00899                 $arr = &$rs->GetRowAssoc(false);
00900                 if ($arr['id'] != 1) {Err("Error 1"); print_r($arr);};
00901                 if (trim($arr['firstname']) != 'Caroline') {Err("Error 2"); print_r($arr);};
00902 
00903         }
00904         
00905         print "<p>GetCol Test</p>";
00906         $col = $db->GetCol('select distinct firstname from adoxyz order by 1');
00907         if (!is_array($col)) Err("Col size is wrong");
00908         if (trim($col[0]) != 'Alan' or trim($col[9]) != 'Yat Sun') Err("Col elements wrong");
00909 
00910         $db->debug = true;
00911         
00912                 
00913         echo "<p>Date Update Test</p>";
00914         $zdate = date('Y-m-d',time()+3600*24);
00915         $zdate = $db->DBDate($zdate);
00916         $db->Execute("update ADOXYZ set created=$zdate where id=1");
00917         $row = $db->GetRow("select created,firstname from ADOXYZ where id=1");
00918         print_r($row); echo "<br>";
00919         
00920         
00921         
00922         print "<p>SelectLimit Distinct Test 1: Should see Caroline, John and Mary</p>";
00923         $rs = &$db->SelectLimit('select distinct * from ADOXYZ order by id',3);
00924         
00925         
00926         if ($rs && !$rs->EOF) {
00927                 if (trim($rs->fields[1]) != 'Caroline') Err("Error 1 (exp Caroline), ".$rs->fields[1]);
00928                 $rs->MoveNext();
00929                 
00930                 if (trim($rs->fields[1]) != 'John') Err("Error 2 (exp John), ".$rs->fields[1]);
00931                 $rs->MoveNext();
00932                 if (trim($rs->fields[1]) != 'Mary') Err("Error 3 (exp Mary),".$rs->fields[1]);
00933                 $rs->MoveNext();
00934                 if (! $rs->EOF) Err("Error EOF");
00935                 //rs2html($rs);
00936         } else Err("Failed SelectLimit Test 1");
00937         
00938         print "<p>SelectLimit Test 2: Should see Mary, George and Mr. Alan</p>";
00939         $rs = &$db->SelectLimit('select * from ADOXYZ order by id',3,2);
00940         if ($rs && !$rs->EOF) {
00941                 if (trim($rs->fields[1]) != 'Mary') Err("Error 1 - No Mary, instead: ".$rs->fields[1]);
00942                 $rs->MoveNext();
00943                 if (trim($rs->fields[1]) != 'George')Err("Error 2 - No George, instead: ".$rs->fields[1]);
00944                 $rs->MoveNext();
00945                 if (trim($rs->fields[1]) != 'Mr. Alan') Err("Error 3 - No Mr. Alan, instead: ".$rs->fields[1]);
00946                 $rs->MoveNext();
00947                 if (! $rs->EOF) Err("Error EOF");
00948         //      rs2html($rs);
00949         }
00950          else Err("Failed SelectLimit Test 2 ". ($rs ? 'EOF':'no RS'));
00951         
00952         print "<p>SelectLimit Test 3: Should see Wai Hun and Steven</p>";
00953         $db->debug=1;
00954         global $A; $A=1;
00955         $rs = &$db->SelectLimit('select * from ADOXYZ order by id',-1,48);
00956         $A=0;
00957         if ($rs && !$rs->EOF) {
00958                 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
00959                 if (trim($rs->fields[1]) != 'Wai Hun') Err("Error 1 ".$rs->fields[1]);
00960                 $rs->MoveNext();
00961                 if (trim($rs->fields[1]) != 'Steven') Err("Error 2 ".$rs->fields[1]);
00962                 $rs->MoveNext();
00963                 if (! $rs->EOF) {
00964                         Err("Error EOF");
00965                 }
00966                 //rs2html($rs);
00967         }
00968          else Err("Failed SelectLimit Test 3");
00969                 $db->debug = false;
00970         
00971         
00972         $rs = &$db->Execute("select * from ADOXYZ order by id");
00973         print "<p>Testing Move()</p>";  
00974         if (!$rs)Err( "Failed Move SELECT");
00975         else {
00976                 if (!$rs->Move(2)) {
00977                         if (!$rs->canSeek) print "<p>$db->databaseType: <b>Move(), MoveFirst() nor MoveLast() not supported.</b></p>";
00978                         else print '<p><b>RecordSet->canSeek property should be set to false</b></p>';
00979                 } else {
00980                         $rs->MoveFirst();
00981                         if (trim($rs->Fields("firstname")) != 'Caroline') {
00982                                 print "<p><b>$db->databaseType: MoveFirst failed -- probably cannot scroll backwards</b></p>";
00983                         }
00984                         else print "MoveFirst() OK<BR>";
00985                                                 
00986                                                 // Move(3) tests error handling -- MoveFirst should not move cursor
00987                         $rs->Move(3);
00988                         if (trim($rs->Fields("firstname")) != 'George') {
00989                                 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) failed</b></p>";
00990                         } else print "Move(3) OK<BR>";
00991                                                 
00992                         $rs->Move(7);
00993                         if (trim($rs->Fields("firstname")) != 'Yat Sun') {
00994                                 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(7) failed</b></p>";
00995                                 print_r($rs);
00996                         } else print "Move(7) OK<BR>";
00997                         if ($rs->EOF) Err("Move(7) is EOF already");
00998                         $rs->MoveLast();
00999                         if (trim($rs->Fields("firstname")) != 'Steven'){
01000                                  print '<p>'.$rs->Fields("id")."<b>$db->databaseType: MoveLast() failed</b></p>";
01001                                  print_r($rs);
01002                         }else print "MoveLast() OK<BR>";
01003                         $rs->MoveNext();
01004                         if (!$rs->EOF) err("Bad MoveNext");
01005                         if ($rs->canSeek) {
01006                                 $rs->Move(3);
01007                                 if (trim($rs->Fields("firstname")) != 'George') {
01008                                         print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) after MoveLast failed</b></p>";
01009                                         
01010                                 } else print "Move(3) after MoveLast() OK<BR>";
01011                         }
01012                         
01013                         print "<p>Empty Move Test";
01014                         $rs = $db->Execute("select * from ADOXYZ where id > 0 and id < 0");
01015                         $rs->MoveFirst();
01016                         if (!$rs->EOF || $rs->fields) Err("Error in empty move first");
01017                 }
01018         }
01019         
01020         $rs = $db->Execute('select * from ADOXYZ where id = 2');
01021         if ($rs->EOF || !is_array($rs->fields)) Err("Error in select");
01022         $rs->MoveNext();
01023         if (!$rs->EOF) Err("Error in EOF (xx) ");
01024  //     $db->debug=true;
01025         print "<p>Testing ADODB_FETCH_ASSOC and concat: concat firstname and lastname</p>";
01026 
01027         $save = $ADODB_FETCH_MODE;
01028         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
01029         if ($db->dataProvider == 'postgres') {
01030                 $sql = "select ".$db->Concat('cast(firstname as varchar)',$db->qstr(' '),'lastname')." as fullname,id,".$db->sysTimeStamp." as d from ADOXYZ";
01031                 $rs = &$db->Execute($sql);
01032         } else {
01033                 $sql = "select distinct ".$db->Concat('firstname',$db->qstr(' '),'lastname')." as fullname,id,".$db->sysTimeStamp." as d from ADOXYZ";
01034                 $rs = &$db->Execute($sql);
01035         }
01036         if ($rs) {
01037                 if (empty($_GET['hide'])) rs2html($rs);
01038         } else {
01039                 Err( "Failed Concat:".$sql);
01040         }
01041         $ADODB_FETCH_MODE = $save;
01042         print "<hr />Testing GetArray() ";
01043         //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
01044         
01045         $rs = &$db->Execute("select * from ADOXYZ order by id");
01046         if ($rs) {
01047                 $arr = &$rs->GetArray(10);
01048                 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>";
01049                 else print " OK<BR>";
01050         }
01051         
01052         $arr = $db->GetArray("select x from ADOXYZ");
01053         $e = $db->ErrorMsg(); $e2 = $db->ErrorNo();
01054         echo "Testing error handling, should see illegal column 'x' error=<i>$e ($e2) </i><br>";
01055         if (!$e || !$e2) Err("Error handling did not work");
01056         print "Testing FetchNextObject for 1 object ";
01057         $rs = &$db->Execute("select distinct lastname,firstname from ADOXYZ where firstname='Caroline'");
01058         $fcnt = 0;
01059         if ($rs)
01060         while ($o = $rs->FetchNextObject()) {
01061                 $fcnt += 1;     
01062         }
01063         if ($fcnt == 1) print " OK<BR>";
01064         else print "<b>FAILED</b><BR>";
01065         
01066         $stmt = $db->Prepare("select * from ADOXYZ where id < 3");
01067         $rs = $db->Execute($stmt);
01068         if (!$rs) Err("Prepare failed");
01069         else {
01070                 $arr = $rs->GetArray();
01071                 if (!$arr) Err("Prepare failed 2");
01072                 if (sizeof($arr) != 2) Err("Prepare failed 3");
01073         }
01074         print "Testing GetAssoc() ";
01075         $savecrecs = $ADODB_COUNTRECS;
01076         $ADODB_COUNTRECS = false;
01077         //$arr = $db->GetArray("select  lastname,firstname from ADOXYZ");
01078         //print_r($arr);
01079         print "<hr />";
01080         $rs =& $db->Execute("select distinct lastname,firstname,created from ADOXYZ");
01081         
01082         if ($rs) {
01083                 $arr = $rs->GetAssoc();
01084                 //print_r($arr);
01085                 if (empty($arr['See']) || trim(reset($arr['See'])) != 'Wai Hun') print $arr['See']." &nbsp; <b>ERROR</b><br>";
01086                 else print " OK 1";
01087         }
01088         
01089         $arr = &$db->GetAssoc("select distinct lastname,firstname from ADOXYZ");
01090         if ($arr) {
01091                 //print_r($arr);
01092                 if (empty($arr['See']) || trim($arr['See']) != 'Wai Hun') print $arr['See']." &nbsp; <b>ERROR</b><br>";
01093                 else print " OK 2<BR>";
01094         }
01095         // Comment this out to test countrecs = false
01096         $ADODB_COUNTRECS = $savecrecs;
01097         $db->debug=1;
01098         $query = $db->Prepare("select count(*) from ADOXYZ");
01099         $rs = $db->CacheExecute(10,$query);
01100         if (reset($rs->fields) != 50) echo Err("$cnt wrong for Prepare/CacheGetOne");
01101         
01102         for ($loop=0; $loop < 1; $loop++) {
01103         print "Testing GetMenu() and CacheExecute<BR>";
01104         $db->debug = true;
01105         $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
01106         
01107         
01108 
01109 
01110         if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu('menu','Steven').'<BR>'; 
01111         else print " Fail<BR>";
01112         $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
01113         
01114         if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu('menu','Steven',false).'<BR>';
01115         else print " Fail<BR>";
01116         
01117         $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
01118         if ($rs) print ' Multiple, Alan selected: '. $rs->GetMenu('menu','Alan',false,true).'<BR>';
01119         else print " Fail<BR>";
01120         print '</p><hr />';
01121         
01122         $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
01123         if ($rs) {
01124                 print ' Multiple, Alan and George selected: '. $rs->GetMenu('menu',array('Alan','George'),false,true);
01125                 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
01126         } else print " Fail<BR>";
01127         print '</p><hr />';
01128         
01129         print "Testing GetMenu3()<br>";
01130         $rs = $db->Execute("select ".$db->Concat('firstname',"'-'",'id').",id, lastname from ADOXYZ order by lastname,id");
01131         if ($rs) print "Grouped Menu: ".$rs->GetMenu3('name');
01132         else Err('Grouped Menu GetMenu3()');
01133         print "<hr />";
01134 
01135         print "Testing GetMenu2() <BR>";
01136         $rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
01137         if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu2('menu',('Oey')).'<BR>'; 
01138         else print " Fail<BR>";
01139         $rs = &$db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ");
01140         if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu2('menu',('Oey'),false).'<BR>';
01141         else print " Fail<BR>";
01142         }
01143         echo "<h3>CacheEXecute</h3>";
01144 
01145         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
01146         $rs = &$db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ");
01147         print_r($rs->fields); echo $rs->fetchMode;echo "<br>";
01148         echo $rs->Fields('firstname');
01149         
01150         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
01151         $rs = &$db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ");
01152         print_r($rs->fields);echo "<br>";
01153         echo $rs->Fields('firstname');
01154         $db->debug = false;
01155         
01156         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
01157         // phplens
01158         
01159         $sql = 'select * from ADOXYZ where 0=1';
01160         echo "<p>**Testing '$sql' (phplens compat 1)</p>";
01161         $rs = &$db->Execute($sql);
01162         if (!$rs) err( "<b>No recordset returned for '$sql'</b>");
01163         if (!$rs->FieldCount()) err( "<b>No fields returned for $sql</b>");
01164         if (!$rs->FetchField(1)) err( "<b>FetchField failed for $sql</b>");
01165         
01166         $sql = 'select * from ADOXYZ order by 1';
01167         echo "<p>**Testing '$sql' (phplens compat 2)</p>";
01168         $rs = &$db->Execute($sql);
01169         if (!$rs) err( "<b>No recordset returned for '$sql'<br>".$db->ErrorMsg()."</b>");
01170         
01171         
01172         $sql = 'select * from ADOXYZ order by 1,1';
01173         echo "<p>**Testing '$sql' (phplens compat 3)</p>";
01174         $rs = &$db->Execute($sql);
01175         if (!$rs) err( "<b>No recordset returned for '$sql'<br>".$db->ErrorMsg()."</b>");
01176         
01177         
01178         // Move
01179         $rs1 = &$db->Execute("select id from ADOXYZ where id <= 2 order by 1");
01180         $rs2 = &$db->Execute("select id from ADOXYZ where id = 3 or id = 4 order by 1");
01181 
01182         if ($rs1) $rs1->MoveLast();
01183         if ($rs2) $rs2->MoveLast();
01184         
01185         if (empty($rs1) || empty($rs2) || $rs1->fields[0] != 2 || $rs2->fields[0] != 4) {
01186                 $a = $rs1->fields[0];
01187                 $b = $rs2->fields[0];
01188                 print "<p><b>Error in multiple recordset test rs1=$a rs2=$b (should be rs1=2 rs2=4)</b></p>";
01189         } else
01190                 print "<p>Testing multiple recordsets OK</p>";
01191                 
01192         
01193         echo "<p> GenID test: ";
01194         for ($i=1; $i <= 10; $i++) 
01195                 echo  "($i: ",$val = $db->GenID($db->databaseType.'abcseq6' ,5), ") ";
01196         if ($val == 0) Err("GenID not supported");
01197         
01198         if ($val) {
01199                 $db->DropSequence('abc_seq2');
01200                 $db->CreateSequence('abc_seq2');
01201                 $val = $db->GenID('abc_seq2');
01202                 $db->DropSequence('abc_seq2');
01203                 $db->CreateSequence('abc_seq2');
01204                 $val = $db->GenID('abc_seq2');
01205                 if ($val != 1) Err("Drop and Create Sequence not supported ($val)");
01206         }
01207         echo "<p>";
01208         
01209         if (substr($db->dataProvider,0,3) != 'notused') { // used to crash ado
01210                 $sql = "select firstnames from adoxyz";
01211                 print "<p>Testing execution of illegal statement: <i>$sql</i></p>";
01212                 if ($db->Execute($sql) === false) {
01213                         print "<p>This returns the following ErrorMsg(): <i>".$db->ErrorMsg()."</i> and ErrorNo(): ".$db->ErrorNo().'</p>';
01214                 } else 
01215                         print "<p><b>Error in error handling -- Execute() should return false</b></p>";
01216         } else 
01217                 print "<p><b>ADO skipped error handling of bad select statement</b></p>";
01218         
01219         print "<p>ASSOC TEST 2<br>";
01220         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
01221         $rs = $db->query('select * from adoxyz order by id');
01222         if ($ee = $db->ErrorMsg()) {
01223                 Err("Error message=$ee");
01224         }
01225         if ($ee = $db->ErrorNo()) {
01226                 Err("Error No = $ee");
01227         }
01228         print_r($rs->fields);
01229         for($i=0;$i<$rs->FieldCount();$i++) 
01230         { 
01231                 $fld=$rs->FetchField($i); 
01232                 print "<br> Field name is ".$fld->name; 
01233                 print " ".$rs->Fields($fld->name); 
01234         } 
01235 
01236                 
01237         print "<p>BOTH TEST 2<br>";
01238         if ($db->dataProvider == 'ado') {
01239                 print "<b>ADODB_FETCH_BOTH not supported</b> for dataProvider=".$db->dataProvider."<br>";
01240         } else {
01241                 $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
01242                 $rs = $db->query('select * from adoxyz order by id');
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>NUM TEST 2<br>";
01252         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
01253         $rs = $db->query('select * from adoxyz order by id');
01254         for($i=0;$i<$rs->FieldCount();$i++) 
01255         { 
01256                 $fld=$rs->FetchField($i); 
01257                 print "<br> Field name is ".$fld->name; 
01258                 print " ".$rs->Fields($fld->name); 
01259         } 
01260         
01261         print "<p>ASSOC Test of SelectLimit<br>";
01262         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
01263         $rs = $db->selectlimit('select * from adoxyz order by id',3,4);
01264         $cnt = 0;
01265         while ($rs && !$rs->EOF) {
01266                 $cnt += 1;
01267                 if (!isset($rs->fields['firstname'])) {
01268                         print "<br><b>ASSOC returned numeric field</b></p>";
01269                         break;
01270                 }
01271                 $rs->MoveNext();
01272         }
01273         if ($cnt != 3) print "<br><b>Count should be 3, instead it was $cnt</b></p>";
01274         
01275         
01276         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
01277         if ($db->sysDate) {
01278                 $saved = $db->debug;
01279                 $db->debug = 1;
01280                 $rs = $db->Execute("select {$db->sysDate} from adoxyz where id=1");
01281                 if (ADORecordSet::UnixDate(date('Y-m-d')) != $rs->UnixDate($rs->fields[0])) {
01282                         print "<p><b>Invalid date {$rs->fields[0]}</b></p>";
01283                 } else
01284                         print "<p>Passed \$sysDate test ({$rs->fields[0]})</p>";
01285                 
01286                 print_r($rs->FetchField(0));
01287                 print time();
01288                 $db->debug=$saved;
01289         } else {
01290                 print "<p><b>\$db->sysDate not defined</b></p>";
01291         }
01292 
01293         print "<p>Test CSV</p>";
01294         include_once('../toexport.inc.php');
01295         //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
01296         $rs = $db->SelectLimit('select id,firstname,lastname,created,\'He, he\' he,\'"\' q  from adoxyz',10);   
01297         
01298         print "<pre>";
01299         print rs2csv($rs);
01300         print "</pre>";
01301         
01302         $rs = $db->SelectLimit('select id,firstname,lastname,created,\'The      "young man", he said\' from adoxyz',10);        
01303         
01304         if (PHP_VERSION < 5) {
01305                 print "<pre>";
01306                 rs2tabout($rs);
01307                 print "</pre>";
01308         }
01309         print " CacheFlush ";
01310         $db->CacheFlush();
01311         
01312         $date = $db->SQLDate('d-m-M-Y-\QQ h:i:s A');
01313         $sql = "SELECT $date from ADOXYZ";
01314         print "<p>Test SQLDate: ".htmlspecialchars($sql)."</p>";
01315         $rs = $db->SelectLimit($sql,1);
01316         $d = date('d-m-M-Y-').'Q'.(ceil(date('m')/3.0)).date(' h:i:s A');
01317         if (!$rs) Err("SQLDate query returned no recordset");
01318         else if ($d != $rs->fields[0]) Err("SQLDate 1 failed expected: <br>act:$d <br>sql:".$rs->fields[0]);
01319         
01320         $date = $db->SQLDate('d-m-M-Y-\QQ h:i:s A',$db->DBDate("1974-02-25"));
01321         $sql = "SELECT $date from ADOXYZ";
01322         print "<p>Test SQLDate: ".htmlspecialchars($sql)."</p>";
01323         $rs = $db->SelectLimit($sql,1);
01324         $ts = ADOConnection::UnixDate('1974-02-25');
01325         $d = date('d-m-M-Y-',$ts).'Q'.(ceil(date('m',$ts)/3.0)).date(' h:i:s A',$ts);
01326         if (!$rs) {
01327                 Err("SQLDate query returned no recordset");
01328                 echo $db->ErrorMsg(),'<br>';
01329         } else if ($d != $rs->fields[0]) Err("SQLDate 2 failed expected: <br>act:$d <br>sql:".$rs->fields[0]);
01330         
01331         
01332         print "<p>Test Filter</p>";
01333         $db->debug = 1;
01334         
01335         $rs = $db->SelectLimit('select * from ADOXYZ where id < 3 order by id');
01336         
01337         $rs = RSFilter($rs,'do_strtolower');
01338         if (trim($rs->fields[1]) != 'caroline'  && trim($rs->fields[2]) != 'miranda') {
01339                 err('**** RSFilter failed');
01340                 print_r($rs->fields);
01341         }
01342         
01343         rs2html($rs);
01344                 
01345         $db->debug=1;
01346         
01347         
01348         print "<p>Test Replace</p>";
01349         
01350         $ret = $db->Replace('adoxyz', 
01351                 array('id'=>1,'firstname'=>'Caroline','lastname'=>'Miranda'),
01352                 array('id'),
01353                 $autoq = true);
01354         if (!$ret) echo "<p>Error in replacing existing record</p>";
01355         else {
01356                 $saved = $db->debug;
01357                 $db->debug = 0;
01358                 $savec = $ADODB_COUNTRECS;
01359                 $ADODB_COUNTRECS = true;
01360                 $rs = $db->Execute('select * FROM ADOXYZ where id=1');
01361                 $db->debug = $saved;
01362                 if ($rs->RecordCount() != 1) {
01363                         $cnt = $rs->RecordCount();
01364                         rs2html($rs);
01365                         print "<b>Error - Replace failed, count=$cnt</b><p>";
01366                 }
01367                 $ADODB_COUNTRECS = $savec;
01368         }
01369         $ret = $db->Replace('adoxyz', 
01370                 array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'),
01371                 array('id','firstname'),
01372                 $autoq = true);
01373         if ($ret != 2) print "<b>Replace failed: </b>";
01374         print "test A return value=$ret (2 expected) <p>";
01375         
01376         $ret = $db->Replace('adoxyz', 
01377                 array('id'=>1000,'firstname'=>'Sherazade','lastname'=>'Al-Rashid'),
01378                 'id',
01379                 $autoq = true);
01380         if ($ret != 1) 
01381                 if ($db->dataProvider == 'ibase' && $ret == 2);
01382                 else print "<b>Replace failed: </b>";
01383         print "test B return value=$ret (1 or if ibase then 2 expected) <p>";
01384         
01385         print "<h3>rs2rs Test</h3>";
01386         
01387         $rs = $db->Execute('select * from adoxyz where id>= 1 order by id');
01388         $rs = $db->_rs2rs($rs);
01389         $rs->valueX = 'X';
01390         $rs->MoveNext();
01391         $rs = $db->_rs2rs($rs);
01392         if (!isset($rs->valueX)) err("rs2rs does not preserve array recordsets");
01393         if (reset($rs->fields) != 1) err("rs2rs does not move to first row: id=".reset($rs->fields));
01394 
01396         include_once('../pivottable.inc.php');
01397         print "<h3>Pivot Test</h3>";
01398         $db->debug=true;
01399         $sql = PivotTableSQL(
01400                 $db,                    # adodb connection
01401                 'adoxyz',               # tables
01402                 'firstname',    # row fields
01403                 'lastname',             # column fields 
01404                 false,                  # join
01405                 'ID',                   # sum
01406                 'Sum ',                 # label for sum
01407                 'sum',                  # aggregate function
01408                 true
01409         );
01410         $rs = $db->Execute($sql);
01411         if ($rs) rs2html($rs);
01412         else Err("Pivot sql error");
01413         
01414         $pear = true; //true;
01415         $db->debug=false;
01416         
01417         if ($pear) {
01418         // PEAR TESTS BELOW
01419         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
01420         
01421         include_once "PEAR.php";
01422         $rs = $db->query('select * from adoxyz where id>0 and id<10 order by id');
01423         
01424         $i = 0;
01425         if ($rs && !$rs->EOF) {
01426                 while ($arr = $rs->fetchRow()) {
01427                         $i++;
01428                         //print "$i ";
01429                         if ($arr[0] != $i) {
01430                                 print_r($arr);
01431                                 print "<p><b>PEAR DB emulation error 1.</b></p>";
01432                                 $pear = false;
01433                                 break;
01434                         }
01435                 }
01436                 $rs->Close();
01437         }
01438         
01439         
01440         if ($i != $db->GetOne('select count(*) from adoxyz where id>0 and id<10')) {
01441                 print "<p><b>PEAR DB emulation error 1.1 EOF ($i)</b></p>";
01442                 $pear = false;
01443         }
01444         
01445         $rs = $db->limitQuery('select * from adoxyz where id>0 order by id',$i=3,$top=3);
01446         $i2 = $i;
01447         if ($rs && !$rs->EOF) {
01448 
01449                 while (!is_object($rs->fetchInto($arr))) {
01450                         $i2++;
01451                         
01452         //                      print_r($arr);
01453         //              print "$i ";print_r($arr);
01454                         if ($arr[0] != $i2) {
01455                                 print "<p><b>PEAR DB emulation error 2.</b></p>";
01456                                 $pear = false;
01457                                 break;
01458                         }
01459                 }
01460                 $rs->Close();
01461         }
01462         if ($i2 != $i+$top) {
01463                 print "<p><b>PEAR DB emulation error 2.1 EOF (correct=$i+$top, actual=$i2)</b></p>";
01464                 $pear = false;
01465         }
01466         }
01467         if ($pear) print "<p>PEAR DB emulation passed.</p>";
01468         flush();
01469 
01470         
01471         $rs = $db->SelectLimit("select ".$db->sysDate." from adoxyz",1);
01472         $date = $rs->fields[0];
01473         if (!$date) Err("Bad sysDate");
01474         else {
01475                 $ds = $db->UserDate($date,"d m Y");
01476                 if ($ds != date("d m Y")) Err("Bad UserDate: ".$ds.' expected='.date("d m Y"));
01477                 else echo "Passed UserDate: $ds<p>";
01478         }
01479         $db->debug=1;
01480         if ($db->dataProvider == 'oci8') 
01481                 $rs = $db->SelectLimit("select to_char(".$db->sysTimeStamp.",'YYYY-MM-DD HH24:MI:SS') from adoxyz",1);
01482         else 
01483                 $rs = $db->SelectLimit("select ".$db->sysTimeStamp." from adoxyz",1);
01484         $date = $rs->fields[0];
01485         if (!$date) Err("Bad sysTimeStamp");
01486         else {
01487                 $ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y");
01488                 if ($ds != date("H \\h\\r\\s-d m Y")) Err("Bad UserTimeStamp: ".$ds.", correct is ".date("H \\h\\r\\s-d m Y"));
01489                 else echo "Passed UserTimeStamp: $ds<p>";
01490                 
01491                 $date = 100;
01492                 $ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y");
01493                 $ds2 = date("H \\h\\r\\s-d m Y",$date);
01494                 if ($ds != $ds2) Err("Bad UserTimeStamp 2: $ds: $ds2");
01495                 else echo "Passed UserTimeStamp 2: $ds<p>";
01496         }
01497         flush();
01498         
01499         if ($db->hasTransactions) {
01500                 //$db->debug=1;
01501                 echo "<p>Testing StartTrans CompleteTrans</p>";
01502                 $db->raiseErrorFn = false;
01503                 $db->StartTrans();
01504                 $rs = $db->Execute('select * from notable');
01505                         $db->StartTrans();
01506                                 $db->BeginTrans();
01507                         $db->Execute("update ADOXYZ set firstname='Carolx' where id=1");
01508                                 $db->CommitTrans();
01509                         $db->CompleteTrans();
01510                 $rez = $db->CompleteTrans();
01511                 if ($rez !== false) {
01512                         if (is_null($rez)) Err("Error: _transOK not modified");
01513                         else Err("Error: CompleteTrans (1) should have failed");
01514                 } else {
01515                         $name = $db->GetOne("Select firstname from ADOXYZ where id=1");
01516                         if ($name == "Carolx") Err("Error: CompleteTrans (2) should have failed");
01517                         else echo "<p> -- Passed StartTrans test1 - rolling back</p>";
01518                 }
01519                 
01520                 $db->StartTrans();
01521                         $db->BeginTrans();
01522                 $db->Execute("update ADOXYZ set firstname='Carolx' where id=1");
01523                         $db->RollbackTrans();
01524                 $rez = $db->CompleteTrans();
01525                 if ($rez !== true) Err("Error: CompleteTrans (1) should have succeeded");
01526                 else {
01527                         $name = $db->GetOne("Select firstname from ADOXYZ where id=1");
01528                         if (trim($name) != "Carolx") Err("Error: CompleteTrans (2) should have succeeded, returned name=$name");
01529                         else echo "<p> -- Passed StartTrans test2 - commiting</p>";
01530                 }
01531         }
01532         flush();
01533         $saved = $db->debug;
01534         $db->debug=1;
01535         $cnt = _adodb_getcount($db, 'select * from ADOXYZ where firstname in (select firstname from ADOXYZ)');
01536         echo "<b>Count=</b> $cnt";
01537         $db->debug=$saved;
01538         
01539         global $TESTERRS;
01540         $debugerr = true;
01541         
01542         global $ADODB_LANG;$ADODB_LANG = 'fr';
01543         $db->debug = false;
01544         $TESTERRS = 0;
01545         $db->raiseErrorFn = 'adodb_test_err';
01546         global $ERRNO; // from adodb_test_err
01547         $db->Execute('select * from nowhere');
01548         $metae = $db->MetaError($ERRNO);
01549         if ($metae !== DB_ERROR_NOSUCHTABLE) print "<p><b>MetaError=".$metae." wrong</b>, should be ".DB_ERROR_NOSUCHTABLE."</p>";
01550         else print "<p>MetaError ok (".DB_ERROR_NOSUCHTABLE."): ".$db->MetaErrorMsg($metae)."</p>";
01551         if ($TESTERRS != 1) print "<b>raiseErrorFn select nowhere failed</b><br>";
01552         $rs = $db->Execute('select * from adoxyz');
01553         if ($debugerr) print " Move";
01554         $rs->Move(100);
01555         $rs->_queryID = false;
01556         if ($debugerr) print " MoveNext";
01557         $rs->MoveNext();
01558         if ($debugerr) print " $rs=false";
01559         $rs = false;
01560 
01561         flush();
01562         
01563         print "<p>SetFetchMode() tests</p>";
01564         $db->SetFetchMode(ADODB_FETCH_ASSOC);
01565         $rs = $db->SelectLimit('select firstname from adoxyz',1);
01566         if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC");
01567         
01568         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;    
01569         $rs = $db->SelectLimit('select firstname from adoxyz',1);
01570         //var_dump($rs->fields);
01571         if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC");
01572         
01573         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;  
01574         $db->SetFetchMode(ADODB_FETCH_NUM);
01575         $rs = $db->SelectLimit('select firstname from adoxyz',1);
01576         if (!isset($rs->fields[0])) Err("BAD FETCH NUM");
01577         
01578         flush();
01579         
01580         print "<p>Test MetaTables again with SetFetchMode()</p>";
01581         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
01582         $db->SetFetchMode(ADODB_FETCH_ASSOC);
01583         print_r($db->MetaTables());
01584         print "<p>";
01585         
01587         
01588         print "<p>Testing Bad Connection</p>";
01589         flush();
01590         
01591         if (true || PHP_VERSION < 5)  {
01592                 if ($db->dataProvider == 'odbtp') $db->databaseType = 'odbtp';
01593                 $conn = NewADOConnection($db->databaseType);
01594                 $conn->raiseErrorFn = 'adodb_test_err';
01595                 if (1) $conn->PConnect('abc','baduser','badpassword');
01596                 if ($TESTERRS == 2) print "raiseErrorFn tests passed<br>";
01597                 else print "<b>raiseErrorFn tests failed ($TESTERRS)</b><br>";
01598                 
01599                 flush();
01600         }
01602         
01603         global $nocountrecs;
01604         
01605         if (isset($nocountrecs) && $ADODB_COUNTRECS) err("Error: \$ADODB_COUNTRECS is set");
01606         if (empty($nocountrecs) && $ADODB_COUNTRECS==false) err("Error: \$ADODB_COUNTRECS is not set");
01607 
01608         flush();
01609 ?>
01610         </p>
01611         <table width=100% ><tr><td bgcolor=beige>&nbsp;</td></tr></table>
01612         </p></form>
01613 <?php
01614 
01615         if ($rs1) $rs1->Close();
01616         if ($rs2) $rs2->Close();
01617         if ($rs) $rs->Close();
01618         $db->Close();
01619         
01620         if ($db->transCnt != 0) Err("Error in transCnt=$db->transCnt (should be 0)");
01621         
01622         
01623         printf("<p>Total queries=%d; total cached=%d</p>",$EXECS+$CACHED, $CACHED);
01624         flush();
01625 }
01626 
01627 function adodb_test_err($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
01628 {
01629 global $TESTERRS,$ERRNO;
01630 
01631         $ERRNO = $errno;
01632         $TESTERRS += 1;
01633         print "<i>** $dbms ($fn): errno=$errno &nbsp; errmsg=$errmsg ($p1,$p2)</i><br>";
01634 }
01635 
01636 //--------------------------------------------------------------------------------------
01637 
01638 
01639 @set_time_limit(240); // increase timeout
01640 
01641 include("../tohtml.inc.php");
01642 include("../adodb.inc.php");
01643 include("../rsfilter.inc.php");
01644 
01645 /* White Space Check */
01646 
01647 if (isset($_SERVER['argv'][1])) {
01648         //print_r($_SERVER['argv']);
01649         $_GET[$_SERVER['argv'][1]] = 1;
01650 }
01651 
01652 if (@$_SERVER['COMPUTERNAME'] == 'TIGRESS') {
01653         CheckWS('mysqlt');
01654         CheckWS('postgres');
01655         CheckWS('oci8po');
01656         
01657         CheckWS('firebird');
01658         CheckWS('sybase');
01659         if (!ini_get('safe_mode')) CheckWS('informix');
01660 
01661         CheckWS('ado_mssql');
01662         CheckWS('ado_access');
01663         CheckWS('mssql');
01664         
01665         CheckWS('vfp');
01666         CheckWS('sqlanywhere');
01667         CheckWS('db2');
01668         CheckWS('access');
01669         CheckWS('odbc_mssql');
01670         CheckWS('firebird15');
01671         //
01672         CheckWS('oracle');
01673         CheckWS('proxy');
01674         CheckWS('fbsql');
01675         print "White Space Check complete<p>";
01676 }
01677 if (sizeof($_GET) == 0) $testmysql = true;
01678 
01679 
01680 foreach($_GET as $k=>$v)  {
01681         //global $$k;
01682         $$k = $v;
01683 }       
01684 if (strpos(PHP_VERSION,'5') === 0) {
01685         //$testaccess=1;
01686         //$testmssql = 1;
01687         //$testsqlite=1;
01688 }
01689 ?>
01690 <html>
01691 <title>ADODB Testing</title>
01692 <body bgcolor=white>
01693 <H1>ADODB Test</H1>
01694 
01695 This script tests the following databases: Interbase, Oracle, Visual FoxPro, Microsoft Access (ODBC and ADO), MySQL, MSSQL (ODBC, native, ADO). 
01696 There is also support for Sybase, PostgreSQL.</p>
01697 For the latest version of ADODB, visit <a href=http://adodb.sourceforge.net/>adodb.sourceforge.net</a>.</p>
01698 
01699 Test <a href=test4.php>GetInsertSQL/GetUpdateSQL</a> &nbsp; 
01700         <a href=testsessions.php>Sessions</a> &nbsp;
01701         <a href=testpaging.php>Paging</a> &nbsp;
01702         <a href=test-perf.php>Perf Monitor</a><p>
01703 <?php
01704 include('./testdatabases.inc.php');
01705 
01706 echo "<br>vers=",ADOConnection::Version();
01707 
01708 
01709 include_once('../adodb-time.inc.php');
01710 if (isset($_GET['time'])) adodb_date_test();
01711 
01712 ?>
01713 <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>
01714 </body>
01715 </html>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6