Commit ff8ed9e1 authored by martinlanghoff's avatar martinlanghoff
Browse files

Merged from MOODLE_15_STABLE: Fix for Secunia Advisory SA18267 and test file cleanup

parent 11d6d230
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>ADODB Benchmarks</title>
</head>
<body>
<?php
/*
V4.51 29 July 2004 (c) 2000-2004 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;
$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.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]
.
.
.
*/
?>
<?php
error_reporting(E_ALL);
include('../adodb.inc.php');
echo "New Connection\n";
$DB = NewADOConnection('pdo');
echo "Connect\n";
$pdo_connection_string = 'odbc:nwind';
$DB->Connect($pdo_connection_string,'','') || die("CONNECT FAILED");
echo "Execute\n";
//$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs = $DB->Execute("select * from products where productid<3");
echo "e=".$DB->ErrorNo() . " ".($DB->ErrorMsg())."\n";
//print_r(get_class_methods($DB->_stmt));
if (!$rs) die("NO RS");
echo "FETCH\n";
$cnt = 0;
while (!$rs->EOF) {
print_r($rs->fields);
$rs->MoveNext();
if ($cnt++ > 1000) break;
}
echo "<br>--------------------------------------------------------<br>\n\n\n";
$stmt = $DB->PrepareStmt("select * from products");
$rs = $stmt->Execute();
echo "e=".$stmt->ErrorNo() . " ".($stmt->ErrorMsg())."\n";
while ($arr = $rs->FetchRow()) {
print_r($arr);
}
die("DONE\n");
?>
\ No newline at end of file
<?php
/*
V4.51 29 July 2004 (c) 2000-2004 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.
*/
error_reporting(E_ALL);
include_once('../adodb.inc.php');
foreach(array('sybase','mysqlt','access','oci8','postgres','odbc_mssql','odbc','sybase','firebird','informix','db2') as $dbType) {
echo "<h3>$dbType</h3><p>";
$db = NewADOConnection($dbType);
$dict = NewDataDictionary($db);
if (!$dict) continue;
$dict->debug = 1;
$opts = array('REPLACE','mysql' => 'TYPE=INNODB', 'oci8' => 'TABLESPACE USERS');
/* $flds = array(
array('id', 'I',
'AUTO','KEY'),
array('name' => 'firstname', 'type' => 'varchar','size' => 30,
'DEFAULT'=>'Joan'),
array('lastname','varchar',28,
'DEFAULT'=>'Chen','key'),
array('averylonglongfieldname','X',1024,
'NOTNULL','default' => 'test'),
array('price','N','7.2',
'NOTNULL','default' => '0.00'),
array('MYDATE', 'D',
'DEFDATE'),
array('TS','T',
'DEFTIMESTAMP')
);*/
$flds = "
ID I AUTO KEY,
FIRSTNAME VARCHAR(30) DEFAULT 'Joan',
LASTNAME VARCHAR(28) DEFAULT 'Chen' key,
averylonglongfieldname X(1024) DEFAULT 'test',
price N(7.2) DEFAULT '0.00',
MYDATE D DEFDATE,
BIGFELLOW X NOTNULL,
TS T DEFTIMESTAMP";
$sqla = $dict->CreateDatabase('KUTU',array('postgres'=>"LOCATION='/u01/postdata'"));
$dict->SetSchema('KUTU');
$sqli = ($dict->CreateTableSQL('testtable',$flds, $opts));
$sqla =& array_merge($sqla,$sqli);
$sqli = $dict->CreateIndexSQL('idx','testtable','firstname,lastname',array('BITMAP','FULLTEXT','CLUSTERED','HASH'));
$sqla =& array_merge($sqla,$sqli);
$sqli = $dict->CreateIndexSQL('idx2','testtable','price,lastname');//,array('BITMAP','FULLTEXT','CLUSTERED'));
$sqla =& array_merge($sqla,$sqli);
$addflds = array(array('height', 'F'),array('weight','F'));
$sqli = $dict->AddColumnSQL('testtable',$addflds);
$sqla =& array_merge($sqla,$sqli);
$addflds = array(array('height', 'F','NOTNULL'),array('weight','F','NOTNULL'));
$sqli = $dict->AlterColumnSQL('testtable',$addflds);
$sqla =& array_merge($sqla,$sqli);
printsqla($dbType,$sqla);
if (file_exists('d:\inetpub\wwwroot\php\phplens\adodb\adodb.inc.php'))
if ($dbType == 'mysql') {
$db->Connect('localhost', "root", "", "test");
$dict->SetSchema('');
$sqla2 = $dict->ChangeTableSQL('adoxyz',$flds);
if ($sqla2) printsqla($dbType,$sqla2);
}
if ($dbType == 'postgres') {
$db->Connect('localhost', "tester", "test", "test");
$dict->SetSchema('');
$sqla2 = $dict->ChangeTableSQL('adoxyz',$flds);
if ($sqla2) printsqla($dbType,$sqla2);
}
}
function printsqla($dbType,$sqla)
{
print "<pre>";
//print_r($dict->MetaTables());
foreach($sqla as $s) {
$s = htmlspecialchars($s);
print "$s;\n";
if ($dbType == 'oci8') print "/\n";
}
print "</pre><hr>";
}
/***
Generated SQL:
mysql
CREATE DATABASE KUTU;
DROP TABLE KUTU.testtable;
CREATE TABLE KUTU.testtable (
id INTEGER NOT NULL AUTO_INCREMENT,
firstname VARCHAR(30) DEFAULT 'Joan',
lastname VARCHAR(28) NOT NULL DEFAULT 'Chen',
averylonglongfieldname LONGTEXT NOT NULL,
price NUMERIC(7,2) NOT NULL DEFAULT 0.00,
MYDATE DATE DEFAULT CURDATE(),
PRIMARY KEY (id, lastname)
)TYPE=ISAM;
CREATE FULLTEXT INDEX idx ON KUTU.testtable (firstname,lastname);
CREATE INDEX idx2 ON KUTU.testtable (price,lastname);
ALTER TABLE KUTU.testtable ADD height DOUBLE;
ALTER TABLE KUTU.testtable ADD weight DOUBLE;
ALTER TABLE KUTU.testtable MODIFY COLUMN height DOUBLE NOT NULL;
ALTER TABLE KUTU.testtable MODIFY COLUMN weight DOUBLE NOT NULL;
--------------------------------------------------------------------------------
oci8
CREATE USER KUTU IDENTIFIED BY tiger;
/
GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO KUTU;
/
DROP TABLE KUTU.testtable CASCADE CONSTRAINTS;
/
CREATE TABLE KUTU.testtable (
id NUMBER(16) NOT NULL,
firstname VARCHAR(30) DEFAULT 'Joan',
lastname VARCHAR(28) DEFAULT 'Chen' NOT NULL,
averylonglongfieldname CLOB NOT NULL,
price NUMBER(7,2) DEFAULT 0.00 NOT NULL,
MYDATE DATE DEFAULT TRUNC(SYSDATE),
PRIMARY KEY (id, lastname)
)TABLESPACE USERS;
/
DROP SEQUENCE KUTU.SEQ_testtable;
/
CREATE SEQUENCE KUTU.SEQ_testtable;
/
CREATE OR REPLACE TRIGGER KUTU.TRIG_SEQ_testtable BEFORE insert ON KUTU.testtable
FOR EACH ROW
BEGIN
select KUTU.SEQ_testtable.nextval into :new.id from dual;
END;
/
CREATE BITMAP INDEX idx ON KUTU.testtable (firstname,lastname);
/
CREATE INDEX idx2 ON KUTU.testtable (price,lastname);
/
ALTER TABLE testtable ADD (
height NUMBER,
weight NUMBER);
/
ALTER TABLE testtable MODIFY(
height NUMBER NOT NULL,
weight NUMBER NOT NULL);
/
--------------------------------------------------------------------------------
postgres
AlterColumnSQL not supported for PostgreSQL
CREATE DATABASE KUTU LOCATION='/u01/postdata';
DROP TABLE KUTU.testtable;
CREATE TABLE KUTU.testtable (
id SERIAL,
firstname VARCHAR(30) DEFAULT 'Joan',
lastname VARCHAR(28) DEFAULT 'Chen' NOT NULL,
averylonglongfieldname TEXT NOT NULL,
price NUMERIC(7,2) DEFAULT 0.00 NOT NULL,
MYDATE DATE DEFAULT CURRENT_DATE,
PRIMARY KEY (id, lastname)
);
CREATE INDEX idx ON KUTU.testtable USING HASH (firstname,lastname);
CREATE INDEX idx2 ON KUTU.testtable (price,lastname);
ALTER TABLE KUTU.testtable ADD height FLOAT8;
ALTER TABLE KUTU.testtable ADD weight FLOAT8;
--------------------------------------------------------------------------------
odbc_mssql
CREATE DATABASE KUTU;
DROP TABLE KUTU.testtable;
CREATE TABLE KUTU.testtable (
id INT IDENTITY(1,1) NOT NULL,
firstname VARCHAR(30) DEFAULT 'Joan',
lastname VARCHAR(28) DEFAULT 'Chen' NOT NULL,
averylonglongfieldname TEXT NOT NULL,
price NUMERIC(7,2) DEFAULT 0.00 NOT NULL,
MYDATE DATETIME DEFAULT GetDate(),
PRIMARY KEY (id, lastname)
);
CREATE CLUSTERED INDEX idx ON KUTU.testtable (firstname,lastname);
CREATE INDEX idx2 ON KUTU.testtable (price,lastname);
ALTER TABLE KUTU.testtable ADD
height REAL,
weight REAL;
ALTER TABLE KUTU.testtable ALTER COLUMN height REAL NOT NULL;
ALTER TABLE KUTU.testtable ALTER COLUMN weight REAL NOT NULL;
--------------------------------------------------------------------------------
*/
echo "<h1>Test XML Schema</h1>";
$ff = file('xmlschema.xml');
echo "<pre>";
foreach($ff as $xml) echo htmlspecialchars($xml);
echo "</pre>";
include_once('test-xmlschema.php');
?>
\ No newline at end of file
<?php
include_once('../adodb-perf.inc.php');
error_reporting(E_ALL);
session_start();
if (isset($_GET)) {
foreach($_GET as $k => $v) {
if (strncmp($k,'test',4) == 0) $_SESSION['_db'] = $k;
}
}
if (isset($_SESSION['_db'])) {
$_db = $_SESSION['_db'];
$_GET[$_db] = 1;
$$_db = 1;
}
echo "<h1>Performance Monitoring</h1>";
include_once('testdatabases.inc.php');
function testdb($db)
{
if (!$db) return;
echo "<font size=1>";print_r($db->ServerInfo()); echo " user=".$db->user."</font>";
$perf = NewPerfMonitor($db);
# unit tests
if (0) {
//$DB->debug=1;
echo "Data Cache Size=".$perf->DBParameter('data cache size').'<p>';
echo $perf->HealthCheck();
echo($perf->SuspiciousSQL());
echo($perf->ExpensiveSQL());
echo($perf->InvalidSQL());
echo $perf->Tables();
echo "<pre>";
echo $perf->HealthCheckCLI();
$perf->Poll(3);
die();
}
if ($perf) $perf->UI(3);
}
?>
<?php
function getmicrotime()
{
$t = microtime();
$t = explode(' ',$t);
return (float)$t[1]+ (float)$t[0];
}
function doloop()
{
global $db,$MAX;
$sql = "select id,firstname,lastname from adoxyz where
firstname not like ? and lastname not like ? and id=?";
$offset = 0;
/*$sql = "select * from juris9.employee join juris9.emp_perf_plan on epp_empkey = emp_id
where emp_name not like ? and emp_name not like ? and emp_id=28000+?";
$offset = 28000;*/
for ($i=1; $i <= $MAX; $i++) {