summaryrefslogtreecommitdiff
path: root/ext/pdo_sqlite/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pdo_sqlite/tests')
-rw-r--r--ext/pdo_sqlite/tests/bug44327_2.phpt50
-rw-r--r--ext/pdo_sqlite/tests/bug44327_3.phpt33
-rw-r--r--ext/pdo_sqlite/tests/bug46139.phpt42
-rw-r--r--ext/pdo_sqlite/tests/debugdumpparams_001.phpt37
-rw-r--r--ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt31
-rw-r--r--ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt37
-rw-r--r--ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt26
-rw-r--r--ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt26
8 files changed, 282 insertions, 0 deletions
diff --git a/ext/pdo_sqlite/tests/bug44327_2.phpt b/ext/pdo_sqlite/tests/bug44327_2.phpt
new file mode 100644
index 000000000..0e704c573
--- /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 000000000..4d704c3d6
--- /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 000000000..c361d7a9b
--- /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/debugdumpparams_001.phpt b/ext/pdo_sqlite/tests/debugdumpparams_001.phpt
new file mode 100644
index 000000000..c263eb143
--- /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_sqlite_createaggregate.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt
new file mode 100644
index 000000000..8661e3679
--- /dev/null
+++ b/ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt
@@ -0,0 +1,31 @@
+--TEST--
+PDO_sqlite: Testing sqliteCreateAggregate()
+--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")');
+
+function test_a(&$a, $b) { $a .= $b; return $a; }
+function test_b(&$a) { return $a; }
+$db->sqliteCreateAggregate('testing', 'test_a', 'test_b');
+
+
+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_createfunction.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt
new file mode 100644
index 000000000..74a79faed
--- /dev/null
+++ b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt
@@ -0,0 +1,37 @@
+--TEST--
+PDO_sqlite: Testing sqliteCreateFunction()
+--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")');
+
+
+function test($v) { return strtolower($v); }
+$db->sqliteCreateFunction('testing', 'test');
+
+
+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_lastinsertid.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt
new file mode 100644
index 000000000..d930e7f0a
--- /dev/null
+++ b/ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt
@@ -0,0 +1,26 @@
+--TEST--
+PDO_sqlite: Testing lastInsertId()
+--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(1) {
+ [0]=>
+ %string|unicode%(5) "00000"
+}
+%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 000000000..75f416987
--- /dev/null
+++ b/ext/pdo_sqlite/tests/pdo_sqlite_transaction.phpt
@@ -0,0 +1,26 @@
+--TEST--
+PDO_sqlite: Testing transaction
+--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)