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