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