import zend pdo_sqlite tests

Esse commit está contido em:
Paul Tarjan
2013-04-23 23:51:54 -07:00
commit de Sara Golemon
commit 8cf864ef14
48 arquivos alterados com 624 adições e 2 exclusões
@@ -0,0 +1,38 @@
<?php
class Foo extends PDO {
function __construct($dsn) {
parent::__construct($dsn, null, null, array(PDO::ATTR_PERSISTENT => true));
}
}
class Baz extends PDO {
function __construct($dsn) {
parent::__construct($dsn, null, null, array(PDO::ATTR_PERSISTENT => true));
}
}
class Bar extends Baz {
function quux() {
echo get_class($this), "\n";
$foo = new Foo("sqlite::memory:");
echo get_class($this), "\n";
}
}
$bar = new Bar("sqlite::memory:");
$bar->quux();
class MyPDO extends PDO {}
$bar = new PDO("sqlite::memory:", null, null, array(PDO::ATTR_PERSISTENT => true));
$baz = new MyPDO("sqlite::memory:", null, null, array(PDO::ATTR_PERSISTENT => true));
var_dump($bar);
unset($bar);
var_dump($baz);
var_dump($bar);
?>
@@ -0,0 +1,8 @@
Bar
Bar
object(MyPDO)#%d (0) {
}
object(MyPDO)#%d (0) {
}
HipHop Notice: %a
NULL
@@ -0,0 +1,19 @@
<?php
$db = new pdo('sqlite::memory:');
$x = $db->query('select 1 as queryString');
var_dump($x, $x->queryString);
$y = $x->fetch();
var_dump($y, @$y->queryString);
print "--------------------------------------------\n";
$x = $db->query('select 1 as queryString');
var_dump($x, $x->queryString);
$y = $x->fetch(PDO::FETCH_LAZY);
var_dump($y, $y->queryString);
?>
@@ -0,0 +1,23 @@
object(PDOStatement)#%d (1) {
["queryString"]=>
string(23) "select 1 as queryString"
}
string(23) "select 1 as queryString"
array(2) {
["queryString"]=>
string(1) "1"
[0]=>
string(1) "1"
}
NULL
--------------------------------------------
object(PDOStatement)#%d (1) {
["queryString"]=>
string(23) "select 1 as queryString"
}
string(23) "select 1 as queryString"
object(PDORow)#%d (1) {
["queryString"]=>
string(1) "1"
}
string(1) "1"
@@ -0,0 +1,13 @@
<?php
$db = new pdo('sqlite::memory:');
$x = $db->query('select 1 as queryStringxx');
$y = $x->fetch(PDO::FETCH_LAZY);
var_dump($y, $y->queryString, $y->queryStringzz, $y->queryStringxx);
print "---\n";
var_dump($y[5], $y->{3});
?>
@@ -0,0 +1,12 @@
object(PDORow)#%d (2) {
["queryString"]=>
string(25) "select 1 as queryStringxx"
["queryStringxx"]=>
string(1) "1"
}
string(25) "select 1 as queryStringxx"
NULL
string(1) "1"
---
NULL
NULL
@@ -0,0 +1,22 @@
<?php
class bar extends PDOStatement {
private function __construct() {
}
}
class foo extends PDO {
public $statementClass = 'bar';
function __construct($dsn, $username, $password, $driver_options = array()) {
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
parent::__construct($dsn, $username, $password, $driver_options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($this->statementClass, array($this)));
}
}
$db = new foo('sqlite::memory:', '', '');
$stmt = $db->query('SELECT 1');
var_dump($stmt);
?>
@@ -0,0 +1,4 @@
object(bar)#%d (1) {
[%u|b%"queryString"]=>
%unicode|string%(8) "SELECT 1"
}
@@ -0,0 +1,7 @@
<?php
try {
$a = new PDO("sqlite:/this/path/should/not/exist.db");
} catch (PDOException $e) {
var_dump($e->getCode());
}
?>
@@ -0,0 +1 @@
int(14)
@@ -0,0 +1,12 @@
<?php
function setUp()
{
$handler = new PDO( "sqlite::memory:" );
$handler->sqliteCreateFunction( "md5", "md5", 1 );
unset( $handler );
}
setUp();
setUp();
echo "done";
?>
@@ -0,0 +1 @@
done
@@ -0,0 +1,13 @@
<?php
$db = new PDO("sqlite::memory:");
$db->exec('CREATE TABLE test (field1 VARCHAR(10))');
$db->exec('INSERT INTO test VALUES("test")');
$result = $db->query('SELECT * FROM test t1 LEFT JOIN test t2 ON t1.field1 = t2.field1');
$meta1 = $result->getColumnMeta(0);
$meta2 = $result->getColumnMeta(1);
var_dump(!empty($meta1['table']) && $meta1['table'] == 'test');
var_dump(!empty($meta2['table']) && $meta2['table'] == 'test');
?>
@@ -0,0 +1,2 @@
bool(true)
bool(true)
@@ -0,0 +1,16 @@
<?php
$num = PHP_INT_MAX; // 32 bits
$conn = new PDO('sqlite::memory:');
$conn->query('CREATE TABLE users (id INTEGER NOT NULL, num INTEGER NOT NULL, PRIMARY KEY(id))');
$stmt = $conn->prepare('insert into users (id, num) values (:id, :num)');
$stmt->bindValue(':id', 1, PDO::PARAM_INT);
$stmt->bindValue(':num', $num, PDO::PARAM_INT);
$stmt->execute();
$stmt = $conn->query('SELECT num FROM users');
$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
var_dump($num,$result[0]);
?>
@@ -0,0 +1,2 @@
int(2147483647)
string(10) "2147483647"
@@ -0,0 +1,16 @@
<?php
$num = 100004313234244; // exceeds 32 bits
$conn = new PDO('sqlite::memory:');
$conn->query('CREATE TABLE users (id INTEGER NOT NULL, num INTEGER NOT NULL, PRIMARY KEY(id))');
$stmt = $conn->prepare('insert into users (id, num) values (:id, :num)');
$stmt->bindValue(':id', 1, PDO::PARAM_INT);
$stmt->bindValue(':num', $num, PDO::PARAM_INT);
$stmt->execute();
$stmt = $conn->query('SELECT num FROM users');
$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
var_dump($num,$result[0]);
?>
@@ -0,0 +1,2 @@
int(100004313234244)
string(15) "100004313234244"
@@ -0,0 +1,11 @@
<?php
$db = new pdo('sqlite::memory:');
$x= $db->prepare('select :a, :b, ?');
$x->bindValue(':a', 1, PDO::PARAM_INT);
$x->bindValue(':b', 'foo');
$x->bindValue(3, 1313);
var_dump($x->debugDumpParams());
?>
@@ -0,0 +1,18 @@
SQL: [16] select :a, :b, ?
Params: 3
Key: Name: [2] :a
paramno=-1
name=[2] ":a"
is_param=1
param_type=1
Key: Name: [2] :b
paramno=-1
name=[2] ":b"
is_param=1
param_type=2
Key: Position #2:
paramno=2
name=[0] ""
is_param=1
param_type=2
NULL
@@ -0,0 +1,67 @@
<?php
$db = new PDO('sqlite::memory:');
$db->exec('CREATE TABLE testing (id INTEGER , name VARCHAR)');
$db->exec('INSERT INTO testing VALUES(1, "php")');
$db->exec('INSERT INTO testing VALUES(2, "")');
$st = $db->query('SELECT * FROM testing');
$st->fetchAll(PDO::FETCH_FUNC, function($x, $y) use ($st) { var_dump($st); print "data: $x, $y\n"; });
$st = $db->query('SELECT name FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, 'strtoupper'));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, 'nothing'));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, ''));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, NULL));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, 1));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('self', 'foo')));
class foo {
public function foo($x) {
return "--- $x ---";
}
}
class bar extends foo {
public function __construct($db) {
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array($this, 'parent::foo')));
}
static public function test($x, $y) {
return $x .'---'. $y;
}
private function test2($x, $y) {
return $x;
}
public function test3($x, $y) {
return $x .'==='. $y;
}
}
new bar($db);
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test')));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test2')));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test3')));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'inexistent')));
?>
@@ -0,0 +1,48 @@
object(PDOStatement)#%d (1) {
[%u|b%"queryString"]=>
%string|unicode%(21) "SELECT * FROM testing"
}
data: 1, php
object(PDOStatement)#%d (1) {
[%u|b%"queryString"]=>
%string|unicode%(21) "SELECT * FROM testing"
}
data: 2,
array(2) {
[0]=>
%string|unicode%(3) "PHP"
[1]=>
%string|unicode%(0) ""
}
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
array(2) {
[0]=>
%string|unicode%(9) "--- 1 ---"
[1]=>
%string|unicode%(9) "--- 2 ---"
}
array(2) {
[0]=>
%string|unicode%(7) "1---php"
[1]=>
%string|unicode%(4) "2---"
}
HipHop Warning: %a
bool(false)
array(2) {
[0]=>
%string|unicode%(7) "1===php"
[1]=>
%string|unicode%(4) "2==="
}
HipHop Warning: %a
bool(false)
@@ -0,0 +1,19 @@
<?php
$db = new pdo('sqlite::memory:');
$db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)');
$db->query('INSERT INTO foobar VALUES (NULL, "PHP")');
$db->query('INSERT INTO foobar VALUES (NULL, "PHP6")');
$db->sqliteCreateAggregate('testing', function(&$a, $b) { $a .= $b; return $a; }, function(&$v) { return $v; });
foreach ($db->query('SELECT testing(name) FROM foobar') as $row) {
var_dump($row);
}
$db->query('DROP TABLE foobar');
?>
@@ -0,0 +1,6 @@
array(2) {
["testing(name)"]=>
%string|unicode%(2) "12"
[0]=>
%string|unicode%(2) "12"
}
@@ -0,0 +1,8 @@
<?php
$pdo = new PDO('sqlite::memory:');
$pdo->sqliteCreateAggregate('foo', 'a', '');
$pdo->sqliteCreateAggregate('foo', 'strlen', '');
?>
@@ -0,0 +1,2 @@
HipHop Warning: %a
HipHop Warning: %a
@@ -0,0 +1,26 @@
<?php
$db = new pdo('sqlite::memory:');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)');
$db->query('INSERT INTO foobar VALUES (NULL, "1")');
$db->query('INSERT INTO foobar VALUES (NULL, "2")');
$db->query('INSERT INTO foobar VALUES (NULL, "10")');
$db->sqliteCreateCollation('MYCOLLATE', function($a, $b) { return strnatcmp($a, $b); });
$result = $db->query('SELECT name FROM foobar ORDER BY name COLLATE MYCOLLATE');
foreach ($result as $row) {
echo $row['name'] . "\n";
}
$result = $db->query('SELECT name FROM foobar ORDER BY name');
foreach ($result as $row) {
echo $row['name'] . "\n";
}
$db->query('DROP TABLE foobar');
?>
@@ -0,0 +1,6 @@
1
2
10
1
10
2
@@ -0,0 +1,20 @@
<?php
$db = new pdo('sqlite::memory:');
$db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)');
$db->query('INSERT INTO foobar VALUES (NULL, "PHP")');
$db->query('INSERT INTO foobar VALUES (NULL, "PHP6")');
$db->sqliteCreateFunction('testing', function($v) { return strtolower($v); });
foreach ($db->query('SELECT testing(name) FROM foobar') as $row) {
var_dump($row);
}
$db->query('DROP TABLE foobar');
?>
@@ -0,0 +1,12 @@
array(2) {
["testing(name)"]=>
%string|unicode%(3) "php"
[0]=>
%string|unicode%(3) "php"
}
array(2) {
["testing(name)"]=>
%string|unicode%(4) "php6"
[0]=>
%string|unicode%(4) "php6"
}
@@ -0,0 +1,13 @@
<?php
$db = new pdo('sqlite::memory:');
$db->query('CREATE TABLE IF NOT EXISTS foo (id INT AUTO INCREMENT, name TEXT)');
$db->query('INSERT INTO foo VALUES (NULL, "PHP")');
$db->query('INSERT INTO foo VALUES (NULL, "PHP6")');
var_dump($db->query('SELECT * FROM foo'));
var_dump($db->errorInfo());
var_dump($db->lastInsertId());
$db->query('DROP TABLE foo');
?>
@@ -0,0 +1,13 @@
object(PDOStatement)#2 (1) {
["queryString"]=>
%string|unicode%(17) "SELECT * FROM foo"
}
array(3) {
[0]=>
%string|unicode%(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
%string|unicode%(1) "2"
@@ -0,0 +1,15 @@
<?php
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
$db->exec('CREATE TABLE test (text)');
$stmt = $db->prepare("INSERT INTO test VALUES ( :text )");
$stmt->bindParam(':text', $name);
$name = 'test1';
var_dump($stmt->execute(), $stmt->rowCount());
$stmt = $db->prepare("UPDATE test SET text = :text ");
$stmt->bindParam(':text', $name);
$name = 'test2';
var_dump($stmt->execute(), $stmt->rowCount());
@@ -0,0 +1,4 @@
bool(true)
int(1)
bool(true)
int(1)
@@ -0,0 +1,15 @@
<?php
class EEE {
function __set ($field, $value) {
echo "hello world\n";
}
}
$a = new PDO("sqlite::memory:");// pool ("sqlite::memory:");
$a->query ("CREATE TABLE test (a integer primary key, b text)");
$b = $a->prepare("insert into test (b) values (?)");
$b->execute(array (5));
$rez = $a->query ("SELECT * FROM test")->fetchAll(PDO::FETCH_CLASS, 'EEE');
echo "Done\n";
?>
@@ -0,0 +1,3 @@
hello world
hello world
Done
@@ -0,0 +1,28 @@
<?php
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
class Person {
public $test = NULL;
public function __construct() {
var_dump($this->test);
}
}
$stmt = $db->query("SELECT 'foo' test, 1");
$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person');
$r1 = $stmt->fetch();
printf("'%s'\n", $r1->test);
$stmt = $db->query("SELECT 'foo' test, 1");
$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person');
$r1 = $stmt->fetchAll();
printf("'%s'\n", $r1[0]->test);
$stmt = $db->query("SELECT 'foo' test, 1");
$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person');
$r1 = $stmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE);
printf("'%s'\n", $r1->test);
?>
@@ -0,0 +1,6 @@
NULL
'foo'
NULL
'foo'
NULL
'foo'
@@ -0,0 +1,12 @@
<?php
class A extends PDO
{ function __call($m, $p) {print __CLASS__."::$m\n";} }
$a = new A('sqlite:' . __DIR__ . '/dummy.db');
$a->truc();
$a->TRUC();
?><?php
unlink(__DIR__ . '/dummy.db');
?>
@@ -0,0 +1,2 @@
A::truc
A::TRUC
@@ -0,0 +1,12 @@
<?php
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
$stmt = $db->prepare("select 1 as attr");
for ($i = 0; $i < 10; $i++) {
$stmt->setFetchMode(PDO::FETCH_INTO, new stdClass);
}
print "ok\n";
?>
@@ -0,0 +1 @@
ok
@@ -0,0 +1,12 @@
--TEST--
SQLite
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded('pdo_sqlite')) print 'skip'; ?>
--REDIRECTTEST--
return array(
'ENV' => array(
'PDOTEST_DSN' => 'sqlite::memory:'
),
'TESTS' => 'ext/pdo/tests'
);
@@ -0,0 +1,7 @@
<?php
$pdo = new PDO('sqlite::memory:');
var_dump($pdo->getAttribute(PDO::ATTR_SERVER_VERSION));
var_dump($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION));
?>
@@ -0,0 +1,2 @@
string(%d) "%s"
string(%d) "%s"
@@ -0,0 +1,21 @@
<?php
$db = new pdo('sqlite::memory:');
$db->beginTransaction();
$db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)');
$db->commit();
$db->beginTransaction();
$db->query('INSERT INTO foobar VALUES (NULL, "PHP")');
$db->query('INSERT INTO foobar VALUES (NULL, "PHP6")');
$db->rollback();
$r = $db->query('SELECT COUNT(*) FROM foobar');
var_dump($r->rowCount());
$db->query('DROP TABLE foobar');
?>
@@ -0,0 +1 @@
int(0)
+3 -2
Ver Arquivo
@@ -78,7 +78,6 @@ no_import = (
'/ext/xmlwriter/examples/',
# not imported yet, but will be
'/ext/pdo_sqlite',
'/ext/spl',
'/ext/standard',
@@ -213,6 +212,8 @@ other_files = (
'/ext-pdo/pdo_test.inc',
'/ext-pdo_mysql/config.inc',
'/ext-pdo_mysql/common.phpt',
'/ext-pdo_sqlite/config.inc',
'/ext-pdo_sqlite/common.phpt',
'/ext-session/save_handler.inc',
'/ext-simplexml/bug24392.xml',
'/ext-soap-bugs/bug30928.wsdl',
@@ -439,7 +440,7 @@ def walk(filename, source):
test = test.replace("_002.xml", "_004.xml")
if 'bug61139.php' in full_dest_filename:
test += "\nunlink('someFile');\n?>"
if '/ext-pdo_mysql/' in full_dest_filename:
if '/ext-pdo_' in full_dest_filename:
test = test.replace('/../../../ext/pdo/tests/pdo_test.inc',
'/../ext-pdo/pdo_test.inc')