Bug #73333 [Asn->Csd]: 2147483647 is fetched as string
| From: | cmb@php.net | Date: | Mon, 17 Oct 2016 22:02:44 +0000 |
| Subject: | Bug #73333 [Asn->Csd]: 2147483647 is fetched as string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204882@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73333&edit=1
ID: 73333
Updated by: cmb@php.net
Reported by: cmb@php.net
Summary: 2147483647 is fetched as string
-Status: Assigned
+Status: Closed
Type: Bug
Package: SQLite related
Operating System: *
PHP Version: 5.6.27
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=86e603a664afdc3a12ead0eaca5d37fa8a379381
Log: Fix #73333: 2147483647 is fetched as string
Previous Comments:
------------------------------------------------------------------------
[2016-10-17 14:20:00] cmb@php.net
Description:
------------
ext/sqlite3 fetches integers greater than or equal to 2147483647
as strings. Even for 32bit PHP 2147483647 should be returned as
int; for 64bit PHP the supported range should be larger, of
course.
The culprit is sqlite_value_to_zval()[1] where comparisons are
made for >= INT_MAX (and <= INT_MIN), what should actually be
> ZEND_LONG_MAX (and < ZEND_LONG_MIN).
[1] <https://github.com/php/php-src/blob/PHP-5.6.27/ext/sqlite3/sqlite3.c#L597>
Test script:
---------------
<?php
$db = new SQLite3(':memory:');
$db->exec('CREATE TABLE foo (bar INT)');
$stmt = $db->prepare('INSERT INTO foo VALUES (?)');
foreach ([-2147483648, -2147483647, 2147483646, 2147483647] as $num) {
$stmt->bindValue(1, $num, SQLITE3_INTEGER);
$stmt->execute();
}
$res = $db->query('SELECT bar FROM foo');
while (($row = $res->fetchArray(SQLITE3_ASSOC)) !== false) {
var_dump($row);
}
Expected result:
----------------
array(1) {
["bar"]=>
int(-2147483648)
}
array(1) {
["bar"]=>
int(-2147483647)
}
array(1) {
["bar"]=>
int(2147483646)
}
array(1) {
["bar"]=>
int(2147483647)
}
Actual result:
--------------
array(1) {
["bar"]=>
string(11) "-2147483648"
}
array(1) {
["bar"]=>
int(-2147483647)
}
array(1) {
["bar"]=>
int(2147483646)
}
array(1) {
["bar"]=>
string(10) "2147483647"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73333&edit=1