summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Strojny <lstrojny@php.net>2013-01-14 17:35:07 +0100
committerLars Strojny <lstrojny@php.net>2013-01-14 17:35:07 +0100
commit99d087e5d437023c55f96dcde4b5b784bd8b0ac8 (patch)
tree3b699123245603e5fab643f810f52a44ae82495f
parent1a96fe0b3260b4b63627cf69d71a5b350ad3163f (diff)
downloadphp-git-99d087e5d437023c55f96dcde4b5b784bd8b0ac8.tar.gz
Fixed bug #63921: sqlite3::bindvalue and relative PHP functions aren't using sqlite3_*_int64 API
-rw-r--r--NEWS4
-rw-r--r--ext/sqlite3/sqlite3.c12
-rw-r--r--ext/sqlite3/tests/bug63921-32bit.phpt27
-rw-r--r--ext/sqlite3/tests/bug63921-64bit.phpt27
4 files changed, 70 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 28040f7262..e411ba43a7 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@ PHP NEWS
- Litespeed:
. Fixed bug #63228 (-Werror=format-security error in lsapi code). (George)
+- ext/sqlite3:
+ . Fixed bug #63921 (sqlite3::bindvalue and relative PHP functions aren't
+ using sqlite3_*_int64 API). (srgoogleguy, Lars)
+
?? ??? 2012, PHP 5.4.11
- Core:
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 881e3c3705..df449d7380 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -730,7 +730,11 @@ static int sqlite3_do_callback(struct php_sqlite3_fci *fc, zval *cb, int argc, s
switch (sqlite3_value_type(argv[i])) {
case SQLITE_INTEGER:
+#if LONG_MAX > 2147483647
+ ZVAL_LONG(*zargs[i + is_agg], sqlite3_value_int64(argv[i]));
+#else
ZVAL_LONG(*zargs[i + is_agg], sqlite3_value_int(argv[i]));
+#endif
break;
case SQLITE_FLOAT:
@@ -774,7 +778,11 @@ static int sqlite3_do_callback(struct php_sqlite3_fci *fc, zval *cb, int argc, s
if (retval) {
switch (Z_TYPE_P(retval)) {
case IS_LONG:
+#if LONG_MAX > 2147483647
+ sqlite3_result_int64(context, Z_LVAL_P(retval));
+#else
sqlite3_result_int(context, Z_LVAL_P(retval));
+#endif
break;
case IS_NULL:
@@ -1493,7 +1501,11 @@ PHP_METHOD(sqlite3stmt, execute)
switch (param->type) {
case SQLITE_INTEGER:
convert_to_long(param->parameter);
+#if LONG_MAX > 2147483647
+ sqlite3_bind_int64(stmt_obj->stmt, param->param_number, Z_LVAL_P(param->parameter));
+#else
sqlite3_bind_int(stmt_obj->stmt, param->param_number, Z_LVAL_P(param->parameter));
+#endif
break;
case SQLITE_FLOAT:
diff --git a/ext/sqlite3/tests/bug63921-32bit.phpt b/ext/sqlite3/tests/bug63921-32bit.phpt
new file mode 100644
index 0000000000..8c1c6b9414
--- /dev/null
+++ b/ext/sqlite3/tests/bug63921-32bit.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #63921 sqlite3::bindvalue and relative PHP functions aren't using sqlite3_*_int64 API
+--SKIPIF--
+<?php
+if (!extension_loaded('sqlite3')) die('skip');
+if (PHP_INT_SIZE > 4) die('skip'); // skip for 64bit builds - there is another test for that
+?>
+--FILE--
+<?php
+$num = PHP_INT_MAX; // 32 bits
+$conn = new sqlite3(':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, SQLITE3_INTEGER);
+$stmt->bindValue(':num', $num, SQLITE3_INTEGER);
+$stmt->execute();
+
+$stmt = $conn->query('SELECT num FROM users');
+$result = $stmt->fetchArray();
+
+var_dump($num,$result[0]);
+
+?>
+--EXPECT--
+int(2147483647)
+string(10) "2147483647"
diff --git a/ext/sqlite3/tests/bug63921-64bit.phpt b/ext/sqlite3/tests/bug63921-64bit.phpt
new file mode 100644
index 0000000000..8e821fd2d0
--- /dev/null
+++ b/ext/sqlite3/tests/bug63921-64bit.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #63921 sqlite3::bindvalue and relative PHP functions aren't using sqlite3_*_int64 API
+--SKIPIF--
+<?php
+if (!extension_loaded('sqlite3')) die('skip');
+if (PHP_INT_SIZE < 8) die('skip'); // skip for 32bit builds - there is another test for that
+?>
+--FILE--
+<?php
+$num = 100004313234244; // notice this exceeds 32 bits
+$conn = new sqlite3(':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, SQLITE3_INTEGER);
+$stmt->bindValue(':num', $num, SQLITE3_INTEGER);
+$stmt->execute();
+
+$stmt = $conn->query('SELECT num FROM users');
+$result = $stmt->fetchArray();
+
+var_dump($num,$result[0]);
+
+?>
+--EXPECT--
+int(100004313234244)
+string(15) "100004313234244"