| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | V4.80 8 Mar 2006 (c) 2000-2009 John Lim (jlim#natsoft.com). All rights reserved. |
|---|
| 4 | Released under both BSD license and Lesser GPL library license. |
|---|
| 5 | Whenever there is any discrepancy between the two licenses, |
|---|
| 6 | the BSD license will take precedence. |
|---|
| 7 | Set tabs to 4 for best viewing. |
|---|
| 8 | |
|---|
| 9 | Latest version is available at http://adodb.sourceforge.net |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | if (!defined('E_STRICT')) define('E_STRICT',E_NOTICE); |
|---|
| 14 | #error_reporting(E_ALL|E_STRICT); |
|---|
| 15 | error_reporting(E_ALL); |
|---|
| 16 | |
|---|
| 17 | $ADODB_FLUSH = true; |
|---|
| 18 | |
|---|
| 19 | define('ADODB_ASSOC_CASE',0); |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | function getmicrotime() |
|---|
| 23 | { |
|---|
| 24 | $t = microtime(); |
|---|
| 25 | $t = explode(' ',$t); |
|---|
| 26 | return (float)$t[1]+ (float)$t[0]; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | if (PHP_VERSION < 5) include_once('../adodb-pear.inc.php'); |
|---|
| 31 | //-------------------------------------------------------------------------------------- |
|---|
| 32 | //define('ADODB_ASSOC_CASE',1); |
|---|
| 33 | // |
|---|
| 34 | function Err($msg) |
|---|
| 35 | { |
|---|
| 36 | print "<b>$msg</b><br>"; |
|---|
| 37 | flush(); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | function CheckWS($conn) |
|---|
| 41 | { |
|---|
| 42 | global $ADODB_EXTENSION; |
|---|
| 43 | |
|---|
| 44 | include_once('../session/adodb-session.php'); |
|---|
| 45 | if (defined('CHECKWSFAIL')){ echo " TESTING $conn ";flush();} |
|---|
| 46 | $saved = $ADODB_EXTENSION; |
|---|
| 47 | $db = ADONewConnection($conn); |
|---|
| 48 | $ADODB_EXTENSION = $saved; |
|---|
| 49 | if (headers_sent()) { |
|---|
| 50 | print "<p><b>White space detected in adodb-$conn.inc.php or include file...</b></p>"; |
|---|
| 51 | //die(); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | function do_strtolower(&$arr) |
|---|
| 56 | { |
|---|
| 57 | foreach($arr as $k => $v) { |
|---|
| 58 | if (is_object($v)) $arr[$k] = adodb_pr($v,true); |
|---|
| 59 | else $arr[$k] = strtolower($v); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | function CountExecs($db, $sql, $inputarray) |
|---|
| 65 | { |
|---|
| 66 | global $EXECS; $EXECS++; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | function CountCachedExecs($db, $secs2cache, $sql, $inputarray) |
|---|
| 70 | { |
|---|
| 71 | global $CACHED; $CACHED++; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | // the table creation code is specific to the database, so we allow the user |
|---|
| 75 | // to define their own table creation stuff |
|---|
| 76 | |
|---|
| 77 | function testdb(&$db,$createtab="create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)") |
|---|
| 78 | { |
|---|
| 79 | GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE,$ADODB_COUNTRECS; |
|---|
| 80 | |
|---|
| 81 | //adodb_pr($db); |
|---|
| 82 | |
|---|
| 83 | ?> <form method=GET> |
|---|
| 84 | </p> |
|---|
| 85 | <table width=100% ><tr><td bgcolor=beige> </td></tr></table> |
|---|
| 86 | </p> |
|---|
| 87 | <?php |
|---|
| 88 | $create =false; |
|---|
| 89 | /*$ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 90 | |
|---|
| 91 | $rs = $db->Execute('select lastname,firstname,lastname,id from ADOXYZ'); |
|---|
| 92 | $arr = $rs->GetAssoc(); |
|---|
| 93 | echo "<pre>";print_r($arr); |
|---|
| 94 | die();*/ |
|---|
| 95 | |
|---|
| 96 | if (!$db) die("testdb: database not inited"); |
|---|
| 97 | GLOBAL $EXECS, $CACHED; |
|---|
| 98 | |
|---|
| 99 | $EXECS = 0; |
|---|
| 100 | $CACHED = 0; |
|---|
| 101 | //$db->Execute("drop table adodb_logsql"); |
|---|
| 102 | if ((rand()%3) == 0) @$db->Execute("delete from adodb_logsql"); |
|---|
| 103 | $db->debug=1; |
|---|
| 104 | |
|---|
| 105 | $db->fnExecute = 'CountExecs'; |
|---|
| 106 | $db->fnCacheExecute = 'CountCachedExecs'; |
|---|
| 107 | |
|---|
| 108 | if (empty($_GET['nolog'])) { |
|---|
| 109 | echo "<h3>SQL Logging enabled</h3>"; |
|---|
| 110 | $db->LogSQL();/* |
|---|
| 111 | $sql = |
|---|
| 112 | "SELECT t1.sid, t1.sid, t1.title, t1.hometext, t1.notes, t1.aid, t1.informant, |
|---|
| 113 | t2.url, t2.email, t1.catid, t3.title, t1.topic, t4.topicname, t4.topicimage, |
|---|
| 114 | t4.topictext, t1.score, t1.ratings, t1.counter, t1.comments, t1.acomm |
|---|
| 115 | FROM `nuke_stories` `t1`, `nuke_authors` `t2`, `nuke_stories_cat` `t3`, `nuke_topics` `t4` |
|---|
| 116 | WHERE ((t2.aid=t1.aid) AND (t3.catid=t1.catid) AND (t4.topicid=t1.topic) |
|---|
| 117 | AND ((t1.alanguage='german') OR (t1.alanguage='')) AND (t1.ihome='0')) |
|---|
| 118 | ORDER BY t1.time DESC"; |
|---|
| 119 | $db->SelectLimit($sql); |
|---|
| 120 | echo $db->ErrorMsg();*/ |
|---|
| 121 | } |
|---|
| 122 | $ADODB_CACHE_DIR = dirname(TempNam('/tmp','testadodb')); |
|---|
| 123 | $db->debug = false; |
|---|
| 124 | //print $db->UnixTimeStamp('2003-7-22 23:00:00'); |
|---|
| 125 | |
|---|
| 126 | $phpv = phpversion(); |
|---|
| 127 | if (defined('ADODB_EXTENSION')) $ext = ' Extension '.ADODB_EXTENSION.' installed'; |
|---|
| 128 | else $ext = ''; |
|---|
| 129 | print "<h3>ADODB Version: $ADODB_vers Host: <i>$db->host</i> Database: <i>$db->database</i> PHP: $phpv $ext</h3>"; |
|---|
| 130 | |
|---|
| 131 | flush(); |
|---|
| 132 | |
|---|
| 133 | if (function_exists('date_default_timezone_set')) date_default_timezone_set('Asia/Kuala_Lumpur'); |
|---|
| 134 | |
|---|
| 135 | $arr = $db->ServerInfo(); |
|---|
| 136 | print_r($arr); |
|---|
| 137 | echo E_ALL,' ',E_STRICT, "<br>"; |
|---|
| 138 | #$e = error_reporting(E_ALL | E_STRICT); |
|---|
| 139 | echo error_reporting(),'<p>'; |
|---|
| 140 | flush(); |
|---|
| 141 | #$db->debug=1; |
|---|
| 142 | $tt = $db->Time(); |
|---|
| 143 | if ($tt == 0) echo '<br><b>$db->Time failed</b>'; |
|---|
| 144 | else echo "<br>db->Time: ".date('d-m-Y H:i:s',$tt); |
|---|
| 145 | echo '<br>'; |
|---|
| 146 | |
|---|
| 147 | echo "Date=",$db->UserDate('2002-04-07'),'<br>'; |
|---|
| 148 | print "<i>date1</i> (1969-02-20) = ".$db->DBDate('1969-2-20'); |
|---|
| 149 | print "<br><i>date1</i> (1999-02-20) = ".$db->DBDate('1999-2-20'); |
|---|
| 150 | print "<br><i>date1.1</i> 1999 = ".$db->DBDate("'1999'"); |
|---|
| 151 | print "<br><i>date2</i> (1970-1-2) = ".$db->DBDate(24*3600)."<p>"; |
|---|
| 152 | print "<i>ts1</i> (1999-02-20 13:40:50) = ".$db->DBTimeStamp('1999-2-20 1:40:50 pm'); |
|---|
| 153 | print "<br><i>ts1.1</i> (1999-02-20 13:40:00) = ".$db->DBTimeStamp('1999-2-20 13:40'); |
|---|
| 154 | print "<br><i>ts2</i> (1999-02-20) = ".$db->DBTimeStamp('1999-2-20'); |
|---|
| 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 | } |
|---|
| 173 | #error_reporting($e); |
|---|
| 174 | flush(); |
|---|
| 175 | |
|---|
| 176 | //$ADODB_COUNTRECS=false; |
|---|
| 177 | $rs=$db->Execute('select * from ADOXYZ order by id'); |
|---|
| 178 | if($rs === false) $create = true; |
|---|
| 179 | else $rs->Close(); |
|---|
| 180 | |
|---|
| 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 { |
|---|
| 188 | $db->debug = 99; |
|---|
| 189 | # $e = error_reporting(E_ALL-E_WARNING); |
|---|
| 190 | $db->Execute($createtab); |
|---|
| 191 | # error_reporting($e); |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| 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 |
|---|
| 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>"; |
|---|
| 206 | $rs = $db->Execute("select id,firstname from ADOXYZ where id=9999"); |
|---|
| 207 | if ($rs && !$rs->EOF) print "<b>Error: </b>RecordSet returned by Execute(select...') on empty table should show EOF</p>"; |
|---|
| 208 | if ($rs->EOF && (($ox = $rs->FetchField(0)) && !empty($ox->name))) { |
|---|
| 209 | $record['id'] = 99; |
|---|
| 210 | $record['firstname'] = 'John'; |
|---|
| 211 | $sql = $db->GetInsertSQL($rs, $record); |
|---|
| 212 | if (strtoupper($sql) != strtoupper("INSERT INTO ADOXYZ ( id, firstname ) VALUES ( 99, 'John' )")) Err("GetInsertSQL does not work on empty table: $sql"); |
|---|
| 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(); |
|---|
| 230 | $rs = $db->Execute("select * from ADOXYZ where id=99"); |
|---|
| 231 | if ($rs === false || $rs->EOF) { |
|---|
| 232 | print '<b>Data not saved</b></p>'; |
|---|
| 233 | $rs = $db->Execute("select * from ADOXYZ where id=99"); |
|---|
| 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 | |
|---|
| 258 | $rs = $db->Execute('delete from ADOXYZ where id>50'); |
|---|
| 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 | |
|---|
| 301 | $db->debug=0; |
|---|
| 302 | $rez = $db->MetaColumns("NOSUCHTABLEHERE"); |
|---|
| 303 | if ($rez !== false) { |
|---|
| 304 | Err("MetaColumns error handling failed"); |
|---|
| 305 | var_dump($rez); |
|---|
| 306 | } |
|---|
| 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 | } |
|---|
| 329 | $rs = $db->Execute('delete from ADOXYZ'); |
|---|
| 330 | if ($rs) $rs->Close(); |
|---|
| 331 | |
|---|
| 332 | $db->debug = false; |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | switch ($db->databaseType) { |
|---|
| 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 | |
|---|
| 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>"; |
|---|
| 353 | $arr = $db->MetaForeignKeys('ADOXYZ',false,true); |
|---|
| 354 | print_r($arr); |
|---|
| 355 | if (!$arr) Err("No MetaForeignKeys"); |
|---|
| 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 |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | CREATE PROCEDURE ADODBTestSP |
|---|
| 394 | @a nvarchar(25) |
|---|
| 395 | AS |
|---|
| 396 | SELECT GETDATE() AS T, @a AS A |
|---|
| 397 | GO |
|---|
| 398 | */ |
|---|
| 399 | print "<h4>Testing Stored Procedures for mssql</h4>"; |
|---|
| 400 | $saved = $db->debug; |
|---|
| 401 | $db->debug=true; |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 429 | $ADODB_FETCH_MODE = $assoc; |
|---|
| 430 | |
|---|
| 431 | /* |
|---|
| 432 | Test out params - works in PHP 4.2.3 and 4.3.3 and 4.3.8 but not 4.3.0: |
|---|
| 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); |
|---|
| 454 | if (empty($begin_date) or empty($end_date) or $begin_date == $end_date) { |
|---|
| 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': |
|---|
| 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 | |
|---|
| 479 | $saved = $db->debug; |
|---|
| 480 | $db->debug=true; |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | /* |
|---|
| 485 | CREATE TABLE PHOTOS |
|---|
| 486 | ( |
|---|
| 487 | ID NUMBER(16), |
|---|
| 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 | |
|---|
| 500 | $sql = "INSERT INTO photos ( ID, photo) ". |
|---|
| 501 | "VALUES ( :id, empty_blob() )". |
|---|
| 502 | " RETURNING photo INTO :xx"; |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 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 | |
|---|
| 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>"; |
|---|
| 539 | $arr = $db->MetaForeignKeys('emp','scott'); |
|---|
| 540 | print_r($arr); |
|---|
| 541 | if (!$arr) Err("Bad MetaForeignKeys"); |
|---|
| 542 | /* |
|---|
| 543 | -- TEST PACKAGE |
|---|
| 544 | -- "Set scan off" turns off substitution variables. |
|---|
| 545 | Set scan off; |
|---|
| 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); |
|---|
| 552 | PROCEDURE data_in(input IN VARCHAR); |
|---|
| 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; |
|---|
| 569 | |
|---|
| 570 | PROCEDURE data_out(input IN VARCHAR, output OUT VARCHAR) IS |
|---|
| 571 | BEGIN |
|---|
| 572 | output := 'Cinta Hati '||input; |
|---|
| 573 | END; |
|---|
| 574 | |
|---|
| 575 | PROCEDURE data_in(input IN VARCHAR) IS |
|---|
| 576 | ignore varchar(1000); |
|---|
| 577 | BEGIN |
|---|
| 578 | ignore := input; |
|---|
| 579 | END; |
|---|
| 580 | |
|---|
| 581 | PROCEDURE myproc (p1 IN NUMBER, p2 OUT NUMBER) AS |
|---|
| 582 | BEGIN |
|---|
| 583 | p2 := p1; |
|---|
| 584 | END; |
|---|
| 585 | END Adodb; |
|---|
| 586 | / |
|---|
| 587 | |
|---|
| 588 | */ |
|---|
| 589 | |
|---|
| 590 | print "<h4>Testing Cursor Variables</h4>"; |
|---|
| 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 | } |
|---|
| 600 | $rs->Close(); |
|---|
| 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 | |
|---|
| 624 | $stmt = $db->PrepareSP("begin adodb.data_in(:a1); end;"); |
|---|
| 625 | $db->InParameter($stmt,$a1,'a1'); |
|---|
| 626 | $db->Execute($stmt); |
|---|
| 627 | |
|---|
| 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 | ); |
|---|
| 639 | //$db->debug=1; |
|---|
| 640 | print "<p>Testing Bulk Insert of 3 rows</p>"; |
|---|
| 641 | |
|---|
| 642 | $sql = "insert into ADOXYZ (id,firstname,lastname) values (".$db->Param('0').",".$db->Param('1').",".$db->Param('2').")"; |
|---|
| 643 | $db->StartTrans(); |
|---|
| 644 | $db->Execute($sql,$arr); |
|---|
| 645 | $db->CompleteTrans(); |
|---|
| 646 | $rs = $db->Execute('select * from ADOXYZ order by id'); |
|---|
| 647 | if (!$rs || $rs->RecordCount() != 3) Err("Bad bulk insert"); |
|---|
| 648 | |
|---|
| 649 | rs2html($rs); |
|---|
| 650 | |
|---|
| 651 | $db->Execute('delete from ADOXYZ'); |
|---|
| 652 | |
|---|
| 653 | print "<p>Inserting 50 rows</p>"; |
|---|
| 654 | |
|---|
| 655 | for ($i = 0; $i < 5; $i++) { |
|---|
| 656 | |
|---|
| 657 | $time = $db->DBDate(time()); |
|---|
| 658 | if (empty($_GET['hide'])) $db->debug = true; |
|---|
| 659 | switch($db->databaseType){ |
|---|
| 660 | case 'mssqlpo': |
|---|
| 661 | case 'mssql': |
|---|
| 662 | $sqlt = "CREATE TABLE mytable ( |
|---|
| 663 | row1 INT IDENTITY(1,1) NOT NULL, |
|---|
| 664 | row2 varchar(16), |
|---|
| 665 | PRIMARY KEY (row1))"; |
|---|
| 666 | //$db->debug=1; |
|---|
| 667 | if (!$db->Execute("delete from mytable")) |
|---|
| 668 | $db->Execute($sqlt); |
|---|
| 669 | |
|---|
| 670 | $ok = $db->Execute("insert into mytable (row2) values ('test')"); |
|---|
| 671 | $ins_id=$db->Insert_ID(); |
|---|
| 672 | echo "Insert ID=";var_dump($ins_id); |
|---|
| 673 | if ($ins_id == 0) Err("Bad Insert_ID()"); |
|---|
| 674 | $ins_id2 = $db->GetOne("select row1 from mytable"); |
|---|
| 675 | if ($ins_id != $ins_id2) Err("Bad Insert_ID() 2"); |
|---|
| 676 | |
|---|
| 677 | $arr = array(0=>'Caroline',1=>'Miranda'); |
|---|
| 678 | $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,?,?,$time)"; |
|---|
| 679 | break; |
|---|
| 680 | case 'mysqli': |
|---|
| 681 | case 'mysqlt': |
|---|
| 682 | case 'mysql': |
|---|
| 683 | $sqlt = "CREATE TABLE `mytable` ( |
|---|
| 684 | `row1` int(11) NOT NULL auto_increment, |
|---|
| 685 | `row2` varchar(16) NOT NULL default '', |
|---|
| 686 | PRIMARY KEY (`row1`), |
|---|
| 687 | KEY `myindex` (`row1`,`row2`) |
|---|
| 688 | ) "; |
|---|
| 689 | if (!$db->Execute("delete from mytable")) |
|---|
| 690 | $db->Execute($sqlt); |
|---|
| 691 | |
|---|
| 692 | $ok = $db->Execute("insert into mytable (row2) values ('test')"); |
|---|
| 693 | $ins_id=$db->Insert_ID(); |
|---|
| 694 | echo "Insert ID=";var_dump($ins_id); |
|---|
| 695 | if ($ins_id == 0) Err("Bad Insert_ID()"); |
|---|
| 696 | $ins_id2 = $db->GetOne("select row1 from mytable"); |
|---|
| 697 | if ($ins_id != $ins_id2) Err("Bad Insert_ID() 2"); |
|---|
| 698 | |
|---|
| 699 | default: |
|---|
| 700 | $arr = array(0=>'Caroline',1=>'Miranda'); |
|---|
| 701 | $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,?,?,$time)"; |
|---|
| 702 | break; |
|---|
| 703 | |
|---|
| 704 | case 'oci8': |
|---|
| 705 | case 'oci805': |
|---|
| 706 | $arr = array('first'=>'Caroline','last'=>'Miranda'); |
|---|
| 707 | $amt = rand() % 100; |
|---|
| 708 | $sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,:first,:last,$time)"; |
|---|
| 709 | break; |
|---|
| 710 | } |
|---|
| 711 | if ($i & 1) { |
|---|
| 712 | $sql = $db->Prepare($sql); |
|---|
| 713 | } |
|---|
| 714 | $rs = $db->Execute($sql,$arr); |
|---|
| 715 | |
|---|
| 716 | if ($rs === false) Err( 'Error inserting with parameters'); |
|---|
| 717 | else $rs->Close(); |
|---|
| 718 | $db->debug = false; |
|---|
| 719 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+1,'John','Lim',$time)"); |
|---|
| 720 | /*$ins_id=$db->Insert_ID(); |
|---|
| 721 | echo "Insert ID=";var_dump($ins_id);*/ |
|---|
| 722 | if ($db->databaseType == 'mysql') if ($ins_id == 0) Err('Bad Insert_ID'); |
|---|
| 723 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+2,'Mary','Lamb',$time )"); |
|---|
| 724 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+3,'George','Washington',$time )"); |
|---|
| 725 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+4,'Mr. Alan','Tam',$time )"); |
|---|
| 726 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+5,'Alan',".$db->quote("Turing'ton").",$time )"); |
|---|
| 727 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created)values ($i*10+6,'Serena','Williams',$time )"); |
|---|
| 728 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+7,'Yat Sun','Sun',$time )"); |
|---|
| 729 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+8,'Wai Hun','See',$time )"); |
|---|
| 730 | $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+9,'Steven','Oey',$time )"); |
|---|
| 731 | } // for |
|---|
| 732 | if (1) { |
|---|
| 733 | $db->debug=1; |
|---|
| 734 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 735 | $cnt = $db->GetOne("select count(*) from ADOXYZ"); |
|---|
| 736 | $rs = $db->Execute('update ADOXYZ set id=id+1'); |
|---|
| 737 | if (!is_object($rs)) { |
|---|
| 738 | print_r($rs); |
|---|
| 739 | err("Update should return object"); |
|---|
| 740 | } |
|---|
| 741 | if (!$rs) err("Update generated error"); |
|---|
| 742 | |
|---|
| 743 | $nrows = $db->Affected_Rows(); |
|---|
| 744 | if ($nrows === false) print "<p><b>Affected_Rows() not supported</b></p>"; |
|---|
| 745 | else if ($nrows != $cnt) print "<p><b>Affected_Rows() Error: $nrows returned (should be 50) </b></p>"; |
|---|
| 746 | else print "<p>Affected_Rows() passed</p>"; |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | if ($db->dataProvider == 'oci8') $array = array('zid'=>1,'zdate'=>date('Y-m-d',time())); |
|---|
| 750 | else $array=array(1,date('Y-m-d',time())); |
|---|
| 751 | |
|---|
| 752 | |
|---|
| 753 | #$array = array(1,date('Y-m-d',time())); |
|---|
| 754 | $id = $db->GetOne("select id from ADOXYZ |
|---|
| 755 | where id=".$db->Param('zid')." and created>=".$db->Param('ZDATE')."", |
|---|
| 756 | $array); |
|---|
| 757 | if ($id != 1) Err("Bad bind; id=$id"); |
|---|
| 758 | else echo "<br>Bind date/integer 1 passed"; |
|---|
| 759 | |
|---|
| 760 | $array =array(1,$db->BindDate(time())); |
|---|
| 761 | $id = $db->GetOne("select id from ADOXYZ |
|---|
| 762 | where id=".$db->Param('0')." and created>=".$db->Param('1')."", |
|---|
| 763 | $array); |
|---|
| 764 | if ($id != 1) Err("Bad bind; id=$id"); |
|---|
| 765 | else echo "<br>Bind date/integer 2 passed"; |
|---|
| 766 | |
|---|
| 767 | $db->debug = false; |
|---|
| 768 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 769 | ////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 770 | |
|---|
| 771 | $rs = $db->Execute("select * from ADOXYZ where firstname = 'not known'"); |
|---|
| 772 | if (!$rs || !$rs->EOF) print "<p><b>Error on empty recordset</b></p>"; |
|---|
| 773 | else if ($rs->RecordCount() != 0) { |
|---|
| 774 | print "<p><b>Error on RecordCount. Should be 0. Was ".$rs->RecordCount()."</b></p>"; |
|---|
| 775 | print_r($rs->fields); |
|---|
| 776 | } |
|---|
| 777 | if ($db->databaseType !== 'odbc') { |
|---|
| 778 | $rs = $db->Execute("select id,firstname,lastname,created,".$db->random." from ADOXYZ order by id"); |
|---|
| 779 | if ($rs) { |
|---|
| 780 | if ($rs->RecordCount() != 50) { |
|---|
| 781 | print "<p><b>RecordCount returns ".$rs->RecordCount().", should be 50</b></p>"; |
|---|
| 782 | adodb_pr($rs->GetArray()); |
|---|
| 783 | $poc = $rs->PO_RecordCount('ADOXYZ'); |
|---|
| 784 | if ($poc == 50) print "<p> PO_RecordCount passed</p>"; |
|---|
| 785 | else print "<p><b>PO_RecordCount returns wrong value: $poc</b></p>"; |
|---|
| 786 | } else print "<p>RecordCount() passed</p>"; |
|---|
| 787 | if (isset($rs->fields['firstname'])) print '<p>The fields columns can be indexed by column name.</p>'; |
|---|
| 788 | else { |
|---|
| 789 | Err( '<p>The fields columns <i>cannot</i> be indexed by column name.</p>'); |
|---|
| 790 | print_r($rs->fields); |
|---|
| 791 | } |
|---|
| 792 | if (empty($_GET['hide'])) rs2html($rs); |
|---|
| 793 | } |
|---|
| 794 | else print "<p><b>Error in Execute of SELECT with random</b></p>"; |
|---|
| 795 | } |
|---|
| 796 | $val = $db->GetOne("select count(*) from ADOXYZ"); |
|---|
| 797 | if ($val == 50) print "<p>GetOne returns ok</p>"; |
|---|
| 798 | else print "<p><b>Fail: GetOne returns $val</b></p>"; |
|---|
| 799 | |
|---|
| 800 | echo "<b>GetRow Test</b>"; |
|---|
| 801 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 802 | $val1 = $db->GetRow("select count(*) from ADOXYZ"); |
|---|
| 803 | $val2 = $db->GetRow("select count(*) from ADOXYZ"); |
|---|
| 804 | if ($val1[0] == 50 and sizeof($val1) == 1 and $val2[0] == 50 and sizeof($val2) == 1) print "<p>GetRow returns ok</p>"; |
|---|
| 805 | else { |
|---|
| 806 | print_r($val); |
|---|
| 807 | print "<p><b>Fail: GetRow returns {$val2[0]}</b></p>"; |
|---|
| 808 | } |
|---|
| 809 | |
|---|
| 810 | print "<p>FetchObject/FetchNextObject Test</p>"; |
|---|
| 811 | $rs = $db->Execute('select * from ADOXYZ'); |
|---|
| 812 | if ($rs) { |
|---|
| 813 | if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>"; |
|---|
| 814 | |
|---|
| 815 | while ($o = $rs->FetchNextObject()) { // calls FetchObject internally |
|---|
| 816 | if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) { |
|---|
| 817 | print_r($o); |
|---|
| 818 | print "<p><b>Firstname is not string</b></p>"; |
|---|
| 819 | break; |
|---|
| 820 | } |
|---|
| 821 | } |
|---|
| 822 | } else { |
|---|
| 823 | print "<p><b>Failed rs</b></p>"; |
|---|
| 824 | die("<p>ADOXYZ table cannot be read - die()"); |
|---|
| 825 | } |
|---|
| 826 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 827 | print "<p>FetchObject/FetchNextObject Test 2</p>"; |
|---|
| 828 | #$db->debug=99; |
|---|
| 829 | $rs = $db->Execute('select * from ADOXYZ'); |
|---|
| 830 | if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>"; |
|---|
| 831 | print_r($rs->fields); |
|---|
| 832 | while ($o = $rs->FetchNextObject()) { // calls FetchObject internally |
|---|
| 833 | if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) { |
|---|
| 834 | print_r($o); |
|---|
| 835 | print "<p><b>Firstname is not string</b></p>"; |
|---|
| 836 | break; |
|---|
| 837 | } |
|---|
| 838 | } |
|---|
| 839 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 840 | |
|---|
| 841 | $savefetch = $ADODB_FETCH_MODE; |
|---|
| 842 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 843 | |
|---|
| 844 | print "<p>CacheSelectLimit Test...</p>"; |
|---|
| 845 | $db->debug=1; |
|---|
| 846 | $rs = $db->CacheSelectLimit('select id, firstname from ADOXYZ order by id',2); |
|---|
| 847 | |
|---|
| 848 | if ($rs && !$rs->EOF) { |
|---|
| 849 | if (isset($rs->fields[0])) { |
|---|
| 850 | Err("ASSOC has numeric fields"); |
|---|
| 851 | print_r($rs->fields); |
|---|
| 852 | } |
|---|
| 853 | if ($rs->fields['id'] != 1) {Err("Error"); print_r($rs->fields);}; |
|---|
| 854 | if (trim($rs->fields['firstname']) != 'Caroline') {print Err("Error 2"); print_r($rs->fields);}; |
|---|
| 855 | |
|---|
| 856 | $rs->MoveNext(); |
|---|
| 857 | if ($rs->fields['id'] != 2) {Err("Error 3"); print_r($rs->fields);}; |
|---|
| 858 | $rs->MoveNext(); |
|---|
| 859 | if (!$rs->EOF) { |
|---|
| 860 | Err("Error EOF"); |
|---|
| 861 | print_r($rs); |
|---|
| 862 | } |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | print "<p>FETCH_MODE = ASSOC: Should get 1, Caroline</p>"; |
|---|
| 866 | $rs = $db->SelectLimit('select id,firstname from ADOXYZ order by id',2); |
|---|
| 867 | if ($rs && !$rs->EOF) { |
|---|
| 868 | if (ADODB_ASSOC_CASE == 2) { |
|---|
| 869 | $id = 'ID'; |
|---|
| 870 | $fname = 'FIRSTNAME'; |
|---|
| 871 | }else { |
|---|
| 872 | $id = 'id'; |
|---|
| 873 | $fname = 'firstname'; |
|---|
| 874 | } |
|---|
| 875 | if ($rs->fields[$id] != 1) {Err("Error 1"); print_r($rs->fields);}; |
|---|
| 876 | if (trim($rs->fields[$fname]) != 'Caroline') {Err("Error 2"); print_r($rs->fields);}; |
|---|
| 877 | $rs->MoveNext(); |
|---|
| 878 | if ($rs->fields[$id] != 2) {Err("Error 3"); print_r($rs->fields);}; |
|---|
| 879 | $rs->MoveNext(); |
|---|
| 880 | if (!$rs->EOF) Err("Error EOF"); |
|---|
| 881 | else if (is_array($rs->fields) || $rs->fields) { |
|---|
| 882 | Err("Error: ## fields should be set to false on EOF"); |
|---|
| 883 | print_r($rs->fields); |
|---|
| 884 | } |
|---|
| 885 | } |
|---|
| 886 | |
|---|
| 887 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 888 | print "<p>FETCH_MODE = NUM: Should get 1, Caroline</p>"; |
|---|
| 889 | $rs = $db->SelectLimit('select id,firstname from ADOXYZ order by id',1); |
|---|
| 890 | if ($rs && !$rs->EOF) { |
|---|
| 891 | if (isset($rs->fields['id'])) Err("FETCH_NUM has ASSOC fields"); |
|---|
| 892 | if ($rs->fields[0] != 1) {Err("Error 1"); print_r($rs->fields);}; |
|---|
| 893 | if (trim($rs->fields[1]) != 'Caroline') {Err("Error 2");print_r($rs->fields);}; |
|---|
| 894 | $rs->MoveNext(); |
|---|
| 895 | if (!$rs->EOF) Err("Error EOF"); |
|---|
| 896 | |
|---|
| 897 | } |
|---|
| 898 | $ADODB_FETCH_MODE = $savefetch; |
|---|
| 899 | |
|---|
| 900 | $db->debug = false; |
|---|
| 901 | print "<p>GetRowAssoc Upper: Should get 1, Caroline</p>"; |
|---|
| 902 | $rs = $db->SelectLimit('select id,firstname from ADOXYZ order by id',1); |
|---|
| 903 | if ($rs && !$rs->EOF) { |
|---|
| 904 | $arr = $rs->GetRowAssoc(); |
|---|
| 905 | if ($arr['ID'] != 1) {Err("Error 1");print_r($arr);}; |
|---|
| 906 | if (trim($arr['FIRSTNAME']) != 'Caroline') {Err("Error 2"); print_r($arr);}; |
|---|
| 907 | $rs->MoveNext(); |
|---|
| 908 | if (!$rs->EOF) Err("Error EOF"); |
|---|
| 909 | |
|---|
| 910 | } |
|---|
| 911 | print "<p>GetRowAssoc Lower: Should get 1, Caroline</p>"; |
|---|
| 912 | $rs = $db->SelectLimit('select id,firstname from ADOXYZ order by id',1); |
|---|
| 913 | if ($rs && !$rs->EOF) { |
|---|
| 914 | $arr = $rs->GetRowAssoc(false); |
|---|
| 915 | if ($arr['id'] != 1) {Err("Error 1"); print_r($arr);}; |
|---|
| 916 | if (trim($arr['firstname']) != 'Caroline') {Err("Error 2"); print_r($arr);}; |
|---|
| 917 | |
|---|
| 918 | } |
|---|
| 919 | |
|---|
| 920 | print "<p>GetCol Test</p>"; |
|---|
| 921 | $col = $db->GetCol('select distinct firstname from ADOXYZ order by 1'); |
|---|
| 922 | if (!is_array($col)) Err("Col size is wrong"); |
|---|
| 923 | if (trim($col[0]) != 'Alan' or trim($col[9]) != 'Yat Sun') Err("Col elements wrong"); |
|---|
| 924 | |
|---|
| 925 | $db->debug = true; |
|---|
| 926 | |
|---|
| 927 | |
|---|
| 928 | echo "<p>Date Update Test</p>"; |
|---|
| 929 | $zdate = date('Y-m-d',time()+3600*24); |
|---|
| 930 | $zdate = $db->DBDate($zdate); |
|---|
| 931 | $db->Execute("update ADOXYZ set created=$zdate where id=1"); |
|---|
| 932 | $row = $db->GetRow("select created,firstname from ADOXYZ where id=1"); |
|---|
| 933 | print_r($row); echo "<br>"; |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | print "<p>SelectLimit Distinct Test 1: Should see Caroline, John and Mary</p>"; |
|---|
| 938 | $rs = $db->SelectLimit('select distinct * from ADOXYZ order by id',3); |
|---|
| 939 | |
|---|
| 940 | |
|---|
| 941 | if ($rs && !$rs->EOF) { |
|---|
| 942 | if (trim($rs->fields[1]) != 'Caroline') Err("Error 1 (exp Caroline), ".$rs->fields[1]); |
|---|
| 943 | $rs->MoveNext(); |
|---|
| 944 | |
|---|
| 945 | if (trim($rs->fields[1]) != 'John') Err("Error 2 (exp John), ".$rs->fields[1]); |
|---|
| 946 | $rs->MoveNext(); |
|---|
| 947 | if (trim($rs->fields[1]) != 'Mary') Err("Error 3 (exp Mary),".$rs->fields[1]); |
|---|
| 948 | $rs->MoveNext(); |
|---|
| 949 | if (! $rs->EOF) Err("Error EOF"); |
|---|
| 950 | //rs2html($rs); |
|---|
| 951 | } else Err("Failed SelectLimit Test 1"); |
|---|
| 952 | |
|---|
| 953 | print "<p>SelectLimit Test 2: Should see Mary, George and Mr. Alan</p>"; |
|---|
| 954 | $rs = $db->SelectLimit('select * from ADOXYZ order by id',3,2); |
|---|
| 955 | if ($rs && !$rs->EOF) { |
|---|
| 956 | if (trim($rs->fields[1]) != 'Mary') Err("Error 1 - No Mary, instead: ".$rs->fields[1]); |
|---|
| 957 | $rs->MoveNext(); |
|---|
| 958 | if (trim($rs->fields[1]) != 'George')Err("Error 2 - No George, instead: ".$rs->fields[1]); |
|---|
| 959 | $rs->MoveNext(); |
|---|
| 960 | if (trim($rs->fields[1]) != 'Mr. Alan') Err("Error 3 - No Mr. Alan, instead: ".$rs->fields[1]); |
|---|
| 961 | $rs->MoveNext(); |
|---|
| 962 | if (! $rs->EOF) Err("Error EOF"); |
|---|
| 963 | // rs2html($rs); |
|---|
| 964 | } |
|---|
| 965 | else Err("Failed SelectLimit Test 2 ". ($rs ? 'EOF':'no RS')); |
|---|
| 966 | |
|---|
| 967 | print "<p>SelectLimit Test 3: Should see Wai Hun and Steven</p>"; |
|---|
| 968 | $db->debug=1; |
|---|
| 969 | global $A; $A=1; |
|---|
| 970 | $rs = $db->SelectLimit('select * from ADOXYZ order by id',-1,48); |
|---|
| 971 | $A=0; |
|---|
| 972 | if ($rs && !$rs->EOF) { |
|---|
| 973 | if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>"; |
|---|
| 974 | if (trim($rs->fields[1]) != 'Wai Hun') Err("Error 1 ".$rs->fields[1]); |
|---|
| 975 | $rs->MoveNext(); |
|---|
| 976 | if (trim($rs->fields[1]) != 'Steven') Err("Error 2 ".$rs->fields[1]); |
|---|
| 977 | $rs->MoveNext(); |
|---|
| 978 | if (! $rs->EOF) { |
|---|
| 979 | Err("Error EOF"); |
|---|
| 980 | } |
|---|
| 981 | //rs2html($rs); |
|---|
| 982 | } |
|---|
| 983 | else Err("Failed SelectLimit Test 3"); |
|---|
| 984 | $db->debug = false; |
|---|
| 985 | |
|---|
| 986 | |
|---|
| 987 | $rs = $db->Execute("select * from ADOXYZ order by id"); |
|---|
| 988 | print "<p>Testing Move()</p>"; |
|---|
| 989 | if (!$rs)Err( "Failed Move SELECT"); |
|---|
| 990 | else { |
|---|
| 991 | if (!$rs->Move(2)) { |
|---|
| 992 | if (!$rs->canSeek) print "<p>$db->databaseType: <b>Move(), MoveFirst() nor MoveLast() not supported.</b></p>"; |
|---|
| 993 | else print '<p><b>RecordSet->canSeek property should be set to false</b></p>'; |
|---|
| 994 | } else { |
|---|
| 995 | $rs->MoveFirst(); |
|---|
| 996 | if (trim($rs->Fields("firstname")) != 'Caroline') { |
|---|
| 997 | print "<p><b>$db->databaseType: MoveFirst failed -- probably cannot scroll backwards</b></p>"; |
|---|
| 998 | } |
|---|
| 999 | else print "MoveFirst() OK<BR>"; |
|---|
| 1000 | |
|---|
| 1001 | // Move(3) tests error handling -- MoveFirst should not move cursor |
|---|
| 1002 | $rs->Move(3); |
|---|
| 1003 | if (trim($rs->Fields("firstname")) != 'George') { |
|---|
| 1004 | print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) failed</b></p>"; |
|---|
| 1005 | } else print "Move(3) OK<BR>"; |
|---|
| 1006 | |
|---|
| 1007 | $rs->Move(7); |
|---|
| 1008 | if (trim($rs->Fields("firstname")) != 'Yat Sun') { |
|---|
| 1009 | print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(7) failed</b></p>"; |
|---|
| 1010 | print_r($rs); |
|---|
| 1011 | } else print "Move(7) OK<BR>"; |
|---|
| 1012 | if ($rs->EOF) Err("Move(7) is EOF already"); |
|---|
| 1013 | $rs->MoveLast(); |
|---|
| 1014 | if (trim($rs->Fields("firstname")) != 'Steven'){ |
|---|
| 1015 | print '<p>'.$rs->Fields("id")."<b>$db->databaseType: MoveLast() failed</b></p>"; |
|---|
| 1016 | print_r($rs); |
|---|
| 1017 | }else print "MoveLast() OK<BR>"; |
|---|
| 1018 | $rs->MoveNext(); |
|---|
| 1019 | if (!$rs->EOF) err("Bad MoveNext"); |
|---|
| 1020 | if ($rs->canSeek) { |
|---|
| 1021 | $rs->Move(3); |
|---|
| 1022 | if (trim($rs->Fields("firstname")) != 'George') { |
|---|
| 1023 | print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) after MoveLast failed</b></p>"; |
|---|
| 1024 | |
|---|
| 1025 | } else print "Move(3) after MoveLast() OK<BR>"; |
|---|
| 1026 | } |
|---|
| 1027 | |
|---|
| 1028 | print "<p>Empty Move Test"; |
|---|
| 1029 | $rs = $db->Execute("select * from ADOXYZ where id > 0 and id < 0"); |
|---|
| 1030 | $rs->MoveFirst(); |
|---|
| 1031 | if (!$rs->EOF || $rs->fields) Err("Error in empty move first"); |
|---|
| 1032 | } |
|---|
| 1033 | } |
|---|
| 1034 | |
|---|
| 1035 | $rs = $db->Execute('select * from ADOXYZ where id = 2'); |
|---|
| 1036 | if ($rs->EOF || !is_array($rs->fields)) Err("Error in select"); |
|---|
| 1037 | $rs->MoveNext(); |
|---|
| 1038 | if (!$rs->EOF) Err("Error in EOF (xx) "); |
|---|
| 1039 | // $db->debug=true; |
|---|
| 1040 | print "<p>Testing ADODB_FETCH_ASSOC and concat: concat firstname and lastname</p>"; |
|---|
| 1041 | |
|---|
| 1042 | $save = $ADODB_FETCH_MODE; |
|---|
| 1043 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 1044 | if ($db->dataProvider == 'postgres') { |
|---|
| 1045 | $sql = "select ".$db->Concat('cast(firstname as varchar)',$db->qstr(' '),'lastname')." as fullname,id,".$db->sysTimeStamp." as d from ADOXYZ"; |
|---|
| 1046 | $rs = $db->Execute($sql); |
|---|
| 1047 | } else { |
|---|
| 1048 | $sql = "select distinct ".$db->Concat('firstname',$db->qstr(' '),'lastname')." as fullname,id,".$db->sysTimeStamp." as d from ADOXYZ"; |
|---|
| 1049 | $rs = $db->Execute($sql); |
|---|
| 1050 | } |
|---|
| 1051 | if ($rs) { |
|---|
| 1052 | if (empty($_GET['hide'])) rs2html($rs); |
|---|
| 1053 | } else { |
|---|
| 1054 | Err( "Failed Concat:".$sql); |
|---|
| 1055 | } |
|---|
| 1056 | $ADODB_FETCH_MODE = $save; |
|---|
| 1057 | print "<hr />Testing GetArray() "; |
|---|
| 1058 | //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 1059 | |
|---|
| 1060 | $rs = $db->Execute("select * from ADOXYZ order by id"); |
|---|
| 1061 | if ($rs) { |
|---|
| 1062 | $arr = $rs->GetArray(10); |
|---|
| 1063 | 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>"; |
|---|
| 1064 | else print " OK<BR>"; |
|---|
| 1065 | } |
|---|
| 1066 | |
|---|
| 1067 | $arr = $db->GetArray("select x from ADOXYZ"); |
|---|
| 1068 | $e = $db->ErrorMsg(); $e2 = $db->ErrorNo(); |
|---|
| 1069 | echo "Testing error handling, should see illegal column 'x' error=<i>$e ($e2) </i><br>"; |
|---|
| 1070 | if (!$e || !$e2) Err("Error handling did not work"); |
|---|
| 1071 | print "Testing FetchNextObject for 1 object "; |
|---|
| 1072 | $rs = $db->Execute("select distinct lastname,firstname from ADOXYZ where firstname='Caroline'"); |
|---|
| 1073 | $fcnt = 0; |
|---|
| 1074 | if ($rs) |
|---|
| 1075 | while ($o = $rs->FetchNextObject()) { |
|---|
| 1076 | $fcnt += 1; |
|---|
| 1077 | } |
|---|
| 1078 | if ($fcnt == 1) print " OK<BR>"; |
|---|
| 1079 | else print "<b>FAILED</b><BR>"; |
|---|
| 1080 | |
|---|
| 1081 | $stmt = $db->Prepare("select * from ADOXYZ where id < 3"); |
|---|
| 1082 | $rs = $db->Execute($stmt); |
|---|
| 1083 | if (!$rs) Err("Prepare failed"); |
|---|
| 1084 | else { |
|---|
| 1085 | $arr = $rs->GetArray(); |
|---|
| 1086 | if (!$arr) Err("Prepare failed 2"); |
|---|
| 1087 | if (sizeof($arr) != 2) Err("Prepare failed 3"); |
|---|
| 1088 | } |
|---|
| 1089 | print "Testing GetAssoc() "; |
|---|
| 1090 | $savecrecs = $ADODB_COUNTRECS; |
|---|
| 1091 | $ADODB_COUNTRECS = false; |
|---|
| 1092 | //$arr = $db->GetArray("select lastname,firstname from ADOXYZ"); |
|---|
| 1093 | //print_r($arr); |
|---|
| 1094 | print "<hr />"; |
|---|
| 1095 | $rs = $db->Execute("select distinct lastname,firstname,created from ADOXYZ"); |
|---|
| 1096 | |
|---|
| 1097 | if ($rs) { |
|---|
| 1098 | $arr = $rs->GetAssoc(); |
|---|
| 1099 | //print_r($arr); |
|---|
| 1100 | if (empty($arr['See']) || trim(reset($arr['See'])) != 'Wai Hun') print $arr['See']." <b>ERROR</b><br>"; |
|---|
| 1101 | else print " OK 1"; |
|---|
| 1102 | } |
|---|
| 1103 | |
|---|
| 1104 | $arr = $db->GetAssoc("select distinct lastname,firstname from ADOXYZ"); |
|---|
| 1105 | if ($arr) { |
|---|
| 1106 | //print_r($arr); |
|---|
| 1107 | if (empty($arr['See']) || trim($arr['See']) != 'Wai Hun') print $arr['See']." <b>ERROR</b><br>"; |
|---|
| 1108 | else print " OK 2<BR>"; |
|---|
| 1109 | } |
|---|
| 1110 | // Comment this out to test countrecs = false |
|---|
| 1111 | $ADODB_COUNTRECS = $savecrecs; |
|---|
| 1112 | $db->debug=1; |
|---|
| 1113 | $query = $db->Prepare("select count(*) from ADOXYZ"); |
|---|
| 1114 | $rs = $db->CacheExecute(10,$query); |
|---|
| 1115 | if (reset($rs->fields) != 50) echo Err("$cnt wrong for Prepare/CacheGetOne"); |
|---|
| 1116 | |
|---|
| 1117 | for ($loop=0; $loop < 1; $loop++) { |
|---|
| 1118 | print "Testing GetMenu() and CacheExecute<BR>"; |
|---|
| 1119 | $db->debug = true; |
|---|
| 1120 | $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1121 | |
|---|
| 1122 | |
|---|
| 1123 | |
|---|
| 1124 | |
|---|
| 1125 | if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu('menu','Steven').'<BR>'; |
|---|
| 1126 | else print " Fail<BR>"; |
|---|
| 1127 | $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1128 | |
|---|
| 1129 | if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu('menu','Steven',false).'<BR>'; |
|---|
| 1130 | else print " Fail<BR>"; |
|---|
| 1131 | |
|---|
| 1132 | $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1133 | |
|---|
| 1134 | if ($rs) print ' 1st line set to **** , Steven selected: '. $rs->GetMenu('menu','Steven','1st:****').'<BR>'; |
|---|
| 1135 | else print " Fail<BR>"; |
|---|
| 1136 | |
|---|
| 1137 | |
|---|
| 1138 | |
|---|
| 1139 | $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1140 | if ($rs) print ' Multiple, Alan selected: '. $rs->GetMenu('menu','Alan',false,true).'<BR>'; |
|---|
| 1141 | else print " Fail<BR>"; |
|---|
| 1142 | print '</p><hr />'; |
|---|
| 1143 | |
|---|
| 1144 | $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1145 | if ($rs) { |
|---|
| 1146 | print ' Multiple, Alan and George selected: '. $rs->GetMenu('menu',array('Alan','George'),false,true); |
|---|
| 1147 | if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>"; |
|---|
| 1148 | } else print " Fail<BR>"; |
|---|
| 1149 | print '</p><hr />'; |
|---|
| 1150 | |
|---|
| 1151 | print "Testing GetMenu3()<br>"; |
|---|
| 1152 | $rs = $db->Execute("select ".$db->Concat('firstname',"'-'",'id').",id, lastname from ADOXYZ order by lastname,id"); |
|---|
| 1153 | if ($rs) print "Grouped Menu: ".$rs->GetMenu3('name'); |
|---|
| 1154 | else Err('Grouped Menu GetMenu3()'); |
|---|
| 1155 | print "<hr />"; |
|---|
| 1156 | |
|---|
| 1157 | print "Testing GetMenu2() <BR>"; |
|---|
| 1158 | $rs = $db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1159 | if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu2('menu',('Oey')).'<BR>'; |
|---|
| 1160 | else print " Fail<BR>"; |
|---|
| 1161 | $rs = $db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1162 | if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu2('menu',('Oey'),false).'<BR>'; |
|---|
| 1163 | else print " Fail<BR>"; |
|---|
| 1164 | } |
|---|
| 1165 | echo "<h3>CacheExecute</h3>"; |
|---|
| 1166 | |
|---|
| 1167 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 1168 | $rs = $db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1169 | print_r($rs->fields); echo $rs->fetchMode;echo "<br>"; |
|---|
| 1170 | echo $rs->Fields('firstname'); |
|---|
| 1171 | |
|---|
| 1172 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 1173 | $rs = $db->CacheExecute(6,"select distinct firstname,lastname from ADOXYZ"); |
|---|
| 1174 | print_r($rs->fields);echo "<br>"; |
|---|
| 1175 | echo $rs->Fields('firstname'); |
|---|
| 1176 | $db->debug = false; |
|---|
| 1177 | |
|---|
| 1178 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 1179 | // phplens |
|---|
| 1180 | |
|---|
| 1181 | $sql = 'select * from ADOXYZ where 0=1'; |
|---|
| 1182 | echo "<p>**Testing '$sql' (phplens compat 1)</p>"; |
|---|
| 1183 | $rs = $db->Execute($sql); |
|---|
| 1184 | if (!$rs) err( "<b>No recordset returned for '$sql'</b>"); |
|---|
| 1185 | if (!$rs->FieldCount()) err( "<b>No fields returned for $sql</b>"); |
|---|
| 1186 | if (!$rs->FetchField(1)) err( "<b>FetchField failed for $sql</b>"); |
|---|
| 1187 | |
|---|
| 1188 | $sql = 'select * from ADOXYZ order by 1'; |
|---|
| 1189 | echo "<p>**Testing '$sql' (phplens compat 2)</p>"; |
|---|
| 1190 | $rs = $db->Execute($sql); |
|---|
| 1191 | if (!$rs) err( "<b>No recordset returned for '$sql'<br>".$db->ErrorMsg()."</b>"); |
|---|
| 1192 | |
|---|
| 1193 | |
|---|
| 1194 | $sql = 'select * from ADOXYZ order by 1,1'; |
|---|
| 1195 | echo "<p>**Testing '$sql' (phplens compat 3)</p>"; |
|---|
| 1196 | $rs = $db->Execute($sql); |
|---|
| 1197 | if (!$rs) err( "<b>No recordset returned for '$sql'<br>".$db->ErrorMsg()."</b>"); |
|---|
| 1198 | |
|---|
| 1199 | |
|---|
| 1200 | // Move |
|---|
| 1201 | $rs1 = $db->Execute("select id from ADOXYZ where id <= 2 order by 1"); |
|---|
| 1202 | $rs2 = $db->Execute("select id from ADOXYZ where id = 3 or id = 4 order by 1"); |
|---|
| 1203 | |
|---|
| 1204 | if ($rs1) $rs1->MoveLast(); |
|---|
| 1205 | if ($rs2) $rs2->MoveLast(); |
|---|
| 1206 | |
|---|
| 1207 | if (empty($rs1) || empty($rs2) || $rs1->fields[0] != 2 || $rs2->fields[0] != 4) { |
|---|
| 1208 | $a = $rs1->fields[0]; |
|---|
| 1209 | $b = $rs2->fields[0]; |
|---|
| 1210 | print "<p><b>Error in multiple recordset test rs1=$a rs2=$b (should be rs1=2 rs2=4)</b></p>"; |
|---|
| 1211 | } else |
|---|
| 1212 | print "<p>Testing multiple recordsets OK</p>"; |
|---|
| 1213 | |
|---|
| 1214 | |
|---|
| 1215 | echo "<p> GenID test: "; |
|---|
| 1216 | for ($i=1; $i <= 10; $i++) |
|---|
| 1217 | echo "($i: ",$val = $db->GenID($db->databaseType.'abcseq6' ,5), ") "; |
|---|
| 1218 | if ($val == 0) Err("GenID not supported"); |
|---|
| 1219 | |
|---|
| 1220 | if ($val) { |
|---|
| 1221 | $db->DropSequence('abc_seq2'); |
|---|
| 1222 | $db->CreateSequence('abc_seq2'); |
|---|
| 1223 | $val = $db->GenID('abc_seq2'); |
|---|
| 1224 | $db->DropSequence('abc_seq2'); |
|---|
| 1225 | $db->CreateSequence('abc_seq2'); |
|---|
| 1226 | $val = $db->GenID('abc_seq2'); |
|---|
| 1227 | if ($val != 1) Err("Drop and Create Sequence not supported ($val)"); |
|---|
| 1228 | } |
|---|
| 1229 | echo "<p>"; |
|---|
| 1230 | |
|---|
| 1231 | if (substr($db->dataProvider,0,3) != 'notused') { // used to crash ado |
|---|
| 1232 | $sql = "select firstnames from ADOXYZ"; |
|---|
| 1233 | print "<p>Testing execution of illegal statement: <i>$sql</i></p>"; |
|---|
| 1234 | if ($db->Execute($sql) === false) { |
|---|
| 1235 | print "<p>This returns the following ErrorMsg(): <i>".$db->ErrorMsg()."</i> and ErrorNo(): ".$db->ErrorNo().'</p>'; |
|---|
| 1236 | } else |
|---|
| 1237 | print "<p><b>Error in error handling -- Execute() should return false</b></p>"; |
|---|
| 1238 | } else |
|---|
| 1239 | print "<p><b>ADO skipped error handling of bad select statement</b></p>"; |
|---|
| 1240 | |
|---|
| 1241 | print "<p>ASSOC TEST 2<br>"; |
|---|
| 1242 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 1243 | $rs = $db->query('select * from ADOXYZ order by id'); |
|---|
| 1244 | if ($ee = $db->ErrorMsg()) { |
|---|
| 1245 | Err("Error message=$ee"); |
|---|
| 1246 | } |
|---|
| 1247 | if ($ee = $db->ErrorNo()) { |
|---|
| 1248 | Err("Error No = $ee"); |
|---|
| 1249 | } |
|---|
| 1250 | print_r($rs->fields); |
|---|
| 1251 | for($i=0;$i<$rs->FieldCount();$i++) |
|---|
| 1252 | { |
|---|
| 1253 | $fld=$rs->FetchField($i); |
|---|
| 1254 | print "<br> Field name is ".$fld->name; |
|---|
| 1255 | print " ".$rs->Fields($fld->name); |
|---|
| 1256 | } |
|---|
| 1257 | |
|---|
| 1258 | |
|---|
| 1259 | print "<p>BOTH TEST 2<br>"; |
|---|
| 1260 | if ($db->dataProvider == 'ado') { |
|---|
| 1261 | print "<b>ADODB_FETCH_BOTH not supported</b> for dataProvider=".$db->dataProvider."<br>"; |
|---|
| 1262 | } else { |
|---|
| 1263 | $ADODB_FETCH_MODE = ADODB_FETCH_BOTH; |
|---|
| 1264 | $rs = $db->query('select * from ADOXYZ order by id'); |
|---|
| 1265 | for($i=0;$i<$rs->FieldCount();$i++) |
|---|
| 1266 | { |
|---|
| 1267 | $fld=$rs->FetchField($i); |
|---|
| 1268 | print "<br> Field name is ".$fld->name; |
|---|
| 1269 | print " ".$rs->Fields($fld->name); |
|---|
| 1270 | } |
|---|
| 1271 | } |
|---|
| 1272 | |
|---|
| 1273 | print "<p>NUM TEST 2<br>"; |
|---|
| 1274 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 1275 | $rs = $db->query('select * from ADOXYZ order by id'); |
|---|
| 1276 | for($i=0;$i<$rs->FieldCount();$i++) |
|---|
| 1277 | { |
|---|
| 1278 | $fld=$rs->FetchField($i); |
|---|
| 1279 | print "<br> Field name is ".$fld->name; |
|---|
| 1280 | print " ".$rs->Fields($fld->name); |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | print "<p>ASSOC Test of SelectLimit<br>"; |
|---|
| 1284 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 1285 | $rs = $db->selectlimit('select * from ADOXYZ order by id',3,4); |
|---|
| 1286 | $cnt = 0; |
|---|
| 1287 | while ($rs && !$rs->EOF) { |
|---|
| 1288 | $cnt += 1; |
|---|
| 1289 | if (!isset($rs->fields['firstname'])) { |
|---|
| 1290 | print "<br><b>ASSOC returned numeric field</b></p>"; |
|---|
| 1291 | break; |
|---|
| 1292 | } |
|---|
| 1293 | $rs->MoveNext(); |
|---|
| 1294 | } |
|---|
| 1295 | if ($cnt != 3) print "<br><b>Count should be 3, instead it was $cnt</b></p>"; |
|---|
| 1296 | |
|---|
| 1297 | |
|---|
| 1298 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 1299 | if ($db->sysDate) { |
|---|
| 1300 | $saved = $db->debug; |
|---|
| 1301 | $db->debug = 1; |
|---|
| 1302 | $rs = $db->Execute("select {$db->sysDate} from ADOXYZ where id=1"); |
|---|
| 1303 | if (ADORecordSet::UnixDate(date('Y-m-d')) != $rs->UnixDate($rs->fields[0])) { |
|---|
| 1304 | print "<p><b>Invalid date {$rs->fields[0]}</b></p>"; |
|---|
| 1305 | } else |
|---|
| 1306 | print "<p>Passed \$sysDate test ({$rs->fields[0]})</p>"; |
|---|
| 1307 | |
|---|
| 1308 | print_r($rs->FetchField(0)); |
|---|
| 1309 | print time(); |
|---|
| 1310 | $db->debug=$saved; |
|---|
| 1311 | } else { |
|---|
| 1312 | print "<p><b>\$db->sysDate not defined</b></p>"; |
|---|
| 1313 | } |
|---|
| 1314 | |
|---|
| 1315 | print "<p>Test CSV</p>"; |
|---|
| 1316 | include_once('../toexport.inc.php'); |
|---|
| 1317 | //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 1318 | $rs = $db->SelectLimit('select id,firstname,lastname,created,\'He, he\' he,\'"\' q from ADOXYZ',10); |
|---|
| 1319 | |
|---|
| 1320 | print "<pre>"; |
|---|
| 1321 | print rs2csv($rs); |
|---|
| 1322 | print "</pre>"; |
|---|
| 1323 | |
|---|
| 1324 | $rs = $db->SelectLimit('select id,firstname,lastname,created,\'The "young man", he said\' from ADOXYZ',10); |
|---|
| 1325 | |
|---|
| 1326 | if (PHP_VERSION < 5) { |
|---|
| 1327 | print "<pre>"; |
|---|
| 1328 | rs2tabout($rs); |
|---|
| 1329 | print "</pre>"; |
|---|
| 1330 | } |
|---|
| 1331 | #print " CacheFlush "; |
|---|
| 1332 | #$db->CacheFlush(); |
|---|
| 1333 | |
|---|
| 1334 | $date = $db->SQLDate('d-m-M-Y-\QQ h:i:s A'); |
|---|
| 1335 | $sql = "SELECT $date from ADOXYZ"; |
|---|
| 1336 | print "<p>Test SQLDate: ".htmlspecialchars($sql)."</p>"; |
|---|
| 1337 | $rs = $db->SelectLimit($sql,1); |
|---|
| 1338 | $d = date('d-m-M-Y-').'Q'.(ceil(date('m')/3.0)).date(' h:i:s A'); |
|---|
| 1339 | if (!$rs) Err("SQLDate query returned no recordset"); |
|---|
| 1340 | else if ($d != $rs->fields[0]) Err("SQLDate 1 failed expected: <br>act:$d <br>sql:".$rs->fields[0]); |
|---|
| 1341 | |
|---|
| 1342 | $date = $db->SQLDate('d-m-M-Y-\QQ h:i:s A',$db->DBDate("1974-02-25")); |
|---|
| 1343 | $sql = "SELECT $date from ADOXYZ"; |
|---|
| 1344 | print "<p>Test SQLDate: ".htmlspecialchars($sql)."</p>"; |
|---|
| 1345 | $db->debug=1; |
|---|
| 1346 | $rs = $db->SelectLimit($sql,1); |
|---|
| 1347 | $ts = ADOConnection::UnixDate('1974-02-25'); |
|---|
| 1348 | $d = date('d-m-M-Y-',$ts).'Q'.(ceil(date('m',$ts)/3.0)).date(' h:i:s A',$ts); |
|---|
| 1349 | if (!$rs) { |
|---|
| 1350 | Err("SQLDate query returned no recordset"); |
|---|
| 1351 | echo $db->ErrorMsg(),'<br>'; |
|---|
| 1352 | } else if ($d != reset($rs->fields)) { |
|---|
| 1353 | Err("SQLDate 2 failed expected: <br>act:$d <br>sql:".$rs->fields[0].' <br>'.$db->ErrorMsg()); |
|---|
| 1354 | } |
|---|
| 1355 | |
|---|
| 1356 | |
|---|
| 1357 | print "<p>Test Filter</p>"; |
|---|
| 1358 | $db->debug = 1; |
|---|
| 1359 | |
|---|
| 1360 | $rs = $db->SelectLimit('select * from ADOXYZ where id < 3 order by id'); |
|---|
| 1361 | |
|---|
| 1362 | $rs = RSFilter($rs,'do_strtolower'); |
|---|
| 1363 | if (trim($rs->fields[1]) != 'caroline' && trim($rs->fields[2]) != 'miranda') { |
|---|
| 1364 | err('**** RSFilter failed'); |
|---|
| 1365 | print_r($rs->fields); |
|---|
| 1366 | } |
|---|
| 1367 | |
|---|
| 1368 | rs2html($rs); |
|---|
| 1369 | |
|---|
| 1370 | $db->debug=1; |
|---|
| 1371 | |
|---|
| 1372 | |
|---|
| 1373 | print "<p>Test Replace</p>"; |
|---|
| 1374 | |
|---|
| 1375 | $ret = $db->Replace('ADOXYZ', |
|---|
| 1376 | array('id'=>1,'firstname'=>'Caroline','lastname'=>'Miranda'), |
|---|
| 1377 | array('id'), |
|---|
| 1378 | $autoq = true); |
|---|
| 1379 | if (!$ret) echo "<p>Error in replacing existing record</p>"; |
|---|
| 1380 | else { |
|---|
| 1381 | $saved = $db->debug; |
|---|
| 1382 | $db->debug = 0; |
|---|
| 1383 | $savec = $ADODB_COUNTRECS; |
|---|
| 1384 | $ADODB_COUNTRECS = true; |
|---|
| 1385 | $rs = $db->Execute('select * FROM ADOXYZ where id=1'); |
|---|
| 1386 | $db->debug = $saved; |
|---|
| 1387 | if ($rs->RecordCount() != 1) { |
|---|
| 1388 | $cnt = $rs->RecordCount(); |
|---|
| 1389 | rs2html($rs); |
|---|
| 1390 | print "<b>Error - Replace failed, count=$cnt</b><p>"; |
|---|
| 1391 | } |
|---|
| 1392 | $ADODB_COUNTRECS = $savec; |
|---|
| 1393 | } |
|---|
| 1394 | $ret = $db->Replace('ADOXYZ', |
|---|
| 1395 | array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'), |
|---|
| 1396 | array('id','firstname'), |
|---|
| 1397 | $autoq = true); |
|---|
| 1398 | if ($ret != 2) print "<b>Replace failed: </b>"; |
|---|
| 1399 | print "test A return value=$ret (2 expected) <p>"; |
|---|
| 1400 | |
|---|
| 1401 | $ret = $db->Replace('ADOXYZ', |
|---|
| 1402 | array('id'=>1000,'firstname'=>'Sherazade','lastname'=>'Al-Rashid'), |
|---|
| 1403 | 'id', |
|---|
| 1404 | $autoq = true); |
|---|
| 1405 | if ($ret != 1) |
|---|
| 1406 | if ($db->dataProvider == 'ibase' && $ret == 2); |
|---|
| 1407 | else print "<b>Replace failed: </b>"; |
|---|
| 1408 | print "test B return value=$ret (1 or if ibase then 2 expected) <p>"; |
|---|
| 1409 | |
|---|
| 1410 | print "<h3>rs2rs Test</h3>"; |
|---|
| 1411 | |
|---|
| 1412 | $rs = $db->Execute('select * from ADOXYZ where id>= 1 order by id'); |
|---|
| 1413 | $rs = $db->_rs2rs($rs); |
|---|
| 1414 | $rs->valueX = 'X'; |
|---|
| 1415 | $rs->MoveNext(); |
|---|
| 1416 | $rs = $db->_rs2rs($rs); |
|---|
| 1417 | if (!isset($rs->valueX)) err("rs2rs does not preserve array recordsets"); |
|---|
| 1418 | if (reset($rs->fields) != 1) err("rs2rs does not move to first row: id=".reset($rs->fields)); |
|---|
| 1419 | |
|---|
| 1420 | ///////////////////////////////////////////////////////////// |
|---|
| 1421 | include_once('../pivottable.inc.php'); |
|---|
| 1422 | print "<h3>Pivot Test</h3>"; |
|---|
| 1423 | $db->debug=true; |
|---|
| 1424 | $sql = PivotTableSQL( |
|---|
| 1425 | $db, # adodb connection |
|---|
| 1426 | 'ADOXYZ', # tables |
|---|
| 1427 | 'firstname', # row fields |
|---|
| 1428 | 'lastname', # column fields |
|---|
| 1429 | false, # join |
|---|
| 1430 | 'ID', # sum |
|---|
| 1431 | 'Sum ', # label for sum |
|---|
| 1432 | 'sum', # aggregate function |
|---|
| 1433 | true |
|---|
| 1434 | ); |
|---|
| 1435 | $rs = $db->Execute($sql); |
|---|
| 1436 | if ($rs) rs2html($rs); |
|---|
| 1437 | else Err("Pivot sql error"); |
|---|
| 1438 | |
|---|
| 1439 | $pear = true; //true; |
|---|
| 1440 | $db->debug=false; |
|---|
| 1441 | |
|---|
| 1442 | if ($pear) { |
|---|
| 1443 | // PEAR TESTS BELOW |
|---|
| 1444 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 1445 | |
|---|
| 1446 | include_once "PEAR.php"; |
|---|
| 1447 | $rs = $db->query('select * from ADOXYZ where id>0 and id<10 order by id'); |
|---|
| 1448 | |
|---|
| 1449 | $i = 0; |
|---|
| 1450 | if ($rs && !$rs->EOF) { |
|---|
| 1451 | while ($arr = $rs->fetchRow()) { |
|---|
| 1452 | $i++; |
|---|
| 1453 | //print "$i "; |
|---|
| 1454 | if ($arr[0] != $i) { |
|---|
| 1455 | print_r($arr); |
|---|
| 1456 | print "<p><b>PEAR DB emulation error 1.</b></p>"; |
|---|
| 1457 | $pear = false; |
|---|
| 1458 | break; |
|---|
| 1459 | } |
|---|
| 1460 | } |
|---|
| 1461 | $rs->Close(); |
|---|
| 1462 | } |
|---|
| 1463 | |
|---|
| 1464 | |
|---|
| 1465 | if ($i != $db->GetOne('select count(*) from ADOXYZ where id>0 and id<10')) { |
|---|
| 1466 | print "<p><b>PEAR DB emulation error 1.1 EOF ($i)</b></p>"; |
|---|
| 1467 | $pear = false; |
|---|
| 1468 | } |
|---|
| 1469 | |
|---|
| 1470 | $rs = $db->limitQuery('select * from ADOXYZ where id>0 order by id',$i=3,$top=3); |
|---|
| 1471 | $i2 = $i; |
|---|
| 1472 | if ($rs && !$rs->EOF) { |
|---|
| 1473 | |
|---|
| 1474 | while (!is_object($rs->fetchInto($arr))) { |
|---|
| 1475 | $i2++; |
|---|
| 1476 | |
|---|
| 1477 | // print_r($arr); |
|---|
| 1478 | // print "$i ";print_r($arr); |
|---|
| 1479 | if ($arr[0] != $i2) { |
|---|
| 1480 | print "<p><b>PEAR DB emulation error 2.</b></p>"; |
|---|
| 1481 | $pear = false; |
|---|
| 1482 | break; |
|---|
| 1483 | } |
|---|
| 1484 | } |
|---|
| 1485 | $rs->Close(); |
|---|
| 1486 | } |
|---|
| 1487 | if ($i2 != $i+$top) { |
|---|
| 1488 | print "<p><b>PEAR DB emulation error 2.1 EOF (correct=$i+$top, actual=$i2)</b></p>"; |
|---|
| 1489 | $pear = false; |
|---|
| 1490 | } |
|---|
| 1491 | } |
|---|
| 1492 | if ($pear) print "<p>PEAR DB emulation passed.</p>"; |
|---|
| 1493 | flush(); |
|---|
| 1494 | |
|---|
| 1495 | |
|---|
| 1496 | $rs = $db->SelectLimit("select ".$db->sysDate." from ADOXYZ",1); |
|---|
| 1497 | $date = $rs->fields[0]; |
|---|
| 1498 | if (!$date) Err("Bad sysDate"); |
|---|
| 1499 | else { |
|---|
| 1500 | $ds = $db->UserDate($date,"d m Y"); |
|---|
| 1501 | if ($ds != date("d m Y")) Err("Bad UserDate: ".$ds.' expected='.date("d m Y")); |
|---|
| 1502 | else echo "Passed UserDate: $ds<p>"; |
|---|
| 1503 | } |
|---|
| 1504 | $db->debug=1; |
|---|
| 1505 | if ($db->dataProvider == 'oci8') |
|---|
| 1506 | $rs = $db->SelectLimit("select to_char(".$db->sysTimeStamp.",'YYYY-MM-DD HH24:MI:SS') from ADOXYZ",1); |
|---|
| 1507 | else |
|---|
| 1508 | $rs = $db->SelectLimit("select ".$db->sysTimeStamp." from ADOXYZ",1); |
|---|
| 1509 | $date = $rs->fields[0]; |
|---|
| 1510 | if (!$date) Err("Bad sysTimeStamp"); |
|---|
| 1511 | else { |
|---|
| 1512 | $ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y"); |
|---|
| 1513 | if ($ds != date("H \\h\\r\\s-d m Y")) Err("Bad UserTimeStamp: ".$ds.", correct is ".date("H \\h\\r\\s-d m Y")); |
|---|
| 1514 | else echo "Passed UserTimeStamp: $ds<p>"; |
|---|
| 1515 | |
|---|
| 1516 | $date = 100; |
|---|
| 1517 | $ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y"); |
|---|
| 1518 | $ds2 = date("H \\h\\r\\s-d m Y",$date); |
|---|
| 1519 | if ($ds != $ds2) Err("Bad UserTimeStamp 2: $ds: $ds2"); |
|---|
| 1520 | else echo "Passed UserTimeStamp 2: $ds<p>"; |
|---|
| 1521 | } |
|---|
| 1522 | flush(); |
|---|
| 1523 | |
|---|
| 1524 | if ($db->hasTransactions) { |
|---|
| 1525 | $db->debug=1; |
|---|
| 1526 | echo "<p>Testing StartTrans CompleteTrans</p>"; |
|---|
| 1527 | $db->raiseErrorFn = false; |
|---|
| 1528 | |
|---|
| 1529 | $db->SetTransactionMode('SERIALIZABLE'); |
|---|
| 1530 | $db->StartTrans(); |
|---|
| 1531 | $rs = $db->Execute('select * from notable'); |
|---|
| 1532 | $db->StartTrans(); |
|---|
| 1533 | $db->BeginTrans(); |
|---|
| 1534 | $db->Execute("update ADOXYZ set firstname='Carolx' where id=1"); |
|---|
| 1535 | $db->CommitTrans(); |
|---|
| 1536 | $db->CompleteTrans(); |
|---|
| 1537 | $rez = $db->CompleteTrans(); |
|---|
| 1538 | $db->SetTransactionMode(''); |
|---|
| 1539 | $db->debug=0; |
|---|
| 1540 | if ($rez !== false) { |
|---|
| 1541 | if (is_null($rez)) Err("Error: _transOK not modified"); |
|---|
| 1542 | else Err("Error: CompleteTrans (1) should have failed"); |
|---|
| 1543 | } else { |
|---|
| 1544 | $name = $db->GetOne("Select firstname from ADOXYZ where id=1"); |
|---|
| 1545 | if ($name == "Carolx") Err("Error: CompleteTrans (2) should have failed"); |
|---|
| 1546 | else echo "<p> -- Passed StartTrans test1 - rolling back</p>"; |
|---|
| 1547 | } |
|---|
| 1548 | |
|---|
| 1549 | $db->StartTrans(); |
|---|
| 1550 | $db->BeginTrans(); |
|---|
| 1551 | $db->Execute("update ADOXYZ set firstname='Carolx' where id=1"); |
|---|
| 1552 | $db->RollbackTrans(); |
|---|
| 1553 | $rez = $db->CompleteTrans(); |
|---|
| 1554 | if ($rez !== true) Err("Error: CompleteTrans (1) should have succeeded"); |
|---|
| 1555 | else { |
|---|
| 1556 | $name = $db->GetOne("Select firstname from ADOXYZ where id=1"); |
|---|
| 1557 | if (trim($name) != "Carolx") Err("Error: CompleteTrans (2) should have succeeded, returned name=$name"); |
|---|
| 1558 | else echo "<p> -- Passed StartTrans test2 - commiting</p>"; |
|---|
| 1559 | } |
|---|
| 1560 | } |
|---|
| 1561 | flush(); |
|---|
| 1562 | $saved = $db->debug; |
|---|
| 1563 | $db->debug=1; |
|---|
| 1564 | $cnt = _adodb_getcount($db, 'select * from ADOXYZ where firstname in (select firstname from ADOXYZ)'); |
|---|
| 1565 | echo "<b>Count=</b> $cnt"; |
|---|
| 1566 | $db->debug=$saved; |
|---|
| 1567 | |
|---|
| 1568 | global $TESTERRS; |
|---|
| 1569 | $debugerr = true; |
|---|
| 1570 | |
|---|
| 1571 | global $ADODB_LANG;$ADODB_LANG = 'fr'; |
|---|
| 1572 | $db->debug = false; |
|---|
| 1573 | $TESTERRS = 0; |
|---|
| 1574 | $db->raiseErrorFn = 'adodb_test_err'; |
|---|
| 1575 | global $ERRNO; // from adodb_test_err |
|---|
| 1576 | $db->Execute('select * from nowhere'); |
|---|
| 1577 | $metae = $db->MetaError($ERRNO); |
|---|
| 1578 | if ($metae !== DB_ERROR_NOSUCHTABLE) print "<p><b>MetaError=".$metae." wrong</b>, should be ".DB_ERROR_NOSUCHTABLE."</p>"; |
|---|
| 1579 | else print "<p>MetaError ok (".DB_ERROR_NOSUCHTABLE."): ".$db->MetaErrorMsg($metae)."</p>"; |
|---|
| 1580 | if ($TESTERRS != 1) print "<b>raiseErrorFn select nowhere failed</b><br>"; |
|---|
| 1581 | $rs = $db->Execute('select * from ADOXYZ'); |
|---|
| 1582 | if ($debugerr) print " Move"; |
|---|
| 1583 | $rs->Move(100); |
|---|
| 1584 | $rs->_queryID = false; |
|---|
| 1585 | if ($debugerr) print " MoveNext"; |
|---|
| 1586 | $rs->MoveNext(); |
|---|
| 1587 | if ($debugerr) print " $rs=false"; |
|---|
| 1588 | $rs = false; |
|---|
| 1589 | |
|---|
| 1590 | flush(); |
|---|
| 1591 | |
|---|
| 1592 | print "<p>SetFetchMode() tests</p>"; |
|---|
| 1593 | $db->SetFetchMode(ADODB_FETCH_ASSOC); |
|---|
| 1594 | $rs = $db->SelectLimit('select firstname from ADOXYZ',1); |
|---|
| 1595 | if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC"); |
|---|
| 1596 | |
|---|
| 1597 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|---|
| 1598 | $rs = $db->SelectLimit('select firstname from ADOXYZ',1); |
|---|
| 1599 | //var_dump($rs->fields); |
|---|
| 1600 | if (!isset($rs->fields['firstname'])) Err("BAD FETCH ASSOC"); |
|---|
| 1601 | |
|---|
| 1602 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 1603 | $db->SetFetchMode(ADODB_FETCH_NUM); |
|---|
| 1604 | $rs = $db->SelectLimit('select firstname from ADOXYZ',1); |
|---|
| 1605 | if (!isset($rs->fields[0])) Err("BAD FETCH NUM"); |
|---|
| 1606 | |
|---|
| 1607 | flush(); |
|---|
| 1608 | |
|---|
| 1609 | print "<p>Test MetaTables again with SetFetchMode()</p>"; |
|---|
| 1610 | $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; |
|---|
| 1611 | $db->SetFetchMode(ADODB_FETCH_ASSOC); |
|---|
| 1612 | print_r($db->MetaTables()); |
|---|
| 1613 | print "<p>"; |
|---|
| 1614 | |
|---|
| 1615 | //////////////////////////////////////////////////////////////////// |
|---|
| 1616 | |
|---|
| 1617 | print "<p>Testing Bad Connection</p>"; |
|---|
| 1618 | flush(); |
|---|
| 1619 | |
|---|
| 1620 | if (true || PHP_VERSION < 5) { |
|---|
| 1621 | if ($db->dataProvider == 'odbtp') $db->databaseType = 'odbtp'; |
|---|
| 1622 | $conn = NewADOConnection($db->databaseType); |
|---|
| 1623 | $conn->raiseErrorFn = 'adodb_test_err'; |
|---|
| 1624 | if (1) $conn->PConnect('abc','baduser','badpassword'); |
|---|
| 1625 | if ($TESTERRS == 2) print "raiseErrorFn tests passed<br>"; |
|---|
| 1626 | else print "<b>raiseErrorFn tests failed ($TESTERRS)</b><br>"; |
|---|
| 1627 | |
|---|
| 1628 | flush(); |
|---|
| 1629 | } |
|---|
| 1630 | //////////////////////////////////////////////////////////////////// |
|---|
| 1631 | |
|---|
| 1632 | global $nocountrecs; |
|---|
| 1633 | |
|---|
| 1634 | if (isset($nocountrecs) && $ADODB_COUNTRECS) err("Error: \$ADODB_COUNTRECS is set"); |
|---|
| 1635 | if (empty($nocountrecs) && $ADODB_COUNTRECS==false) err("Error: \$ADODB_COUNTRECS is not set"); |
|---|
| 1636 | |
|---|
| 1637 | flush(); |
|---|
| 1638 | ?> |
|---|
| 1639 | </p> |
|---|
| 1640 | <table width=100% ><tr><td bgcolor=beige> </td></tr></table> |
|---|
| 1641 | </p></form> |
|---|
| 1642 | <?php |
|---|
| 1643 | |
|---|
| 1644 | if ($rs1) $rs1->Close(); |
|---|
| 1645 | if ($rs2) $rs2->Close(); |
|---|
| 1646 | if ($rs) $rs->Close(); |
|---|
| 1647 | $db->Close(); |
|---|
| 1648 | |
|---|
| 1649 | if ($db->transCnt != 0) Err("Error in transCnt=$db->transCnt (should be 0)"); |
|---|
| 1650 | |
|---|
| 1651 | |
|---|
| 1652 | printf("<p>Total queries=%d; total cached=%d</p>",$EXECS+$CACHED, $CACHED); |
|---|
| 1653 | flush(); |
|---|
| 1654 | } |
|---|
| 1655 | |
|---|
| 1656 | function adodb_test_err($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) |
|---|
| 1657 | { |
|---|
| 1658 | global $TESTERRS,$ERRNO; |
|---|
| 1659 | |
|---|
| 1660 | $ERRNO = $errno; |
|---|
| 1661 | $TESTERRS += 1; |
|---|
| 1662 | print "<i>** $dbms ($fn): errno=$errno errmsg=$errmsg ($p1,$p2)</i><br>"; |
|---|
| 1663 | } |
|---|
| 1664 | |
|---|
| 1665 | //-------------------------------------------------------------------------------------- |
|---|
| 1666 | |
|---|
| 1667 | |
|---|
| 1668 | @set_time_limit(240); // increase timeout |
|---|
| 1669 | |
|---|
| 1670 | include("../tohtml.inc.php"); |
|---|
| 1671 | include("../adodb.inc.php"); |
|---|
| 1672 | include("../rsfilter.inc.php"); |
|---|
| 1673 | |
|---|
| 1674 | /* White Space Check */ |
|---|
| 1675 | |
|---|
| 1676 | if (isset($_SERVER['argv'][1])) { |
|---|
| 1677 | //print_r($_SERVER['argv']); |
|---|
| 1678 | $_GET[$_SERVER['argv'][1]] = 1; |
|---|
| 1679 | } |
|---|
| 1680 | |
|---|
| 1681 | if (@$_SERVER['COMPUTERNAME'] == 'TIGRESS') { |
|---|
| 1682 | CheckWS('mysqlt'); |
|---|
| 1683 | CheckWS('postgres'); |
|---|
| 1684 | CheckWS('oci8po'); |
|---|
| 1685 | |
|---|
| 1686 | CheckWS('firebird'); |
|---|
| 1687 | CheckWS('sybase'); |
|---|
| 1688 | if (!ini_get('safe_mode')) CheckWS('informix'); |
|---|
| 1689 | |
|---|
| 1690 | CheckWS('ado_mssql'); |
|---|
| 1691 | CheckWS('ado_access'); |
|---|
| 1692 | CheckWS('mssql'); |
|---|
| 1693 | |
|---|
| 1694 | CheckWS('vfp'); |
|---|
| 1695 | CheckWS('sqlanywhere'); |
|---|
| 1696 | CheckWS('db2'); |
|---|
| 1697 | CheckWS('access'); |
|---|
| 1698 | CheckWS('odbc_mssql'); |
|---|
| 1699 | CheckWS('firebird15'); |
|---|
| 1700 | // |
|---|
| 1701 | CheckWS('oracle'); |
|---|
| 1702 | CheckWS('proxy'); |
|---|
| 1703 | CheckWS('fbsql'); |
|---|
| 1704 | print "White Space Check complete<p>"; |
|---|
| 1705 | } |
|---|
| 1706 | if (sizeof($_GET) == 0) $testmysql = true; |
|---|
| 1707 | |
|---|
| 1708 | |
|---|
| 1709 | foreach($_GET as $k=>$v) { |
|---|
| 1710 | //global $$k; |
|---|
| 1711 | $$k = $v; |
|---|
| 1712 | } |
|---|
| 1713 | if (strpos(PHP_VERSION,'5') === 0) { |
|---|
| 1714 | //$testaccess=1; |
|---|
| 1715 | //$testmssql = 1; |
|---|
| 1716 | //$testsqlite=1; |
|---|
| 1717 | } |
|---|
| 1718 | ?> |
|---|
| 1719 | <html> |
|---|
| 1720 | <title>ADODB Testing</title> |
|---|
| 1721 | <body bgcolor=white> |
|---|
| 1722 | <H1>ADODB Test</H1> |
|---|
| 1723 | |
|---|
| 1724 | This script tests the following databases: Interbase, Oracle, Visual FoxPro, Microsoft Access (ODBC and ADO), MySQL, MSSQL (ODBC, native, ADO). |
|---|
| 1725 | There is also support for Sybase, PostgreSQL.</p> |
|---|
| 1726 | For the latest version of ADODB, visit <a href=http://adodb.sourceforge.net/>adodb.sourceforge.net</a>.</p> |
|---|
| 1727 | |
|---|
| 1728 | Test <a href=test4.php>GetInsertSQL/GetUpdateSQL</a> |
|---|
| 1729 | <a href=testsessions.php>Sessions</a> |
|---|
| 1730 | <a href=testpaging.php>Paging</a> |
|---|
| 1731 | <a href=test-perf.php>Perf Monitor</a><p> |
|---|
| 1732 | <?php |
|---|
| 1733 | |
|---|
| 1734 | |
|---|
| 1735 | include_once('../adodb-time.inc.php'); |
|---|
| 1736 | if (isset($_GET['time'])) adodb_date_test(); |
|---|
| 1737 | |
|---|
| 1738 | include('./testdatabases.inc.php'); |
|---|
| 1739 | |
|---|
| 1740 | echo "<br>vers=",ADOConnection::Version(); |
|---|
| 1741 | |
|---|
| 1742 | |
|---|
| 1743 | |
|---|
| 1744 | ?> |
|---|
| 1745 | <p><i>ADODB Database Library (c) 2000-2009 John Lim. All rights reserved. Released under BSD and LGPL, PHP <?php echo PHP_VERSION ?>.</i></p> |
|---|
| 1746 | </body> |
|---|
| 1747 | </html> |
|---|