mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Import from DCARF SVN
This commit is contained in:
76
include/pear/tests/driver/01connect.phpt
Normal file
76
include/pear/tests/driver/01connect.phpt
Normal file
@@ -0,0 +1,76 @@
|
||||
--TEST--
|
||||
DB_driver::connect
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './connect.inc';
|
||||
|
||||
/**
|
||||
* Determine if the database connection matches what's expected
|
||||
*
|
||||
* @param object $dbh the PEAR DB object
|
||||
* @param string $name the name of the current test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function check_dbh($dbh, $name) {
|
||||
if (DB::isError($dbh)) {
|
||||
die('connect.inc: ' . $dbh->toString());
|
||||
}
|
||||
if (is_object($dbh)) {
|
||||
print "$name is an object\n";
|
||||
}
|
||||
switch ($dbh->phptype) {
|
||||
case 'dbase':
|
||||
if (is_int($dbh->connection)) {
|
||||
print "$name is connected\n";
|
||||
} else {
|
||||
print "$name NOT connected\n";
|
||||
}
|
||||
break;
|
||||
case 'mysqli':
|
||||
if (is_a($dbh->connection, 'mysqli')) {
|
||||
print "$name is connected\n";
|
||||
} else {
|
||||
print "$name NOT connected\n";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (gettype($dbh->connection) == 'resource') {
|
||||
print "$name is connected\n";
|
||||
} else {
|
||||
print "$name NOT connected\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
check_dbh($dbh, '$dbh');
|
||||
|
||||
|
||||
$test_array_dsn = DB::parseDSN($dsn);
|
||||
foreach ($test_array_dsn as $key => $value) {
|
||||
if ($value === false) {
|
||||
unset($test_array_dsn[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$dbha =& DB::connect($test_array_dsn, $options);
|
||||
check_dbh($dbha, '$dbha');
|
||||
|
||||
|
||||
$tmp = serialize($dbha);
|
||||
$dbhu = unserialize($tmp);
|
||||
check_dbh($dbhu, '$dbhu');
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
$dbh is an object
|
||||
$dbh is connected
|
||||
$dbha is an object
|
||||
$dbha is connected
|
||||
$dbhu is an object
|
||||
$dbhu is connected
|
||||
40
include/pear/tests/driver/02fetch.phpt
Normal file
40
include/pear/tests/driver/02fetch.phpt
Normal file
@@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
DB_driver::fetch
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './mktable.inc';
|
||||
require_once '../fetchmodes.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
testing fetchrow:
|
||||
row 1: 42, bing, This is a test, 1999-11-21
|
||||
row 2: 1, one, One, 2001-02-16
|
||||
row 3: 2, two, Two, 2001-02-15
|
||||
row 4: 3, three, Three, 2001-02-14
|
||||
row 5: NULL
|
||||
testing fetchmodes: fetchrow default default, portability mode DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM
|
||||
0 1 2 3
|
||||
output matched expected format
|
||||
testing fetchmodes: fetchinto default default
|
||||
0 1 2 3
|
||||
42 bing This is a test 1999-11-21
|
||||
testing fetchmodes: fetchrow ordered default
|
||||
0 1 2 3
|
||||
testing fetchmodes: fetchrow assoc default
|
||||
a b c d
|
||||
testing fetchmodes: fetchrow ordered default with assoc specified
|
||||
a b c d
|
||||
testing fetchmodes: fetchrow assoc default with ordered specified
|
||||
0 1 2 3
|
||||
testing fetchmodes: fetchinto ordered default
|
||||
0 1 2 3
|
||||
testing fetchmodes: fetchinto assoc default
|
||||
a b c d
|
||||
testing fetchmodes: fetchinto ordered default with assoc specified
|
||||
a b c d
|
||||
testing fetchmodes: fetchinto assoc default with ordered specified
|
||||
0 1 2 3
|
||||
13
include/pear/tests/driver/03simplequery.phpt
Normal file
13
include/pear/tests/driver/03simplequery.phpt
Normal file
@@ -0,0 +1,13 @@
|
||||
--TEST--
|
||||
DB_driver::simpleQuery
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './mktable.inc';
|
||||
require_once '../simplequery.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
passed
|
||||
16
include/pear/tests/driver/04numcols.phpt
Normal file
16
include/pear/tests/driver/04numcols.phpt
Normal file
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
DB_driver::numCols
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './mktable.inc';
|
||||
require_once '../numcols.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
28
include/pear/tests/driver/05sequences.phpt
Normal file
28
include/pear/tests/driver/05sequences.phpt
Normal file
@@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
DB_driver::sequences
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
chdir(dirname(__FILE__));
|
||||
require_once './skipif.inc';
|
||||
$tableInfo = $db->dropSequence('ajkdslfajoijkadie');
|
||||
if (DB::isError($tableInfo) && $tableInfo->code == DB_ERROR_NOT_CAPABLE) {
|
||||
die("skip $tableInfo->message");
|
||||
}
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './connect.inc';
|
||||
require_once '../sequences.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
an error is the proper response here
|
||||
an error cought by the error handler is good
|
||||
a=1
|
||||
b=2
|
||||
b-a=1
|
||||
c=1
|
||||
d=1
|
||||
e=1
|
||||
50
include/pear/tests/driver/06prepexec.phpt
Normal file
50
include/pear/tests/driver/06prepexec.phpt
Normal file
@@ -0,0 +1,50 @@
|
||||
--TEST--
|
||||
DB_driver::prepare/execute
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './mktable.inc';
|
||||
require_once '../prepexe.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
------------1------------
|
||||
sth1,sth2,sth3,sth4 created
|
||||
sth1: ? as param, passing as array... sth1 executed
|
||||
sth2: ! and ? as params, passing as array... sth2 executed
|
||||
sth3: ?, ! and & as params, passing as array... sth3 executed
|
||||
sth4: no params... sth4 executed
|
||||
results:
|
||||
|72 - a - - |
|
||||
|72 - direct - - |
|
||||
|72 - it's good - opaque placeholder's test - |
|
||||
|72 - that's right - - |
|
||||
|
||||
------------2------------
|
||||
results:
|
||||
|72 - set1 - opaque placeholder's test - 1234-56-78|
|
||||
|72 - set2 - opaque placeholder's test - |
|
||||
|72 - set3 - opaque placeholder's test - |
|
||||
|
||||
------------3------------
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
------------4------------
|
||||
|72 - set1 - opaque placeholder's test - 1234-56-78|
|
||||
|72 - set2 - opaque placeholder's test - |
|
||||
|72 - set3 - opaque placeholder's test - |
|
||||
~~
|
||||
~~
|
||||
|72 - set1 - opaque placeholder's test - 1234-56-78|
|
||||
~~
|
||||
|72 - set1 - opaque placeholder's test - 1234-56-78|
|
||||
|72 - set2 - opaque placeholder's test - |
|
||||
|72 - set3 - opaque placeholder's test - |
|
||||
~~
|
||||
|
||||
------------5------------
|
||||
insert: okay
|
||||
a = 11, b = three, d = got expected outcome
|
||||
62
include/pear/tests/driver/08affectedrows.phpt
Normal file
62
include/pear/tests/driver/08affectedrows.phpt
Normal file
@@ -0,0 +1,62 @@
|
||||
--TEST--
|
||||
DB_driver::affectedRows
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './mktable.inc';
|
||||
|
||||
/**
|
||||
* Local error callback handler.
|
||||
*
|
||||
* Drops the phptest table, prints out an error message and kills the
|
||||
* process.
|
||||
*
|
||||
* @param object $o PEAR error object automatically passed to this method
|
||||
* @return void
|
||||
* @see PEAR::setErrorHandling()
|
||||
*/
|
||||
function pe($o) {
|
||||
global $dbh;
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'phptest');
|
||||
|
||||
die($o->toString());
|
||||
}
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
|
||||
|
||||
|
||||
// Clean table
|
||||
$dbh->query("DELETE FROM phptest");
|
||||
|
||||
// Affected rows by INSERT statement
|
||||
$dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')");
|
||||
$dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')");
|
||||
printf("%d after insert\n", $dbh->affectedRows());
|
||||
|
||||
// Affected rows by SELECT statement
|
||||
$dbh->query("SELECT * FROM phptest");
|
||||
printf("%d after select\n", $dbh->affectedRows());
|
||||
$dbh->query("DELETE FROM phptest WHERE b = 'test'");
|
||||
printf("%d after delete\n", $dbh->affectedRows());
|
||||
|
||||
// Affected rows by DELETE statement
|
||||
$dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')");
|
||||
$dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')");
|
||||
$dbh->query("DELETE FROM phptest");
|
||||
printf("%d after delete all\n", $dbh->affectedRows());
|
||||
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'phptest');
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
1 after insert
|
||||
0 after select
|
||||
2 after delete
|
||||
2 after delete all
|
||||
22
include/pear/tests/driver/09numrows.phpt
Normal file
22
include/pear/tests/driver/09numrows.phpt
Normal file
@@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
DB_driver::numRows
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './mktable.inc';
|
||||
require_once '../numrows.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
(want 1) got 1 from first
|
||||
(want 2) got 2 from 0
|
||||
(want 3) got 3 from 1
|
||||
(want 4) got 4 from 2
|
||||
(want 5) got 5 from 3
|
||||
(want 6) got 6 from 4
|
||||
(want 5) got 5 from > 0 (passing params to query)
|
||||
(want 4) got 4 from < 4 (doing prepare/execute)
|
||||
(want 2) got 2 from 5 and 6 not deleted
|
||||
(want 0) got 0 from < 0
|
||||
37
include/pear/tests/driver/10errormap.phpt
Normal file
37
include/pear/tests/driver/10errormap.phpt
Normal file
@@ -0,0 +1,37 @@
|
||||
--TEST--
|
||||
DB_driver::error mapping
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './mktable.inc';
|
||||
require_once '../errors.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
DB_ERROR_NOSUCHTABLE for select: matches expected outcome
|
||||
DB_ERROR_NOSUCHTABLE for drop: matches expected outcome
|
||||
DB_ERROR_NOT_FOUND for drop index: matches expected outcome
|
||||
DB_ERROR_ALREADY_EXISTS for create table: matches expected outcome
|
||||
DB_ERROR_ALREADY_EXISTS for create index: matches expected outcome
|
||||
DB_ERROR_CONSTRAINT for primary key insert duplicate: matches expected outcome
|
||||
DB_ERROR_CONSTRAINT for primary key update duplicate: matches expected outcome
|
||||
DB_ERROR_CONSTRAINT for unique key insert duplicate: matches expected outcome
|
||||
DB_ERROR_CONSTRAINT for unique key update duplicate: matches expected outcome
|
||||
DB_ERROR_CONSTRAINT for foreign key on insert: matches expected outcome
|
||||
DB_ERROR_CONSTRAINT for foreign key on delete: matches expected outcome
|
||||
DB_ERROR_CONSTRAINT_NOT_NULL on insert: matches expected outcome
|
||||
DB_ERROR_CONSTRAINT_NOT_NULL on update: matches expected outcome
|
||||
DB_ERROR_NOSUCHFIELD joining ON bogus column: matches expected outcome
|
||||
DB_ERROR_NOSUCHFIELD joining USING bogus column: matches expected outcome
|
||||
DB_ERROR_DIVZERO: matches expected outcome
|
||||
DB_ERROR_INVALID_NUMBER putting chars in INT column: matches expected outcome
|
||||
DB_ERROR_INVALID_NUMBER putting float in INT column: matches expected outcome
|
||||
DB_ERROR_INVALID_NUMBER putting excessive int in INT column: matches expected outcome
|
||||
DB_ERROR_INVALID_NUMBER putting int in CHAR column: matches expected outcome
|
||||
DB_ERROR_NOSUCHFIELD: matches expected outcome
|
||||
DB_ERROR_SYNTAX: matches expected outcome
|
||||
DB_ERROR_VALUE_COUNT_ON_ROW: matches expected outcome
|
||||
DB_ERROR_INVALID on CHAR column data too long: matches expected outcome
|
||||
DB_ERROR_INVALID on VARCHAR column data too long: matches expected outcome
|
||||
26
include/pear/tests/driver/11transactions.phpt
Normal file
26
include/pear/tests/driver/11transactions.phpt
Normal file
@@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
DB_driver::transaction test
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php
|
||||
chdir(dirname(__FILE__)); require_once './skipif.inc';
|
||||
if (!$db->features['transactions']) {
|
||||
die('skip this driver does not support transactions');
|
||||
}
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$needinnodb = true;
|
||||
require_once './mktable.inc';
|
||||
require_once '../transactions.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
1) after autocommit: bing one. ops=ok
|
||||
2) before commit: bing one two three. ops=ok
|
||||
3) after commit: bing one two three. ops=ok
|
||||
4) before rollback: bing one two three four five. ops=ok
|
||||
5) after rollback: bing one two three. ops=ok
|
||||
6) before autocommit+rollback: bing one two three six seven. ops=ok
|
||||
7) after autocommit+rollback: bing one two three six seven. ops=ok
|
||||
8) testing that select doesn't disturbe opcount: ok
|
||||
54
include/pear/tests/driver/13limit.phpt
Normal file
54
include/pear/tests/driver/13limit.phpt
Normal file
@@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
DB_driver::row limit
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './connect.inc';
|
||||
require_once './droptable.inc';
|
||||
require_once '../limit.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
======= From: 0 || Number of rows to fetch: 10 =======
|
||||
1.- result 0
|
||||
2.- result 1
|
||||
3.- result 2
|
||||
4.- result 3
|
||||
5.- result 4
|
||||
6.- result 5
|
||||
7.- result 6
|
||||
8.- result 7
|
||||
9.- result 8
|
||||
10.- result 9
|
||||
======= From: 10 || Number of rows to fetch: 10 =======
|
||||
11.- result 10
|
||||
12.- result 11
|
||||
13.- result 12
|
||||
14.- result 13
|
||||
15.- result 14
|
||||
16.- result 15
|
||||
17.- result 16
|
||||
18.- result 17
|
||||
19.- result 18
|
||||
20.- result 19
|
||||
======= From: 20 || Number of rows to fetch: 10 =======
|
||||
21.- result 20
|
||||
22.- result 21
|
||||
23.- result 22
|
||||
24.- result 23
|
||||
25.- result 24
|
||||
26.- result 25
|
||||
27.- result 26
|
||||
28.- result 27
|
||||
29.- result 28
|
||||
30.- result 29
|
||||
======= From: 30 || Number of rows to fetch: 10 =======
|
||||
31.- result 30
|
||||
32.- result 31
|
||||
33.- result 32
|
||||
======= Passing $params || From: 11 || Number of rows to fetch: 3 =======
|
||||
12.- result 11
|
||||
13.- result 12
|
||||
14.- result 13
|
||||
24
include/pear/tests/driver/14fetchmode_object.phpt
Normal file
24
include/pear/tests/driver/14fetchmode_object.phpt
Normal file
@@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
DB_driver::fetchmode object
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './mktable.inc';
|
||||
require_once '../fetchmode_object.inc';
|
||||
?>
|
||||
--EXPECT--
|
||||
--- fetch with param DB_FETCHMODE_OBJECT ---
|
||||
stdclass -> a b c d
|
||||
stdclass -> a b c d
|
||||
--- fetch with default fetchmode DB_FETCHMODE_OBJECT ---
|
||||
stdclass -> a b c d
|
||||
stdclass -> a b c d
|
||||
--- fetch with default fetchmode DB_FETCHMODE_OBJECT and class DB_row ---
|
||||
db_row -> a b c d
|
||||
db_row -> a b c d
|
||||
--- fetch with default fetchmode DB_FETCHMODE_OBJECT with no class then DB_row ---
|
||||
stdclass -> a b c d
|
||||
db_row -> a b c d
|
||||
273
include/pear/tests/driver/15quote.phpt
Normal file
273
include/pear/tests/driver/15quote.phpt
Normal file
@@ -0,0 +1,273 @@
|
||||
--TEST--
|
||||
DB_driver::quote
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once './connect.inc';
|
||||
require_once './droptable.inc';
|
||||
|
||||
|
||||
/**
|
||||
* Local error callback handler.
|
||||
*
|
||||
* Drops the phptest table, prints out an error message and kills the
|
||||
* process.
|
||||
*
|
||||
* @param object $o PEAR error object automatically passed to this method
|
||||
* @return void
|
||||
* @see PEAR::setErrorHandling()
|
||||
*/
|
||||
function pe($o) {
|
||||
global $dbh;
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'pearquote');
|
||||
|
||||
die($o->toString());
|
||||
}
|
||||
|
||||
// DBMS boolean column type simulation...
|
||||
$boolean_col_type = array(
|
||||
'dbase' => 'Logical',
|
||||
'fbsql' => 'BOOLEAN',
|
||||
'ibase' => 'SMALLINT',
|
||||
'ifx' => 'SMALLINT',
|
||||
'msql' => 'INTEGER',
|
||||
'mssql' => 'BIT',
|
||||
'mysql' => 'TINYINT(1)',
|
||||
'mysqli' => 'TINYINT(1)',
|
||||
'oci8' => 'NUMBER(1)',
|
||||
'odbc' => 'SMALLINT',
|
||||
'pgsql' => 'BOOLEAN',
|
||||
'sqlite' => 'INTEGER',
|
||||
'sybase' => 'TINYINT',
|
||||
);
|
||||
|
||||
// adjust things for specific DBMS's
|
||||
|
||||
if ($dbh->phptype == 'odbc') {
|
||||
if ($dbh->dbsyntax == 'odbc') {
|
||||
$type = $dbh->phptype;
|
||||
} else {
|
||||
$type = $dbh->dbsyntax;
|
||||
}
|
||||
} else {
|
||||
$type = $dbh->phptype;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'access':
|
||||
$decimal = 'SINGLE';
|
||||
$null = '';
|
||||
$chr = 'VARCHAR(8)';
|
||||
$identifier = 'q\ut "dnt';
|
||||
break;
|
||||
case 'db2':
|
||||
case 'ibase':
|
||||
$decimal = 'DECIMAL(3,1)';
|
||||
$null = '';
|
||||
$chr = 'VARCHAR(8)';
|
||||
$identifier = 'q\ut] "dn[t';
|
||||
break;
|
||||
case 'ifx':
|
||||
// doing this for ifx to keep certain versions happy
|
||||
$decimal = 'DECIMAL(3,1)';
|
||||
$null = '';
|
||||
$chr = 'CHAR(8)';
|
||||
$identifier = '';
|
||||
break;
|
||||
case 'msql':
|
||||
$decimal = 'REAL';
|
||||
$null = '';
|
||||
$chr = 'CHAR(8)';
|
||||
$identifier = '';
|
||||
break;
|
||||
case 'fbsql':
|
||||
case 'oci8':
|
||||
$decimal = 'DECIMAL(3,1)';
|
||||
$null = '';
|
||||
$chr = 'VARCHAR(8)';
|
||||
$identifier = 'q\ut] dn[t';
|
||||
break;
|
||||
default:
|
||||
$decimal = 'DECIMAL(3,1)';
|
||||
$null = 'NULL';
|
||||
$chr = 'VARCHAR(8)';
|
||||
$identifier = 'q\ut] "dn[t';
|
||||
}
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'pearquote');
|
||||
|
||||
|
||||
if ($identifier) {
|
||||
switch ($dbh->phptype) {
|
||||
case 'sybase':
|
||||
$res = $dbh->query('set quoted_identifier on');
|
||||
if (DB::isError($res) ) {
|
||||
pe($res);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
$create = $dbh->query("
|
||||
CREATE TABLE pearquote (
|
||||
n $decimal $null,
|
||||
s $chr $null,
|
||||
" . $dbh->quoteIdentifier($identifier) . " $decimal $null,
|
||||
b {$boolean_col_type[$dbh->phptype]} $null
|
||||
)
|
||||
");
|
||||
|
||||
if (DB::isError($create) ) {
|
||||
pe($create);
|
||||
}
|
||||
|
||||
$info = $dbh->tableInfo('pearquote');
|
||||
if (DB::isError($info) ) {
|
||||
if ($info->code == DB_ERROR_NOT_CAPABLE) {
|
||||
print "Got outcome expected from delimited identifier.\n";
|
||||
} else {
|
||||
print "tableInfo() failed.\n";
|
||||
}
|
||||
} else {
|
||||
if ($identifier == $info[2]['name']) {
|
||||
print "Got outcome expected from delimited identifier.\n";
|
||||
// print "COLUMN NAME IS: {$info[2]['name']}\n";
|
||||
} else {
|
||||
print "Expected column name: '$identifier' ... ";
|
||||
print "Actual column name: '{$info[2]['name']}'\n";
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$dbh->query("
|
||||
CREATE TABLE pearquote (
|
||||
n $decimal $null,
|
||||
s $chr $null,
|
||||
plainidentifier $decimal $null,
|
||||
b {$boolean_col_type[$dbh->phptype]} $null
|
||||
)
|
||||
");
|
||||
print "Got outcome expected from delimited identifier.\n";
|
||||
}
|
||||
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
|
||||
|
||||
|
||||
$strings = array(
|
||||
"'",
|
||||
"\"",
|
||||
"\\",
|
||||
"%",
|
||||
"_",
|
||||
"''",
|
||||
"\"\"",
|
||||
"\\\\",
|
||||
"\\'\\'",
|
||||
"\\\"\\\""
|
||||
);
|
||||
|
||||
$nums = array(
|
||||
12.3,
|
||||
15,
|
||||
);
|
||||
|
||||
$bools = array(
|
||||
TRUE,
|
||||
FALSE,
|
||||
);
|
||||
|
||||
|
||||
echo "String escape test: ";
|
||||
foreach ($strings as $s) {
|
||||
$quoted = $dbh->quoteSmart($s);
|
||||
$dbh->query("INSERT INTO pearquote (s) VALUES ($quoted)");
|
||||
}
|
||||
$diff = array_diff($strings, $res = $dbh->getCol("SELECT s FROM pearquote"));
|
||||
if (count($diff) > 0) {
|
||||
echo "FAIL";
|
||||
print_r($strings);
|
||||
print_r($res);
|
||||
} else {
|
||||
echo "OK";
|
||||
}
|
||||
|
||||
$dbh->query("DELETE FROM pearquote");
|
||||
|
||||
|
||||
echo "\nNumber escape test: ";
|
||||
foreach ($nums as $n) {
|
||||
$quoted = $dbh->quoteSmart($n);
|
||||
$dbh->query("INSERT INTO pearquote (n) VALUES ($quoted)");
|
||||
}
|
||||
|
||||
$diff = array();
|
||||
$res =& $dbh->getCol('SELECT n FROM pearquote ORDER BY n');
|
||||
foreach ($nums as $key => $val) {
|
||||
if ($val != $res[$key]) {
|
||||
$diff[] = "$val != {$res[$key]}";
|
||||
}
|
||||
}
|
||||
|
||||
if (count($diff) > 0) {
|
||||
echo "FAIL\n";
|
||||
print_r($diff);
|
||||
} else {
|
||||
echo 'OK';
|
||||
}
|
||||
|
||||
$dbh->query('DELETE FROM pearquote');
|
||||
|
||||
|
||||
echo "\nBoolean escape test: ";
|
||||
$i = 1;
|
||||
foreach ($bools as $b) {
|
||||
$quoted = $dbh->quoteSmart($b);
|
||||
$dbh->query("INSERT INTO pearquote (n, b) VALUES ($i, $quoted)");
|
||||
$i++;
|
||||
}
|
||||
|
||||
$diff = array();
|
||||
$res =& $dbh->getCol('SELECT b, n FROM pearquote ORDER BY n');
|
||||
foreach ($bools as $key => $val) {
|
||||
if ($val === true) {
|
||||
if ($res[$key] == 1 || $res[$key] == true ||
|
||||
substr(strtolower($res[$key]), 0, 1) == 't')
|
||||
{
|
||||
// good
|
||||
} else {
|
||||
$diff[] = "in:true != out:{$res[$key]}";
|
||||
}
|
||||
} else {
|
||||
if ($res[$key] == 0 || $res[$key] == false ||
|
||||
substr(strtolower($res[$key]), 0, 1) == 'f')
|
||||
{
|
||||
// good
|
||||
} else {
|
||||
$diff[] = "in:false != out:{$res[$key]}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($diff) > 0) {
|
||||
echo "FAIL\n";
|
||||
print_r($diff);
|
||||
} else {
|
||||
echo "OK\n";
|
||||
}
|
||||
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'pearquote');
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Got outcome expected from delimited identifier.
|
||||
String escape test: OK
|
||||
Number escape test: OK
|
||||
Boolean escape test: OK
|
||||
1340
include/pear/tests/driver/16tableinfo.phpt
Normal file
1340
include/pear/tests/driver/16tableinfo.phpt
Normal file
File diff suppressed because it is too large
Load Diff
140
include/pear/tests/driver/17query.phpt
Normal file
140
include/pear/tests/driver/17query.phpt
Normal file
@@ -0,0 +1,140 @@
|
||||
--TEST--
|
||||
DB_driver::query
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Calls the query() method in various ways against any DBMS.
|
||||
*
|
||||
* @see DB_common::query()
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: 17query.phpt,v 1.13 2005/02/16 13:54:52 danielc Exp $
|
||||
* @category Database
|
||||
* @author Daniel Convissor <danielc@analysisandsolutions.com>
|
||||
* @internal
|
||||
*/
|
||||
|
||||
chdir(dirname(__FILE__));
|
||||
require_once './skipif.inc';
|
||||
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
// $Id: 17query.phpt,v 1.13 2005/02/16 13:54:52 danielc Exp $
|
||||
|
||||
/**
|
||||
* Connect to the database and make the phptest table.
|
||||
*/
|
||||
require_once './mktable.inc';
|
||||
|
||||
|
||||
/**
|
||||
* Local error callback handler.
|
||||
*
|
||||
* Drops the phptest table, prints out an error message and kills the
|
||||
* process.
|
||||
*
|
||||
* @param object $o PEAR error object automatically passed to this method
|
||||
* @return void
|
||||
* @see PEAR::setErrorHandling()
|
||||
*/
|
||||
function pe($o) {
|
||||
global $dbh;
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'phptest');
|
||||
|
||||
die($o->toString());
|
||||
}
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
|
||||
|
||||
|
||||
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
|
||||
$res =& $dbh->query('DELETE FROM phptest WHERE a = 17');
|
||||
print '1) delete: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
|
||||
|
||||
$res =& $dbh->query("INSERT INTO phptest (a, b, c) VALUES (17, 'one', 'One')");
|
||||
print '2) insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
|
||||
|
||||
$res =& $dbh->query('INSERT INTO phptest (a, b, c) VALUES (?, ?, ?)', array(17, 'two', 'Two'));
|
||||
print '3) insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
|
||||
|
||||
|
||||
$res =& $dbh->query('SELECT a, b FROM phptest WHERE a = 17');
|
||||
$row = $res->fetchRow();
|
||||
print "4) a = {$row['a']}, b = {$row['b']}\n";
|
||||
$res->free(); // keep fbsql happy.
|
||||
|
||||
$res =& $dbh->query('SELECT a, b FROM phptest WHERE c = ?', array('Two'));
|
||||
$row = $res->fetchRow();
|
||||
print "5) a = {$row['a']}, b = {$row['b']}\n";
|
||||
|
||||
|
||||
$array = array(
|
||||
'foo' => 11,
|
||||
'bar' => 'three',
|
||||
'baz' => null,
|
||||
);
|
||||
$res =& $dbh->query('INSERT INTO phptest (a, b, d) VALUES (?, ?, ?)', $array);
|
||||
print '6) insert: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
|
||||
|
||||
$res =& $dbh->query('SELECT a, b, d FROM phptest WHERE a = ?', 11);
|
||||
$row = $res->fetchRow();
|
||||
print "7) a = {$row['a']}, b = {$row['b']}, d = ";
|
||||
if ($dbh->phptype == 'msql') {
|
||||
if (array_key_exists('d', $row)) {
|
||||
$type = gettype($row['d']);
|
||||
if ($type == 'NULL' || $row['d'] == '') {
|
||||
print "got expected value\n";
|
||||
} else {
|
||||
print "ERR: expected d's type to be NULL but it's $type and the value is ";
|
||||
print $row['d'] . "\n";
|
||||
}
|
||||
} else {
|
||||
// http://bugs.php.net/?id=31960
|
||||
print "Prior to PHP 4.3.11 or 5.0.4, PHP's msql extension silently"
|
||||
. " dropped columns with null values. You need to upgrade.\n";
|
||||
}
|
||||
} else {
|
||||
$type = gettype($row['d']);
|
||||
if ($type == 'NULL' || $row['d'] == '') {
|
||||
print "got expected value\n";
|
||||
} else {
|
||||
print "ERR: expected d's type to be NULL but it's $type and the value is ";
|
||||
print $row['d'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$res =& $dbh->query('DELETE FROM phptest WHERE a = ?', array(17));
|
||||
print '8) delete: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
|
||||
|
||||
$res =& $dbh->query('DELETE FROM phptest WHERE a = ?', array(0));
|
||||
print '9) delete with array(0) as param: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
|
||||
|
||||
$res =& $dbh->query('DELETE FROM phptest WHERE a = ?', 0);
|
||||
print '10) delete with 0 as param: ' . ($res === DB_OK ? 'okay' : 'error') . "\n";
|
||||
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'phptest');
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
1) delete: okay
|
||||
2) insert: okay
|
||||
3) insert: okay
|
||||
4) a = 17, b = one
|
||||
5) a = 17, b = two
|
||||
6) insert: okay
|
||||
7) a = 11, b = three, d = got expected value
|
||||
8) delete: okay
|
||||
9) delete with array(0) as param: okay
|
||||
10) delete with 0 as param: okay
|
||||
661
include/pear/tests/driver/18get.phpt
Normal file
661
include/pear/tests/driver/18get.phpt
Normal file
@@ -0,0 +1,661 @@
|
||||
--TEST--
|
||||
DB_driver::get
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Calls the get*() methods in various ways against any DBMS.
|
||||
*
|
||||
* @see DB_Common::getAll(), DB_Common::getAssoc(), DB_Common::getCol()
|
||||
* DB_Common::getListOf(), DB_Common::getOne(), DB_Common::getRow()
|
||||
*
|
||||
* @package DB
|
||||
* @version $Id: 18get.phpt,v 1.9 2005/02/14 23:47:54 danielc Exp $
|
||||
* @category Database
|
||||
* @author Daniel Convissor <danielc@analysisandsolutions.com>
|
||||
* @internal
|
||||
*/
|
||||
|
||||
chdir(dirname(__FILE__));
|
||||
require_once './skipif.inc';
|
||||
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
// $Id: 18get.phpt,v 1.9 2005/02/14 23:47:54 danielc Exp $
|
||||
|
||||
/**
|
||||
* Connect to the database and make the <kbd>phptest</kbd> table.
|
||||
*/
|
||||
require_once './mktable.inc';
|
||||
|
||||
|
||||
/**
|
||||
* Local error callback handler.
|
||||
*
|
||||
* Drops the phptest table, prints out an error message and kills the
|
||||
* process.
|
||||
*
|
||||
* @param object $o PEAR error object automatically passed to this method
|
||||
* @return void
|
||||
* @see PEAR::setErrorHandling()
|
||||
*/
|
||||
function pe($o){
|
||||
global $dbh;
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'phptest');
|
||||
|
||||
die($o->toString());
|
||||
}
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
|
||||
|
||||
|
||||
$dbh->query("INSERT INTO phptest VALUES (2, 'two', 'Two', '2002-02-22')");
|
||||
$dbh->query("INSERT INTO phptest VALUES (42, 'three', 'Three', '2003-03-23')");
|
||||
|
||||
|
||||
print "===================================================\n";
|
||||
print 'testing getOne: ';
|
||||
$ret =& $dbh->getOne("SELECT * FROM phptest WHERE c = 'Two'");
|
||||
print_r($ret);
|
||||
print "\n";
|
||||
|
||||
print 'testing getOne with string params: ';
|
||||
$ret =& $dbh->getOne('SELECT * FROM phptest WHERE c = ?', 'Three');
|
||||
print_r($ret);
|
||||
print "\n";
|
||||
|
||||
print 'testing getOne with array params: ';
|
||||
$ret =& $dbh->getOne('SELECT * FROM phptest WHERE c = ?', array('Two'));
|
||||
print_r($ret);
|
||||
print "\n";
|
||||
|
||||
print "\n===================================================\n";
|
||||
print "testing getRow:\n";
|
||||
$ret =& $dbh->getRow("SELECT * FROM phptest WHERE c = 'Two'");
|
||||
print_r($ret);
|
||||
|
||||
print "testing getRow with null params, DB_FETCHMODE_ORDERED:\n";
|
||||
$ret =& $dbh->getRow("SELECT * FROM phptest WHERE c = 'Two'",
|
||||
null, DB_FETCHMODE_ORDERED);
|
||||
print_r($ret);
|
||||
|
||||
// THIS DOESN'T WORK DUE TO BACKWARDS COMPATIBILITY CRAP
|
||||
// print "testing getRow with string params, DB_FETCHMODE_ORDERED:\n";
|
||||
// $ret =& $dbh->getRow('SELECT * FROM phptest WHERE c = ?',
|
||||
// 'Two', DB_FETCHMODE_ORDERED);
|
||||
// print_r($ret);
|
||||
//
|
||||
// testing getRow with string params, DB_FETCHMODE_ORDERED:
|
||||
// Array
|
||||
// (
|
||||
// [0] => 2
|
||||
// [1] => two
|
||||
// [2] => Two
|
||||
// [3] => 2002-02-22
|
||||
// )
|
||||
|
||||
print "testing getRow with REVERSED args: DB_FETCHMODE_ASSOC, array params:\n";
|
||||
$ret =& $dbh->getRow('SELECT * FROM phptest WHERE c = ?',
|
||||
DB_FETCHMODE_ASSOC, array('Two'));
|
||||
print_r($ret);
|
||||
|
||||
print "testing getRow with REVERSED args: DB_FETCHMODE_ASSOC:\n";
|
||||
$ret =& $dbh->getRow("SELECT * FROM phptest WHERE c = 'Two'",
|
||||
DB_FETCHMODE_ASSOC);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getRow with array params, DB_FETCHMODE_ASSOC:\n";
|
||||
$ret =& $dbh->getRow('SELECT * FROM phptest WHERE c = ?',
|
||||
array('Two'), DB_FETCHMODE_ASSOC);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getRow with array params, DB_FETCHMODE_OBJECT:\n";
|
||||
$ret =& $dbh->getRow('SELECT * FROM phptest WHERE c = ?',
|
||||
array('Two'), DB_FETCHMODE_OBJECT);
|
||||
print_r($ret);
|
||||
|
||||
|
||||
print "\n===================================================\n";
|
||||
print "testing getCol:\n";
|
||||
$ret =& $dbh->getCol("SELECT * FROM phptest ORDER BY b");
|
||||
print_r($ret);
|
||||
|
||||
print "testing getCol on query with no records:\n";
|
||||
$ret =& $dbh->getCol('SELECT * FROM phptest WHERE a > 200');
|
||||
print_r($ret);
|
||||
|
||||
print "testing getCol with invalid column id:\n";
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
$ret =& $dbh->getCol('SELECT b FROM phptest ORDER BY b', 1);
|
||||
if (DB::isError($ret)) {
|
||||
echo $ret->getMessage() . "\n";
|
||||
} else {
|
||||
print ">> Should have produced 'no such field' error\n";
|
||||
}
|
||||
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
|
||||
|
||||
print "testing getCol with 1 col:\n";
|
||||
$ret =& $dbh->getCol("SELECT * FROM phptest ORDER BY b", 1);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getCol with b col:\n";
|
||||
$ret =& $dbh->getCol("SELECT * FROM phptest ORDER BY b", 'b');
|
||||
print_r($ret);
|
||||
|
||||
print "testing getCol with b col, scalar params:\n";
|
||||
$ret =& $dbh->getCol("SELECT * FROM phptest WHERE a < ? ORDER BY b",
|
||||
'b', 100);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getCol with b col, array params:\n";
|
||||
$ret =& $dbh->getCol("SELECT * FROM phptest WHERE a < ? ORDER BY b",
|
||||
'b', array(100));
|
||||
print_r($ret);
|
||||
|
||||
|
||||
print "\n===================================================\n";
|
||||
print "testing getAssoc:\n";
|
||||
$ret =& $dbh->getAssoc('SELECT a, b, c FROM phptest WHERE a < 100 ORDER BY b');
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAssoc with false force, null params, DB_FETCHMODE_ORDERED:\n";
|
||||
$ret =& $dbh->getAssoc("SELECT a, b, c FROM phptest WHERE a < 100 ORDER BY b",
|
||||
false, null, DB_FETCHMODE_ORDERED);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAssoc with false force, scalar params, DB_FETCHMODE_ASSOC:\n";
|
||||
$ret =& $dbh->getAssoc('SELECT a, b, c FROM phptest WHERE a < ? ORDER BY b',
|
||||
false, 100, DB_FETCHMODE_ASSOC);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAssoc with two cols, false force, scalar params, DB_FETCHMODE_ASSOC:\n";
|
||||
$ret =& $dbh->getAssoc('SELECT a, b FROM phptest WHERE a < ? ORDER BY b',
|
||||
false, 100, DB_FETCHMODE_ASSOC);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAssoc with two cols, true force, scalar params, DB_FETCHMODE_ASSOC:\n";
|
||||
$ret =& $dbh->getAssoc('SELECT a, b FROM phptest WHERE a < ? ORDER BY b',
|
||||
true, 100, DB_FETCHMODE_ASSOC);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAssoc with false force, scalar params, DB_FETCHMODE_ASSOC, true group:\n";
|
||||
$ret =& $dbh->getAssoc('SELECT a, b, c FROM phptest WHERE a < ? ORDER BY b',
|
||||
false, 100, DB_FETCHMODE_ASSOC, true);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAssoc with false force, array params, DB_FETCHMODE_OBJECT:\n";
|
||||
$ret =& $dbh->getAssoc('SELECT a, b, c FROM phptest WHERE a < ? ORDER BY b',
|
||||
false, array(100), DB_FETCHMODE_OBJECT);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAssoc with true force, array params, DB_FETCHMODE_OBJECT, true group:\n";
|
||||
$ret =& $dbh->getAssoc('SELECT a, b, c FROM phptest WHERE a < ? ORDER BY b',
|
||||
false, array(100), DB_FETCHMODE_OBJECT, true);
|
||||
print_r($ret);
|
||||
|
||||
|
||||
print "\n===================================================\n";
|
||||
print "testing getAll:\n";
|
||||
$ret =& $dbh->getAll("SELECT * FROM phptest WHERE c = 'Two' OR c = 'Three'");
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAll with null params, DB_FETCHMODE_ORDERED:\n";
|
||||
$ret =& $dbh->getAll("SELECT * FROM phptest WHERE c = 'Two' OR c = 'Three'",
|
||||
null, DB_FETCHMODE_ORDERED);
|
||||
print_r($ret);
|
||||
|
||||
// THIS DOESN'T WORK DUE TO BACKWARDS COMPATIBILITY CRAP
|
||||
// print "testing getAll with string params, DB_FETCHMODE_ORDERED:\n";
|
||||
// $ret =& $dbh->getAll('SELECT * FROM phptest WHERE c = ?',
|
||||
// 'Two', DB_FETCHMODE_ORDERED);
|
||||
// print_r($ret);
|
||||
//
|
||||
// testing getAll with string params, DB_FETCHMODE_ORDERED:
|
||||
// Array
|
||||
// (
|
||||
// [0] => 2
|
||||
// [1] => two
|
||||
// [2] => Two
|
||||
// [3] => 2002-02-22
|
||||
// )
|
||||
|
||||
print "testing getAll with REVERSED args: DB_FETCHMODE_ASSOC, array params:\n";
|
||||
$ret =& $dbh->getAll('SELECT * FROM phptest WHERE c = ? OR c = ? ORDER BY c',
|
||||
DB_FETCHMODE_ASSOC, array('Two', 'Three'));
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAll with REVERSED args: DB_FETCHMODE_ASSOC:\n";
|
||||
$ret =& $dbh->getAll("SELECT * FROM phptest WHERE c = 'Two' OR c = 'Three'",
|
||||
DB_FETCHMODE_ASSOC);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAll with array params, DB_FETCHMODE_ASSOC:\n";
|
||||
$ret =& $dbh->getAll('SELECT * FROM phptest WHERE c = ? OR c = ? ORDER BY c',
|
||||
array('Two', 'Three'), DB_FETCHMODE_ASSOC);
|
||||
print_r($ret);
|
||||
|
||||
print "testing getAll with array params, DB_FETCHMODE_OBJECT:\n";
|
||||
$ret =& $dbh->getAll('SELECT * FROM phptest WHERE c = ? OR c = ? ORDER BY c',
|
||||
array('Two', 'Three'), DB_FETCHMODE_OBJECT);
|
||||
print_r($ret);
|
||||
|
||||
|
||||
print "\n===================================================\n";
|
||||
print 'testing getOne with null value in column: ';
|
||||
$dbh->query("INSERT INTO phptest VALUES (9, 'nine', '', NULL)");
|
||||
$ret =& $dbh->getOne('SELECT d FROM phptest WHERE a = 9');
|
||||
if ($ret === '') {
|
||||
print "matches expected result\n";
|
||||
} else {
|
||||
if ($dbh->phptype == 'msql') {
|
||||
if (gettype($ret) == 'NULL') {
|
||||
// msql doesn't even return the column. Joy! :)
|
||||
// http://bugs.php.net/?id=31960
|
||||
print "matches expected result\n";
|
||||
} else {
|
||||
print "WOW, mSQL now returns columns that have NULLS in them\n";
|
||||
}
|
||||
} else {
|
||||
print 'type=' . gettype($ret) . ", value=$ret\n";
|
||||
}
|
||||
}
|
||||
|
||||
print 'testing getOne with empty string in column: ';
|
||||
$ret =& $dbh->getOne('SELECT c FROM phptest WHERE a = 9');
|
||||
if ($ret === '') {
|
||||
print "empty string\n";
|
||||
} else {
|
||||
print 'type=' . gettype($ret) . ", value=$ret\n";
|
||||
}
|
||||
|
||||
|
||||
print "\n===================================================\n";
|
||||
|
||||
|
||||
drop_table($dbh, 'phptest');
|
||||
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
===================================================
|
||||
testing getOne: 2
|
||||
testing getOne with string params: 42
|
||||
testing getOne with array params: 2
|
||||
|
||||
===================================================
|
||||
testing getRow:
|
||||
Array
|
||||
(
|
||||
[0] => 2
|
||||
[1] => two
|
||||
[2] => Two
|
||||
[3] => 2002-02-22
|
||||
)
|
||||
testing getRow with null params, DB_FETCHMODE_ORDERED:
|
||||
Array
|
||||
(
|
||||
[0] => 2
|
||||
[1] => two
|
||||
[2] => Two
|
||||
[3] => 2002-02-22
|
||||
)
|
||||
testing getRow with REVERSED args: DB_FETCHMODE_ASSOC, array params:
|
||||
Array
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
[d] => 2002-02-22
|
||||
)
|
||||
testing getRow with REVERSED args: DB_FETCHMODE_ASSOC:
|
||||
Array
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
[d] => 2002-02-22
|
||||
)
|
||||
testing getRow with array params, DB_FETCHMODE_ASSOC:
|
||||
Array
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
[d] => 2002-02-22
|
||||
)
|
||||
testing getRow with array params, DB_FETCHMODE_OBJECT:
|
||||
stdClass Object
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
[d] => 2002-02-22
|
||||
)
|
||||
|
||||
===================================================
|
||||
testing getCol:
|
||||
Array
|
||||
(
|
||||
[0] => 42
|
||||
[1] => 42
|
||||
[2] => 2
|
||||
)
|
||||
testing getCol on query with no records:
|
||||
Array
|
||||
(
|
||||
)
|
||||
testing getCol with invalid column id:
|
||||
DB Error: no such field
|
||||
testing getCol with 1 col:
|
||||
Array
|
||||
(
|
||||
[0] => bing
|
||||
[1] => three
|
||||
[2] => two
|
||||
)
|
||||
testing getCol with b col:
|
||||
Array
|
||||
(
|
||||
[0] => bing
|
||||
[1] => three
|
||||
[2] => two
|
||||
)
|
||||
testing getCol with b col, scalar params:
|
||||
Array
|
||||
(
|
||||
[0] => bing
|
||||
[1] => three
|
||||
[2] => two
|
||||
)
|
||||
testing getCol with b col, array params:
|
||||
Array
|
||||
(
|
||||
[0] => bing
|
||||
[1] => three
|
||||
[2] => two
|
||||
)
|
||||
|
||||
===================================================
|
||||
testing getAssoc:
|
||||
Array
|
||||
(
|
||||
[42] => Array
|
||||
(
|
||||
[0] => three
|
||||
[1] => Three
|
||||
)
|
||||
|
||||
[2] => Array
|
||||
(
|
||||
[0] => two
|
||||
[1] => Two
|
||||
)
|
||||
|
||||
)
|
||||
testing getAssoc with false force, null params, DB_FETCHMODE_ORDERED:
|
||||
Array
|
||||
(
|
||||
[42] => Array
|
||||
(
|
||||
[0] => three
|
||||
[1] => Three
|
||||
)
|
||||
|
||||
[2] => Array
|
||||
(
|
||||
[0] => two
|
||||
[1] => Two
|
||||
)
|
||||
|
||||
)
|
||||
testing getAssoc with false force, scalar params, DB_FETCHMODE_ASSOC:
|
||||
Array
|
||||
(
|
||||
[42] => Array
|
||||
(
|
||||
[b] => three
|
||||
[c] => Three
|
||||
)
|
||||
|
||||
[2] => Array
|
||||
(
|
||||
[b] => two
|
||||
[c] => Two
|
||||
)
|
||||
|
||||
)
|
||||
testing getAssoc with two cols, false force, scalar params, DB_FETCHMODE_ASSOC:
|
||||
Array
|
||||
(
|
||||
[42] => three
|
||||
[2] => two
|
||||
)
|
||||
testing getAssoc with two cols, true force, scalar params, DB_FETCHMODE_ASSOC:
|
||||
Array
|
||||
(
|
||||
[42] => Array
|
||||
(
|
||||
[b] => three
|
||||
)
|
||||
|
||||
[2] => Array
|
||||
(
|
||||
[b] => two
|
||||
)
|
||||
|
||||
)
|
||||
testing getAssoc with false force, scalar params, DB_FETCHMODE_ASSOC, true group:
|
||||
Array
|
||||
(
|
||||
[42] => Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[b] => bing
|
||||
[c] => This is a test
|
||||
)
|
||||
|
||||
[1] => Array
|
||||
(
|
||||
[b] => three
|
||||
[c] => Three
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[2] => Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[b] => two
|
||||
[c] => Two
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
testing getAssoc with false force, array params, DB_FETCHMODE_OBJECT:
|
||||
Array
|
||||
(
|
||||
[42] => stdClass Object
|
||||
(
|
||||
[a] => 42
|
||||
[b] => three
|
||||
[c] => Three
|
||||
)
|
||||
|
||||
[2] => stdClass Object
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
)
|
||||
|
||||
)
|
||||
testing getAssoc with true force, array params, DB_FETCHMODE_OBJECT, true group:
|
||||
Array
|
||||
(
|
||||
[42] => Array
|
||||
(
|
||||
[0] => stdClass Object
|
||||
(
|
||||
[a] => 42
|
||||
[b] => bing
|
||||
[c] => This is a test
|
||||
)
|
||||
|
||||
[1] => stdClass Object
|
||||
(
|
||||
[a] => 42
|
||||
[b] => three
|
||||
[c] => Three
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
[2] => Array
|
||||
(
|
||||
[0] => stdClass Object
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
===================================================
|
||||
testing getAll:
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => 2
|
||||
[1] => two
|
||||
[2] => Two
|
||||
[3] => 2002-02-22
|
||||
)
|
||||
|
||||
[1] => Array
|
||||
(
|
||||
[0] => 42
|
||||
[1] => three
|
||||
[2] => Three
|
||||
[3] => 2003-03-23
|
||||
)
|
||||
|
||||
)
|
||||
testing getAll with null params, DB_FETCHMODE_ORDERED:
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => 2
|
||||
[1] => two
|
||||
[2] => Two
|
||||
[3] => 2002-02-22
|
||||
)
|
||||
|
||||
[1] => Array
|
||||
(
|
||||
[0] => 42
|
||||
[1] => three
|
||||
[2] => Three
|
||||
[3] => 2003-03-23
|
||||
)
|
||||
|
||||
)
|
||||
testing getAll with REVERSED args: DB_FETCHMODE_ASSOC, array params:
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[a] => 42
|
||||
[b] => three
|
||||
[c] => Three
|
||||
[d] => 2003-03-23
|
||||
)
|
||||
|
||||
[1] => Array
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
[d] => 2002-02-22
|
||||
)
|
||||
|
||||
)
|
||||
testing getAll with REVERSED args: DB_FETCHMODE_ASSOC:
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
[d] => 2002-02-22
|
||||
)
|
||||
|
||||
[1] => Array
|
||||
(
|
||||
[a] => 42
|
||||
[b] => three
|
||||
[c] => Three
|
||||
[d] => 2003-03-23
|
||||
)
|
||||
|
||||
)
|
||||
testing getAll with array params, DB_FETCHMODE_ASSOC:
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[a] => 42
|
||||
[b] => three
|
||||
[c] => Three
|
||||
[d] => 2003-03-23
|
||||
)
|
||||
|
||||
[1] => Array
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
[d] => 2002-02-22
|
||||
)
|
||||
|
||||
)
|
||||
testing getAll with array params, DB_FETCHMODE_OBJECT:
|
||||
Array
|
||||
(
|
||||
[0] => stdClass Object
|
||||
(
|
||||
[a] => 42
|
||||
[b] => three
|
||||
[c] => Three
|
||||
[d] => 2003-03-23
|
||||
)
|
||||
|
||||
[1] => stdClass Object
|
||||
(
|
||||
[a] => 2
|
||||
[b] => two
|
||||
[c] => Two
|
||||
[d] => 2002-02-22
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
===================================================
|
||||
testing getOne with null value in column: matches expected result
|
||||
testing getOne with empty string in column: empty string
|
||||
|
||||
===================================================
|
||||
208
include/pear/tests/driver/19getlistof.phpt
Normal file
208
include/pear/tests/driver/19getlistof.phpt
Normal file
@@ -0,0 +1,208 @@
|
||||
--TEST--
|
||||
DB_driver::getListOf
|
||||
--INI--
|
||||
error_reporting = 2047
|
||||
--SKIPIF--
|
||||
<?php chdir(dirname(__FILE__)); require_once './skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once './mktable.inc';
|
||||
|
||||
/*
|
||||
* An array with keys containing the $type to be passed to the getListOf()
|
||||
* method. The values of the main array are a sub-array that has keys
|
||||
* listing the phptype and dbsyntax of each driver and values of the
|
||||
* result expected from the combination of all these factors.
|
||||
*/
|
||||
$tests = array(
|
||||
'tables' => array(
|
||||
'dbase:dbase' => DB_ERROR_UNSUPPORTED,
|
||||
'fbsql:fbsql' => 'array',
|
||||
'ibase:ibase' => 'array',
|
||||
'ibase:firebird' => 'array',
|
||||
'ifx:ifx' => 'array',
|
||||
'msql:msql' => 'array',
|
||||
'mssql:mssql' => 'array',
|
||||
'mysql:mysql' => 'array',
|
||||
'mysqli:mysqli' => 'array',
|
||||
'oci8:oci8' => 'array',
|
||||
'odbc:access' => 'array',
|
||||
'odbc:db2' => 'array',
|
||||
'pgsql:pgsql' => 'array',
|
||||
'sqlite:sqlite' => 'array',
|
||||
'sybase:sybase' => 'array',
|
||||
),
|
||||
'views' => array(
|
||||
'dbase:dbase' => DB_ERROR_UNSUPPORTED,
|
||||
'fbsql:fbsql' => 'array',
|
||||
'ibase:ibase' => 'array',
|
||||
'ibase:firebird' => 'array',
|
||||
'ifx:ifx' => DB_ERROR_UNSUPPORTED,
|
||||
'msql:msql' => DB_ERROR_UNSUPPORTED,
|
||||
'mssql:mssql' => 'array',
|
||||
'mysql:mysql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysqli:mysqli' => DB_ERROR_UNSUPPORTED,
|
||||
'oci8:oci8' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:access' => 'array',
|
||||
'odbc:db2' => 'array',
|
||||
'pgsql:pgsql' => 'array',
|
||||
'sqlite:sqlite' => DB_ERROR_UNSUPPORTED,
|
||||
'sybase:sybase' => 'array',
|
||||
),
|
||||
'users' => array(
|
||||
'dbase:dbase' => DB_ERROR_UNSUPPORTED,
|
||||
'fbsql:fbsql' => 'array',
|
||||
'ibase:ibase' => 'array',
|
||||
'ibase:firebird' => 'array',
|
||||
'ifx:ifx' => DB_ERROR_UNSUPPORTED,
|
||||
'msql:msql' => DB_ERROR_UNSUPPORTED,
|
||||
'mssql:mssql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysql:mysql' => DB_ERROR_ACCESS_VIOLATION,
|
||||
'mysqli:mysqli' => DB_ERROR_ACCESS_VIOLATION,
|
||||
'oci8:oci8' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:access' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:db2' => DB_ERROR_UNSUPPORTED,
|
||||
'pgsql:pgsql' => 'array',
|
||||
'sqlite:sqlite' => DB_ERROR_UNSUPPORTED,
|
||||
'sybase:sybase' => DB_ERROR_UNSUPPORTED,
|
||||
),
|
||||
'databases' => array(
|
||||
'dbase:dbase' => DB_ERROR_UNSUPPORTED,
|
||||
'fbsql:fbsql' => DB_ERROR_UNSUPPORTED,
|
||||
'ibase:ibase' => DB_ERROR_UNSUPPORTED,
|
||||
'ibase:firebird' => DB_ERROR_UNSUPPORTED,
|
||||
'ifx:ifx' => DB_ERROR_UNSUPPORTED,
|
||||
'msql:msql' => 'array',
|
||||
'mssql:mssql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysql:mysql' => 'array',
|
||||
'mysqli:mysqli' => 'array',
|
||||
'oci8:oci8' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:access' => 'array',
|
||||
'odbc:db2' => 'array',
|
||||
'pgsql:pgsql' => 'array',
|
||||
'sqlite:sqlite' => DB_ERROR_UNSUPPORTED,
|
||||
'sybase:sybase' => DB_ERROR_UNSUPPORTED,
|
||||
),
|
||||
'functions' => array(
|
||||
'dbase:dbase' => DB_ERROR_UNSUPPORTED,
|
||||
'fbsql:fbsql' => 'array',
|
||||
'ibase:ibase' => DB_ERROR_UNSUPPORTED,
|
||||
'ibase:firebird' => DB_ERROR_UNSUPPORTED,
|
||||
'ifx:ifx' => DB_ERROR_UNSUPPORTED,
|
||||
'msql:msql' => DB_ERROR_UNSUPPORTED,
|
||||
'mssql:mssql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysql:mysql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysqli:mysqli' => DB_ERROR_UNSUPPORTED,
|
||||
'oci8:oci8' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:access' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:db2' => DB_ERROR_UNSUPPORTED,
|
||||
'pgsql:pgsql' => 'array',
|
||||
'sqlite:sqlite' => DB_ERROR_UNSUPPORTED,
|
||||
'sybase:sybase' => DB_ERROR_UNSUPPORTED,
|
||||
),
|
||||
'procedures' => array(
|
||||
'dbase:dbase' => DB_ERROR_UNSUPPORTED,
|
||||
'fbsql:fbsql' => 'array',
|
||||
'ibase:ibase' => DB_ERROR_UNSUPPORTED,
|
||||
'ibase:firebird' => DB_ERROR_UNSUPPORTED,
|
||||
'ifx:ifx' => DB_ERROR_UNSUPPORTED,
|
||||
'msql:msql' => DB_ERROR_UNSUPPORTED,
|
||||
'mssql:mssql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysql:mysql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysqli:mysqli' => DB_ERROR_UNSUPPORTED,
|
||||
'oci8:oci8' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:access' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:db2' => DB_ERROR_UNSUPPORTED,
|
||||
'pgsql:pgsql' => 'array',
|
||||
'sqlite:sqlite' => DB_ERROR_UNSUPPORTED,
|
||||
'sybase:sybase' => DB_ERROR_UNSUPPORTED,
|
||||
),
|
||||
'schema.tables' => array(
|
||||
'dbase:dbase' => DB_ERROR_UNSUPPORTED,
|
||||
'fbsql:fbsql' => DB_ERROR_UNSUPPORTED,
|
||||
'ibase:ibase' => DB_ERROR_UNSUPPORTED,
|
||||
'ibase:firebird' => DB_ERROR_UNSUPPORTED,
|
||||
'ifx:ifx' => DB_ERROR_UNSUPPORTED,
|
||||
'msql:msql' => DB_ERROR_UNSUPPORTED,
|
||||
'mssql:mssql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysql:mysql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysqli:mysqli' => DB_ERROR_UNSUPPORTED,
|
||||
'oci8:oci8' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:access' => 'array',
|
||||
'odbc:db2' => 'array',
|
||||
'pgsql:pgsql' => 'array',
|
||||
'sqlite:sqlite' => DB_ERROR_UNSUPPORTED,
|
||||
'sybase:sybase' => DB_ERROR_UNSUPPORTED,
|
||||
),
|
||||
'synonyms' => array(
|
||||
'dbase:dbase' => DB_ERROR_UNSUPPORTED,
|
||||
'fbsql:fbsql' => DB_ERROR_UNSUPPORTED,
|
||||
'ibase:ibase' => DB_ERROR_UNSUPPORTED,
|
||||
'ibase:firebird' => DB_ERROR_UNSUPPORTED,
|
||||
'ifx:ifx' => DB_ERROR_UNSUPPORTED,
|
||||
'msql:msql' => DB_ERROR_UNSUPPORTED,
|
||||
'mssql:mssql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysql:mysql' => DB_ERROR_UNSUPPORTED,
|
||||
'mysqli:mysqli' => DB_ERROR_UNSUPPORTED,
|
||||
'oci8:oci8' => 'array',
|
||||
'odbc:access' => DB_ERROR_UNSUPPORTED,
|
||||
'odbc:db2' => DB_ERROR_UNSUPPORTED,
|
||||
'pgsql:pgsql' => DB_ERROR_UNSUPPORTED,
|
||||
'sqlite:sqlite' => DB_ERROR_UNSUPPORTED,
|
||||
'sybase:sybase' => DB_ERROR_UNSUPPORTED,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Determine if the output from the driver matches what we expect
|
||||
*
|
||||
* If things are as we expect, nothing is printed out.
|
||||
*
|
||||
* If things go wrong, print "UNEXPECTED OUTCOME" and display
|
||||
* what happened.
|
||||
*
|
||||
* @param mixed $result the result from getListOf
|
||||
* @param mixed $expected the expected result
|
||||
* @param string $name the name of the current test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function check_output($result, $expected, $name) {
|
||||
if (is_object($result)) {
|
||||
if ($result->getCode() !== $expected) {
|
||||
echo "UNEXPECTED OUTCOME FOR $name...\n";
|
||||
echo $result->getDebugInfo() . "\n";
|
||||
}
|
||||
} else {
|
||||
$type = gettype($result);
|
||||
if ($type != $expected) {
|
||||
if ($expected === DB_ERROR_ACCESS_VIOLATION
|
||||
&& $type == 'array')
|
||||
{
|
||||
// This user has access to the mysql table.
|
||||
// Not a problem
|
||||
} else {
|
||||
echo "UNEXPECTED OUTCOME FOR $name...\n";
|
||||
echo " Expected: $expected\n";
|
||||
echo ' Result: ';
|
||||
print_r($result);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
foreach ($tests as $test => $dbms) {
|
||||
check_output($dbh->getListOf($test),
|
||||
$dbms[$dbh->phptype . ':' . $dbh->dbsyntax],
|
||||
$test);
|
||||
}
|
||||
|
||||
|
||||
drop_table($dbh, 'phptest');
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
46
include/pear/tests/driver/connect.inc
Normal file
46
include/pear/tests/driver/connect.inc
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Connects to the database
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version $Id: connect.inc,v 1.12 2005/02/02 00:40:23 danielc Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Setting of $options and requiring DB are done in setup.inc
|
||||
|
||||
/**
|
||||
* Establish the include_path, DSN's and connection $options
|
||||
*/
|
||||
require_once './setup.inc';
|
||||
|
||||
if (empty($dsns)) {
|
||||
die('At least one element of $dsns must be defined in setup.inc');
|
||||
}
|
||||
|
||||
list($dbms, $dsn) = each($dsns);
|
||||
|
||||
if ($dbms == 'mssql') {
|
||||
ini_set('mssql.textlimit', 4096);
|
||||
ini_set('mssql.textsize', 4096);
|
||||
}
|
||||
|
||||
$dbh =& DB::connect($dsn, $options);
|
||||
if (DB::isError($dbh)) {
|
||||
die('connect.inc: ' . $dbh->toString());
|
||||
}
|
||||
161
include/pear/tests/driver/mktable.inc
Normal file
161
include/pear/tests/driver/mktable.inc
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Creates the <kbd>phptest</kbd> table
|
||||
*
|
||||
* Tries to drop the table first, in case it already exists.
|
||||
*
|
||||
* <pre>
|
||||
* CREATE TABLE phptest (
|
||||
* a INTEGER NULL,
|
||||
* b CHAR(40) DEFAULT 'def' NOT NULL,
|
||||
* c VARCHAR(255) NULL,
|
||||
* d VARCHAR(20) NULL)
|
||||
* </pre>
|
||||
*
|
||||
* Need <kbd>NOT NULL</kbd> on <kbd>b</kbd> to test
|
||||
* <kbd>DB_PORTABILITY_RTRIM</kbd>. MS SQL and Sybase trim output from
|
||||
* <kbd>VARCHAR</kbd>, but not on <kbd>CHAR</kbd>.
|
||||
*
|
||||
* Need <kbd>DEFAULT</kbd> value on <kbd>b</kbd> because Oracle considers
|
||||
* an empty string to be <kbd>NULL</kbd>.
|
||||
*
|
||||
* In Oracle, when using placeholders in <kbd>WHERE</kbd> clauses on
|
||||
* <kbd>CHAR</kbd> columns, the column must have <kbd>RTRIM()</kbd> run on
|
||||
* the column:
|
||||
* <samp>
|
||||
* SELECT * FROM phptest WHERE RTRIM(b) = ?
|
||||
* </samp>
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version $Id: mktable.inc,v 1.19 2005/02/14 23:33:20 danielc Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
/**
|
||||
* Establishes the DB object and connects to the database
|
||||
*/
|
||||
require_once './connect.inc';
|
||||
|
||||
/**
|
||||
* Get the drop_table() function
|
||||
*/
|
||||
require_once './droptable.inc';
|
||||
|
||||
/**
|
||||
* The error handler for the drop table procedure
|
||||
*
|
||||
* Prints out an error message and dies.
|
||||
*/
|
||||
function debug_die($o){
|
||||
die($o->toString());
|
||||
}
|
||||
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
drop_table($dbh, 'phptest');
|
||||
|
||||
//$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
|
||||
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'debug_die');
|
||||
|
||||
if ($dbh->phptype == 'odbc') {
|
||||
if ($dbh->dbsyntax == 'odbc') {
|
||||
$type = $dbh->phptype;
|
||||
} else {
|
||||
$type = $dbh->dbsyntax;
|
||||
}
|
||||
} else {
|
||||
$type = $dbh->phptype;
|
||||
}
|
||||
|
||||
|
||||
switch ($type) {
|
||||
case 'access':
|
||||
$null = 'NULL';
|
||||
$chrc = 'VARCHAR(255)';
|
||||
$chrd = 'VARCHAR(20)';
|
||||
$default = '';
|
||||
$tabletype = '';
|
||||
break;
|
||||
case 'db2':
|
||||
case 'ibase':
|
||||
$null = '';
|
||||
$chrc = 'VARCHAR(255)';
|
||||
$chrd = 'VARCHAR(20)';
|
||||
$default = "DEFAULT 'def' NOT NULL";
|
||||
$tabletype = '';
|
||||
break;
|
||||
case 'fbsql':
|
||||
$null = '';
|
||||
$chrc = 'CHAR(255)';
|
||||
$chrd = 'CHAR(20)';
|
||||
$default = "DEFAULT 'def' NOT NULL";
|
||||
$date_literal = ' DATE ';
|
||||
$tabletype = '';
|
||||
break;
|
||||
case 'ifx':
|
||||
// doing this for ifx to keep certain versions happy
|
||||
$null = '';
|
||||
$chrc = 'CHAR(255)';
|
||||
$chrd = 'CHAR(20)';
|
||||
$default = "DEFAULT 'def' NOT NULL";
|
||||
$tabletype = '';
|
||||
break;
|
||||
case 'msql':
|
||||
$null = '';
|
||||
$chrc = 'CHAR(255)';
|
||||
$chrd = 'CHAR(20)';
|
||||
$default = '';
|
||||
$tabletype = '';
|
||||
break;
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
$null = 'NULL';
|
||||
$chrc = 'VARCHAR(255)';
|
||||
$chrd = 'VARCHAR(20)';
|
||||
$default = "DEFAULT 'def' NOT NULL";
|
||||
if (!empty($needinnodb)) {
|
||||
$tabletype = 'TYPE=INNODB';
|
||||
} else {
|
||||
$tabletype = '';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$null = 'NULL';
|
||||
$chrc = 'VARCHAR(255)';
|
||||
$chrd = 'VARCHAR(20)';
|
||||
$default = "DEFAULT 'def' NOT NULL";
|
||||
$tabletype = '';
|
||||
}
|
||||
|
||||
switch ($dbh->phptype) {
|
||||
case 'dbase':
|
||||
// file exists or was created in DB_dbase::connect()
|
||||
break;
|
||||
default:
|
||||
$test_mktable_query = "
|
||||
CREATE TABLE phptest (
|
||||
a INTEGER $null,
|
||||
b CHAR(40) $default,
|
||||
c $chrc $null,
|
||||
d $chrd $null) $tabletype
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
$dbh->query($test_mktable_query);
|
||||
$dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
|
||||
|
||||
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
83
include/pear/tests/driver/multiconnect.php
Normal file
83
include/pear/tests/driver/multiconnect.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests the various ways DB's connect() function operates
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version $Id: multiconnect.php,v 1.2 2005/02/03 05:49:45 danielc Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
* @since File available since Release 1.7.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Establish the include_path, DSN's and connection $options
|
||||
*/
|
||||
require_once './setup.inc';
|
||||
|
||||
foreach ($dsns as $dbms => $dsn) {
|
||||
echo "======== $dbms ========\n";
|
||||
$options['persistent'] = false;
|
||||
$dbh =& DB::connect($dsn, $options);
|
||||
if (DB::isError($dbh)) {
|
||||
echo 'PROBLEM: ' . $dbh->getUserInfo() . "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($dbh->provides('new_link')
|
||||
&& version_compare(phpversion(), $dbh->provides('new_link'), '>='))
|
||||
{
|
||||
$probs = false;
|
||||
$dsn = DB::parseDSN($dsn);
|
||||
$dsn['new_link'] = true;
|
||||
$dbh =& DB::connect($dsn, $options);
|
||||
if (DB::isError($dbh)) {
|
||||
echo 'NEW LINK PROBLEM: ' . $dbh->getUserInfo() . "\n";
|
||||
$probs = true;
|
||||
}
|
||||
|
||||
if ($dbh->provides('pconnect')) {
|
||||
$options['persistent'] = true;
|
||||
$dbh->disconnect();
|
||||
$dbh =& DB::connect($dsn, $options);
|
||||
if (DB::isError($dbh)) {
|
||||
echo 'PERSIST NEWCON PROBLEM: ' . $dbh->getUserInfo() . "\n";
|
||||
$probs = true;
|
||||
}
|
||||
|
||||
unset($dsn['new_link']);
|
||||
$dbh->disconnect();
|
||||
$dbh =& DB::connect($dsn, $options);
|
||||
if (DB::isError($dbh)) {
|
||||
echo 'PERSIST OLDCON PROBLEM: ' . $dbh->getUserInfo() . "\n";
|
||||
$probs = true;
|
||||
}
|
||||
}
|
||||
if ($probs) {
|
||||
continue;
|
||||
}
|
||||
$dbh->disconnect();
|
||||
|
||||
} elseif ($dbh->provides('pconnect')) {
|
||||
$options['persistent'] = true;
|
||||
$dbh->disconnect();
|
||||
$dbh =& DB::connect($dsn, $options);
|
||||
if (DB::isError($dbh)) {
|
||||
echo 'PERSIST PROBLEM: ' . $dbh->getUserInfo() . "\n";
|
||||
continue;
|
||||
}
|
||||
$dbh->disconnect();
|
||||
}
|
||||
echo "GOOD\n";
|
||||
}
|
||||
40
include/pear/tests/driver/run.cvs
Normal file
40
include/pear/tests/driver/run.cvs
Normal file
@@ -0,0 +1,40 @@
|
||||
#! /bin/sh
|
||||
|
||||
# $Id: run.cvs,v 1.2 2004/02/20 18:57:52 danielc Exp $
|
||||
|
||||
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
||||
# PEAR DB TEST STARTER
|
||||
#
|
||||
# To run all tests: ./run
|
||||
# To run one test: ./run <test file name>
|
||||
# Example: ./run db_parsedsn.phpt
|
||||
#
|
||||
# Before running the tests you must adjust the
|
||||
# following three variables:
|
||||
|
||||
# The full path to your PHP directory:
|
||||
DB_TEST_PHP_PATH=c:/progra~1/php
|
||||
|
||||
# The name of your PHP CLI executable
|
||||
# (examples php.exe, php-cli.exe, cli/php.exe):
|
||||
DB_TEST_PHP_CLI=php.exe
|
||||
|
||||
# The full path to the present directory
|
||||
# (not using $PWD due to Cygwin):
|
||||
DB_TEST_DIR=d:/peartest/pear/DB/tests/driver
|
||||
|
||||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
|
||||
TEST_PHP_EXECUTABLE=$DB_TEST_PHP_PATH/$DB_TEST_PHP_CLI
|
||||
export TEST_PHP_EXECUTABLE
|
||||
|
||||
if [ $# -gt 0 ]
|
||||
then
|
||||
test=$1
|
||||
else
|
||||
test=*.phpt
|
||||
fi
|
||||
|
||||
$TEST_PHP_EXECUTABLE $DB_TEST_PHP_PATH/run-tests.php $DB_TEST_DIR/${test}
|
||||
115
include/pear/tests/driver/setup.inc.cvs
Normal file
115
include/pear/tests/driver/setup.inc.cvs
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Establishes the include_path, DSN's and connection $options
|
||||
*
|
||||
* If this file is named "setup.inc.cvs," it is the original one from CVS.
|
||||
* Please do the following:
|
||||
* 1) Make a copy of this file named "setup.inc".
|
||||
* 2) Then, in the copy, edit the $dsns array as appropriate for your
|
||||
* environment.
|
||||
* 3) At least one element of the $dsns array needs to be uncommented.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version $Id: setup.inc.cvs,v 1.6 2005/02/14 23:33:20 danielc Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
if (!defined('PATH_SEPARATOR')) {
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
/**
|
||||
* The string used to delimit elements of the path.
|
||||
*/
|
||||
define('PATH_SEPARATOR', ';');
|
||||
} else {
|
||||
/**
|
||||
* The string used to delimit elements of the path.
|
||||
*/
|
||||
define('PATH_SEPARATOR', ':');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the path to your PEAR installation is found in the left hand
|
||||
* portion of the if() expression below, that means this file has
|
||||
* come from the PEAR installer. Therefore, let's use the
|
||||
* installed version of DB, which should be found via the
|
||||
* computer's default include_path. Add '.' to the include_path
|
||||
* to ensure '.' is in there.
|
||||
*
|
||||
* If the path has not been substituted in the if() expression,
|
||||
* this file has likely come from a CVS checkout or a .tar file.
|
||||
* Therefore, we'll assume the tests should use the version of
|
||||
* DB that has come from there as well.
|
||||
*/
|
||||
if ('@include_path@' != '@'.'include_path'.'@') {
|
||||
ini_set('include_path', ini_get('include_path')
|
||||
. PATH_SEPARATOR . '.'
|
||||
);
|
||||
} else {
|
||||
ini_set('include_path', realpath(dirname(__FILE__) . '/../..')
|
||||
. PATH_SEPARATOR . '.' . PATH_SEPARATOR
|
||||
. ini_get('include_path')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the PEAR DB classes.
|
||||
*/
|
||||
require_once 'DB.php';
|
||||
|
||||
// Options used when connecting
|
||||
$options = array(
|
||||
//'optimize' => 'portability',
|
||||
'portability' => DB_PORTABILITY_ALL,
|
||||
'debug' => 2,
|
||||
);
|
||||
|
||||
$dbasedsn = array(
|
||||
'phptype' => 'dbase',
|
||||
'database' => '/path/and/name/of/dbase/file',
|
||||
'mode' => 2,
|
||||
'fields' => array(
|
||||
array('a', 'N', 5, 0),
|
||||
array('b', 'C', 40),
|
||||
array('c', 'C', 255),
|
||||
array('d', 'C', 20),
|
||||
),
|
||||
);
|
||||
|
||||
/*
|
||||
* Uncomment at least one of the following elements.
|
||||
* When running the .phpt tests, the first uncommented element is used.
|
||||
* When running the multiconnect.php test, all uncommented elements are used.
|
||||
*/
|
||||
$dsns = array(
|
||||
// 'dbase' => $dbasedsn,
|
||||
// 'fbsql' => 'fbsql://_system:@/db',
|
||||
// 'firebird' => 'ibase(firebird)://SYSDBA:masterkey@//opt/interbase/examples/employee.gdb?dialect=3',
|
||||
// 'ifx' => 'ifx://user:pw@localhost/db',
|
||||
// 'msql' => 'msql:///db',
|
||||
|
||||
// It's advisable to use only one of the following at a time:
|
||||
// 'mssql' => 'mssql://sa@somehost/pubs',
|
||||
// 'sybase' => 'sybase://sa@somehost/pubs',
|
||||
|
||||
// 'mysql' => 'mysql://root@localhost/test',
|
||||
// 'mysqli' => 'mysqli://root@localhost/test',
|
||||
// 'oci8' => 'oci8://system:manager@',
|
||||
// 'access' => 'odbc(access)://admin@/SystemDsnName',
|
||||
// 'db2' => 'odbc(db2)://db2inst1:XXXX@/SAMPLE',
|
||||
// 'pgsql' => 'pgsql://postgres@localhost/test',
|
||||
// 'sqlite' => 'sqlite://dummy:@localhost/' . getcwd() . DIRECTORY_SEPARATOR . 'test.db?mode=0644',
|
||||
);
|
||||
37
include/pear/tests/driver/skipif.inc
Normal file
37
include/pear/tests/driver/skipif.inc
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A test to make sure the database can be connected to
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Database
|
||||
* @package DB
|
||||
* @author Daniel Convissor <danielc@php.net>
|
||||
* @copyright 1997-2005 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version $Id: skipif.inc,v 1.7 2005/02/02 00:40:23 danielc Exp $
|
||||
* @link http://pear.php.net/package/DB
|
||||
*/
|
||||
|
||||
/**
|
||||
* Establish the include_path, DSN's and connection $options
|
||||
*/
|
||||
require_once './setup.inc';
|
||||
|
||||
if (empty($dsns)) {
|
||||
die('skip At least one element of $dsns must be defined in setup.inc');
|
||||
}
|
||||
|
||||
list($dbms, $dsn) = each($dsns);
|
||||
|
||||
$dbh =& DB::connect($dsn, $options);
|
||||
if (DB::isError($dbh)) {
|
||||
die('skip ' . $dbh->message);
|
||||
}
|
||||
Reference in New Issue
Block a user