]> granicus.if.org Git - php/commitdiff
Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds...
authorLars Strojny <lstrojny@php.net>
Mon, 14 Jan 2013 16:59:11 +0000 (17:59 +0100)
committerLars Strojny <lstrojny@php.net>
Mon, 14 Jan 2013 16:59:11 +0000 (17:59 +0100)
NEWS
ext/pdo_sqlite/sqlite_statement.c
ext/pdo_sqlite/tests/bug_63916-2.phpt [new file with mode: 0644]
ext/pdo_sqlite/tests/bug_63916.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index e411ba43a79ca1813110ad0b122172d5cb65fa6f..26ce1183a917bf887e3a4dab0ba53f3dec75b2ac 100644 (file)
--- 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:
index d5b4df1fda0cbe9fb9aa073870bebfa60edd2f04..e970ad3e062b5bd6f8c7143e885b765dfca02963 100644 (file)
@@ -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 (file)
index 0000000..bc9bfc9
--- /dev/null
@@ -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 (file)
index 0000000..582413d
--- /dev/null
@@ -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"