diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/pdo_sqlite/tests | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/pdo_sqlite/tests')
24 files changed, 803 insertions, 0 deletions
diff --git a/ext/pdo_sqlite/tests/bug33841.phpt b/ext/pdo_sqlite/tests/bug33841.phpt new file mode 100644 index 0000000..d472af7 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug33841.phpt @@ -0,0 +1,28 @@ +--TEST-- +PDO SQLite Bug #33841 (rowCount() does not work on prepared statements) +--SKIPIF-- +<?php # vim:ft=php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?php +require dirname(__FILE__) . '/../../../ext/pdo/tests/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()); + +--EXPECT-- +bool(true) +int(1) +bool(true) +int(1) diff --git a/ext/pdo_sqlite/tests/bug35336.phpt b/ext/pdo_sqlite/tests/bug35336.phpt new file mode 100644 index 0000000..59dbda3 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug35336.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #35336 (crash on PDO::FETCH_CLASS + __set()) +--SKIPIF-- +<?php # vim:ft=php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?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"; +?> +--EXPECTF-- +hello world +hello world +Done diff --git a/ext/pdo_sqlite/tests/bug43831.phpt b/ext/pdo_sqlite/tests/bug43831.phpt new file mode 100644 index 0000000..2746e7c --- /dev/null +++ b/ext/pdo_sqlite/tests/bug43831.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #43831 ($this gets mangled when extending PDO with persistent connection) +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?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); + + +?> +--EXPECTF-- +Bar +Bar +object(MyPDO)#%d (0) { +} +object(MyPDO)#%d (0) { +} + +Notice: Undefined variable: bar in %s on line %d +NULL diff --git a/ext/pdo_sqlite/tests/bug44327_2.phpt b/ext/pdo_sqlite/tests/bug44327_2.phpt new file mode 100644 index 0000000..4add073 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug44327_2.phpt @@ -0,0 +1,50 @@ +--TEST-- +Bug #44327.2 (PDORow::queryString property & numeric offsets / Crash) +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?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); + +?> +--EXPECTF-- +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" diff --git a/ext/pdo_sqlite/tests/bug44327_3.phpt b/ext/pdo_sqlite/tests/bug44327_3.phpt new file mode 100644 index 0000000..86f5642 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug44327_3.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #44327.3 (PDORow::queryString property & numeric offsets / Crash) +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?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}); + +?> +--EXPECTF-- +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 diff --git a/ext/pdo_sqlite/tests/bug46139.phpt b/ext/pdo_sqlite/tests/bug46139.phpt new file mode 100644 index 0000000..c361d7a --- /dev/null +++ b/ext/pdo_sqlite/tests/bug46139.phpt @@ -0,0 +1,42 @@ +--TEST-- +Bug #46139 (PDOStatement->setFetchMode() forgets FETCH_PROPS_LATE) +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?php + +require dirname(__FILE__) . '/../../../ext/pdo/tests/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); + +?> +--EXPECT-- +NULL +'foo' +NULL +'foo' +NULL +'foo' diff --git a/ext/pdo_sqlite/tests/bug46542.phpt b/ext/pdo_sqlite/tests/bug46542.phpt new file mode 100644 index 0000000..2de0c05 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug46542.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #46542 Extending PDO class with a __call() function +--SKIPIF-- +<?php # vim:ft=php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?php +class A extends PDO +{ function __call($m, $p) {print __CLASS__."::$m\n";} } + +$a = new A('sqlite:' . __DIR__ . '/dummy.db'); + +$a->truc(); +$a->TRUC(); + +?> +--CLEAN-- +<?php +unlink(__DIR__ . '/dummy.db'); +?> +--EXPECT-- +A::truc +A::TRUC diff --git a/ext/pdo_sqlite/tests/bug48773.phpt b/ext/pdo_sqlite/tests/bug48773.phpt new file mode 100644 index 0000000..b8bdea9 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug48773.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #48773 (Incorrect error when setting PDO::ATTR_STATEMENT_CLASS with ctor_args) +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?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); + +?> +--EXPECTF-- +object(bar)#%d (1) { + [%u|b%"queryString"]=> + %unicode|string%(8) "SELECT 1" +} diff --git a/ext/pdo_sqlite/tests/bug50728.phpt b/ext/pdo_sqlite/tests/bug50728.phpt new file mode 100644 index 0000000..3dbbb1f --- /dev/null +++ b/ext/pdo_sqlite/tests/bug50728.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #50728 (All PDOExceptions hardcode 'code' property to 0) +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?php +try { + $a = new PDO("sqlite:/this/path/should/not/exist.db"); +} catch (PDOException $e) { + var_dump($e->getCode()); +} +?> +--EXPECTF-- +int(14) diff --git a/ext/pdo_sqlite/tests/bug52487.phpt b/ext/pdo_sqlite/tests/bug52487.phpt new file mode 100644 index 0000000..fc65bd3 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug52487.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #52487 (PDO::FETCH_INTO leaks memory) +--SKIPIF-- +<?php # vim:ft=php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?php +require dirname(__FILE__) . '/../../../ext/pdo/tests/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"; + +?> +--EXPECT-- +ok diff --git a/ext/pdo_sqlite/tests/bug60104.phpt b/ext/pdo_sqlite/tests/bug60104.phpt new file mode 100644 index 0000000..fd36b57 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug60104.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #60104 (Segmentation Fault in pdo_sqlite when using sqliteCreateFunction()) +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?php +function setUp() +{ + $handler = new PDO( "sqlite::memory:" ); + $handler->sqliteCreateFunction( "md5", "md5", 1 ); + unset( $handler ); +} + +setUp(); +setUp(); +echo "done"; +?> +--EXPECTF-- +done diff --git a/ext/pdo_sqlite/tests/bug_42589.phpt b/ext/pdo_sqlite/tests/bug_42589.phpt new file mode 100644 index 0000000..abd5e8c --- /dev/null +++ b/ext/pdo_sqlite/tests/bug_42589.phpt @@ -0,0 +1,23 @@ +--TEST-- +PDO SQLite Feature Request #42589 (getColumnMeta() should also return table name) +--SKIPIF-- +<?php +if (!extension_loaded('pdo') || !extension_loaded('pdo_sqlite')) die('skip not loaded'); +?> +--FILE-- +<?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'); +?> +--EXPECTF-- +bool(true) +bool(true) diff --git a/ext/pdo_sqlite/tests/bug_63916-2.phpt b/ext/pdo_sqlite/tests/bug_63916-2.phpt new file mode 100644 index 0000000..bc9bfc9 --- /dev/null +++ b/ext/pdo_sqlite/tests/bug_63916-2.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #63916 PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) die('skip'); +if (PHP_INT_SIZE > 4) die('skip'); +?> +--FILE-- +<?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]); + +?> +--EXPECT-- +int(2147483647) +string(10) "2147483647" diff --git a/ext/pdo_sqlite/tests/bug_63916.phpt b/ext/pdo_sqlite/tests/bug_63916.phpt new file mode 100644 index 0000000..582413d --- /dev/null +++ b/ext/pdo_sqlite/tests/bug_63916.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #63916 PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) die('skip'); +if (PHP_INT_SIZE < 8) die('skip'); +?> +--FILE-- +<?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]); + +?> +--EXPECT-- +int(100004313234244) +string(15) "100004313234244" diff --git a/ext/pdo_sqlite/tests/common.phpt b/ext/pdo_sqlite/tests/common.phpt new file mode 100644 index 0000000..65ea0c9 --- /dev/null +++ b/ext/pdo_sqlite/tests/common.phpt @@ -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' + ); diff --git a/ext/pdo_sqlite/tests/debugdumpparams_001.phpt b/ext/pdo_sqlite/tests/debugdumpparams_001.phpt new file mode 100644 index 0000000..3e51b53 --- /dev/null +++ b/ext/pdo_sqlite/tests/debugdumpparams_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +Testing PDOStatement::debugDumpParams() with bound params +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?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()); + +?> +--EXPECT-- +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 diff --git a/ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt b/ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt new file mode 100644 index 0000000..efcb2e7 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt @@ -0,0 +1,130 @@ +--TEST-- +Testing several callbacks using PDO::FETCH_FUNC +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; +?> +--FILE-- +<?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'))); + +?> +--EXPECTF-- +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) "" +} + +Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: function 'nothing' not found or invalid function name in %s on line %d +bool(false) + +Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: function '' not found or invalid function name in %s on line %d +bool(false) + +Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: no array or string given in %s on line %d +bool(false) + +Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: no array or string given in %s on line %d +bool(false) + +Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: cannot access self:: when no class scope is active in %s on line %d +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---" +} + +Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: cannot access private method bar::test2() in %s on line %d +bool(false) +array(2) { + [0]=> + %string|unicode%(7) "1===php" + [1]=> + %string|unicode%(4) "2===" +} + +Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: class 'bar' does not have a method 'inexistent' in %s on line %d +bool(false) diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt new file mode 100644 index 0000000..975dcd9 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt @@ -0,0 +1,31 @@ +--TEST-- +PDO_sqlite: Testing sqliteCreateAggregate() +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?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'); + +?> +--EXPECTF-- +array(2) { + ["testing(name)"]=> + %string|unicode%(2) "12" + [0]=> + %string|unicode%(2) "12" +} diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate_002.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate_002.phpt new file mode 100644 index 0000000..671e4b3 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate_002.phpt @@ -0,0 +1,17 @@ +--TEST-- +PDO_sqlite: Testing invalid callback for sqliteCreateAggregate() +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?php + +$pdo = new PDO('sqlite::memory:'); + +$pdo->sqliteCreateAggregate('foo', 'a', ''); +$pdo->sqliteCreateAggregate('foo', 'strlen', ''); + +?> +--EXPECTF-- +Warning: PDO::sqliteCreateAggregate(): function 'a' is not callable in %s on line %d + +Warning: PDO::sqliteCreateAggregate(): function '' is not callable in %s on line %d diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createcollation.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createcollation.phpt new file mode 100644 index 0000000..c35e363 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_createcollation.phpt @@ -0,0 +1,38 @@ +--TEST-- +PDO_sqlite: Testing sqliteCreateCollation() +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?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'); + +?> +--EXPECTF-- +1 +2 +10 +1 +10 +2 diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt new file mode 100644 index 0000000..b675879 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt @@ -0,0 +1,38 @@ +--TEST-- +PDO_sqlite: Testing sqliteCreateFunction() +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?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'); + +?> +--EXPECTF-- +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" +} diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_get_attribute.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_get_attribute.phpt new file mode 100644 index 0000000..d6e095d --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_get_attribute.phpt @@ -0,0 +1,15 @@ +--TEST-- +PDO_sqlite: Testing getAttribute() +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?php + +$pdo = new PDO('sqlite::memory:'); +var_dump($pdo->getAttribute(PDO::ATTR_SERVER_VERSION)); +var_dump($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION)); + +?> +--EXPECTF-- +string(%d) "%s" +string(%d) "%s" diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt new file mode 100644 index 0000000..2ff0acd --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt @@ -0,0 +1,32 @@ +--TEST-- +PDO_sqlite: Testing lastInsertId() +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?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'); + +?> +--EXPECTF-- +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" diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt new file mode 100644 index 0000000..101cc73 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt @@ -0,0 +1,28 @@ +--TEST-- +PDO_sqlite: Testing transaction +--SKIPIF-- +<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?> +--FILE-- +<?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'); + +?> +--EXPECTF-- +int(0) |