summaryrefslogtreecommitdiff
path: root/ext/pdo_sqlite/tests
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-12-23 10:57:19 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-12-23 11:25:31 +0100
commit438b025a28cda2935613af412fc13702883dd3a2 (patch)
treea826f7d6dae1c50889dff1cbc9ed905666a78ef2 /ext/pdo_sqlite/tests
parent012439b78e5dbb41ae90fbdf09ab1d8da50bb9fc (diff)
downloadphp-git-438b025a28cda2935613af412fc13702883dd3a2.tar.gz
Support native types in PDO SQLite
Return integers and floats as native types if possible. As usual, the old behavior can be restored by enabling ATTR_STRINGIFY_FETCHES. Fixes bug #38334.
Diffstat (limited to 'ext/pdo_sqlite/tests')
-rw-r--r--ext/pdo_sqlite/tests/bug38334.phpt46
-rw-r--r--ext/pdo_sqlite/tests/bug44327_2.phpt8
-rw-r--r--ext/pdo_sqlite/tests/bug44327_3.phpt4
-rw-r--r--ext/pdo_sqlite/tests/bug78192.phpt4
-rw-r--r--ext/pdo_sqlite/tests/bug79664.phpt4
-rw-r--r--ext/pdo_sqlite/tests/bug_63916-2.phpt2
-rw-r--r--ext/pdo_sqlite/tests/bug_63916.phpt2
7 files changed, 58 insertions, 12 deletions
diff --git a/ext/pdo_sqlite/tests/bug38334.phpt b/ext/pdo_sqlite/tests/bug38334.phpt
new file mode 100644
index 0000000000..6537a28d19
--- /dev/null
+++ b/ext/pdo_sqlite/tests/bug38334.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Bug #38334: Proper data-type support for PDO_SQLITE
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
+?>
+--FILE--
+<?php
+
+$db = new PDO('sqlite::memory:');
+$db->exec('CREATE TABLE test (i INTEGER , f DOUBLE, s VARCHAR(255))');
+$db->exec('INSERT INTO test VALUES (42, 46.7, "test")');
+var_dump($db->query('SELECT * FROM test')->fetch(PDO::FETCH_ASSOC));
+
+// Check handling of integers larger than 32-bit.
+$db->exec('INSERT INTO test VALUES (10000000000, 0.0, "")');
+$i = $db->query('SELECT i FROM test WHERE f = 0.0')->fetchColumn(0);
+if (PHP_INT_SIZE >= 8) {
+ var_dump($i === 10000000000);
+} else {
+ var_dump($i === '10000000000');
+}
+
+// Check storing of strings into integer/float columns.
+$db->exec('INSERT INTO test VALUES ("test", "test", "x")');
+var_dump($db->query('SELECT * FROM test WHERE s = "x"')->fetch(PDO::FETCH_ASSOC));
+
+?>
+--EXPECT--
+array(3) {
+ ["i"]=>
+ int(42)
+ ["f"]=>
+ float(46.7)
+ ["s"]=>
+ string(4) "test"
+}
+bool(true)
+array(3) {
+ ["i"]=>
+ string(4) "test"
+ ["f"]=>
+ string(4) "test"
+ ["s"]=>
+ string(1) "x"
+}
diff --git a/ext/pdo_sqlite/tests/bug44327_2.phpt b/ext/pdo_sqlite/tests/bug44327_2.phpt
index 531af9586c..a9b428b2cc 100644
--- a/ext/pdo_sqlite/tests/bug44327_2.phpt
+++ b/ext/pdo_sqlite/tests/bug44327_2.phpt
@@ -32,9 +32,9 @@ object(PDOStatement)#%d (1) {
string(23) "select 1 as queryString"
array(2) {
["queryString"]=>
- string(1) "1"
+ int(1)
[0]=>
- string(1) "1"
+ int(1)
}
NULL
--------------------------------------------
@@ -45,6 +45,6 @@ object(PDOStatement)#%d (1) {
string(23) "select 1 as queryString"
object(PDORow)#%d (1) {
["queryString"]=>
- string(1) "1"
+ int(1)
}
-string(1) "1"
+int(1)
diff --git a/ext/pdo_sqlite/tests/bug44327_3.phpt b/ext/pdo_sqlite/tests/bug44327_3.phpt
index 45cdbff0c4..462fbab6dc 100644
--- a/ext/pdo_sqlite/tests/bug44327_3.phpt
+++ b/ext/pdo_sqlite/tests/bug44327_3.phpt
@@ -23,11 +23,11 @@ object(PDORow)#%d (2) {
["queryString"]=>
string(25) "select 1 as queryStringxx"
["queryStringxx"]=>
- string(1) "1"
+ int(1)
}
string(25) "select 1 as queryStringxx"
NULL
-string(1) "1"
+int(1)
---
NULL
NULL
diff --git a/ext/pdo_sqlite/tests/bug78192.phpt b/ext/pdo_sqlite/tests/bug78192.phpt
index defdafb681..be20756d3b 100644
--- a/ext/pdo_sqlite/tests/bug78192.phpt
+++ b/ext/pdo_sqlite/tests/bug78192.phpt
@@ -29,7 +29,7 @@ array(1) {
[0]=>
array(2) {
["id"]=>
- string(2) "10"
+ int(10)
["name"]=>
string(4) "test"
}
@@ -38,7 +38,7 @@ array(1) {
[0]=>
array(3) {
["id"]=>
- string(2) "10"
+ int(10)
["name"]=>
string(4) "test"
["new_col"]=>
diff --git a/ext/pdo_sqlite/tests/bug79664.phpt b/ext/pdo_sqlite/tests/bug79664.phpt
index a3648099dc..6c7b0e7740 100644
--- a/ext/pdo_sqlite/tests/bug79664.phpt
+++ b/ext/pdo_sqlite/tests/bug79664.phpt
@@ -18,11 +18,11 @@ if ($stmt->columnCount()) {
array(6) {
["native_type"]=>
string(4) "null"
+ ["pdo_type"]=>
+ int(0)
["flags"]=>
array(0) {
}
- ["pdo_type"]=>
- int(3)
["name"]=>
string(1) "1"
["len"]=>
diff --git a/ext/pdo_sqlite/tests/bug_63916-2.phpt b/ext/pdo_sqlite/tests/bug_63916-2.phpt
index 4535410b55..688ab82ad0 100644
--- a/ext/pdo_sqlite/tests/bug_63916-2.phpt
+++ b/ext/pdo_sqlite/tests/bug_63916-2.phpt
@@ -24,4 +24,4 @@ var_dump($num,$result[0]);
?>
--EXPECT--
int(2147483647)
-string(10) "2147483647"
+int(2147483647)
diff --git a/ext/pdo_sqlite/tests/bug_63916.phpt b/ext/pdo_sqlite/tests/bug_63916.phpt
index 582413db4d..5b77f6bb98 100644
--- a/ext/pdo_sqlite/tests/bug_63916.phpt
+++ b/ext/pdo_sqlite/tests/bug_63916.phpt
@@ -24,4 +24,4 @@ var_dump($num,$result[0]);
?>
--EXPECT--
int(100004313234244)
-string(15) "100004313234244"
+int(100004313234244)