Update to upstream version 4.94
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / tests / test.php
1 <?php
2 /*
3 V4.80 8 Mar 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
4 Released under both BSD license and Lesser GPL library license.
5 Whenever there is any discrepancy between the two licenses,
6 the BSD license will take precedence.
7 Set tabs to 4 for best viewing.
8
9 Latest version is available at http://adodb.sourceforge.net
10 */
11
12
13 if (!defined('E_STRICT')) define('E_STRICT',0);
14 error_reporting(E_ALL|E_STRICT);
15
16 $ADODB_FLUSH = true;
17
18 define('ADODB_ASSOC_CASE',0);
19
20
21 function getmicrotime()
22 {
23 $t = microtime();
24 $t = explode(' ',$t);
25 return (float)$t[1]+ (float)$t[0];
26 }
27
28
29 if (PHP_VERSION < 5) include_once('../adodb-pear.inc.php');
30 //--------------------------------------------------------------------------------------
31 //define('ADODB_ASSOC_CASE',1);
32 //
33 function Err($msg)
34 {
35 print "<b>$msg</b><br>";
36 flush();
37 }
38
39 function CheckWS($conn)
40 {
41 global $ADODB_EXTENSION;
42
43 include_once('../session/adodb-session.php');
44 if (defined('CHECKWSFAIL')){ echo " TESTING $conn ";flush();}
45 $saved = $ADODB_EXTENSION;
46 $db = ADONewConnection($conn);
47 $ADODB_EXTENSION = $saved;
48 if (headers_sent()) {
49 print "<p><b>White space detected in adodb-$conn.inc.php or include file...</b></p>";
50 //die();
51 }
52 }
53
54 function do_strtolower(&$arr)
55 {
56 foreach($arr as $k => $v) {
57 if (is_object($v)) $arr[$k] = adodb_pr($v,true);
58 else $arr[$k] = strtolower($v);
59 }
60 }
61
62
63 function CountExecs($db, $sql, $inputarray)
64 {
65 global $EXECS; $EXECS++;
66 }
67
68 function CountCachedExecs($db, $secs2cache, $sql, $inputarray)
69 {
70 global $CACHED; $CACHED++;
71 }
72
73 // the table creation code is specific to the database, so we allow the user
74 // to define their own table creation stuff
75
76 function testdb(&$db,$createtab="create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)")
77 {
78 GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE,$ADODB_COUNTRECS;
79
80 //adodb_pr($db);
81
82 ?> <form method=GET>
83 </p>
84 <table width=100% ><tr><td bgcolor=beige>&nbsp;</td></tr></table>
85 </p>
86 <?php
87 $create =false;
88 /*$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
89
90 $rs = $db->Execute('select lastname,firstname,lastname,id from ADOXYZ');
91 $arr = $rs->GetAssoc();
92 echo "<pre>";print_r($arr);
93 die();*/
94
95 if (!$db) die("testdb: database not inited");
96 GLOBAL $EXECS, $CACHED;
97
98 $EXECS = 0;
99 $CACHED = 0;
100 //$db->Execute("drop table adodb_logsql");
101 if ((rand()%3) == 0) @$db->Execute("delete from adodb_logsql");
102 $db->debug=1;
103
104 $db->fnExecute = 'CountExecs';
105 $db->fnCacheExecute = 'CountCachedExecs';
106
107 if (empty($_GET['nolog'])) {
108 echo "<h3>SQL Logging enabled</h3>";
109 $db->LogSQL();/*
110 $sql =
111 "SELECT t1.sid, t1.sid, t1.title, t1.hometext, t1.notes, t1.aid, t1.informant,
112 t2.url, t2.email, t1.catid, t3.title, t1.topic, t4.topicname, t4.topicimage,
113 t4.topictext, t1.score, t1.ratings, t1.counter, t1.comments, t1.acomm
114 FROM `nuke_stories` `t1`, `nuke_authors` `t2`, `nuke_stories_cat` `t3`, `nuke_topics` `t4`
115 WHERE ((t2.aid=t1.aid) AND (t3.catid=t1.catid) AND (t4.topicid=t1.topic)
116 AND ((t1.alanguage='german') OR (t1.alanguage='')) AND (t1.ihome='0'))
117 ORDER BY t1.time DESC";
118 $db->SelectLimit($sql);
119 echo $db->ErrorMsg();*/
120 }
121 $ADODB_CACHE_DIR = dirname(TempNam('/tmp','testadodb'));
122 $db->debug = false;
123 //print $db->UnixTimeStamp('2003-7-22 23:00:00');
124
125 $phpv = phpversion();
126 if (defined('ADODB_EXTENSION')) $ext = ' &nbsp; Extension '.ADODB_EXTENSION.' installed';
127 else $ext = '';
128 print "<h3>ADODB Version: $ADODB_vers Host: <i>$db->host</i> &nbsp; Database: <i>$db->database</i> &nbsp; PHP: $phpv $ext</h3>";
129
130 flush();
131
132 if (function_exists('date_default_timezone_set')) date_default_timezone_set('Asia/Kuala_Lumpur');
133
134 $arr = $db->ServerInfo();
135 print_r($arr);
136 echo E_ALL,' ',E_STRICT, "<br>";
137 $e = error_reporting(E_ALL | E_STRICT);
138 echo error_reporting(),'<p>';
139 flush();
140 #$db->debug=1;
141 $tt = $db->Time();
142 if ($tt == 0) echo '<br><b>$db->Time failed</b>';
143 else echo "<br>db->Time: ".date('d-m-Y H:i:s',$tt);
144 echo '<br>';
145
146 echo "Date=",$db->UserDate('2002-04-07'),'<br>';
147 print "<i>date1</i> (1969-02-20) = ".$db->DBDate('1969-2-20');
148 print "<br><i>date1</i> (1999-02-20) = ".$db->DBDate('1999-2-20');
149 print "<br><i>date1.1</i> 1999 = ".$db->DBDate("'1999'");
150 print "<br><i>date2</i> (1970-1-2) = ".$db->DBDate(24*3600)."<p>";
151 print "<i>ts1</i> (1999-02-20 13:40:50) = ".$db->DBTimeStamp('1999-2-20 1:40:50 pm');
152 print "<br><i>ts1.1</i> (1999-02-20 13:40:00) = ".$db->DBTimeStamp('1999-2-20 13:40');
153 print "<br><i>ts2</i> (1999-02-20) = ".$db->DBTimeStamp('1999-2-20');
154 print "<br><i>ts3</i> (1970-1-2 +/- timezone) = ".$db->DBTimeStamp(24*3600);
155 print "<br> Fractional TS (1999-2-20 13:40:50.91): ".$db->DBTimeStamp($db->UnixTimeStamp('1999-2-20 13:40:50.91+1'));
156 $dd = $db->UnixDate('1999-02-20');
157 print "<br>unixdate</i> 1999-02-20 = ".date('Y-m-d',$dd)."<p>";
158 print "<br><i>ts4</i> =".($db->UnixTimeStamp("19700101000101")+8*3600);
159 print "<br><i>ts5</i> =".$db->DBTimeStamp($db->UnixTimeStamp("20040110092123"));
160 print "<br><i>ts6</i> =".$db->UserTimeStamp("20040110092123");
161 print "<br><i>ts7</i> =".$db->DBTimeStamp("20040110092123");
162 flush();
163 // mssql too slow in failing bad connection
164 if (false && $db->databaseType != 'mssql') {
165 print "<p>Testing bad connection. Ignore following error msgs:<br>";
166 $db2 = ADONewConnection();
167 $rez = $db2->Connect("bad connection");
168 $err = $db2->ErrorMsg();
169 print "<i>Error='$err'</i></p>";
170 if ($rez) print "<b>Cannot check if connection failed.</b> The Connect() function returned true.</p>";
171 }
172 #error_reporting($e);
173 flush();
174
175 //$ADODB_COUNTRECS=false;
176 $rs=$db->Execute('select * from ADOXYZ order by id');
177 if($rs === false) $create = true;
178 else $rs->Close();
179
180 //if ($db->databaseType !='vfp') $db->Execute("drop table ADOXYZ");
181
182 if ($create) {
183 if (false && $db->databaseType == 'ibase') {
184 print "<b>Please create the following table for testing:</b></p>$createtab</p>";
185 return;
186 } else {
187 $db->debug = 99;
188 # $e = error_reporting(E_ALL-E_WARNING);
189 $db->Execute($createtab);
190 # error_reporting($e);
191 }
192 }
193 #error_reporting(E_ALL);
194 echo "<p>Testing Metatypes</p>";
195 $t = $db->MetaType('varchar');
196 if ($t != 'C') Err("Bad Metatype for varchar");
197
198 $rs = $db->Execute("delete from ADOXYZ"); // some ODBC drivers will fail the drop so we delete
199 if ($rs) {
200 if(! $rs->EOF) print "<b>Error: </b>RecordSet returned by Execute('delete...') should show EOF</p>";
201 $rs->Close();
202 } else print "err=".$db->ErrorMsg();
203
204 print "<p>Test select on empty table, FetchField when EOF, and GetInsertSQL</p>";
205 $rs = $db->Execute("select id,firstname from ADOXYZ where id=9999");
206 if ($rs && !$rs->EOF) print "<b>Error: </b>RecordSet returned by Execute(select...') on empty table should show EOF</p>";
207 if ($rs->EOF && (($ox = $rs->FetchField(0)) && !empty($ox->name))) {
208 $record['id'] = 99;
209 $record['firstname'] = 'John';
210 $sql = $db->GetInsertSQL($rs, $record);
211 if (strtoupper($sql) != strtoupper("INSERT INTO ADOXYZ ( id, firstname ) VALUES ( 99, 'John' )")) Err("GetInsertSQL does not work on empty table: $sql");
212 } else {
213 Err("FetchField does not work on empty recordset, meaning GetInsertSQL will fail...");
214 }
215 if ($rs) $rs->Close();
216 flush();
217 //$db->debug=true;
218 print "<p>Testing Commit: ";
219 $time = $db->DBDate(time());
220 if (!$db->BeginTrans()) {
221 print '<b>Transactions not supported</b></p>';
222 if ($db->hasTransactions) Err("hasTransactions should be false");
223 } else { /* COMMIT */
224 if (!$db->hasTransactions) Err("hasTransactions should be true");
225 if ($db->transCnt != 1) Err("Invalid transCnt = $db->transCnt (should be 1)");
226 $rs = $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (99,'Should Not','Exist (Commit)',$time)");
227 if ($rs && $db->CommitTrans()) {
228 $rs->Close();
229 $rs = $db->Execute("select * from ADOXYZ where id=99");
230 if ($rs === false || $rs->EOF) {
231 print '<b>Data not saved</b></p>';
232 $rs = $db->Execute("select * from ADOXYZ where id=99");
233 print_r($rs);
234 die();
235 } else print 'OK</p>';
236 if ($rs) $rs->Close();
237 } else {
238 if (!$rs) {
239 print "<b>Insert failed</b></p>";
240 $db->RollbackTrans();
241 } else print "<b>Commit failed</b></p>";
242 }
243 if ($db->transCnt != 0) Err("Invalid transCnt = $db->transCnt (should be 0)");
244
245 /* ROLLBACK */
246 if (!$db->BeginTrans()) print "<p><b>Error in BeginTrans</b>()</p>";
247 print "<p>Testing Rollback: ";
248 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (100,'Should Not','Exist (Rollback)',$time)");
249 if ($db->RollbackTrans()) {
250 $rs = $db->Execute("select * from ADOXYZ where id=100");
251 if ($rs && !$rs->EOF) print '<b>Fail: Data should rollback</b></p>';
252 else print 'OK</p>';
253 if ($rs) $rs->Close();
254 } else
255 print "<b>Commit failed</b></p>";
256
257 $rs = $db->Execute('delete from ADOXYZ where id>50');
258 if ($rs) $rs->Close();
259
260 if ($db->transCnt != 0) Err("Invalid transCnt = $db->transCnt (should be 0)");
261 }
262
263 if (1) {
264 print "<p>Testing MetaDatabases()</p>";
265 print_r( $db->MetaDatabases());
266
267 print "<p>Testing MetaTables() and MetaColumns()</p>";
268 $a = $db->MetaTables();
269 if ($a===false) print "<b>MetaTables not supported</b></p>";
270 else {
271 print "Array of tables and views: ";
272 foreach($a as $v) print " ($v) ";
273 print '</p>';
274 }
275
276 $a = $db->MetaTables('VIEW');
277 if ($a===false) print "<b>MetaTables not supported (views)</b></p>";
278 else {
279 print "Array of views: ";
280 foreach($a as $v) print " ($v) ";
281 print '</p>';
282 }
283
284 $a = $db->MetaTables(false,false,'aDo%');
285 if ($a===false) print "<b>MetaTables not supported (mask)</b></p>";
286 else {
287 print "Array of ado%: ";
288 foreach($a as $v) print " ($v) ";
289 print '</p>';
290 }
291
292 $a = $db->MetaTables('TABLE');
293 if ($a===false) print "<b>MetaTables not supported</b></p>";
294 else {
295 print "Array of tables: ";
296 foreach($a as $v) print " ($v) ";
297 print '</p>';
298 }
299
300 $db->debug=0;
301 $rez = $db->MetaColumns("NOSUCHTABLEHERE");
302 if ($rez !== false) {
303 Err("MetaColumns error handling failed");
304 var_dump($rez);
305 }
306 $db->debug=1;
307 $a = $db->MetaColumns('ADOXYZ');
308 if ($a===false) print "<b>MetaColumns not supported</b></p>";
309 else {
310 print "<p>Columns of ADOXYZ: <font size=1><br>";
311 foreach($a as $v) {print_r($v); echo "<br>";}
312 echo "</font>";
313 }
314
315 print "<p>Testing MetaIndexes</p>";
316
317 $a = $db->MetaIndexes(('ADOXYZ'),true);
318 if ($a===false) print "<b>MetaIndexes not supported</b></p>";
319 else {
320 print "<p>Indexes of ADOXYZ: <font size=1><br>";
321 adodb_pr($a);
322 echo "</font>";
323 }
324 print "<p>Testing MetaPrimaryKeys</p>";
325 $a = $db->MetaPrimaryKeys('ADOXYZ');
326 var_dump($a);
327 }
328 $rs = $db->Execute('delete from ADOXYZ');
329 if ($rs) $rs->Close();
330
331 $db->debug = false;
332
333
334 switch ($db->databaseType) {
335 case 'vfp':
336
337 if (0) {
338 // memo test
339 $rs = $db->Execute("select data from memo");
340 rs2html($rs);
341 }
342 break;
343
344 case 'postgres7':
345 case 'postgres64':
346 case 'postgres':
347 case 'ibase':
348 print "<p>Encode=".$db->BlobEncode("abc\0d\"'
349 ef")."</p>";//'
350
351 print "<p>Testing Foreign Keys</p>";
352 $arr = $db->MetaForeignKeys('ADOXYZ',false,true);
353 print_r($arr);
354 if (!$arr) Err("No MetaForeignKeys");
355 break;
356
357 case 'odbc_mssql':
358 case 'mssqlpo':
359 print "<p>Testing Foreign Keys</p>";
360 $arr = $db->MetaForeignKeys('Orders',false,true);
361 print_r($arr);
362 if (!$arr) Err("Bad MetaForeignKeys");
363 if ($db->databaseType == 'odbc_mssql') break;
364
365 case 'mssql':
366
367
368 /*
369 ASSUME Northwind available...
370
371 CREATE PROCEDURE SalesByCategory
372 @CategoryName nvarchar(15), @OrdYear nvarchar(4) = '1998'
373 AS
374 IF @OrdYear != '1996' AND @OrdYear != '1997' AND @OrdYear != '1998'
375 BEGIN
376 SELECT @OrdYear = '1998'
377 END
378
379 SELECT ProductName,
380 TotalPurchase=ROUND(SUM(CONVERT(decimal(14,2), OD.Quantity * (1-OD.Discount) * OD.UnitPrice)), 0)
381 FROM [Order Details] OD, Orders O, Products P, Categories C
382 WHERE OD.OrderID = O.OrderID
383 AND OD.ProductID = P.ProductID
384 AND P.CategoryID = C.CategoryID
385 AND C.CategoryName = @CategoryName
386 AND SUBSTRING(CONVERT(nvarchar(22), O.OrderDate, 111), 1, 4) = @OrdYear
387 GROUP BY ProductName
388 ORDER BY ProductName
389 GO
390
391
392 CREATE PROCEDURE ADODBTestSP
393 @a nvarchar(25)
394 AS
395 SELECT GETDATE() AS T, @a AS A
396 GO
397 */
398 print "<h4>Testing Stored Procedures for mssql</h4>";
399 $saved = $db->debug;
400 $db->debug=true;
401 $assoc = $ADODB_FETCH_MODE;
402 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
403 $cmd = $db->PrepareSP('ADODBTestSP');
404 $ss = "You should see me in the output.";
405 $db->InParameter($cmd,$ss,'a');
406 $rs = $db->Execute($cmd);
407 #var_dump($rs->fields);
408 echo $rs->fields['T']." --- ".$rs->fields['A']."---<br>";
409
410 $cat = 'Dairy Products';
411 $yr = '1998';
412
413 $stmt = $db->PrepareSP('SalesByCategory');
414 $db->InParameter($stmt,$cat,'CategoryName');
415 $db->InParameter($stmt,$yr,'OrdYear');
416 $rs = $db->Execute($stmt);
417 rs2html($rs);
418
419 $cat = 'Grains/Cereals';
420 $yr = 1998;
421
422 $stmt = $db->PrepareSP('SalesByCategory');
423 $db->InParameter($stmt,$cat,'CategoryName');
424 $db->InParameter($stmt,$yr,'OrdYear');
425 $rs = $db->Execute($stmt);
426 rs2html($rs);
427
428 $ADODB_FETCH_MODE = $assoc;
429
430 /*
431 Test out params - works in PHP 4.2.3 and 4.3.3 and 4.3.8 but not 4.3.0:
432
433 CREATE PROCEDURE at_date_interval
434 @days INTEGER,
435 @start VARCHAR(20) OUT,
436 @end VARCHAR(20) OUT
437 AS
438 BEGIN
439 set @start = CONVERT(VARCHAR(20), getdate(), 101)
440 set @end =CONVERT(VARCHAR(20), dateadd(day, @days, getdate()), 101 )
441 END
442 GO
443 */
444 $db->debug=1;
445 $stmt = $db->PrepareSP('at_date_interval');
446 $days = 10;
447 $begin_date = '';
448 $end_date = '';
449 $db->InParameter($stmt,$days,'days', 4, SQLINT4);
450 $db->OutParameter($stmt,$begin_date,'start', 20, SQLVARCHAR );
451 $db->OutParameter($stmt,$end_date,'end', 20, SQLVARCHAR );
452 $db->Execute($stmt);
453 if (empty($begin_date) or empty($end_date) or $begin_date == $end_date) {
454 Err("MSSQL SP Test for OUT Failed");
455 print "begin=$begin_date end=$end_date<p>";
456 } else print "(Today +10days) = (begin=$begin_date end=$end_date)<p>";
457
458 $db->debug = $saved;
459 break;
460 case 'oci8':
461 case 'oci8po':
462
463 if (0) {
464 $t = getmicrotime();
465 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
466 $arr = $db->GetArray('select * from abalone_tree');
467 $arr = $db->GetArray('select * from abalone_tree');
468 $arr = $db->GetArray('select * from abalone_tree');
469 echo "<p>t = ",getmicrotime() - $t,"</p>";
470 die();
471 }
472
473 # cleanup
474 $db->Execute("delete from photos where id=99 or id=1");
475 $db->Execute("insert into photos (id) values(1)");
476 $db->Execute("update photos set photo=null,descclob=null where id=1");
477
478 $saved = $db->debug;
479 $db->debug=true;
480
481
482
483 /*
484 CREATE TABLE PHOTOS
485 (
486 ID NUMBER(16),
487 PHOTO BLOB,
488 DESCRIPTION VARCHAR2(4000 BYTE),
489 DESCCLOB CLOB
490 );
491
492 INSERT INTO PHOTOS (ID) VALUES(1);
493 */
494 $s = '';
495 for ($i = 0; $i <= 500; $i++) {
496 $s .= '1234567890';
497 }
498
499 $sql = "INSERT INTO photos ( ID, photo) ".
500 "VALUES ( :id, empty_blob() )".
501 " RETURNING photo INTO :xx";
502
503
504 $blob_data = $s;
505 $id = 99;
506
507 $stmt = $db->PrepareSP($sql);
508 $db->InParameter($stmt, $id, 'id');
509 $blob = $db->InParameter($stmt, $s, 'xx',-1, OCI_B_BLOB);
510 $db->StartTrans();
511 $result = $db->Execute($stmt);
512 $db->CompleteTrans();
513
514 $s2= $db->GetOne("select photo from photos where id=99");
515 echo "<br>---$s2";
516 if ($s !== $s2) Err("insert blob does not match");
517
518 print "<h4>Testing Blob: size=".strlen($s)."</h4>";
519 $ok = $db->Updateblob('photos','photo',$s,'id=1');
520 if (!$ok) Err("Blob failed 1");
521 else {
522 $s2= $db->GetOne("select photo from photos where id=1");
523 if ($s !== $s2) Err("updateblob does not match");
524 }
525
526 print "<h4>Testing Clob: size=".strlen($s)."</h4>";
527 $ok = $db->UpdateClob('photos','descclob',$s,'id=1');
528 if (!$ok) Err("Clob failed 1");
529 else {
530 $s2= $db->GetOne("select descclob from photos where id=1");
531 if ($s !== $s2) Err("updateclob does not match");
532 }
533
534
535 $s = '';
536 $s2 = '';
537 print "<h4>Testing Foreign Keys</h4>";
538 $arr = $db->MetaForeignKeys('emp','scott');
539 print_r($arr);
540 if (!$arr) Err("Bad MetaForeignKeys");
541 /*
542 -- TEST PACKAGE
543 -- "Set scan off" turns off substitution variables.
544 Set scan off;
545
546 CREATE OR REPLACE PACKAGE Adodb AS
547 TYPE TabType IS REF CURSOR RETURN TAB%ROWTYPE;
548 PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames IN VARCHAR);
549 PROCEDURE open_tab2 (tabcursor IN OUT TabType,tablenames IN OUT VARCHAR) ;
550 PROCEDURE data_out(input IN VARCHAR, output OUT VARCHAR);
551 PROCEDURE data_in(input IN VARCHAR);
552 PROCEDURE myproc (p1 IN NUMBER, p2 OUT NUMBER);
553 END Adodb;
554 /
555
556
557 CREATE OR REPLACE PACKAGE BODY Adodb AS
558 PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames IN VARCHAR) IS
559 BEGIN
560 OPEN tabcursor FOR SELECT * FROM TAB WHERE tname LIKE tablenames;
561 END open_tab;
562
563 PROCEDURE open_tab2 (tabcursor IN OUT TabType,tablenames IN OUT VARCHAR) IS
564 BEGIN
565 OPEN tabcursor FOR SELECT * FROM TAB WHERE tname LIKE tablenames;
566 tablenames := 'TEST';
567 END open_tab2;
568
569 PROCEDURE data_out(input IN VARCHAR, output OUT VARCHAR) IS
570 BEGIN
571 output := 'Cinta Hati '||input;
572 END;
573
574 PROCEDURE data_in(input IN VARCHAR) IS
575 ignore varchar(1000);
576 BEGIN
577 ignore := input;
578 END;
579
580 PROCEDURE myproc (p1 IN NUMBER, p2 OUT NUMBER) AS
581 BEGIN
582 p2 := p1;
583 END;
584 END Adodb;
585 /
586
587 */
588
589 print "<h4>Testing Cursor Variables</h4>";
590 $rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:zz,'A%'); END;",'zz');
591
592 if ($rs && !$rs->EOF) {
593 $v = $db->GetOne("SELECT count(*) FROM tab where tname like 'A%'");
594 if ($v == $rs->RecordCount()) print "Test 1 RowCount: OK<p>";
595 else Err("Test 1 RowCount ".$rs->RecordCount().", actual = $v");
596 } else {
597 print "<b>Error in using Cursor Variables 1</b><p>";
598 }
599 $rs->Close();
600
601 print "<h4>Testing Stored Procedures for oci8</h4>";
602
603 $stmt = $db->PrepareSP("BEGIN adodb.data_out(:a1, :a2); END;");
604 $a1 = 'Malaysia';
605 //$a2 = ''; # a2 doesn't even need to be defined!
606 $db->InParameter($stmt,$a1,'a1');
607 $db->OutParameter($stmt,$a2,'a2');
608 $rs = $db->Execute($stmt);
609 if ($rs) {
610 if ($a2 !== 'Cinta Hati Malaysia') print "<b>Stored Procedure Error: a2 = $a2</b><p>";
611 else echo "OK: a2=$a2<p>";
612 } else {
613 print "<b>Error in using Stored Procedure IN/Out Variables</b><p>";
614 }
615
616 $tname = 'A%';
617
618 $stmt = $db->PrepareSP('select * from tab where tname like :tablename');
619 $db->Parameter($stmt,$tname,'tablename');
620 $rs = $db->Execute($stmt);
621 rs2html($rs);
622
623 $stmt = $db->PrepareSP("begin adodb.data_in(:a1); end;");
624 $db->InParameter($stmt,$a1,'a1');
625 $db->Execute($stmt);
626
627 $db->debug = $saved;
628 break;
629
630 default:
631 break;
632 }
633 $arr = array(
634 array(1,'Caroline','Miranda'),
635 array(2,'John','Lim'),
636 array(3,'Wai Hun','See')
637 );
638 //$db->debug=1;
639 print "<p>Testing Bulk Insert of 3 rows</p>";
640
641 $sql = "insert into ADOXYZ (id,firstname,lastname) values (".$db->Param('0').",".$db->Param('1').",".$db->Param('2').")";
642 $db->StartTrans();
643 $db->Execute($sql,$arr);
644 $db->CompleteTrans();
645 $rs = $db->Execute('select * from ADOXYZ order by id');
646 if (!$rs || $rs->RecordCount() != 3) Err("Bad bulk insert");
647
648 rs2html($rs);
649
650 $db->Execute('delete from ADOXYZ');
651
652 print "<p>Inserting 50 rows</p>";
653
654 for ($i = 0; $i < 5; $i++) {
655
656 $time = $db->DBDate(time());
657 if (empty($_GET['hide'])) $db->debug = true;
658 switch($db->databaseType){
659 case 'mssqlpo':
660 case 'mssql':
661 $sqlt = "CREATE TABLE mytable (
662 row1 INT IDENTITY(1,1) NOT NULL,
663 row2 varchar(16),
664 PRIMARY KEY (row1))";
665 //$db->debug=1;
666 if (!$db->Execute("delete from mytable"))
667 $db->Execute($sqlt);
668
669 $ok = $db->Execute("insert into mytable (row2) values ('test')");
670 $ins_id=$db->Insert_ID();
671 echo "Insert ID=";var_dump($ins_id);
672 if ($ins_id == 0) Err("Bad Insert_ID()");
673 $ins_id2 = $db->GetOne("select row1 from mytable");
674 if ($ins_id != $ins_id2) Err("Bad Insert_ID() 2");
675
676 $arr = array(0=>'Caroline',1=>'Miranda');
677 $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,?,?,$time)";
678 break;
679 case 'mysqli':
680 case 'mysqlt':
681 case 'mysql':
682 $sqlt = "CREATE TABLE `mytable` (
683 `row1` int(11) NOT NULL auto_increment,
684 `row2` varchar(16) NOT NULL default '',
685 PRIMARY KEY (`row1`),
686 KEY `myindex` (`row1`,`row2`)
687 ) ";
688 if (!$db->Execute("delete from mytable"))
689 $db->Execute($sqlt);
690
691 $ok = $db->Execute("insert into mytable (row2) values ('test')");
692 $ins_id=$db->Insert_ID();
693 echo "Insert ID=";var_dump($ins_id);
694 if ($ins_id == 0) Err("Bad Insert_ID()");
695 $ins_id2 = $db->GetOne("select row1 from mytable");
696 if ($ins_id != $ins_id2) Err("Bad Insert_ID() 2");
697
698 default:
699 $arr = array(0=>'Caroline',1=>'Miranda');
700 $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,?,?,$time)";
701 break;
702
703 case 'oci8':
704 case 'oci805':
705 $arr = array('first'=>'Caroline','last'=>'Miranda');
706 $amt = rand() % 100;
707 $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,:first,:last,$time)";
708 break;
709 }
710 if ($i & 1) {
711 $sql = $db->Prepare($sql);
712 }
713 $rs = $db->Execute($sql,$arr);
714
715 if ($rs === false) Err( 'Error inserting with parameters');
716 else $rs->Close();
717 $db->debug = false;
718 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+1,'John','Lim',$time)");
719 /*$ins_id=$db->Insert_ID();
720 echo "Insert ID=";var_dump($ins_id);*/
721 if ($db->databaseType == 'mysql') if ($ins_id == 0) Err('Bad Insert_ID');
722 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+2,'Mary','Lamb',$time )");
723 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+3,'George','Washington',$time )");
724 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+4,'Mr. Alan','Tam',$time )");
725 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+5,'Alan',".$db->quote("Turing'ton").",$time )");
726 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created)values ($i*10+6,'Serena','Williams',$time )");
727 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+7,'Yat Sun','Sun',$time )");
728 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+8,'Wai Hun','See',$time )");
729 $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+9,'Steven','Oey',$time )");
730 } // for
731 if (1) {
732 $db->debug=1;
733 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
734 $cnt = $db->GetOne("select count(*) from ADOXYZ");
735 $rs = $db->Execute('update ADOXYZ set id=id+1');
736 if (!is_object($rs)) {
737 print_r($rs);
738 err("Update should return object");
739 }
740 if (!$rs) err("Update generated error");
741
742 $nrows = $db->Affected_Rows();
743 if ($nrows === false) print "<p><b>Affected_Rows() not supported</b></p>";
744 else if ($nrows != $cnt) print "<p><b>Affected_Rows() Error: $nrows returned (should be 50) </b></p>";
745 else print "<p>Affected_Rows() passed</p>";
746 }
747
748 if ($db->dataProvider == 'oci8') $array = array('zid'=>1,'zdate'=>date('Y-m-d',time()));
749 else $array=array(1,date('Y-m-d',time()));
750
751
752 #$array = array(1,date('Y-m-d',time()));
753 $id = $db->GetOne("select id from ADOXYZ
754 where id=".$db->Param('zid')." and created>=".$db->Param('ZDATE')."",
755 $array);
756 if ($id != 1) Err("Bad bind; id=$id");
757 else echo "<br>Bind date/integer 1 passed";
758
759 $array =array(1,$db->BindDate(time()));
760 $id = $db->GetOne("select id from ADOXYZ
761 where id=".$db->Param('0')." and created>=".$db->Param('1')."",
762 $array);
763 if ($id != 1) Err("Bad bind; id=$id");
764 else echo "<br>Bind date/integer 2 passed";
765
766 $db->debug = false;
767 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
768 //////////////////////////////////////////////////////////////////////////////////////////
769
770 $rs = $db->Execute("select * from ADOXYZ where firstname = 'not known'");
771 if (!$rs || !$rs->EOF) print "<p><b>Error on empty recordset</b></p>";
772 else if ($rs->RecordCount() != 0) {
773 print "<p><b>Error on RecordCount. Should be 0. Was ".$rs->RecordCount()."</b></p>";
774 print_r($rs->fields);
775 }
776 if ($db->databaseType !== 'odbc') {
777 $rs = $db->Execute("select id,firstname,lastname,created,".$db->random." from ADOXYZ order by id");
778 if ($rs) {
779 if ($rs->RecordCount() != 50) {
780 print "<p><b>RecordCount returns ".$rs->RecordCount().", should be 50</b></p>";
781 adodb_pr($rs->GetArray());
782 $poc = $rs->PO_RecordCount('ADOXYZ');
783 if ($poc == 50) print "<p> &nbsp; &nbsp; PO_RecordCount passed</p>";
784 else print "<p><b>PO_RecordCount returns wrong value: $poc</b></p>";
785 } else print "<p>RecordCount() passed</p>";
786 if (isset($rs->fields['firstname'])) print '<p>The fields columns can be indexed by column name.</p>';
787 else {
788 Err( '<p>The fields columns <i>cannot</i> be indexed by column name.</p>');
789 print_r($rs->fields);
790 }
791 if (empty($_GET['hide'])) rs2html($rs);
792 }
793 else print "<p><b>Error in Execute of SELECT with random</b></p>";
794 }
795 $val = $db->GetOne("select count(*) from ADOXYZ");
796 if ($val == 50) print "<p>GetOne returns ok</p>";
797 else print "<p><b>Fail: GetOne returns $val</b></p>";
798
799 echo "<b>GetRow Test</b>";
800 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
801 $val1 = $db->GetRow("select count(*) from ADOXYZ");
802 $val2 = $db->GetRow("select count(*) from ADOXYZ");
803 if ($val1[0] == 50 and sizeof($val1) == 1 and $val2[0] == 50 and sizeof($val2) == 1) print "<p>GetRow returns ok</p>";
804 else {
805 print_r($val);
806 print "<p><b>Fail: GetRow returns {$val2[0]}</b></p>";
807 }
808
809 print "<p>FetchObject/FetchNextObject Test</p>";
810 $rs = $db->Execute('select * from ADOXYZ');
811 if ($rs) {
812 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
813
814 while ($o = $rs->FetchNextObject()) { // calls FetchObject internally
815 if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) {
816 print_r($o);
817 print "<p><b>Firstname is not string</b></p>";
818 break;
819 }
820 }
821 } else {
822 print "<p><b>Failed rs</b></p>";
823 die("<p>ADOXYZ table cannot be read - die()");
824 }
825 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
826 print "<p>FetchObject/FetchNextObject Test 2</p>";
827 #$db->debug=99;
828 $rs = $db->Execute('select * from ADOXYZ');
829 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
830 print_r($rs->fields);
831 while ($o = $rs->FetchNextObject()) { // calls FetchObject internally
832 if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) {
833 print_r($o);
834 print "<p><b>Firstname is not string</b></p>";
835 break;
836 }
837 }
838 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
839
840 $savefetch = $ADODB_FETCH_MODE;
841 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
842
843 print "<p>CacheSelectLimit Test...</p>";
844 $db->debug=1;
845 $rs = $db->CacheSelectLimit('select id, firstname from ADOXYZ order by id',2);
846
847 if ($rs && !$rs->EOF) {
848 if (isset($rs->fields[0])) {
849 Err("ASSOC has numeric fields");
850 print_r($rs->fields);
851 }
852 if ($rs->fields['id'] != 1) {Err("Error"); print_r($rs->fields);};
853 if (trim($rs->fields['firstname']) != 'Caroline') {print Err("Error 2"); print_r($rs->fields);};
854
855 $rs->MoveNext();
856 if ($rs->fields['id'] != 2) {Err("Error 3"); print_r($rs->fields);};
857 $rs->MoveNext();
858 if (!$rs->EOF) {
859 Err("Error EOF");
860 print_r($rs);
861 }
862 }
863
864 print "<p>FETCH_MODE = ASSOC: Should get 1, Caroline</p>";
865 $rs = $db->SelectLimit('select id,firstname from ADOXYZ order by id',2);
866 if ($rs && !$rs->EOF) {
867 if (ADODB_ASSOC_CASE == 2) {
868 $id = 'ID';
869 $fname = 'FIRSTNAME';
870 }else {
871 $id = 'id';
872 $fname = 'firstname';
873 }
874 if ($rs->fields[$id] != 1) {Err("Error 1"); print_r($rs->fields);};
875 if (trim($rs->fields[$fname]) != 'Caroline') {Err("Error 2"); print_r($rs->fields);};
876 $rs->MoveNext();
877 if ($rs->fields[$id] != 2) {Err("Error 3"); print_r($rs->fields);};
878 $rs->MoveNext();
879 if (!$rs->EOF) Err("Error EOF");
880 else if (is_array($rs->fields) || $rs->fields) {
881 Err("Error: ## fields should be set to false on EOF");
882 print_r($rs->fields);
883 }
884 }
885
886 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
887 print "<p>FETCH_MODE = NUM: Should get 1, Caroline</p>";
888 $rs = $db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
889 if ($rs && !$rs->EOF) {
890 if (isset($rs->fields['id'])) Err("FETCH_NUM has ASSOC fields");
891 if ($rs->fields[0] != 1) {Err("Error 1"); print_r($rs->fields);};
892 if (trim($rs->fields[1]) != 'Caroline') {Err("Error 2");print_r($rs->fields);};
893 $rs->MoveNext();
894 if (!$rs->EOF) Err("Error EOF");
895
896 }
897 $ADODB_FETCH_MODE = $savefetch;
898
899 $db->debug = false;
900 print "<p>GetRowAssoc Upper: Should get 1, Caroline</p>";
901 $rs = $db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
902 if ($rs && !$rs->EOF) {
903 $arr = $rs->GetRowAssoc();
904 if ($arr['ID'] != 1) {Err("Error 1");print_r($arr);};
905 if (trim($arr['FIRSTNAME']) != 'Caroline') {Err("Error 2"); print_r($arr);};
906 $rs->MoveNext();
907 if (!$rs->EOF) Err("Error EOF");
908
909 }
910 print "<p>GetRowAssoc Lower: Should get 1, Caroline</p>";
911 $rs = $db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
912 if ($rs && !$rs->EOF) {
913 $arr = $rs->GetRowAssoc(false);
914 if ($arr['id'] != 1) {Err("Error 1"); print_r($arr);};
915 if (trim($arr['firstname']) != 'Caroline') {Err("Error 2"); print_r($arr);};
916
917 }
918
919 print "<p>GetCol Test</p>";
920 $col = $db->GetCol('select distinct firstname from ADOXYZ order by 1');
921 if (!is_array($col)) Err("Col size is wrong");
922 if (trim($col[0]) != 'Alan' or trim($col[9]) != 'Yat Sun') Err("Col elements wrong");
923
924 $db->debug = true;
925
926
927 echo "<p>Date Update Test</p>";
928 $zdate = date('Y-m-d',time()+3600*24);
929 $zdate = $db->DBDate($zdate);
930 $db->Execute("update ADOXYZ set created=$zdate where id=1");
931 $row = $db->GetRow("select created,firstname from ADOXYZ where id=1");
932 print_r($row); echo "<br>";
933
934
935
936 print "<p>SelectLimit Distinct Test 1: Should see Caroline, John and Mary</p>";
937 $rs = $db->SelectLimit('select distinct * from ADOXYZ order by id',3);
938
939
940 if ($rs && !$rs->EOF) {
941 if (trim($rs->fields[1]) != 'Caroline') Err("Error 1 (exp Caroline), ".$rs->fields[1]);
942 $rs->MoveNext();
943
944 if (trim($rs->fields[1]) != 'John') Err("Error 2 (exp John), ".$rs->fields[1]);
945 $rs->MoveNext();
946 if (trim($rs->fields[1]) != 'Mary') Err("Error 3 (exp Mary),".$rs->fields[1]);
947 $rs->MoveNext();
948 if (! $rs->EOF) Err("Error EOF");
949 //rs2html($rs);
950 } else Err("Failed SelectLimit Test 1");
951
952 print "<p>SelectLimit Test 2: Should see Mary, George and Mr. Alan</p>";
953 $rs = $db->SelectLimit('select * from ADOXYZ order by id',3,2);
954 if ($rs && !$rs->EOF) {
955 if (trim($rs->fields[1]) != 'Mary') Err("Error 1 - No Mary, instead: ".$rs->fields[1]);
956 $rs->MoveNext();
957 if (trim($rs->fields[1]) != 'George')Err("Error 2 - No George, instead: ".$rs->fields[1]);
958 $rs->MoveNext();
959 if (trim($rs->fields[1]) != 'Mr. Alan') Err("Error 3 - No Mr. Alan, instead: ".$rs->fields[1]);
960 $rs->MoveNext();
961 if (! $rs->EOF) Err("Error EOF");
962 // rs2html($rs);
963 }
964 else Err("Failed SelectLimit Test 2 ". ($rs ? 'EOF':'no RS'));
965
966 print "<p>SelectLimit Test 3: Should see Wai Hun and Steven</p>";
967 $db->debug=1;
968 global $A; $A=1;
969 $rs = $db->SelectLimit('select * from ADOXYZ order by id',-1,48);
970 $A=0;
971 if ($rs && !$rs->EOF) {
972 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
973 if (trim($rs->fields[1]) != 'Wai Hun') Err("Error 1 ".$rs->fields[1]);
974 $rs->MoveNext();
975 if (trim($rs->fields[1]) != 'Steven') Err("Error 2 ".$rs->fields[1]);
976 $rs->MoveNext();
977 if (! $rs->EOF) {
978 Err("Error EOF");
979 }
980 //rs2html($rs);
981 }
982 else Err("Failed SelectLimit Test 3");
983 $db->debug = false;
984
985
986 $rs = $db->Execute("select * from ADOXYZ order by id");
987 print "<p>Testing Move()</p>";
988 if (!$rs)Err( "Failed Move SELECT");
989 else {
990 if (!$rs->Move(2)) {
991 if (!$rs->canSeek) print "<p>$db->databaseType: <b>Move(), MoveFirst() nor MoveLast() not supported.</b></p>";
992 else print '<p><b>RecordSet->canSeek property should be set to false</b></p>';
993 } else {
994 $rs->MoveFirst();
995 if (trim($rs->Fields("firstname")) != 'Caroline') {
996 print "<p><b>$db->databaseType: MoveFirst failed -- probably cannot scroll backwards</b></p>";
997 }
998 else print "MoveFirst() OK<BR>";
999
1000 // Move(3) tests error handling -- MoveFirst should not move cursor
1001 $rs->Move(3);
1002 if (trim($rs->Fields("firstname")) != 'George') {
1003 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) failed</b></p>";
1004 } else print "Move(3) OK<BR>";
1005
1006 $rs->Move(7);
1007 if (trim($rs->Fields("firstname")) != 'Yat Sun') {
1008 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(7) failed</b></p>";
1009 print_r($rs);
1010 } else print "Move(7) OK<BR>";
1011 if ($rs->EOF) Err("Move(7) is EOF already");
1012 $rs->MoveLast();
1013 if (trim($rs->Fields("firstname")) != 'Steven'){
1014 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: MoveLast() failed</b></p>";
1015 print_r($rs);
1016 }else print "MoveLast() OK<BR>";
1017 $rs->MoveNext();
1018 if (!$rs->EOF) err("Bad MoveNext");
1019 if ($rs->canSeek) {
1020 $rs->Move(3);
1021 if (trim($rs->Fields("firstname")) != 'George') {
1022 print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) after MoveLast failed</b></p>";
1023
1024 } else print "Move(3) after MoveLast() OK<BR>";
1025 }
1026
1027 print "<p>Empty Move Test";
1028 $rs = $db->Execute("select * from ADOXYZ where id > 0 and id < 0");
1029 $rs->MoveFirst();
1030 if (!$rs->EOF || $rs->fields) Err("Error in empty move first");
1031 }
1032 }
1033
1034 $rs = $db->Execute('select * from ADOXYZ where id = 2');
1035 if ($rs->EOF || !is_array($rs->fields)) Err("Error in select");
1036 $rs->MoveNext();
1037 if (!$rs->EOF) Err("Error in EOF (xx) ");
1038 // $db->debug=true;
1039 print "<p>Testing ADODB_FETCH_ASSOC and concat: concat firstname and lastname</p>";
1040
1041 $save = $ADODB_FETCH_MODE;
1042 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1043 if ($db->dataProvider == 'postgres') {
1044 $sql = "select ".$db->Concat('cast(firstname as varchar)',$db->qstr(' '),'lastname')." as fullname,id,".$db->sysTimeStamp." as d from ADOXYZ";
1045 $rs = $db->Execute($sql);
1046 } else {
1047 $sql = "select distinct ".$db->Concat('firstname',$db->qstr(' '),'lastname')." as fullname,id,".$db->sysTimeStamp." as d from ADOXYZ";
1048 $rs = $db->Execute($sql);
1049 }
1050 if ($rs) {
1051 if (empty($_GET['hide'])) rs2html($rs);
1052 } else {
1053 Err( "Failed Concat:".$sql);
1054 }
1055 $ADODB_FETCH_MODE = $save;
1056 print "<hr />Testing GetArray() ";
1057 //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1058
1059 $rs = $db->Execute("select * from ADOXYZ order by id");
1060 if ($rs) {
1061 $arr = $rs->GetArray(10);
1062 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>";
1063 else print " OK<BR>";
1064 }
1065
1066 $arr = $db->GetArray("select x from ADOXYZ");
1067 $e = $db->ErrorMsg(); $e2 = $db->ErrorNo();
1068 echo "Testing error handling, should see illegal column 'x' error=<i>$e ($e2) </i><br>";
1069 if (!$e || !$e2) Err("Error handling did not work");
1070 print "Testing FetchNextObject for 1 object ";
1071 $rs = $db->Execute("select distinct lastname,firstname from ADOXYZ where firstname='Caroline'");
1072 $fcnt = 0;
1073 if ($rs)
1074 while ($o = $rs->FetchNextObject()) {
1075 $fcnt += 1;
1076 }
1077 if ($fcnt == 1) print " OK<BR>";
1078 else print "<b>FAILED</b><BR>";
1079
1080 $stmt = $db->Prepare("select * from ADOXYZ where id < 3");
1081 $rs = $db->Execute($stmt);
1082 if (!$rs) Err("Prepare failed");
1083 else {
1084 $arr = $rs->GetArray();
1085 if (!$arr) Err("Prepare failed 2");
1086 if (sizeof($arr) != 2) Err("Prepare failed 3");
1087 }
1088 print "Testing GetAssoc() ";
1089 $savecrecs = $ADODB_COUNTRECS;
1090 $ADODB_COUNTRECS = false;
1091 //$arr = $db->GetArray("select lastname,firstname from ADOXYZ");
1092 //print_r($arr);
1093 print "<hr />";
1094 $rs = $db->Execute("select distinct lastname,firstname,created from ADOXYZ");
1095
1096 if ($rs) {
1097 $arr = $rs->GetAssoc();
1098 //print_r($arr);
1099 if (empty($arr['See']) || trim(reset($arr['See'])) != 'Wai Hun') print $arr['See']." &nbsp; <b>ERROR</b><br>";
1100 else print " OK 1";
1101 }
1102
1103 $arr = $db->GetAssoc("select distinct lastname,firstname from ADOXYZ");
1104 if ($arr) {
1105 //print_r($arr);
1106 if (empty($arr['See']) || trim($arr['See']) != 'Wai Hun') print $arr['See']." &nbsp; <b>ERROR</b><br>";
1107 else print " OK 2<BR>";
1108 }
1109 // Comment this out to test countrecs = false
1110 $ADODB_COUNTRECS = $savecrecs;
1111 $db->debug=1;
1112 $query = $db->Prepare("select count(*) from ADOXYZ");
1113 $rs = $db->CacheExecute(10,$query);
1114 if (reset($rs->fields) != 50) echo Err("$cnt wrong for Prepare/CacheGetOne");
1115
1116 for ($loop=0; $loop < 1; $loop++) {
1117 print "Testing GetMenu() and CacheExecute<BR>";
1118 $db->debug = true;
1119 $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
1120
1121
1122
1123
1124 if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu('menu','Steven').'<BR>';
1125 else print " Fail<BR>";
1126 $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
1127
1128 if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu('menu','Steven',false).'<BR>';
1129 else print " Fail<BR>";
1130
1131 $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
1132
1133 if ($rs) print ' 1st line set to **** , Steven selected: '. $rs->GetMenu('menu','Steven','1st:****').'<BR>';
1134 else print " Fail<BR>";
1135
1136
1137
1138 $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
1139 if ($rs) print ' Multiple, Alan selected: '. $rs->GetMenu('menu','Alan',false,true).'<BR>';
1140 else print " Fail<BR>";
1141 print '</p><hr />';
1142
1143 $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
1144 if ($rs) {
1145 print ' Multiple, Alan and George selected: '. $rs->GetMenu('menu',array('Alan','George'),false,true);
1146 if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
1147 } else print " Fail<BR>";
1148 print '</p><hr />';
1149
1150 print "Testing GetMenu3()<br>";
1151 $rs = $db->Execute("select ".$db->Concat('firstname',"'-'",'id').",id, lastname from ADOXYZ order by lastname,id");
1152 if ($rs) print "Grouped Menu: ".$rs->GetMenu3('name');
1153 else Err('Grouped Menu GetMenu3()');
1154 print "<hr />";
1155
1156 print "Testing GetMenu2() <BR>";
1157 $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
1158 if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu2('menu',('Oey')).'<BR>';
1159 else print " Fail<BR>";
1160 $rs = $db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ");
1161 if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu2('menu',('Oey'),false).'<BR>';
1162 else print " Fail<BR>";
1163 }
1164 echo "<h3>CacheExecute</h3>";
1165
1166 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
1167 $rs = $db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ");
1168 print_r($rs->fields); echo $rs->fetchMode;echo "<br>";
1169 echo $rs->Fields('firstname');
1170
1171 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1172 $rs = $db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ");
1173 print_r($rs->fields);echo "<br>";
1174 echo $rs->Fields('firstname');
1175 $db->debug = false;
1176
1177 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
1178 // phplens
1179
1180 $sql = 'select * from ADOXYZ where 0=1';
1181 echo "<p>**Testing '$sql' (phplens compat 1)</p>";
1182 $rs = $db->Execute($sql);
1183 if (!$rs) err( "<b>No recordset returned for '$sql'</b>");
1184 if (!$rs->FieldCount()) err( "<b>No fields returned for $sql</b>");
1185 if (!$rs->FetchField(1)) err( "<b>FetchField failed for $sql</b>");
1186
1187 $sql = 'select * from ADOXYZ order by 1';
1188 echo "<p>**Testing '$sql' (phplens compat 2)</p>";
1189 $rs = $db->Execute($sql);
1190 if (!$rs) err( "<b>No recordset returned for '$sql'<br>".$db->ErrorMsg()."</b>");
1191
1192
1193 $sql = 'select * from ADOXYZ order by 1,1';
1194 echo "<p>**Testing '$sql' (phplens compat 3)</p>";
1195 $rs = $db->Execute($sql);
1196 if (!$rs) err( "<b>No recordset returned for '$sql'<br>".$db->ErrorMsg()."</b>");
1197
1198
1199 // Move
1200 $rs1 = $db->Execute("select id from ADOXYZ where id <= 2 order by 1");
1201 $rs2 = $db->Execute("select id from ADOXYZ where id = 3 or id = 4 order by 1");
1202
1203 if ($rs1) $rs1->MoveLast();
1204 if ($rs2) $rs2->MoveLast();
1205
1206 if (empty($rs1) || empty($rs2) || $rs1->fields[0] != 2 || $rs2->fields[0] != 4) {
1207 $a = $rs1->fields[0];
1208 $b = $rs2->fields[0];
1209 print "<p><b>Error in multiple recordset test rs1=$a rs2=$b (should be rs1=2 rs2=4)</b></p>";
1210 } else
1211 print "<p>Testing multiple recordsets OK</p>";
1212
1213
1214 echo "<p> GenID test: ";
1215 for ($i=1; $i <= 10; $i++)
1216 echo "($i: ",$val = $db->GenID($db->databaseType.'abcseq6' ,5), ") ";
1217 if ($val == 0) Err("GenID not supported");
1218
1219 if ($val) {
1220 $db->DropSequence('abc_seq2');
1221 $db->CreateSequence('abc_seq2');
1222 $val = $db->GenID('abc_seq2');
1223 $db->DropSequence('abc_seq2');
1224 $db->CreateSequence('abc_seq2');
1225 $val = $db->GenID('abc_seq2');
1226 if ($val != 1) Err("Drop and Create Sequence not supported ($val)");
1227 }
1228 echo "<p>";
1229
1230 if (substr($db->dataProvider,0,3) != 'notused') { // used to crash ado
1231 $sql = "select firstnames from ADOXYZ";
1232 print "<p>Testing execution of illegal statement: <i>$sql</i></p>";
1233 if ($db->Execute($sql) === false) {
1234 print "<p>This returns the following ErrorMsg(): <i>".$db->ErrorMsg()."</i> and ErrorNo(): ".$db->ErrorNo().'</p>';
1235 } else
1236 print "<p><b>Error in error handling -- Execute() should return false</b></p>";
1237 } else
1238 print "<p><b>ADO skipped error handling of bad select statement</b></p>";
1239
1240 print "<p>ASSOC TEST 2<br>";
1241 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1242 $rs = $db->query('select * from ADOXYZ order by id');
1243 if ($ee = $db->ErrorMsg()) {
1244 Err("Error message=$ee");
1245 }
1246 if ($ee = $db->ErrorNo()) {
1247 Err("Error No = $ee");
1248 }
1249 print_r($rs->fields);
1250 for($i=0;$i<$rs->FieldCount();$i++)
1251 {
1252 $fld=$rs->FetchField($i);
1253 print "<br> Field name is ".$fld->name;
1254 print " ".$rs->Fields($fld->name);
1255 }
1256
1257
1258 print "<p>BOTH TEST 2<br>";
1259 if ($db->dataProvider == 'ado') {
1260 print "<b>ADODB_FETCH_BOTH not supported</b> for dataProvider=".$db->dataProvider."<br>";
1261 } else {
1262 $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
1263 $rs = $db->query('select * from ADOXYZ order by id');
1264 for($i=0;$i<$rs->FieldCount();$i++)
1265 {
1266 $fld=$rs->FetchField($i);
1267 print "<br> Field name is ".$fld->name;
1268 print " ".$rs->Fields($fld->name);
1269 }
1270 }
1271
1272 print "<p>NUM TEST 2<br>";
1273 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
1274 $rs = $db->query('select * from ADOXYZ order by id');
1275 for($i=0;$i<$rs->FieldCount();$i++)
1276 {
1277 $fld=$rs->FetchField($i);
1278 print "<br> Field name is ".$fld->name;
1279 print " ".$rs->Fields($fld->name);
1280 }
1281
1282 print "<p>ASSOC Test of SelectLimit<br>";
1283 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1284 $rs = $db->selectlimit('select * from ADOXYZ order by id',3,4);
1285 $cnt = 0;
1286 while ($rs && !$rs->EOF) {
1287 $cnt += 1;
1288 if (!isset($rs->fields['firstname'])) {
1289 print "<br><b>ASSOC returned numeric field</b></p>";
1290 break;
1291 }
1292 $rs->MoveNext();
1293 }
1294 if ($cnt != 3) print "<br><b>Count should be 3, instead it was $cnt</b></p>";
1295
1296
1297 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
1298 if ($db->sysDate) {
1299 $saved = $db->debug;
1300 $db->debug = 1;
1301 $rs = $db->Execute("select {$db->sysDate} from ADOXYZ where id=1");
1302 if (ADORecordSet::UnixDate(date('Y-m-d')) != $rs->UnixDate($rs->fields[0])) {
1303 print "<p><b>Invalid date {$rs->fields[0]}</b></p>";
1304 } else
1305 print "<p>Passed \$sysDate test ({$rs->fields[0]})</p>";
1306
1307 print_r($rs->FetchField(0));
1308 print time();
1309 $db->debug=$saved;
1310 } else {
1311 print "<p><b>\$db->sysDate not defined</b></p>";
1312 }
1313
1314 print "<p>Test CSV</p>";
1315 include_once('../toexport.inc.php');
1316 //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1317 $rs = $db->SelectLimit('select id,firstname,lastname,created,\'He, he\' he,\'"\' q from ADOXYZ',10);
1318
1319 print "<pre>";
1320 print rs2csv($rs);
1321 print "</pre>";
1322
1323 $rs = $db->SelectLimit('select id,firstname,lastname,created,\'The "young man", he said\' from ADOXYZ',10);
1324
1325 if (PHP_VERSION < 5) {
1326 print "<pre>";
1327 rs2tabout($rs);
1328 print "</pre>";
1329 }
1330 print " CacheFlush ";
1331 $db->CacheFlush();
1332
1333 $date = $db->SQLDate('d-m-M-Y-\QQ h:i:s A');
1334 $sql = "SELECT $date from ADOXYZ";
1335 print "<p>Test SQLDate: ".htmlspecialchars($sql)."</p>";
1336 $rs = $db->SelectLimit($sql,1);
1337 $d = date('d-m-M-Y-').'Q'.(ceil(date('m')/3.0)).date(' h:i:s A');
1338 if (!$rs) Err("SQLDate query returned no recordset");
1339 else if ($d != $rs->fields[0]) Err("SQLDate 1 failed expected: <br>act:$d <br>sql:".$rs->fields[0]);
1340
1341 $date = $db->SQLDate('d-m-M-Y-\QQ h:i:s A',$db->DBDate("1974-02-25"));
1342 $sql = "SELECT $date from ADOXYZ";
1343 print "<p>Test SQLDate: ".htmlspecialchars($sql)."</p>";
1344 $db->debug=1;
1345 $rs = $db->SelectLimit($sql,1);
1346 $ts = ADOConnection::UnixDate('1974-02-25');
1347 $d = date('d-m-M-Y-',$ts).'Q'.(ceil(date('m',$ts)/3.0)).date(' h:i:s A',$ts);
1348 if (!$rs) {
1349 Err("SQLDate query returned no recordset");
1350 echo $db->ErrorMsg(),'<br>';
1351 } else if ($d != reset($rs->fields)) {
1352 Err("SQLDate 2 failed expected: <br>act:$d <br>sql:".$rs->fields[0].' <br>'.$db->ErrorMsg());
1353 }
1354
1355
1356 print "<p>Test Filter</p>";
1357 $db->debug = 1;
1358
1359 $rs = $db->SelectLimit('select * from ADOXYZ where id < 3 order by id');
1360
1361 $rs = RSFilter($rs,'do_strtolower');
1362 if (trim($rs->fields[1]) != 'caroline' && trim($rs->fields[2]) != 'miranda') {
1363 err('**** RSFilter failed');
1364 print_r($rs->fields);
1365 }
1366
1367 rs2html($rs);
1368
1369 $db->debug=1;
1370
1371
1372 print "<p>Test Replace</p>";
1373
1374 $ret = $db->Replace('ADOXYZ',
1375 array('id'=>1,'firstname'=>'Caroline','lastname'=>'Miranda'),
1376 array('id'),
1377 $autoq = true);
1378 if (!$ret) echo "<p>Error in replacing existing record</p>";
1379 else {
1380 $saved = $db->debug;
1381 $db->debug = 0;
1382 $savec = $ADODB_COUNTRECS;
1383 $ADODB_COUNTRECS = true;
1384 $rs = $db->Execute('select * FROM ADOXYZ where id=1');
1385 $db->debug = $saved;
1386 if ($rs->RecordCount() != 1) {
1387 $cnt = $rs->RecordCount();
1388 rs2html($rs);
1389 print "<b>Error - Replace failed, count=$cnt</b><p>";
1390 }
1391 $ADODB_COUNTRECS = $savec;
1392 }
1393 $ret = $db->Replace('ADOXYZ',
1394 array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'),
1395 array('id','firstname'),
1396 $autoq = true);
1397 if ($ret != 2) print "<b>Replace failed: </b>";
1398 print "test A return value=$ret (2 expected) <p>";
1399
1400 $ret = $db->Replace('ADOXYZ',
1401 array('id'=>1000,'firstname'=>'Sherazade','lastname'=>'Al-Rashid'),
1402 'id',
1403 $autoq = true);
1404 if ($ret != 1)
1405 if ($db->dataProvider == 'ibase' && $ret == 2);
1406 else print "<b>Replace failed: </b>";
1407 print "test B return value=$ret (1 or if ibase then 2 expected) <p>";
1408
1409 print "<h3>rs2rs Test</h3>";
1410
1411 $rs = $db->Execute('select * from ADOXYZ where id>= 1 order by id');
1412 $rs = $db->_rs2rs($rs);
1413 $rs->valueX = 'X';
1414 $rs->MoveNext();
1415 $rs = $db->_rs2rs($rs);
1416 if (!isset($rs->valueX)) err("rs2rs does not preserve array recordsets");
1417 if (reset($rs->fields) != 1) err("rs2rs does not move to first row: id=".reset($rs->fields));
1418
1419 /////////////////////////////////////////////////////////////
1420 include_once('../pivottable.inc.php');
1421 print "<h3>Pivot Test</h3>";
1422 $db->debug=true;
1423 $sql = PivotTableSQL(
1424 $db, # adodb connection
1425 'ADOXYZ', # tables
1426 'firstname', # row fields
1427 'lastname', # column fields
1428 false, # join
1429 'ID', # sum
1430 'Sum ', # label for sum
1431 'sum', # aggregate function
1432 true
1433 );
1434 $rs = $db->Execute($sql);
1435 if ($rs) rs2html($rs);
1436 else Err("Pivot sql error");
1437
1438 $pear = true; //true;
1439 $db->debug=false;
1440
1441 if ($pear) {
1442 // PEAR TESTS BELOW
1443 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
1444
1445 include_once "PEAR.php";
1446 $rs = $db->query('select * from ADOXYZ where id>0 and id<10 order by id');
1447
1448 $i = 0;
1449 if ($rs && !$rs->EOF) {
1450 while ($arr = $rs->fetchRow()) {
1451 $i++;
1452 //print "$i ";
1453 if ($arr[0] != $i) {
1454 print_r($arr);
1455 print "<p><b>PEAR DB emulation error 1.</b></p>";
1456 $pear = false;
1457 break;
1458 }
1459 }
1460 $rs->Close();
1461 }
1462
1463
1464 if ($i != $db->GetOne('select count(*) from ADOXYZ where id>0 and id<10')) {
1465 print "<p><b>PEAR DB emulation error 1.1 EOF ($i)</b></p>";
1466 $pear = false;
1467 }
1468
1469 $rs = $db->limitQuery('select * from ADOXYZ where id>0 order by id',$i=3,$top=3);
1470 $i2 = $i;
1471 if ($rs && !$rs->EOF) {
1472
1473 while (!is_object($rs->fetchInto($arr))) {
1474 $i2++;
1475
1476 // print_r($arr);
1477 // print "$i ";print_r($arr);
1478 if ($arr[0] != $i2) {
1479 print "<p><b>PEAR DB emulation error 2.</b></p>";
1480 $pear = false;
1481 break;
1482 }
1483 }
1484 $rs->Close();
1485 }
1486 if ($i2 != $i+$top) {
1487 print "<p><b>PEAR DB emulation error 2.1 EOF (correct=$i+$top, actual=$i2)</b></p>";
1488 $pear = false;
1489 }
1490 }
1491 if ($pear) print "<p>PEAR DB emulation passed.</p>";
1492 flush();
1493
1494
1495 $rs = $db->SelectLimit("select ".$db->sysDate." from ADOXYZ",1);
1496 $date = $rs->fields[0];
1497 if (!$date) Err("Bad sysDate");
1498 else {
1499 $ds = $db->UserDate($date,"d m Y");
1500 if ($ds != date("d m Y")) Err("Bad UserDate: ".$ds.' expected='.date("d m Y"));
1501 else echo "Passed UserDate: $ds<p>";
1502 }
1503 $db->debug=1;
1504 if ($db->dataProvider == 'oci8')
1505 $rs = $db->SelectLimit("select to_char(".$db->sysTimeStamp.",'YYYY-MM-DD HH24:MI:SS') from ADOXYZ",1);
1506 else
1507 $rs = $db->SelectLimit("select ".$db->sysTimeStamp." from ADOXYZ",1);
1508 $date = $rs->fields[0];
1509 if (!$date) Err("Bad sysTimeStamp");
1510 else {
1511 $ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y");
1512 if ($ds != date("H \\h\\r\\s-d m Y")) Err("Bad UserTimeStamp: ".$ds.", correct is ".date("H \\h\\r\\s-d m Y"));
1513 else echo "Passed UserTimeStamp: $ds<p>";
1514
1515 $date = 100;
1516 $ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y");
1517 $ds2 = date("H \\h\\r\\s-d m Y",$date);
1518 if ($ds != $ds2) Err("Bad UserTimeStamp 2: $ds: $ds2");
1519 else echo "Passed UserTimeStamp 2: $ds<p>";
1520 }
1521 flush();
1522
1523 if ($db->hasTransactions) {
1524 $db->debug=1;
1525 echo "<p>Testing StartTrans CompleteTrans</p>";
1526 $db->raiseErrorFn = false;
1527
1528 $db->SetTransactionMode('SERIALIZABLE');
1529 $db->StartTrans();
1530 $rs = $db->Execute('select * from notable');
1531 $db->StartTrans();
1532 $db->BeginTrans();
1533 $db->Execute("update ADOXYZ set firstname='Carolx' where id=1");
1534 $db->CommitTrans();
1535 $db->CompleteTrans();
1536 $rez = $db->CompleteTrans();
1537 $db->SetTransactionMode('');
1538 $db->debug=0;
1539 if ($rez !== false) {
1540 if (is_null($rez)) Err("Error: _transOK not modified");
1541 else Err("Error: CompleteTrans (1) should have failed");
1542 } else {
1543 $name = $db->GetOne("Select firstname from ADOXYZ where id=1");
1544 if ($name == "Carolx") Err("Error: CompleteTrans (2) should have failed");
1545 else echo "<p> -- Passed StartTrans test1 - rolling back</p>";
1546 }
1547
1548 $db->StartTrans();
1549 $db->BeginTrans();
1550 $db->Execute("update ADOXYZ set firstname='Carolx' where id=1");
1551 $db->RollbackTrans();
1552 $rez = $db->CompleteTrans();
1553 if ($rez !== true) Err("Error: CompleteTrans (1) should have succeeded");
1554 else {
1555 $name = $db->GetOne("Select firstname from ADOXYZ where id=1");
1556 if (trim($name) != "Carolx") Err("Error: CompleteTrans (2) should have succeeded, returned name=$name");
1557 else echo "<p> -- Passed StartTrans test2 - commiting</p>";
1558 }
1559 }
1560 flush();
1561 $saved = $db->debug;
1562 $db->debug=1;
1563 $cnt = _adodb_getcount($db, 'select * from ADOXYZ where firstname in (select firstname from ADOXYZ)');
1564 echo "<b>Count=</b> $cnt";
1565 $db->debug=$saved;
1566
1567 global $TESTERRS;
1568 $debugerr = true;
1569
1570 global $ADODB_LANG;$ADODB_LANG = 'fr';
1571 $db->debug = false;
1572 $TESTERRS = 0;
1573 $db->raiseErrorFn = 'adodb_test_err';
1574 global $ERRNO; // from adodb_test_err
1575 $db->Execute('select * from nowhere');
1576 $metae = $db->MetaError($ERRNO);
1577 if ($metae !== DB_ERROR_NOSUCHTABLE) print "<p><b>MetaError=".$metae." wrong</b>, should be ".DB_ERROR_NOSUCHTABLE."</p>";
1578 else print "<p>MetaError ok (".DB_ERROR_NOSUCHTABLE."): ".$db->MetaErrorMsg($metae)."</p>";
1579 if ($TESTERRS != 1) print "<b>raiseErrorFn select nowhere failed</b><br>";
1580 $rs = $db->Execute('select * from ADOXYZ');
1581 if ($debugerr) print " Move";
1582 $rs->Move(100);
1583 $rs->_queryID = false;
1584 if ($debugerr) print " MoveNext";
1585 $rs->MoveNext();
1586 if ($debugerr) print " $rs=false";
1587 $rs = false;
1588
1589 flush();
1590
1591 print "<p>SetFetchMode() tests</p>";
1592 $db->SetFetchMode(ADODB_FETCH_ASSOC);
1593 $rs = $db->SelectLimit('select firstname from ADOXYZ',1);
1594 if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC");
1595
1596 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
1597 $rs = $db->SelectLimit('select firstname from ADOXYZ',1);
1598 //var_dump($rs->fields);
1599 if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC");
1600
1601 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1602 $db->SetFetchMode(ADODB_FETCH_NUM);
1603 $rs = $db->SelectLimit('select firstname from ADOXYZ',1);
1604 if (!isset($rs->fields[0])) Err("BAD FETCH NUM");
1605
1606 flush();
1607
1608 print "<p>Test MetaTables again with SetFetchMode()</p>";
1609 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1610 $db->SetFetchMode(ADODB_FETCH_ASSOC);
1611 print_r($db->MetaTables());
1612 print "<p>";
1613
1614 ////////////////////////////////////////////////////////////////////
1615
1616 print "<p>Testing Bad Connection</p>";
1617 flush();
1618
1619 if (true || PHP_VERSION < 5) {
1620 if ($db->dataProvider == 'odbtp') $db->databaseType = 'odbtp';
1621 $conn = NewADOConnection($db->databaseType);
1622 $conn->raiseErrorFn = 'adodb_test_err';
1623 if (1) $conn->PConnect('abc','baduser','badpassword');
1624 if ($TESTERRS == 2) print "raiseErrorFn tests passed<br>";
1625 else print "<b>raiseErrorFn tests failed ($TESTERRS)</b><br>";
1626
1627 flush();
1628 }
1629 ////////////////////////////////////////////////////////////////////
1630
1631 global $nocountrecs;
1632
1633 if (isset($nocountrecs) && $ADODB_COUNTRECS) err("Error: \$ADODB_COUNTRECS is set");
1634 if (empty($nocountrecs) && $ADODB_COUNTRECS==false) err("Error: \$ADODB_COUNTRECS is not set");
1635
1636 flush();
1637 ?>
1638 </p>
1639 <table width=100% ><tr><td bgcolor=beige>&nbsp;</td></tr></table>
1640 </p></form>
1641 <?php
1642
1643 if ($rs1) $rs1->Close();
1644 if ($rs2) $rs2->Close();
1645 if ($rs) $rs->Close();
1646 $db->Close();
1647
1648 if ($db->transCnt != 0) Err("Error in transCnt=$db->transCnt (should be 0)");
1649
1650
1651 printf("<p>Total queries=%d; total cached=%d</p>",$EXECS+$CACHED, $CACHED);
1652 flush();
1653 }
1654
1655 function adodb_test_err($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
1656 {
1657 global $TESTERRS,$ERRNO;
1658
1659 $ERRNO = $errno;
1660 $TESTERRS += 1;
1661 print "<i>** $dbms ($fn): errno=$errno &nbsp; errmsg=$errmsg ($p1,$p2)</i><br>";
1662 }
1663
1664 //--------------------------------------------------------------------------------------
1665
1666
1667 @set_time_limit(240); // increase timeout
1668
1669 include("../tohtml.inc.php");
1670 include("../adodb.inc.php");
1671 include("../rsfilter.inc.php");
1672
1673 /* White Space Check */
1674
1675 if (isset($_SERVER['argv'][1])) {
1676 //print_r($_SERVER['argv']);
1677 $_GET[$_SERVER['argv'][1]] = 1;
1678 }
1679
1680 if (@$_SERVER['COMPUTERNAME'] == 'TIGRESS') {
1681 CheckWS('mysqlt');
1682 CheckWS('postgres');
1683 CheckWS('oci8po');
1684
1685 CheckWS('firebird');
1686 CheckWS('sybase');
1687 if (!ini_get('safe_mode')) CheckWS('informix');
1688
1689 CheckWS('ado_mssql');
1690 CheckWS('ado_access');
1691 CheckWS('mssql');
1692
1693 CheckWS('vfp');
1694 CheckWS('sqlanywhere');
1695 CheckWS('db2');
1696 CheckWS('access');
1697 CheckWS('odbc_mssql');
1698 CheckWS('firebird15');
1699 //
1700 CheckWS('oracle');
1701 CheckWS('proxy');
1702 CheckWS('fbsql');
1703 print "White Space Check complete<p>";
1704 }
1705 if (sizeof($_GET) == 0) $testmysql = true;
1706
1707
1708 foreach($_GET as $k=>$v) {
1709 //global $$k;
1710 $$k = $v;
1711 }
1712 if (strpos(PHP_VERSION,'5') === 0) {
1713 //$testaccess=1;
1714 //$testmssql = 1;
1715 //$testsqlite=1;
1716 }
1717 ?>
1718 <html>
1719 <title>ADODB Testing</title>
1720 <body bgcolor=white>
1721 <H1>ADODB Test</H1>
1722
1723 This script tests the following databases: Interbase, Oracle, Visual FoxPro, Microsoft Access (ODBC and ADO), MySQL, MSSQL (ODBC, native, ADO).
1724 There is also support for Sybase, PostgreSQL.</p>
1725 For the latest version of ADODB, visit <a href=http://adodb.sourceforge.net/>adodb.sourceforge.net</a>.</p>
1726
1727 Test <a href=test4.php>GetInsertSQL/GetUpdateSQL</a> &nbsp;
1728 <a href=testsessions.php>Sessions</a> &nbsp;
1729 <a href=testpaging.php>Paging</a> &nbsp;
1730 <a href=test-perf.php>Perf Monitor</a><p>
1731 <?php
1732 include('./testdatabases.inc.php');
1733
1734 echo "<br>vers=",ADOConnection::Version();
1735
1736
1737 include_once('../adodb-time.inc.php');
1738 if (isset($_GET['time'])) adodb_date_test();
1739
1740 ?>
1741 <p><i>ADODB Database Library (c) 2000-2007 John Lim. All rights reserved. Released under BSD and LGPL, PHP <?php echo PHP_VERSION ?>.</i></p>
1742 </body>
1743 </html>