Commit 78a82059 authored by Francois Marier's avatar Francois Marier
Browse files

adodb: remove test subdirectory



We don't use this and the directory is full of executable PHP files.
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent 9beed15b
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>ADODB Benchmarks</title>
</head>
<body>
<?php
/*
V4.81 3 May 2006 (c) 2000-2010 John Lim (jlim#natsoft.com). 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;
$testsqlite = 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;
adodb_backtrace();
$max = 100;
$sql = 'select * from ADOXYZ';
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
//print "<h3>ADODB Version: $ADODB_version Host: <i>$db->host</i> &nbsp; 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;
global $ADODB_COUNTRECS;
$ADODB_COUNTRECS = false;
$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();
//$db->Close();
}
include("testdatabases.inc.php");
?>
</body>
</html>
<html>
<body bgcolor=white>
<?php
/**
* V4.50 6 July 2004 (c) 2001-2002 John Lim (jlim#natsoft.com). 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
echo PHP_VERSION,'<br>';
var_dump(parse_url('odbc_mssql://userserver/'));
die();
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]
.
.
.
*/
?>
<?php
error_reporting(E_ALL);
include('../adodb.inc.php');
echo "<pre>";
try {
echo "New Connection\n";
$dsn = 'pdo_mysql://root:@localhost/northwind?persist';
if (!empty($dsn)) {
$DB = NewADOConnection($dsn) || die("CONNECT FAILED");
$connstr = $dsn;
} else {
$DB = NewADOConnection('pdo');
echo "Connect\n";
$u = ''; $p = '';
/*
$connstr = 'odbc:nwind';
$connstr = 'oci:';
$u = 'scott';
$p = 'natsoft';
$connstr ="sqlite:d:\inetpub\adodb\sqlite.db";
*/
$connstr = "mysql:dbname=northwind";
$u = 'root';
$connstr = "pgsql:dbname=test";
$u = 'tester';
$p = 'test';
$DB->Connect($connstr,$u,$p) || die("CONNECT FAILED");
}
echo "connection string=$connstr\n Execute\n";
//$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs = $DB->Execute("select * from ADOXYZ where id<3");
if ($DB->ErrorNo()) echo "*** errno=".$DB->ErrorNo() . " ".($DB->ErrorMsg())."\n";
//print_r(get_class_methods($DB->_stmt));
if (!$rs) die("NO RS");
echo "Meta\n";
for ($i=0; $i < $rs->NumCols(); $i++) {
var_dump($rs->FetchField($i));
echo "<br>";
}
echo "FETCH\n";
$cnt = 0;
while (!$rs->EOF) {
adodb_pr($rs->fields);
$rs->MoveNext();
if ($cnt++ > 1000) break;
}
echo "<br>--------------------------------------------------------<br>\n\n\n";
$stmt = $DB->PrepareStmt("select * from ADOXYZ");
$rs = $stmt->Execute();
$cols = $stmt->NumCols(); // execute required
echo "COLS = $cols";
for($i=1;$i<=$cols;$i++) {
$v = $stmt->_stmt->getColumnMeta($i);
var_dump($v);
}
echo "e=".$stmt->ErrorNo() . " ".($stmt->ErrorMsg())."\n";
while ($arr = $rs->FetchRow()) {
adodb_pr($arr);
}
die("DONE\n");
} catch (exception $e) {
echo "<pre>";
echo $e;
echo "</pre>";
}
?>
\ No newline at end of file
<?php
include_once('../adodb.inc.php');
include_once('../adodb-active-record.inc.php');
// uncomment the following if you want to test exceptions
if (@$_GET['except']) {
if (PHP_VERSION >= 5) {
include('../adodb-exceptions.inc.php');
echo "<h3>Exceptions included</h3>";
}
}
$db = NewADOConnection('mysql://root@localhost/northwind?persist');
$db->debug=1;
ADOdb_Active_Record::SetDatabaseAdapter($db);
$db->Execute("CREATE TEMPORARY TABLE `persons` (
`id` int(10) unsigned NOT NULL auto_increment,
`name_first` varchar(100) NOT NULL default '',
`name_last` varchar(100) NOT NULL default '',
`favorite_color` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
");
$db->Execute("CREATE TEMPORARY TABLE `children` (
`id` int(10) unsigned NOT NULL auto_increment,
`person_id` int(10) unsigned NOT NULL,
`name_first` varchar(100) NOT NULL default '',
`name_last` varchar(100) NOT NULL default '',
`favorite_pet` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
");
class Person extends ADOdb_Active_Record{ function ret($v) {return $v;} }
$person = new Person();
ADOdb_Active_Record::$_quoteNames = '111';
echo "<p>Output of getAttributeNames: ";
var_dump($person->getAttributeNames());
/**
* Outputs the following:
* array(4) {
* [0]=>
* string(2) "id"
* [1]=>
* string(9) "name_first"
* [2]=>
* string(8) "name_last"
* [3]=>
* string(13) "favorite_color"
* }
*/
$person = new Person();
$person->name_first = 'Andi';
$person->name_last = 'Gutmans';
$person->save(); // this save() will fail on INSERT as favorite_color is a must fill...
$person = new Person();
$person->name_first = 'Andi';
$person->name_last = 'Gutmans';
$person->favorite_color = 'blue';
$person->save(); // this save will perform an INSERT successfully
echo "<p>The Insert ID generated:"; print_r($person->id);
$person->favorite_color = 'red';
$person->save(); // this save() will perform an UPDATE
$person = new Person();
$person->name_first = 'John';
$person->name_last = 'Lim';
$person->favorite_color = 'lavender';
$person->save(); // this save will perform an INSERT successfully
// load record where id=2 into a new ADOdb_Active_Record
$person2 = new Person();
$person2->Load('id=2');
$activeArr = $db->GetActiveRecordsClass($class = "Person",$table = "Persons","id=".$db->Param(0),array(2));
$person2 = $activeArr[0];
echo "<p>Name (should be John): ",$person->name_first, " <br> Class (should be Person): ",get_class($person2),"<br>";
$db->Execute("insert into children (person_id,name_first,name_last) values (2,'Jill','Lim')");
$db->Execute("insert into children (person_id,name_first,name_last) values (2,'Joan','Lim')");
$db->Execute("insert into children (person_id,name_first,name_last) values (2,'JAMIE','Lim')");
$newperson2 = new Person();
$person2->HasMany('children','person_id');
$person2->Load('id=2');
$person2->name_last='green';
$c = $person2->children;
$person2->save();
if (is_array($c) && sizeof($c) == 3 && $c[0]->name_first=='Jill' && $c[1]->name_first=='Joan'
&& $c[2]->name_first == 'JAMIE') echo "OK Loaded HasMany</br>";
else {
var_dump($c);
echo "error loading hasMany should have 3 array elements Jill Joan Jamie<br>";
}
class Child extends ADOdb_Active_Record{};
$ch = new Child('children',array('id'));
$ch->BelongsTo('person','person_id','id');
$ch->Load('id=1');
if ($ch->name_first !== 'Jill') echo "error in Loading Child<br>";
$p = $ch->person;
if ($p->name_first != 'John') echo "Error loading belongsTo<br>";
else echo "OK loading BelongTo<br>";
$p->hasMany('children','person_id');
$p->LoadRelations('children', " Name_first like 'J%' order by id",1,2);
if (sizeof($p->children) == 2 && $p->children[1]->name_first == 'JAMIE') echo "OK LoadRelations<br>";
else echo "error LoadRelations<br>";
$db->Execute("CREATE TEMPORARY TABLE `persons2` (
`id` int(10) unsigned NOT NULL auto_increment,
`name_first` varchar(100) NOT NULL default '',
`name_last` varchar(100) NOT NULL default '',
`favorite_color` varchar(100) default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
");
$p = new adodb_active_record('persons2');
$p->name_first = 'James';
$p->name_last = 'James';
$p->HasMany('children','person_id');
$p->children;
var_dump($p);
$p->Save();
?>
\ No newline at end of file
<?php
error_reporting(E_ALL);
include('../adodb.inc.php');
include('../adodb-active-record.inc.php');
###########################
$ADODB_ACTIVE_CACHESECS = 36;
$DBMS = @$_GET['db'];
$DBMS = 'mysql';
if ($DBMS == 'mysql') {
$db = NewADOConnection('mysql://root@localhost/northwind');
} else if ($DBMS == 'postgres') {
$db = NewADOConnection('postgres');
$db->Connect("localhost","tester","test","test");
} else
$db = NewADOConnection('oci8://scott:natsoft@/');
$arr = $db->ServerInfo();
echo "<h3>$db->dataProvider: {$arr['description']}</h3>";
$arr = $db->GetActiveRecords('products',' productid<10');
adodb_pr($arr);
ADOdb_Active_Record::SetDatabaseAdapter($db);
if (!$db) die('failed');
$rec = new ADODB_Active_Record('photos');
$rec = new ADODB_Active_Record('products');
adodb_pr($rec->getAttributeNames());
echo "<hr>";
$rec->load('productid=2');
adodb_pr($rec);
$db->debug=1;
$rec->productname = 'Changie Chan'.rand();
$rec->insert();
$rec->update();
$rec->productname = 'Changie Chan 99';
$rec->replace();
$rec2 = new ADODB_Active_Record('products');
$rec->load('productid=3');
$rec->save();
$rec = new ADODB_Active_record('products');
$rec->productname = 'John ActiveRec';
$rec->notes = 22;
#$rec->productid=0;
$rec->discontinued=1;
$rec->Save();
$rec->supplierid=33;
$rec->Save();
$rec->discontinued=0;
$rec->Save();
$rec->Delete();
echo "<p>Affected Rows after delete=".$db->Affected_Rows()."</p>";
?>
\ No newline at end of file
<?php
/*
V4.81 3 May 2006 (c) 2000-2010 John Lim (jlim#natsoft.com). 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.
*/
error_reporting(E_ALL);
include_once('../adodb.inc.php');
<