diff --git a/NEWS b/NEWS index 7f2fba21eb5..8de5a5e9d13 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 7.1.0RC5 +- SQLite3: + . Fixed bug #73333 (2147483647 is fetched as string). (cmb) 19 Oct 2016, PHP 7.1.0RC4 diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 67b14bbb85c..9eaf714b965 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -567,13 +567,20 @@ PHP_METHOD(sqlite3, query) static void sqlite_value_to_zval(sqlite3_stmt *stmt, int column, zval *data) /* {{{ */ { + sqlite3_int64 val; + switch (sqlite3_column_type(stmt, column)) { case SQLITE_INTEGER: - if ((sqlite3_column_int64(stmt, column)) >= INT_MAX || sqlite3_column_int64(stmt, column) <= INT_MIN) { + val = sqlite3_column_int64(stmt, column); +#if LONG_MAX <= 2147483647 + if (val > ZEND_LONG_MAX || val < ZEND_LONG_MIN) { ZVAL_STRINGL(data, (char *)sqlite3_column_text(stmt, column), sqlite3_column_bytes(stmt, column)); } else { - ZVAL_LONG(data, sqlite3_column_int64(stmt, column)); +#endif + ZVAL_LONG(data, val); +#if LONG_MAX <= 2147483647 } +#endif break; case SQLITE_FLOAT: diff --git a/ext/sqlite3/tests/bug63921-32bit.phpt b/ext/sqlite3/tests/bug63921-32bit.phpt index 8c1c6b9414c..d2cc7b20022 100644 --- a/ext/sqlite3/tests/bug63921-32bit.phpt +++ b/ext/sqlite3/tests/bug63921-32bit.phpt @@ -24,4 +24,4 @@ var_dump($num,$result[0]); ?> --EXPECT-- int(2147483647) -string(10) "2147483647" +int(2147483647) diff --git a/ext/sqlite3/tests/bug63921-64bit.phpt b/ext/sqlite3/tests/bug63921-64bit.phpt index 8e821fd2d07..d6c539e185a 100644 --- a/ext/sqlite3/tests/bug63921-64bit.phpt +++ b/ext/sqlite3/tests/bug63921-64bit.phpt @@ -24,4 +24,4 @@ var_dump($num,$result[0]); ?> --EXPECT-- int(100004313234244) -string(15) "100004313234244" +int(100004313234244) diff --git a/ext/sqlite3/tests/bug73333.phpt b/ext/sqlite3/tests/bug73333.phpt new file mode 100644 index 00000000000..7315751810c --- /dev/null +++ b/ext/sqlite3/tests/bug73333.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #73333 (2147483647 is fetched as string) +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE foo (bar INT)'); +foreach ([PHP_INT_MIN, PHP_INT_MAX] as $value) { + $db->exec("INSERT INTO foo VALUES ($value)"); +} + +$res = $db->query('SELECT bar FROM foo'); +while (($row = $res->fetchArray(SQLITE3_NUM)) !== false) { + echo gettype($row[0]), PHP_EOL; +} +?> +===DONE=== +--EXPECT-- +integer +integer +===DONE===