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