Skip to content

Commit 1e9a3ed

Browse files
committed
Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
1 parent 99d087e commit 1e9a3ed

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
. Fixed bug #63921 (sqlite3::bindvalue and relative PHP functions aren't
1717
using sqlite3_*_int64 API). (srgoogleguy, Lars)
1818

19+
- PDO_sqlite:
20+
. Fixed bug #63916 (PDO::PARAM_INT casts to 32bit int internally even
21+
on 64bit builds in pdo_sqlite). (srgoogleguy, Lars)
22+
1923
?? ??? 2012, PHP 5.4.11
2024

2125
- Core:

ext/pdo_sqlite/sqlite_statement.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
112112
}
113113
} else {
114114
convert_to_long(param->parameter);
115+
#if LONG_MAX > 2147483647
116+
if (SQLITE_OK == sqlite3_bind_int64(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
117+
return 1;
118+
}
119+
#else
115120
if (SQLITE_OK == sqlite3_bind_int(S->stmt, param->paramno + 1, Z_LVAL_P(param->parameter))) {
116121
return 1;
117122
}
123+
#endif
118124
}
119125
pdo_sqlite_error_stmt(stmt);
120126
return 0;

ext/pdo_sqlite/tests/bug_63916-2.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #63916 PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_sqlite')) die('skip');
6+
if (PHP_INT_SIZE > 4) die('skip');
7+
?>
8+
--FILE--
9+
<?php
10+
$num = PHP_INT_MAX; // 32 bits
11+
$conn = new PDO('sqlite::memory:');
12+
$conn->query('CREATE TABLE users (id INTEGER NOT NULL, num INTEGER NOT NULL, PRIMARY KEY(id))');
13+
14+
$stmt = $conn->prepare('insert into users (id, num) values (:id, :num)');
15+
$stmt->bindValue(':id', 1, PDO::PARAM_INT);
16+
$stmt->bindValue(':num', $num, PDO::PARAM_INT);
17+
$stmt->execute();
18+
19+
$stmt = $conn->query('SELECT num FROM users');
20+
$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
21+
22+
var_dump($num,$result[0]);
23+
24+
?>
25+
--EXPECT--
26+
int(2147483647)
27+
string(10) "2147483647"

ext/pdo_sqlite/tests/bug_63916.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #63916 PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_sqlite')) die('skip');
6+
if (PHP_INT_SIZE < 8) die('skip');
7+
?>
8+
--FILE--
9+
<?php
10+
$num = 100004313234244; // exceeds 32 bits
11+
$conn = new PDO('sqlite::memory:');
12+
$conn->query('CREATE TABLE users (id INTEGER NOT NULL, num INTEGER NOT NULL, PRIMARY KEY(id))');
13+
14+
$stmt = $conn->prepare('insert into users (id, num) values (:id, :num)');
15+
$stmt->bindValue(':id', 1, PDO::PARAM_INT);
16+
$stmt->bindValue(':num', $num, PDO::PARAM_INT);
17+
$stmt->execute();
18+
19+
$stmt = $conn->query('SELECT num FROM users');
20+
$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
21+
22+
var_dump($num,$result[0]);
23+
24+
?>
25+
--EXPECT--
26+
int(100004313234244)
27+
string(15) "100004313234244"

0 commit comments

Comments
 (0)