Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on …

…64bit builds in pdo_sqlite
  • Loading branch information...
commit 1e9a3ed234af443170d9ea8280a556d85299e301 1 parent 99d087e
@lstrojny lstrojny authored
View
4 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:
View
6 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;
View
27 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"
View
27 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"

0 comments on commit 1e9a3ed

Please sign in to comment.
Something went wrong with that request. Please try again.