summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Strojny <lstrojny@php.net>2013-01-14 17:59:11 +0100
committerLars Strojny <lstrojny@php.net>2013-01-14 17:59:11 +0100
commit1e9a3ed234af443170d9ea8280a556d85299e301 (patch)
tree6f41889291d75d85d9c676b62cd3bb64cc11866b
parent99d087e5d437023c55f96dcde4b5b784bd8b0ac8 (diff)
downloadphp-git-1e9a3ed234af443170d9ea8280a556d85299e301.tar.gz
Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
-rw-r--r--NEWS4
-rw-r--r--ext/pdo_sqlite/sqlite_statement.c6
-rw-r--r--ext/pdo_sqlite/tests/bug_63916-2.phpt27
-rw-r--r--ext/pdo_sqlite/tests/bug_63916.phpt27
4 files changed, 64 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index e411ba43a7..26ce1183a9 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,10 @@ PHP NEWS
. Fixed bug #63921 (sqlite3::bindvalue and relative PHP functions aren't
using sqlite3_*_int64 API). (srgoogleguy, Lars)
+- PDO_sqlite:
+ . Fixed bug #63916 (PDO::PARAM_INT casts to 32bit int internally even
+ on 64bit builds in pdo_sqlite). (srgoogleguy, Lars)
+
?? ??? 2012, PHP 5.4.11
- Core:
diff --git a/ext/pdo_sqlite/sqlite_statement.c b/ext/pdo_sqlite/sqlite_statement.c
index d5b4df1fda..e970ad3e06 100644
--- a/ext/pdo_sqlite/sqlite_statement.c
+++ b/ext/pdo_sqlite/sqlite_statement.c
@@ -112,9 +112,15 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
}
} else {
convert_to_long(param->parameter);
+#if LONG_MAX > 2147483647
+ if (SQLITE_OK == sqlite3_bind_int64(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
+ return 1;
+ }
+#else
if (SQLITE_OK == sqlite3_bind_int(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
return 1;
}
+#endif
}
pdo_sqlite_error_stmt(stmt);
return 0;
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 0000000000..bc9bfc9c98
--- /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 0000000000..582413db4d
--- /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"