mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 05:54:19 +02:00
Upgraded ADOdb to 2.00
This commit is contained in:
parent
28bbcf011c
commit
9fa730a60b
85
lib/adodb/tests/benchmark.php
Normal file
85
lib/adodb/tests/benchmark.php
Normal file
@ -0,0 +1,85 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>ADODB Benchmarks</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
|
||||
Benchmark code to test the speed to the ADODB library with different databases.
|
||||
This is a simplistic benchmark to be used as the basis for further testing.
|
||||
It should not be used as proof of the superiority of one database over the other.
|
||||
*/
|
||||
|
||||
//$testmssql = true;
|
||||
//$testvfp = true;
|
||||
$testoracle = true;
|
||||
//$testado = true;
|
||||
//$testibase = true;
|
||||
$testaccess = true;
|
||||
$testmysql = true;
|
||||
|
||||
set_time_limit(240); // increase timeout
|
||||
|
||||
include("../tohtml.inc.php");
|
||||
include("../adodb.inc.php");
|
||||
|
||||
function testdb(&$db,$createtab="create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)")
|
||||
{
|
||||
GLOBAL $ADODB_version,$ADODB_FETCH_MODE;
|
||||
|
||||
|
||||
$max = 100;
|
||||
$sql = 'select * from ADOXYZ';
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
|
||||
print "<h3>ADODB Version: $ADODB_version Host: <i>$db->host</i> Database: <i>$db->database</i></h3>";
|
||||
|
||||
// perform query once to cache results so we are only testing throughput
|
||||
$rs = $db->Execute($sql);
|
||||
if (!$rs){
|
||||
print "Error in recordset<p>";
|
||||
return;
|
||||
}
|
||||
$arr = $rs->GetArray();
|
||||
//$db->debug = true;
|
||||
|
||||
$start = microtime();
|
||||
for ($i=0; $i < $max; $i++) {
|
||||
$rs = $db->Execute($sql);
|
||||
$arr = $rs->GetArray();
|
||||
// print $arr[0][1];
|
||||
}
|
||||
$end = microtime();
|
||||
$start = explode(' ',$start);
|
||||
$end = explode(' ',$end);
|
||||
|
||||
print_r($start);
|
||||
print_r($end);
|
||||
|
||||
// print_r($arr);
|
||||
$total = $end[0]+trim($end[1]) - $start[0]-trim($start[1]);
|
||||
printf ("<p>seconds = %8.2f for %d iterations each with %d records</p>",$total,$max, sizeof($arr));
|
||||
flush();
|
||||
|
||||
?>
|
||||
</p>
|
||||
<table width=100% ><tr><td bgcolor=beige> </td></tr></table>
|
||||
</p>
|
||||
<?php
|
||||
//$db->Close();
|
||||
}
|
||||
include("testdatabases.inc.php");
|
||||
|
||||
?>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
194
lib/adodb/tests/client.php
Normal file
194
lib/adodb/tests/client.php
Normal file
@ -0,0 +1,194 @@
|
||||
<html>
|
||||
<body bgcolor=white>
|
||||
<?php
|
||||
/**
|
||||
* (c)2001,2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
* Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
*
|
||||
* set tabs to 8
|
||||
*/
|
||||
|
||||
// documentation on usage is at http://php.weblogs.com/adodb_csv
|
||||
|
||||
include('../adodb.inc.php');
|
||||
include('../tohtml.inc.php');
|
||||
|
||||
function &send2server($url,$sql)
|
||||
{
|
||||
$url .= '?sql='.urlencode($sql);
|
||||
print "<p>$url</p>";
|
||||
$rs = csv2rs($url,$err);
|
||||
if ($err) print $err;
|
||||
return $rs;
|
||||
}
|
||||
|
||||
function print_pre($s)
|
||||
{
|
||||
print "<pre>";print_r($s);print "</pre>";
|
||||
}
|
||||
|
||||
|
||||
$serverURL = 'http://localhost/php/phplens/adodb/server.php';
|
||||
$testhttp = false;
|
||||
|
||||
$sql1 = "insertz into products (productname) values ('testprod 1')";
|
||||
$sql2 = "insert into products (productname) values ('testprod 1')";
|
||||
$sql3 = "insert into products (productname) values ('testprod 2')";
|
||||
$sql4 = "delete from products where productid>80";
|
||||
$sql5 = 'select * from products';
|
||||
|
||||
if ($testhttp) {
|
||||
print "<a href=#c>Client Driver Tests</a><p>";
|
||||
print "<h3>Test Error</h3>";
|
||||
$rs = send2server($serverURL,$sql1);
|
||||
print_pre($rs);
|
||||
print "<hr>";
|
||||
|
||||
print "<h3>Test Insert</h3>";
|
||||
|
||||
$rs = send2server($serverURL,$sql2);
|
||||
print_pre($rs);
|
||||
print "<hr>";
|
||||
|
||||
print "<h3>Test Insert2</h3>";
|
||||
|
||||
$rs = send2server($serverURL,$sql3);
|
||||
print_pre($rs);
|
||||
print "<hr>";
|
||||
|
||||
print "<h3>Test Delete</h3>";
|
||||
|
||||
$rs = send2server($serverURL,$sql4);
|
||||
print_pre($rs);
|
||||
print "<hr>";
|
||||
|
||||
|
||||
print "<h3>Test Select</h3>";
|
||||
$rs = send2server($serverURL,$sql5);
|
||||
if ($rs) rs2html($rs);
|
||||
|
||||
print "<hr>";
|
||||
}
|
||||
|
||||
|
||||
print "<a name=c><h1>CLIENT Driver Tests</h1>";
|
||||
$conn = ADONewConnection('csv');
|
||||
$conn->Connect($serverURL);
|
||||
$conn->debug = true;
|
||||
|
||||
print "<h3>Bad SQL</h3>";
|
||||
|
||||
$rs = $conn->Execute($sql1);
|
||||
|
||||
print "<h3>Insert SQL 1</h3>";
|
||||
$rs = $conn->Execute($sql2);
|
||||
|
||||
print "<h3>Insert SQL 2</h3>";
|
||||
$rs = $conn->Execute($sql3);
|
||||
|
||||
print "<h3>Select SQL</h3>";
|
||||
$rs = $conn->Execute($sql5);
|
||||
if ($rs) rs2html($rs);
|
||||
|
||||
print "<h3>Delete SQL</h3>";
|
||||
$rs = $conn->Execute($sql4);
|
||||
|
||||
print "<h3>Select SQL</h3>";
|
||||
$rs = $conn->Execute($sql5);
|
||||
if ($rs) rs2html($rs);
|
||||
|
||||
|
||||
/* EXPECTED RESULTS FOR HTTP TEST:
|
||||
|
||||
Test Insert
|
||||
http://localhost/php/adodb/server.php?sql=insert+into+products+%28productname%29+values+%28%27testprod%27%29
|
||||
|
||||
adorecordset Object
|
||||
(
|
||||
[dataProvider] => native
|
||||
[fields] =>
|
||||
[blobSize] => 64
|
||||
[canSeek] =>
|
||||
[EOF] => 1
|
||||
[emptyTimeStamp] =>
|
||||
[emptyDate] =>
|
||||
[debug] =>
|
||||
[timeToLive] => 0
|
||||
[bind] =>
|
||||
[_numOfRows] => -1
|
||||
[_numOfFields] => 0
|
||||
[_queryID] => 1
|
||||
[_currentRow] => -1
|
||||
[_closed] =>
|
||||
[_inited] =>
|
||||
[sql] => insert into products (productname) values ('testprod')
|
||||
[affectedrows] => 1
|
||||
[insertid] => 81
|
||||
)
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Test Insert2
|
||||
http://localhost/php/adodb/server.php?sql=insert+into+products+%28productname%29+values+%28%27testprod%27%29
|
||||
|
||||
adorecordset Object
|
||||
(
|
||||
[dataProvider] => native
|
||||
[fields] =>
|
||||
[blobSize] => 64
|
||||
[canSeek] =>
|
||||
[EOF] => 1
|
||||
[emptyTimeStamp] =>
|
||||
[emptyDate] =>
|
||||
[debug] =>
|
||||
[timeToLive] => 0
|
||||
[bind] =>
|
||||
[_numOfRows] => -1
|
||||
[_numOfFields] => 0
|
||||
[_queryID] => 1
|
||||
[_currentRow] => -1
|
||||
[_closed] =>
|
||||
[_inited] =>
|
||||
[sql] => insert into products (productname) values ('testprod')
|
||||
[affectedrows] => 1
|
||||
[insertid] => 82
|
||||
)
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Test Delete
|
||||
http://localhost/php/adodb/server.php?sql=delete+from+products+where+productid%3E80
|
||||
|
||||
adorecordset Object
|
||||
(
|
||||
[dataProvider] => native
|
||||
[fields] =>
|
||||
[blobSize] => 64
|
||||
[canSeek] =>
|
||||
[EOF] => 1
|
||||
[emptyTimeStamp] =>
|
||||
[emptyDate] =>
|
||||
[debug] =>
|
||||
[timeToLive] => 0
|
||||
[bind] =>
|
||||
[_numOfRows] => -1
|
||||
[_numOfFields] => 0
|
||||
[_queryID] => 1
|
||||
[_currentRow] => -1
|
||||
[_closed] =>
|
||||
[_inited] =>
|
||||
[sql] => delete from products where productid>80
|
||||
[affectedrows] => 2
|
||||
[insertid] => 0
|
||||
)
|
||||
|
||||
[more stuff deleted]
|
||||
.
|
||||
.
|
||||
.
|
||||
*/
|
||||
?>
|
755
lib/adodb/tests/test.php
Normal file
755
lib/adodb/tests/test.php
Normal file
@ -0,0 +1,755 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
*/
|
||||
|
||||
|
||||
foreach($HTTP_GET_VARS as $k=>$v) {
|
||||
global $$k;
|
||||
|
||||
$$k = $v;
|
||||
}
|
||||
|
||||
if (sizeof($HTTP_GET_VARS) == 0) $testmysql = true;
|
||||
?>
|
||||
<html>
|
||||
<title>ADODB Testing</title>
|
||||
<body bgcolor=white>
|
||||
<H1>ADODB Test</H1>
|
||||
|
||||
This script tests the following databases: Interbase, Oracle, Visual FoxPro, Microsoft Access (ODBC and ADO), MySQL, MSSQL (ODBC, native, ADO).
|
||||
There is also support for Sybase, PostgreSQL.</p>
|
||||
For the latest version of ADODB, visit <a href=http://php.weblogs.com/ADODB>php.weblogs.com</a>.</p>
|
||||
|
||||
<form method=get>
|
||||
<input type=checkbox name=testaccess value=1 <?php echo !empty($testaccess) ? 'checked' : '' ?>> Access<br>
|
||||
<input type=checkbox name=testibase value=1 <?php echo !empty($testibase) ? 'checked' : '' ?>> Interbase<br>
|
||||
<input type=checkbox name=testmssql value=1 <?php echo !empty($testmssql) ? 'checked' : '' ?>> MSSQL<br>
|
||||
<input type=checkbox name=testmysql value=1 <?php echo !empty($testmysql) ? 'checked' : '' ?>> <b>MySQL</b><br>
|
||||
<input type=checkbox name=testoracle value=1 <?php echo !empty($testoracle) ? 'checked' : '' ?>> <b>Oracle (oci8)</b> <br>
|
||||
<input type=checkbox name=testpostgres value=1 <?php echo !empty($testpostgres) ? 'checked' : '' ?>> <b>PostgreSQL</b><br>
|
||||
<input type=checkbox name=testvfp value=1 <?php echo !empty($testvfp) ? 'checked' : '' ?>> VFP<br>
|
||||
<input type=checkbox name=testado value=1 <?php echo !empty($testado) ? 'checked' : '' ?>> ADO (for mssql and access)<br>
|
||||
<input type=submit>
|
||||
</form>
|
||||
|
||||
Test <a href=test4.php>GetInsertSQL/GetUpdateSQL</a>
|
||||
<a href=testsessions.php>Sessions</a>
|
||||
<a href=testpaging.php>Paging</a>
|
||||
<?php
|
||||
|
||||
|
||||
// Set the following control flags to true/false to enable testing for a particular database.
|
||||
/*
|
||||
$testoracle = true;
|
||||
$testibase = true;
|
||||
$testaccess = true;
|
||||
//testpostgres = true;
|
||||
$testmysql = true;
|
||||
//$testmssql = true;
|
||||
//$testvfp = true;
|
||||
//$testado = true;
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
set_time_limit(240); // increase timeout
|
||||
|
||||
include("../tohtml.inc.php");
|
||||
include("../adodb.inc.php");
|
||||
|
||||
if ($ADODB_FETCH_MODE != ADODB_FETCH_DEFAULT) print "<h3>FETCH MODE IS NOT ADODB_FETCH_DEFAULT</h3>";
|
||||
|
||||
// the table creation code is specific to the database, so we allow the user
|
||||
// to define their own table creation stuff
|
||||
function testdb(&$db,$createtab="create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)")
|
||||
{
|
||||
GLOBAL $ADODB_vers,$ADODB_CACHE_DIR,$ADODB_FETCH_MODE, $HTTP_GET_VARS,$ADODB_COUNTRECS;
|
||||
?> <form>
|
||||
</p>
|
||||
<table width=100% ><tr><td bgcolor=beige> </td></tr></table>
|
||||
</p>
|
||||
<?php
|
||||
$create =false;
|
||||
$ADODB_CACHE_DIR = dirname(TempNam('/tmp','testadodb'));
|
||||
|
||||
$db->debug = false;
|
||||
|
||||
$phpv = phpversion();
|
||||
print "<h3>ADODB Version: $ADODB_vers Host: <i>$db->host</i> Database: <i>$db->database</i> PHP: $phpv</h3>";
|
||||
$e = error_reporting(E_ALL-E_WARNING);
|
||||
|
||||
|
||||
print "<i>date1</i> (1999-02-20) = ".$db->DBDate('1999-2-20');
|
||||
print "<br><i>date2</i> (1970-1-2) = ".$db->DBDate(24*3600)."<p>";
|
||||
print "<i>ts1</i> (1999-02-20 3:40:50) = ".$db->DBTimeStamp('1999-2-20 3:40:50');
|
||||
print "<br><i>ts2</i> (1999-02-20) = ".$db->DBTimeStamp('1999-2-20');
|
||||
print "<br><i>ts3</i> (1970-1-2 +/- timezone) = ".$db->DBTimeStamp(24*3600);
|
||||
$dd = $db->UnixDate('1999-02-20');
|
||||
print "<br>unixdate</i> 1999-02-20 = ".date('Y-m-d',$dd)."<p>";
|
||||
// mssql too slow in failing bad connection
|
||||
if ($db->databaseType != 'mssql') {
|
||||
print "<p>Testing bad connection. Ignore following error msgs:<br>";
|
||||
$db2 = ADONewConnection();
|
||||
$rez = $db2->Connect("bad connection");
|
||||
$err = $db2->ErrorMsg();
|
||||
print "<i>Error='$err'</i></p>";
|
||||
if ($rez) print "<b>Cannot check if connection failed.</b> The Connect() function returned true.</p>";
|
||||
}
|
||||
error_reporting($e);
|
||||
|
||||
//$ADODB_COUNTRECS=false;
|
||||
$rs=$db->Execute('select * from adoxyz order by id');
|
||||
//print_r($rs);
|
||||
//OCIFetchStatement($rs->_queryID,$rez,0,-1);//,OCI_ASSOC | OCI_FETCHSTATEMENT_BY_ROW);
|
||||
//print_r($rez);
|
||||
//die();
|
||||
if($rs === false) $create = true;
|
||||
else $rs->Close();
|
||||
|
||||
//if ($db->databaseType !='vfp') $db->Execute("drop table ADOXYZ");
|
||||
|
||||
if ($create) {
|
||||
if ($db->databaseType == 'ibase') {
|
||||
print "<b>Please create the following table for testing:</b></p>$createtab</p>";
|
||||
return;
|
||||
} else {
|
||||
$db->debug = 1;
|
||||
$e = error_reporting(E_ALL-E_WARNING);
|
||||
$db->Execute($createtab);
|
||||
error_reporting($e);
|
||||
}
|
||||
}
|
||||
|
||||
$rs = &$db->Execute("delete from ADOXYZ"); // some ODBC drivers will fail the drop so we delete
|
||||
if ($rs) {
|
||||
if(! $rs->EOF)print "<b>Error: </b>RecordSet returned by Execute('delete...') should show EOF</p>";
|
||||
$rs->Close();
|
||||
} else print "err=".$db->ErrorMsg();
|
||||
|
||||
print "<p>Test select on empty table</p>";
|
||||
$rs = &$db->Execute("select * from ADOXYZ where id=9999");
|
||||
if ($rs && !$rs->EOF) print "<b>Error: </b>RecordSet returned by Execute(select...') on empty table should show EOF</p>";
|
||||
if ($rs) $rs->Close();
|
||||
|
||||
|
||||
$db->debug=false;
|
||||
print "<p>Testing Commit: ";
|
||||
$time = $db->DBDate(time());
|
||||
if (!$db->BeginTrans()) print '<b>Transactions not supported</b></p>';
|
||||
else { /* COMMIT */
|
||||
$rs = $db->Execute("insert into ADOXYZ values (99,'Should Not','Exist (Commit)',$time)");
|
||||
if ($rs && $db->CommitTrans()) {
|
||||
$rs->Close();
|
||||
$rs = &$db->Execute("select * from ADOXYZ where id=99");
|
||||
if ($rs === false || $rs->EOF) {
|
||||
print '<b>Data not saved</b></p>';
|
||||
$rs = &$db->Execute("select * from ADOXYZ where id=99");
|
||||
print_r($rs);
|
||||
die();
|
||||
} else print 'OK</p>';
|
||||
if ($rs) $rs->Close();
|
||||
} else
|
||||
print "<b>Commit failed</b></p>";
|
||||
|
||||
/* ROLLBACK */
|
||||
if (!$db->BeginTrans()) print "<p><b>Error in BeginTrans</b>()</p>";
|
||||
print "<p>Testing Rollback: ";
|
||||
$db->Execute("insert into ADOXYZ values (100,'Should Not','Exist (Rollback)',$time)");
|
||||
if ($db->RollbackTrans()) {
|
||||
$rs = $db->Execute("select * from ADOXYZ where id=100");
|
||||
if ($rs && !$rs->EOF) print '<b>Fail: Data should rollback</b></p>';
|
||||
else print 'OK</p>';
|
||||
if ($rs) $rs->Close();
|
||||
} else
|
||||
print "<b>Commit failed</b></p>";
|
||||
|
||||
$rs = &$db->Execute('delete from ADOXYZ where id>50');
|
||||
if ($rs) $rs->Close();
|
||||
}
|
||||
|
||||
if (1) {
|
||||
print "<p>Testing MetaDatabases()</p>";
|
||||
print_r( $db->MetaDatabases());
|
||||
|
||||
print "<p>Testing MetaTables() and MetaColumns()</p>";
|
||||
$a = $db->MetaTables();
|
||||
if ($a===false) print "<b>MetaTables not supported</b></p>";
|
||||
else {
|
||||
print "Array of tables: ";
|
||||
foreach($a as $v) print " ($v) ";
|
||||
print '</p>';
|
||||
}
|
||||
$a = $db->MetaColumns('ADOXYZ');
|
||||
if ($a===false) print "<b>MetaColumns not supported</b></p>";
|
||||
else {
|
||||
print "<p>Columns of ADOXYZ: ";
|
||||
foreach($a as $v) print " ($v->name $v->type $v->max_length) ";
|
||||
}
|
||||
}
|
||||
$rs = &$db->Execute('delete from ADOXYZ');
|
||||
if ($rs) $rs->Close();
|
||||
|
||||
$db->debug = false;
|
||||
|
||||
if ($db->databaseType == 'mssql') {
|
||||
/*
|
||||
ASSUME Northwind available...
|
||||
|
||||
CREATE PROCEDURE SalesByCategory
|
||||
@CategoryName nvarchar(15), @OrdYear nvarchar(4) = '1998'
|
||||
AS
|
||||
IF @OrdYear != '1996' AND @OrdYear != '1997' AND @OrdYear != '1998'
|
||||
BEGIN
|
||||
SELECT @OrdYear = '1998'
|
||||
END
|
||||
|
||||
SELECT ProductName,
|
||||
TotalPurchase=ROUND(SUM(CONVERT(decimal(14,2), OD.Quantity * (1-OD.Discount) * OD.UnitPrice)), 0)
|
||||
FROM [Order Details] OD, Orders O, Products P, Categories C
|
||||
WHERE OD.OrderID = O.OrderID
|
||||
AND OD.ProductID = P.ProductID
|
||||
AND P.CategoryID = C.CategoryID
|
||||
AND C.CategoryName = @CategoryName
|
||||
AND SUBSTRING(CONVERT(nvarchar(22), O.OrderDate, 111), 1, 4) = @OrdYear
|
||||
GROUP BY ProductName
|
||||
ORDER BY ProductName
|
||||
GO
|
||||
*/
|
||||
print "<h4>Testing Stored Procedures for mssql</h4>";
|
||||
$saved = $db->debug;
|
||||
$db->debug=true;
|
||||
|
||||
$cat = 'Dairy Products';
|
||||
$yr = '1998';
|
||||
|
||||
$stmt = $db->PrepareSP('SalesByCategory');
|
||||
$db->Parameter($stmt,$cat,'CategoryName');
|
||||
$db->Parameter($stmt,$yr,'OrdYear');
|
||||
$rs = $db->Execute($stmt);
|
||||
rs2html($rs);
|
||||
|
||||
$cat = 'Grains/Cereals';
|
||||
$yr = 1998;
|
||||
|
||||
$stmt = $db->PrepareSP('SalesByCategory');
|
||||
$db->Parameter($stmt,$cat,'CategoryName');
|
||||
$db->Parameter($stmt,$yr,'OrdYear');
|
||||
$rs = $db->Execute($stmt);
|
||||
rs2html($rs);
|
||||
|
||||
$db->debug = $saved;
|
||||
} else if (substr($db->databaseType,0,4) == 'oci8') {
|
||||
print "<h4>Testing Stored Procedures for oci8</h4>";
|
||||
$saved = $db->debug;
|
||||
$db->debug=true;
|
||||
|
||||
$tname = 'A%';
|
||||
|
||||
$stmt = $db->PrepareSP('select * from tab where tname like :tablename');
|
||||
$db->Parameter($stmt,$tname,'tablename');
|
||||
$rs = $db->Execute($stmt);
|
||||
rs2html($rs);
|
||||
|
||||
$db->debug = $saved;
|
||||
}
|
||||
print "<p>Inserting 50 rows</p>";
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
|
||||
$time = $db->DBDate(time());
|
||||
if (empty($HTTP_GET_VARS['hide'])) $db->debug = true;
|
||||
switch($db->databaseType){
|
||||
default:
|
||||
$arr = array(0=>'Caroline',1=>'Miranda');
|
||||
$sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,?,?,$time)";
|
||||
break;
|
||||
case 'oci8':
|
||||
case 'oci805':
|
||||
$arr = array('first'=>'Caroline','last'=>'Miranda');
|
||||
$sql = "insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+0,:first,:last,$time)";
|
||||
break;
|
||||
}
|
||||
if ($i & 1) {
|
||||
$sql = $db->Prepare($sql);
|
||||
}
|
||||
$rs = $db->Execute($sql,$arr);
|
||||
|
||||
if ($rs === false) print '<b>Error inserting with parameters</b><br>';
|
||||
else $rs->Close();
|
||||
|
||||
$db->debug = false;
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+1,'John','Lim',$time)");
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+2,'Mary','Lamb',$time )");
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+3,'George','Washington',$time )");
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+4,'Mr. Alan','Tam',$time )");
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+5,'Alan','Turing',$time )");
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created)values ($i*10+6,'Serena','Williams',$time )");
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+7,'Yat Sun','Sun',$time )");
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+8,'Wai Hun','See',$time )");
|
||||
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+9,'Steven','Oey',$time )");
|
||||
}
|
||||
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||
|
||||
$db->Execute('update ADOXYZ set id=id+1');
|
||||
$nrows = $db->Affected_Rows();
|
||||
if ($nrows === false) print "<p><b>Affected_Rows() not supported</b></p>";
|
||||
else if ($nrows != 50) print "<p><b>Affected_Rows() Error: $nrows returned (should be 50) </b></p>";
|
||||
else print "<p>Affected_Rows() passed</p>";
|
||||
$db->debug = false;
|
||||
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
|
||||
///////////////////////////////
|
||||
|
||||
$rs = &$db->Execute("select * from ADOXYZ order by id");
|
||||
if ($rs) {
|
||||
// print_r($rs);
|
||||
if ($rs->RecordCount() != 50) {
|
||||
print "<p><b>RecordCount returns -1</b></p>";
|
||||
if ($rs->PO_RecordCount('ADOXYZ') == 50) print "<p> PO_RecordCount passed</p>";
|
||||
else print "<p><b>PO_RecordCount returns wrong value</b></p>";
|
||||
} else print "<p>RecordCount() passed</p>";
|
||||
if (isset($rs->fields['firstname'])) print '<p>The fields columns can be indexed by column name.</p>';
|
||||
else print '<p>The fields columns <i>cannot</i> be indexed by column name.</p>';
|
||||
if (empty($HTTP_GET_VARS['hide'])) rs2html($rs);
|
||||
}
|
||||
else print "<b>Error in Execute of SELECT</b></p>";
|
||||
|
||||
$val = $db->GetOne("select count(*) from ADOXYZ");
|
||||
if ($val == 50) print "<p>GetOne returns ok</p>";
|
||||
else print "<p><b>Fail: GetOne returns $val</b></p>";
|
||||
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
$val = $db->GetRow("select count(*) from ADOXYZ");
|
||||
if ($val[0] == 50 and sizeof($val) == 1) print "<p>GetRow returns ok</p>";
|
||||
else {
|
||||
print_r($val);
|
||||
print "<p><b>Fail: GetRow returns {$val[0]}</b></p>";
|
||||
}
|
||||
|
||||
print "<p>FetchObject/FetchNextObject Test</p>";
|
||||
$rs = &$db->Execute('select * from ADOXYZ');
|
||||
if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
|
||||
|
||||
while ($o = $rs->FetchNextObject()) { // calls FetchObject internally
|
||||
if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) {
|
||||
print_r($o);
|
||||
print "<p><b>Firstname is not string</b></p>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||
print "<p>FetchObject/FetchNextObject Test 2</p>";
|
||||
$rs = &$db->Execute('select * from ADOXYZ');
|
||||
if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
|
||||
|
||||
while ($o = $rs->FetchNextObject()) { // calls FetchObject internally
|
||||
if (!is_string($o->FIRSTNAME) || !is_string($o->LASTNAME)) {
|
||||
print_r($o);
|
||||
print "<p><b>Firstname is not string</b></p>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
|
||||
$savefetch = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||
|
||||
print "<p>CacheSelectLimit Test</p>";
|
||||
$rs = $db->CacheSelectLimit('select id, firstname from ADOXYZ order by id',2);
|
||||
if ($rs && !$rs->EOF) {
|
||||
if ($rs->fields['id'] != 1) {print "<b>Error 1</b><br>"; print_r($rs->fields);};
|
||||
if (trim($rs->fields['firstname']) != 'Caroline') {print "<b>Error 2</b><br>"; print_r($rs->fields);};
|
||||
$rs->MoveNext();
|
||||
if ($rs->fields['id'] != 2) {print "<b>Error 3</b><br>"; print_r($rs->fields);};
|
||||
$rs->MoveNext();
|
||||
if (!$rs->EOF) print "<b>EOF Error</b><br>";
|
||||
}
|
||||
|
||||
print "<p>FETCH_MODE = ASSOC: Should get 1, Caroline</p>";
|
||||
$rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',2);
|
||||
if ($rs && !$rs->EOF) {
|
||||
if ($rs->fields['id'] != 1) {print "<b>Error 1</b><br>"; print_r($rs->fields);};
|
||||
if (trim($rs->fields['firstname']) != 'Caroline') {print "<b>Error 2</b><br>"; print_r($rs->fields);};
|
||||
$rs->MoveNext();
|
||||
if ($rs->fields['id'] != 2) {print "<b>Error 3</b><br>"; print_r($rs->fields);};
|
||||
$rs->MoveNext();
|
||||
if (!$rs->EOF) print "<b>EOF Error</b><br>";
|
||||
}
|
||||
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
print "<p>FETCH_MODE = NUM: Should get 1, Caroline</p>";
|
||||
$rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
|
||||
if ($rs && !$rs->EOF) {
|
||||
if ($rs->fields[0] != 1) {print "<b>Error 1</b><br>"; print_r($rs->fields);};
|
||||
if (trim($rs->fields[1]) != 'Caroline') {print "<b>Error 2</b><br>"; print_r($rs->fields);};
|
||||
$rs->MoveNext();
|
||||
if (!$rs->EOF) print "<b>EOF Error</b><br>";
|
||||
|
||||
}
|
||||
$ADODB_FETCH_MODE = $savefetch;
|
||||
|
||||
$db->debug = false;
|
||||
print "<p>GetRowAssoc Upper: Should get 1, Caroline</p>";
|
||||
$rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
|
||||
if ($rs && !$rs->EOF) {
|
||||
$arr = &$rs->GetRowAssoc();
|
||||
if ($arr['ID'] != 1) {print "<b>Error 1</b><br>"; print_r($arr);};
|
||||
if (trim($arr['FIRSTNAME']) != 'Caroline') {print "<b>Error 2</b><br>"; print_r($arr);};
|
||||
$rs->MoveNext();
|
||||
if (!$rs->EOF) print "<b>EOF Error</b><br>";
|
||||
|
||||
}
|
||||
print "<p>GetRowAssoc Lower: Should get 1, Caroline</p>";
|
||||
$rs = &$db->SelectLimit('select id,firstname from ADOXYZ order by id',1);
|
||||
if ($rs && !$rs->EOF) {
|
||||
$arr = &$rs->GetRowAssoc(false);
|
||||
if ($arr['id'] != 1) {print "<b>Error 1</b><br>"; print_r($arr);};
|
||||
if (trim($arr['firstname']) != 'Caroline') {print "<b>Error 2</b><br>"; print_r($arr);};
|
||||
|
||||
}
|
||||
//$db->debug = true;
|
||||
print "<p>SelectLimit Test 1: Should see Caroline, John and Mary</p>";
|
||||
$rs = &$db->SelectLimit('select distinct * from ADOXYZ order by id',3);
|
||||
if ($rs && !$rs->EOF) {
|
||||
if (trim($rs->fields[1]) != 'Caroline') print "<b>Error 1</b><br>";
|
||||
$rs->MoveNext();
|
||||
if (trim($rs->fields[1]) != 'John') print "<b>Error 2</b><br>";
|
||||
$rs->MoveNext();
|
||||
if (trim($rs->fields[1]) != 'Mary') print "<b>Error 3</b><br>";
|
||||
$rs->MoveNext();
|
||||
if (! $rs->EOF) print "<b>Not EOF</b><br>";
|
||||
//rs2html($rs);
|
||||
}
|
||||
else "<p><b>Failed SelectLimit Test 1</b></p>";
|
||||
print "<p>SelectLimit Test 2: Should see Mary, George and Mr. Alan</p>";
|
||||
$rs = &$db->SelectLimit('select * from ADOXYZ order by id',3,2);
|
||||
if ($rs && !$rs->EOF) {
|
||||
if (trim($rs->fields[1]) != 'Mary') print "<b>Error 1</b><br>";
|
||||
$rs->MoveNext();
|
||||
if (trim($rs->fields[1]) != 'George') print "<b>Error 2</b><br>";
|
||||
$rs->MoveNext();
|
||||
if (trim($rs->fields[1]) != 'Mr. Alan') print "<b>Error 3</b><br>";
|
||||
$rs->MoveNext();
|
||||
if (! $rs->EOF) print "<b>Not EOF</b><br>";
|
||||
// rs2html($rs);
|
||||
}
|
||||
else "<p><b>Failed SelectLimit Test 2</b></p>";
|
||||
|
||||
print "<p>SelectLimit Test 3: Should see Wai Hun and Steven</p>";
|
||||
$rs = &$db->SelectLimit('select * from ADOXYZ order by id',-1,48);
|
||||
if ($rs && !$rs->EOF) {
|
||||
if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
|
||||
if (trim($rs->fields[1]) != 'Wai Hun') print "<b>Error 1</b><br>";
|
||||
$rs->MoveNext();
|
||||
if (trim($rs->fields[1]) != 'Steven') print "<b>Error 2</b><br>";
|
||||
$rs->MoveNext();
|
||||
if (! $rs->EOF) print "<b>Not EOF</b><br>";
|
||||
//rs2html($rs);
|
||||
}
|
||||
else "<p><b>Failed SelectLimit Test 3</b></p>";
|
||||
$db->debug = false;
|
||||
|
||||
$rs = &$db->Execute("select * from ADOXYZ order by id");
|
||||
print "<p>Testing Move()</p>";
|
||||
if (!$rs)print "<b>Failed Move SELECT</b></p>";
|
||||
else {
|
||||
if (!$rs->Move(2)) {
|
||||
if (!$rs->canSeek) print "<p>$db->databaseType: <b>Move(), MoveFirst() nor MoveLast() not supported.</b></p>";
|
||||
else print '<p><b>RecordSet->canSeek property should be set to false</b></p>';
|
||||
} else {
|
||||
$rs->MoveFirst();
|
||||
if (trim($rs->Fields("firstname")) != 'Caroline') {
|
||||
print "<p><b>$db->databaseType: MoveFirst failed -- probably cannot scroll backwards</b></p>";
|
||||
}
|
||||
else print "MoveFirst() OK<BR>";
|
||||
|
||||
// Move(3) tests error handling -- MoveFirst should not move cursor
|
||||
$rs->Move(3);
|
||||
if (trim($rs->Fields("firstname")) != 'George') {
|
||||
print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(3) failed</b></p>";
|
||||
print_r($rs);
|
||||
} else print "Move(3) OK<BR>";
|
||||
|
||||
$rs->Move(7);
|
||||
if (trim($rs->Fields("firstname")) != 'Yat Sun') {
|
||||
print '<p>'.$rs->Fields("id")."<b>$db->databaseType: Move(7) failed</b></p>";
|
||||
print_r($rs);
|
||||
} else print "Move(7) OK<BR>";
|
||||
|
||||
$rs->MoveLast();
|
||||
if (trim($rs->Fields("firstname")) != 'Steven'){
|
||||
print '<p>'.$rs->Fields("id")."<b>$db->databaseType: MoveLast() failed</b></p>";
|
||||
print_r($rs);
|
||||
}else print "MoveLast() OK<BR>";
|
||||
}
|
||||
}
|
||||
|
||||
// $db->debug=true;
|
||||
print "<p>Testing ADODB_FETCH_ASSOC and concat: concat firstname and lastname</p>";
|
||||
|
||||
$save = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||
if ($db->dataProvider == 'postgres')
|
||||
$rs = &$db->Execute("select distinct ".$db->Concat('(firstname',$db->qstr(' ').')','lastname').",id from ADOXYZ");
|
||||
else
|
||||
$rs = &$db->Execute("select distinct ".$db->Concat('firstname',$db->qstr(' '),'lastname').",id from ADOXYZ");
|
||||
if ($rs) {
|
||||
if (empty($HTTP_GET_VARS['hide'])) rs2html($rs);
|
||||
} else print "<b>Failed Concat</b></p>";
|
||||
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
print "<hr>Testing GetArray() ";
|
||||
$rs = &$db->Execute("select * from ADOXYZ order by id");
|
||||
if ($rs) {
|
||||
$arr = &$rs->GetArray(10);
|
||||
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>";
|
||||
else print " OK<BR>";
|
||||
}
|
||||
|
||||
print "Testing FetchNextObject for 1 object ";
|
||||
$rs = &$db->Execute("select distinct lastname,firstname from ADOXYZ where firstname='Caroline'");
|
||||
$fcnt = 0;
|
||||
if ($rs)
|
||||
while ($o = $rs->FetchNextObject()) {
|
||||
$fcnt += 1;
|
||||
}
|
||||
if ($fcnt == 1) print " OK<BR>";
|
||||
else print "<b>FAILED</b><BR>";
|
||||
|
||||
print "Testing GetAssoc() ";
|
||||
$rs = &$db->Execute("select distinct lastname,firstname from ADOXYZ");
|
||||
if ($rs) {
|
||||
$arr = $rs->GetAssoc();
|
||||
if (trim($arr['See']) != 'Wai Hun') print $arr['See']." <b>ERROR</b><br>";
|
||||
else print " OK<BR>";
|
||||
}
|
||||
|
||||
for ($loop=0; $loop < 1; $loop++) {
|
||||
print "Testing GetMenu() and CacheExecute<BR>";
|
||||
$db->debug = true;
|
||||
$rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
|
||||
if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu('menu','Steven').'<BR>';
|
||||
else print " Fail<BR>";
|
||||
$rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
|
||||
if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu('menu','Steven',false).'<BR>';
|
||||
else print " Fail<BR>";
|
||||
|
||||
$rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
|
||||
if ($rs) print ' Multiple, Alan selected: '. $rs->GetMenu('menu','Alan',false,true).'<BR>';
|
||||
else print " Fail<BR>";
|
||||
print '</p><hr>';
|
||||
|
||||
$rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
|
||||
if ($rs) {
|
||||
print ' Multiple, Alan and George selected: '. $rs->GetMenu('menu',array('Alan','George'),false,true);
|
||||
if (empty($rs->connection)) print "<b>Connection object missing from recordset</b></br>";
|
||||
} else print " Fail<BR>";
|
||||
print '</p><hr>';
|
||||
|
||||
print "Testing GetMenu2() <BR>";
|
||||
$rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
|
||||
if ($rs) print 'With blanks, Steven selected:'. $rs->GetMenu2('menu',('Oey')).'<BR>';
|
||||
else print " Fail<BR>";
|
||||
$rs = &$db->CacheExecute(4,"select distinct firstname,lastname from ADOXYZ");
|
||||
if ($rs) print ' No blanks, Steven selected: '. $rs->GetMenu2('menu',('Oey'),false).'<BR>';
|
||||
else print " Fail<BR>";
|
||||
}
|
||||
|
||||
$db->debug = false;
|
||||
$rs1 = &$db->Execute("select id from ADOXYZ where id = 2 or id = 1 order by 1");
|
||||
$rs2 = &$db->Execute("select id from ADOXYZ where id = 3 or id = 4 order by 1");
|
||||
|
||||
if ($rs1) $rs1->MoveLast();
|
||||
if ($rs2) $rs2->MoveLast();
|
||||
|
||||
if (empty($rs1) || empty($rs2) || $rs1->fields[0] != 2 || $rs2->fields[0] != 4) {
|
||||
$a = $rs1->fields[0];
|
||||
$b = $rs2->fields[0];
|
||||
print "<p><b>Error in multiple recordset test rs1=$a rs2=%b (should be rs1=2 rs2=4)</b></p>";
|
||||
} else
|
||||
print "<p>Testing multiple recordsets OK</p>";
|
||||
|
||||
|
||||
echo "<p> GenID test: ";
|
||||
for ($i=1; $i <= 10; $i++)
|
||||
echo "($i: ",$val = $db->GenID('abcseq5' ,5), ") ";
|
||||
if ($val == 0) echo " <p><b>GenID not supported</b>";
|
||||
echo "<p>";
|
||||
|
||||
if (substr($db->dataProvider,0,3) != 'ado') { // crashes ado
|
||||
$sql = "select firstnames from adoxyz";
|
||||
print "<p>Testing execution of illegal statement: <i>$sql</i></p>";
|
||||
if ($db->Execute($sql) === false) {
|
||||
print "<p>This returns the following ErrorMsg(): <i>".$db->ErrorMsg()."</i> and ErrorNo(): ".$db->ErrorNo().'</p>';
|
||||
} else
|
||||
print "<p><b>Error in error handling -- Execute() should return false</b></p>";
|
||||
} else
|
||||
print "<p><b>ADO skipped error handling of bad select statement</b></p>";
|
||||
|
||||
print "<p>ASSOC TEST 2<br>";
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||
$rs = $db->query('select * from adoxyz order by id');
|
||||
for($i=0;$i<$rs->FieldCount();$i++)
|
||||
{
|
||||
$fld=$rs->FetchField($i);
|
||||
print "<br> Field name is ".$fld->name;
|
||||
print " ".$rs->Fields($fld->name);
|
||||
}
|
||||
|
||||
|
||||
print "<p>BOTH TEST 2<br>";
|
||||
if ($db->dataProvider == 'ado') {
|
||||
print "<b>ADODB_FETCH_BOTH not supported</b> for dataProvider=".$db->dataProvider."<br>";
|
||||
} else {
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_BOTH;
|
||||
$rs = $db->query('select * from adoxyz order by id');
|
||||
for($i=0;$i<$rs->FieldCount();$i++)
|
||||
{
|
||||
$fld=$rs->FetchField($i);
|
||||
print "<br> Field name is ".$fld->name;
|
||||
print " ".$rs->Fields($fld->name);
|
||||
}
|
||||
}
|
||||
|
||||
print "<p>NUM TEST 2<br>";
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
$rs = $db->query('select * from adoxyz order by id');
|
||||
for($i=0;$i<$rs->FieldCount();$i++)
|
||||
{
|
||||
$fld=$rs->FetchField($i);
|
||||
print "<br> Field name is ".$fld->name;
|
||||
print " ".$rs->Fields($fld->name);
|
||||
}
|
||||
|
||||
print "<p>ASSOC Test of SelectLimit<br>";
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||
$rs = $db->selectlimit('select * from adoxyz order by id',3,4);
|
||||
$cnt = 0;
|
||||
while ($rs && !$rs->EOF) {
|
||||
$cnt += 1;
|
||||
if (!isset($rs->fields['firstname'])) {
|
||||
print "<br><b>ASSOC returned numeric field</b></p>";
|
||||
break;
|
||||
}
|
||||
$rs->MoveNext();
|
||||
}
|
||||
if ($cnt != 3) print "<br><b>Count should be 3, instead it was $cnt</b></p>";
|
||||
|
||||
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
if ($db->sysDate) {
|
||||
$saved = $db->debug;
|
||||
$db->debug = 1;
|
||||
$rs = $db->Execute("select {$db->sysDate} from adoxyz where id=1");
|
||||
if (ADORecordSet::UnixDate(date('Y-m-d')) != $rs->UnixDate($rs->fields[0])) {
|
||||
print "<p><b>Invalid date {$rs->fields[0]}</b></p>";
|
||||
} else
|
||||
print "<p>Passed \$sysDate test ({$rs->fields[0]})</p>";
|
||||
|
||||
$db->debug=$saved;
|
||||
} else {
|
||||
print "<p><b>\$db->sysDate not defined</b></p>";
|
||||
}
|
||||
// PEAR TESTS BELOW
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
$pear = true;
|
||||
$rs = $db->query('select * from adoxyz order by id');
|
||||
|
||||
$i = 0;
|
||||
if ($rs && !$rs->EOF) {
|
||||
while ($arr = $rs->fetchRow()) {
|
||||
$i++;
|
||||
//print "$i ";
|
||||
if ($arr[0] != $i) {
|
||||
print "<p><b>PEAR DB emulation error 1.</b></p>";
|
||||
$pear = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$rs->Close();
|
||||
}
|
||||
|
||||
|
||||
include_once "PEAR.php";
|
||||
$db->debug =true;
|
||||
if ($i != 50) {
|
||||
print "<p><b>PEAR DB emulation error 1.1 EOF ($i)</b></p>";
|
||||
$pear = false;
|
||||
}
|
||||
|
||||
$rs = $db->limitQuery('select * from adoxyz order by id',$i=3,$top=3);
|
||||
$i2 = $i;
|
||||
if ($rs && !$rs->EOF) {
|
||||
|
||||
while (!is_object($rs->fetchInto($arr))) {
|
||||
$i2++;
|
||||
|
||||
// print_r($arr);
|
||||
// print "$i ";print_r($arr);
|
||||
if ($arr[0] != $i2) {
|
||||
print "<p><b>PEAR DB emulation error 2.</b></p>";
|
||||
$pear = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$rs->Close();
|
||||
}
|
||||
if ($i2 != $i+$top) {
|
||||
print "<p><b>PEAR DB emulation error 2.1 EOF (correct=$i+$top, actual=$i2)</b></p>";
|
||||
$pear = false;
|
||||
}
|
||||
|
||||
if ($pear) print "<p>PEAR DB emulation passed.</p>";
|
||||
|
||||
|
||||
global $TESTERRS;
|
||||
$db->debug = false;
|
||||
$TESTERRS = 0;
|
||||
$db->raiseErrorFn = 'adodb_test_err';
|
||||
$db->Execute('select * from nowhere');
|
||||
$rs = $db->Execute('select * from adoxyz');
|
||||
$rs->Move(100);
|
||||
$rs->_queryID = false;
|
||||
$rs->MoveNext();
|
||||
$rs = false;
|
||||
$conn = NewADOConnection($db->databaseType);
|
||||
$conn->raiseErrorFn = 'adodb_test_err';
|
||||
@$conn->Connect('abc');
|
||||
if ($TESTERRS == 2) print "raiseErrorFn tests passed<br>";
|
||||
else print "<b>raiseErrorFn tests failed ($TESTERRS)</b><br>";
|
||||
?>
|
||||
</p>
|
||||
<table width=100% ><tr><td bgcolor=beige> </td></tr></table>
|
||||
</p></form>
|
||||
<?php
|
||||
|
||||
if ($rs1) $rs1->Close();
|
||||
if ($rs2) $rs2->Close();
|
||||
if ($rs) $rs->Close();
|
||||
$db->Close();
|
||||
}
|
||||
|
||||
function adodb_test_err($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
|
||||
{
|
||||
global $TESTERRS;
|
||||
|
||||
$TESTERRS += 1;
|
||||
print "<i>** $dbms ($fn): errno=$errno errmsg=$errmsg ($p1,$p2)</i><br>";
|
||||
|
||||
}
|
||||
include('./testdatabases.inc.php');
|
||||
|
||||
?>
|
||||
<p><i>ADODB Database Library (c) 2000-2002 John Lim. All rights reserved. Released under BSD and LGPL.</i></p>
|
||||
</body>
|
||||
</html>
|
54
lib/adodb/tests/test2.php
Normal file
54
lib/adodb/tests/test2.php
Normal file
@ -0,0 +1,54 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Untitled</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 8.
|
||||
*/
|
||||
#
|
||||
# test connecting to 2 MySQL databases simultaneously and ensure that each connection
|
||||
# is independant.
|
||||
#
|
||||
include("../tohtml.inc.php");
|
||||
include("../adodb.inc.php");
|
||||
|
||||
ADOLoadCode('mysql');
|
||||
|
||||
$c1 = ADONewConnection('mysql');
|
||||
$c2 = ADONewConnection('mysql');
|
||||
|
||||
if (!$c1->PConnect('flipper','','',"test"))
|
||||
die("Cannot connect to flipper");
|
||||
if (!$c2->PConnect('mangrove','root','',"northwind"))
|
||||
die("Cannot connect to mangrove");
|
||||
|
||||
print "<h3>Flipper</h3>";
|
||||
$t = $c1->MetaTables(); # list all tables in DB
|
||||
print_r($t);
|
||||
# select * from last table in DB
|
||||
rs2html($c1->Execute("select * from ".$t[sizeof($t)-1]));
|
||||
|
||||
print "<h3>Mangrove</h3>";
|
||||
$t = $c2->MetaTables();
|
||||
print_r($t);
|
||||
rs2html($c2->Execute("select * from ".$t[sizeof($t)-1] ));
|
||||
|
||||
print "<h3>Flipper</h3>";
|
||||
$t = $c1->MetaTables();
|
||||
print_r($t);
|
||||
rs2html($c1->Execute("select * from ".$t[sizeof($t)-1]));
|
||||
|
||||
?>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
32
lib/adodb/tests/test3.php
Normal file
32
lib/adodb/tests/test3.php
Normal file
@ -0,0 +1,32 @@
|
||||
<code>
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 8.
|
||||
*/
|
||||
#
|
||||
# Code to test Move
|
||||
#
|
||||
include("../adodb.inc.php");
|
||||
|
||||
$c1 = &ADONewConnection('postgres');
|
||||
if (!$c1->PConnect("susetikus","tester","test","test"))
|
||||
die("Cannot connect to database");
|
||||
|
||||
# select * from last table in DB
|
||||
$rs = $c1->Execute("select * from adoxyz order by 1");
|
||||
|
||||
$i = 0;
|
||||
$max = $rs->RecordCount();
|
||||
if ($max == -1) "RecordCount returns -1<br>";
|
||||
while (!$rs->EOF and $i < $max) {
|
||||
$rs->Move($i);
|
||||
print_r( $rs->fields);
|
||||
print '<BR>';
|
||||
$i++;
|
||||
}
|
||||
?>
|
||||
</code>
|
78
lib/adodb/tests/test4.php
Normal file
78
lib/adodb/tests/test4.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
* Released under both BSD license and Lesser GPL library license.
|
||||
* Whenever there is any discrepancy between the two licenses,
|
||||
* the BSD license will take precedence.
|
||||
*
|
||||
* Set tabs to 4 for best viewing.
|
||||
*
|
||||
* Latest version is available at http://php.weblogs.com
|
||||
*
|
||||
* Test GetUpdateSQL and GetInsertSQL.
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
function testsql()
|
||||
{
|
||||
|
||||
include('../adodb.inc.php');
|
||||
include('../tohtml.inc.php');
|
||||
|
||||
//==========================
|
||||
// This code tests an insert
|
||||
|
||||
$sql = "SELECT * FROM ADOXYZ WHERE id = -1";
|
||||
// Select an empty record from the database
|
||||
|
||||
$conn = &ADONewConnection("mysql"); // create a connection
|
||||
$conn->debug=1;
|
||||
$conn->PConnect("localhost", "root", "", "test"); // connect to MySQL, testdb
|
||||
$conn->Execute("delete from adoxyz where lastname like 'Smith%'");
|
||||
|
||||
$rs = $conn->Execute($sql); // Execute the query and get the empty recordset
|
||||
$record = array(); // Initialize an array to hold the record data to insert
|
||||
|
||||
// Set the values for the fields in the record
|
||||
$record["firstname"] = "Bob";
|
||||
$record["lastname"] = "Smith\$@//";
|
||||
$record["created"] = time();
|
||||
|
||||
// Pass the empty recordset and the array containing the data to insert
|
||||
// into the GetInsertSQL function. The function will process the data and return
|
||||
// a fully formatted insert sql statement.
|
||||
$insertSQL = $conn->GetInsertSQL($rs, $record);
|
||||
|
||||
$conn->Execute($insertSQL); // Insert the record into the database
|
||||
|
||||
//==========================
|
||||
// This code tests an update
|
||||
|
||||
$sql = "SELECT * FROM ADOXYZ WHERE lastname=".$conn->qstr($record['lastname']);
|
||||
// Select a record to update
|
||||
|
||||
$rs = $conn->Execute($sql); // Execute the query and get the existing record to update
|
||||
if (!$rs) print "<p>No record found!</p>";
|
||||
$record = array(); // Initialize an array to hold the record data to update
|
||||
|
||||
// Set the values for the fields in the record
|
||||
$record["firstname"] = "Caroline".rand();
|
||||
$record["lastname"] = "Smithy"; // Update Caroline's lastname from Miranda to Smith
|
||||
$record["created"] = '2002-12-'.(rand()%30+1);
|
||||
|
||||
// Pass the single record recordset and the array containing the data to update
|
||||
// into the GetUpdateSQL function. The function will process the data and return
|
||||
// a fully formatted update sql statement.
|
||||
// If the data has not changed, no recordset is returned
|
||||
$updateSQL = $conn->GetUpdateSQL($rs, $record);
|
||||
|
||||
$conn->Execute($updateSQL); // Update the record in the database
|
||||
print "<p>Rows Affected=".$conn->Affected_Rows()."</p>";
|
||||
|
||||
rs2html($conn->Execute("select * from adoxyz where lastname like 'Smith%'"));
|
||||
}
|
||||
|
||||
|
||||
testsql();
|
||||
?>
|
45
lib/adodb/tests/test5.php
Normal file
45
lib/adodb/tests/test5.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
*/
|
||||
|
||||
|
||||
// Select an empty record from the database
|
||||
|
||||
include('../adodb.inc.php');
|
||||
include('../tohtml.inc.php');
|
||||
|
||||
if (0) {
|
||||
$conn = &ADONewConnection('mysql');
|
||||
$conn->debug=1;
|
||||
$conn->PConnect("localhost","root","","xphplens");
|
||||
print $conn->databaseType.':'.$conn->GenID().'<br>';
|
||||
}
|
||||
|
||||
if (0) {
|
||||
$conn = &ADONewConnection("oci8"); // create a connection
|
||||
$conn->debug=1;
|
||||
$conn->PConnect("falcon", "scott", "tiger", "juris8.ecosystem.natsoft.com.my"); // connect to MySQL, testdb
|
||||
print $conn->databaseType.':'.$conn->GenID();
|
||||
}
|
||||
|
||||
if (0) {
|
||||
$conn = &ADONewConnection("ibase"); // create a connection
|
||||
$conn->debug=1;
|
||||
$conn->Connect("localhost:c:\\Interbase\\Examples\\Database\\employee.gdb", "sysdba", "masterkey", ""); // connect to MySQL, testdb
|
||||
print $conn->databaseType.':'.$conn->GenID().'<br>';
|
||||
}
|
||||
|
||||
if (0) {
|
||||
$conn = &ADONewConnection('postgres');
|
||||
$conn->debug=1;
|
||||
@$conn->PConnect("susetikus","tester","test","test");
|
||||
print $conn->databaseType.':'.$conn->GenID().'<br>';
|
||||
}
|
||||
?>
|
29
lib/adodb/tests/testcache.php
Normal file
29
lib/adodb/tests/testcache.php
Normal file
@ -0,0 +1,29 @@
|
||||
<html>
|
||||
<body>
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
*/
|
||||
|
||||
$ADODB_CACHE_DIR = dirname(tempnam('/tmp',''));
|
||||
include("../adodb.inc.php");
|
||||
|
||||
if (isset($access)) {
|
||||
$db=ADONewConnection('access');
|
||||
$db->PConnect('nwind');
|
||||
} else {
|
||||
$db = ADONewConnection('mysql');
|
||||
$db->PConnect('mangrove','root','','xphplens');
|
||||
}
|
||||
if (isset($cache)) $rs = $db->CacheExecute(120,'select * from products');
|
||||
else $rs = $db->Execute('select * from products');
|
||||
|
||||
$arr = $rs->GetArray();
|
||||
print sizeof($arr);
|
||||
?>
|
189
lib/adodb/tests/testdatabases.inc.php
Normal file
189
lib/adodb/tests/testdatabases.inc.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
*/
|
||||
|
||||
/* this file is used by the ADODB test program: test.php */
|
||||
|
||||
// cannot test databases below, but we include them anyway to check
|
||||
// if they parse ok...
|
||||
ADOLoadCode("sybase");
|
||||
ADOLoadCode("postgres");
|
||||
ADOLoadCode("postgres7");
|
||||
ADOLoadCode("firebird");
|
||||
ADOLoadCode("borland_ibase");
|
||||
ADOLoadCode("informix");
|
||||
ADOLoadCode("sqlanywhere");
|
||||
|
||||
if (!empty($testpostgres)) {
|
||||
//ADOLoadCode("postgres");
|
||||
$db = &ADONewConnection('postgres64');
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
if (@$db->PConnect("susetikus","tester","test","test")) {
|
||||
testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname varchar,created date)");
|
||||
}else
|
||||
print "ERROR: PostgreSQL requires a database called test on server susetikus, user tester, password test.<BR>".$db->ErrorMsg();
|
||||
}
|
||||
if (!empty($testibase)) {
|
||||
|
||||
$db = &ADONewConnection('ibase');
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
if (@$db->PConnect("localhost:e:\\interbase\\examples\\database\\employee.gdb", "sysdba", "masterkey", ""))
|
||||
testdb($db,"create table ADOXYZ (id integer, firstname char(24), lastname char(24),created date)");
|
||||
else print "ERROR: Interbase test requires a database called employee.gdb".'<BR>'.$db->ErrorMsg();
|
||||
|
||||
}
|
||||
|
||||
// REQUIRES ODBC DSN CALLED nwind
|
||||
if (!empty($testaccess)) {
|
||||
|
||||
$db = &ADONewConnection('access');
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
|
||||
if (@$db->PConnect("nwind", "", "", ""))
|
||||
testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
|
||||
else print "ERROR: Access test requires a Windows ODBC DSN=nwind, Access driver";
|
||||
|
||||
}
|
||||
|
||||
if (!empty($testaccess) && !empty($testado)) { // ADO ACCESS
|
||||
|
||||
$db = &ADONewConnection("ado_access");
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
|
||||
$access = 'd:\inetpub\wwwroot\php\NWIND.MDB';
|
||||
$myDSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;'
|
||||
. 'DATA SOURCE=' . $access . ';';
|
||||
//. 'USER ID=;PASSWORD=;';
|
||||
|
||||
if (@$db->PConnect($myDSN, "", "", "")) {
|
||||
print "ADO version=".$db->_connectionID->version."<br>";
|
||||
testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
|
||||
} else print "ERROR: Access test requires a Access database $access".'<BR>'.$db->ErrorMsg();
|
||||
|
||||
}
|
||||
|
||||
if (!empty($testvfp)) { // ODBC
|
||||
|
||||
|
||||
$db = &ADONewConnection('vfp');
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
if (@$db->PConnect("logos2", "", "", ""))
|
||||
testdb($db,"create table d:\\inetpub\\wwwroot\\logos2\\data\\ADOXYZ (id int, firstname char(24), lastname char(24),created date)");
|
||||
else print "ERROR: Visual FoxPro test requires a Windows ODBC DSN=logos2, VFP driver";
|
||||
|
||||
}
|
||||
|
||||
|
||||
// REQUIRES MySQL server at localhost with database 'test'
|
||||
if (!empty($testmysql)) { // MYSQL
|
||||
|
||||
$db = &ADONewConnection('maxsql');
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
if ($HTTP_SERVER_VARS['HTTP_HOST'] == 'localhost') $server = 'localhost';
|
||||
else $server = "mangrove";
|
||||
if ($db->PConnect($server, "root", "", "test"))
|
||||
testdb($db,
|
||||
"create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");
|
||||
else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
|
||||
|
||||
$db = &ADONewConnection('proxy');
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
if ($HTTP_SERVER_VARS['HTTP_HOST'] == 'localhost') $server = 'localhost';
|
||||
|
||||
if ($db->PConnect('http://localhost/php/phplens/adodb/server.php'))
|
||||
testdb($db,
|
||||
"create table ADOXYZ (id int, firstname char(24), lastname char(24), created date) type=innodb");
|
||||
else print "ERROR: MySQL test requires a MySQL server on localhost, userid='admin', password='', database='test'".'<BR>'.$db->ErrorMsg();
|
||||
|
||||
}
|
||||
|
||||
ADOLoadCode('oci805');
|
||||
ADOLoadCode("oci8po");
|
||||
if (!empty($testoracle)) {
|
||||
|
||||
$db = ADONewConnection();
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
if ($db->Connect('', "scott", "tiger",'natsoft.ecosystem.natsoft.com.my'))
|
||||
//if ($db->PConnect("", "scott", "tiger", "juris.ecosystem.natsoft.com.my"))
|
||||
testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
|
||||
else print "ERROR: Oracle test requires an Oracle server setup with scott/tiger".'<BR>'.$db->ErrorMsg();
|
||||
|
||||
}
|
||||
ADOLoadCode("oracle"); // no longer supported
|
||||
if (false && !empty($testoracle)) {
|
||||
|
||||
$db = ADONewConnection();
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
if ($db->PConnect("", "scott", "tiger", "natsoft.domain"))
|
||||
testdb($db,"create table ADOXYZ (id int, firstname varchar(24), lastname varchar(24),created date)");
|
||||
else print "ERROR: Oracle test requires an Oracle server setup with scott/tiger".'<BR>'.$db->ErrorMsg();
|
||||
|
||||
}
|
||||
|
||||
|
||||
ADOLoadCode("odbc_mssql");
|
||||
if (!empty($testmssql) and false) { // MS SQL Server via ODBC
|
||||
|
||||
$db = ADONewConnection();
|
||||
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
if (@$db->PConnect("sqlserver", "sa", "natsoft", ""))
|
||||
testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
|
||||
else print "ERROR: MSSQL test 1 requires a MS SQL 7 server setup with DSN='sqlserver', userid='sa', password='natsoft'";
|
||||
|
||||
}
|
||||
|
||||
ADOLoadCode("ado_mssql");
|
||||
|
||||
if (!empty($testmssql) && !empty($testado) ) { // ADO ACCESS MSSQL -- thru ODBC -- DSN-less
|
||||
|
||||
$db = &ADONewConnection("ado_mssql");
|
||||
print "<h1>Connecting DSN-less $db->databaseType...</h1>";
|
||||
|
||||
$myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};"
|
||||
. "SERVER=(local);DATABASE=NorthWind;UID=sa;PWD=natsoft;" ;
|
||||
|
||||
|
||||
if (@$db->PConnect($myDSN, "", "", ""))
|
||||
testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
|
||||
else print "ERROR: MSSQL test 2 requires a MS SQL 7 on a server='mangrove', userid='sa', password='natsoft', database='ai'";
|
||||
|
||||
}
|
||||
|
||||
|
||||
ADOLoadCode("mssql");
|
||||
if (!empty($testmssql)) { // MS SQL Server -- the extension is buggy -- probably better to use ODBC
|
||||
$db = ADONewConnection();
|
||||
print "<h1>Connecting $db->databaseType...</h1>";
|
||||
|
||||
$db->Connect('(local)\NetSDK','','','northwind');
|
||||
|
||||
if (true or @$db->PConnect("mangrove", "sa", "natsoft", "ai")) {
|
||||
AutoDetect_MSSQL_Date_Order($db);
|
||||
testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
|
||||
} else print "ERROR: MSSQL test 2 requires a MS SQL 7 on a server='192.168.0.1', userid='sa', password='natsoft', database='ai'".'<BR>'.$db->ErrorMsg();
|
||||
|
||||
}
|
||||
|
||||
if (!empty($testmssql) && !empty($testado)) { // ADO ACCESS MSSQL with OLEDB provider
|
||||
|
||||
$db = &ADONewConnection("ado_mssql");
|
||||
print "<h1>Connecting DSN-less OLEDB Provider $db->databaseType...</h1>";
|
||||
|
||||
$myDSN="SERVER=mangrove;DATABASE=ai;";
|
||||
//$myDSN='SERVER=(local)\NetSDK;DATABASE=northwind;';
|
||||
if ($db->PConnect($myDSN, "sa", "natsoft", 'SQLOLEDB'))
|
||||
testdb($db,"create table ADOXYZ (id int, firstname char(24), lastname char(24),created datetime)");
|
||||
else print "ERROR: MSSQL test 2 requires a MS SQL 7 on a server='mangrove', userid='sa', password='', database='ai'";
|
||||
|
||||
}
|
||||
|
||||
|
||||
print "<h3>Tests Completed</h3>";
|
||||
|
||||
?>
|
34
lib/adodb/tests/testgenid.php
Normal file
34
lib/adodb/tests/testgenid.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
Run multiple copies of this php script at the same time
|
||||
to test unique generation of id's in multiuser mode
|
||||
*/
|
||||
include_once('../adodb.inc.php');
|
||||
$testaccess = true;
|
||||
include_once('testdatabases.inc.php');
|
||||
|
||||
function testdb(&$db,$createtab="create table ADOXYZ (id int, firstname char(24), lastname char(24), created date)")
|
||||
{
|
||||
$table = 'adodbseq';
|
||||
|
||||
$db->Execute("drop table $table");
|
||||
//$db->debug=true;
|
||||
|
||||
$ctr = 5000;
|
||||
$lastnum = 0;
|
||||
|
||||
while (--$ctr >= 0) {
|
||||
$num = $db->GenID($table);
|
||||
if ($num === false) {
|
||||
print "GenID returned false";
|
||||
break;
|
||||
}
|
||||
if ($lastnum + 1 == $num) print " $num ";
|
||||
else {
|
||||
print " <font color=red>$num</font> ";
|
||||
flush();
|
||||
}
|
||||
$lastnum = $num;
|
||||
}
|
||||
}
|
||||
?>
|
70
lib/adodb/tests/testoci8.php
Normal file
70
lib/adodb/tests/testoci8.php
Normal file
@ -0,0 +1,70 @@
|
||||
<html>
|
||||
<body>
|
||||
<?php
|
||||
/*
|
||||
V1.81 22 March 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
*/
|
||||
error_reporting(63);
|
||||
include("../adodb.inc.php");
|
||||
include("../tohtml.inc.php");
|
||||
|
||||
if (1) {
|
||||
$db = ADONewConnection('oci8po');
|
||||
$db->PConnect('','scott','tiger','natsoftmts');
|
||||
$db->debug = true;
|
||||
|
||||
if (!empty($testblob)) {
|
||||
$varHoldingBlob = 'ABC DEF GEF John TEST';
|
||||
$num = time()%10240;
|
||||
// create table atable (id integer, ablob blob);
|
||||
$db->Execute('insert into ATABLE (id,ablob) values('.$num.',empty_blob())');
|
||||
$db->UpdateBlob('ATABLE', 'ablob', $varHoldingBlob, 'id='.$num, 'BLOB');
|
||||
|
||||
$rs = &$db->Execute('select * from atable');
|
||||
|
||||
if (!$rs) die("Empty RS");
|
||||
if ($rs->EOF) die("EOF RS");
|
||||
rs2html($rs);
|
||||
}
|
||||
$stmt = $db->Prepare('select * from adoxyz where id=?');
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$rs = &$db->Execute(
|
||||
$stmt,
|
||||
array($i));
|
||||
|
||||
if (!$rs) die("Empty RS");
|
||||
if ($rs->EOF) die("EOF RS");
|
||||
rs2html($rs);
|
||||
}
|
||||
}
|
||||
if (1) {
|
||||
$db = ADONewConnection('oci8');
|
||||
$db->PConnect('','scott','tiger');
|
||||
$db->debug = true;
|
||||
$db->Execute("delete from emp where ename='John'");
|
||||
print $db->Affected_Rows().'<BR>';
|
||||
$stmt = &$db->Prepare('insert into emp (empno, ename) values (:empno, :ename)');
|
||||
$rs = $db->Execute($stmt,array('empno'=>4321,'ename'=>'John'));
|
||||
// prepare not quite ready for prime time
|
||||
//$rs = $db->Execute($stmt,array('empno'=>3775,'ename'=>'John'));
|
||||
if (!$rs) die("Empty RS");
|
||||
}
|
||||
|
||||
if (0) {
|
||||
$db = ADONewConnection('odbc_oracle');
|
||||
if (!$db->PConnect('local_oracle','scott','tiger')) die('fail connect');
|
||||
$db->debug = true;
|
||||
$rs = &$db->Execute(
|
||||
'select * from adoxyz where firstname=? and trim(lastname)=?',
|
||||
array('first'=>'Caroline','last'=>'Miranda'));
|
||||
if (!$rs) die("Empty RS");
|
||||
if ($rs->EOF) die("EOF RS");
|
||||
rs2html($rs);
|
||||
}
|
||||
?>
|
54
lib/adodb/tests/testpaging.php
Normal file
54
lib/adodb/tests/testpaging.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
|
||||
|
||||
include_once('../adodb-pear.inc.php');
|
||||
include_once('../tohtml.inc.php');
|
||||
session_register('curr_page');
|
||||
|
||||
$db = NewADOConnection('mysql');
|
||||
$db->debug = true;
|
||||
//$db->Connect('localhost:4321','scott','tiger','natsoft.domain');
|
||||
$db->Connect('localhost','root','','xphplens');
|
||||
|
||||
$num_of_rows_per_page = 7;
|
||||
$sql = "select * from adoxyz ";
|
||||
|
||||
if (isset($HTTP_GET_VARS['next_page']))
|
||||
$curr_page = $HTTP_GET_VARS['next_page'];
|
||||
if (empty($curr_page)) $curr_page = 1; ## at first page
|
||||
|
||||
$rs = $db->PageExecute($sql, $num_of_rows_per_page, $curr_page);
|
||||
if (!$rs) die('Query Failed');
|
||||
|
||||
if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) {
|
||||
if (!$rs->AtFirstPage()) {
|
||||
?>
|
||||
<a href="<?php echo $PHP_SELF;?>?next_page=1">First page</a>
|
||||
<a href="<?php echo $PHP_SELF,'?next_page=',$rs->AbsolutePage() - 1 ?>">Previous page</a>
|
||||
<?php
|
||||
} else {
|
||||
echo " First Page Previous Page ";
|
||||
}
|
||||
if (!$rs->AtLastPage()) {
|
||||
?>
|
||||
<a href="<?php echo $PHP_SELF,'?next_page=',$rs->AbsolutePage() + 1 ?>">Next Page</a>
|
||||
<?php
|
||||
} else
|
||||
print "Next Page";
|
||||
rs2html($rs);
|
||||
}
|
||||
|
||||
|
||||
?>
|
34
lib/adodb/tests/testpear.php
Normal file
34
lib/adodb/tests/testpear.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include_once('../adodb-pear.inc.php');
|
||||
$username = 'root';
|
||||
$password = '';
|
||||
$hostname = 'localhost';
|
||||
$databasename = 'xphplens';
|
||||
$driver = 'mysql';
|
||||
|
||||
$dsn = "$driver://$username:$password@$hostname/$databasename";
|
||||
|
||||
$db = DB::Connect($dsn);
|
||||
$db->setFetchMode(ADODB_FETCH_ASSOC);
|
||||
$rs = $db->Query('select firstname,lastname from adoxyz');
|
||||
$cnt = 0;
|
||||
while ($arr = $rs->FetchRow()) {
|
||||
print_r($arr);
|
||||
print "<br>";
|
||||
$cnt += 1;
|
||||
}
|
||||
|
||||
if ($cnt != 50) print "<b>Error in \$cnt = $cnt</b>";
|
||||
?>
|
24
lib/adodb/tests/testsessions.php
Normal file
24
lib/adodb/tests/testsessions.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
*/
|
||||
|
||||
GLOBAL $HTTP_SESSION_VARS;
|
||||
|
||||
$ADODB_SESS_DEBUG = true;
|
||||
include('adodb.inc.php');
|
||||
include('adodb-session.php');
|
||||
session_start();
|
||||
session_register('AVAR');
|
||||
$HTTP_SESSION_VARS['AVAR'] += 1;
|
||||
$AVAR += 1;
|
||||
|
||||
print "<p>\$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}</p>";
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user