From: Adam Baratz Date: Thu, 27 Oct 2016 17:52:59 +0000 (-0400) Subject: Fix #73396: bigint columns are returned as strings X-Git-Tag: php-7.2.0alpha1~1027 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a2c02cb57d2d2f3cb0bd762b686a45b83d129ca;p=php Fix #73396: bigint columns are returned as strings --- diff --git a/NEWS b/NEWS index c6a5f3e223..bf3d949540 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,7 @@ PHP NEWS - PDO_DBlib: . Fixed bug #73234 (Emulated statements let value dictate parameter type). (Adam Baratz) + . Fixed bug #73396 (bigint columns are returned as strings). - SOAP: . Fixed bug #69137 (Peer verification fails when using a proxy with SoapClient) diff --git a/ext/pdo_dblib/dblib_stmt.c b/ext/pdo_dblib/dblib_stmt.c index 74e91a84b1..18e9ab65c1 100644 --- a/ext/pdo_dblib/dblib_stmt.c +++ b/ext/pdo_dblib/dblib_stmt.c @@ -268,7 +268,9 @@ static int pdo_dblib_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, data_len = dbdatlen(H->link, colno+1); if (data_len != 0 || data != NULL) { - if (stmt->dbh->stringify) { + /* force stringify if DBBIGINT won't fit in zend_long */ + /* this should only be an issue for 32-bit machines */ + if (stmt->dbh->stringify || (coltype == SQLINT8 && sizeof(zend_long) < sizeof(DBBIGINT))) { switch (coltype) { case SQLDECIMAL: case SQLNUMERIC: @@ -277,6 +279,7 @@ static int pdo_dblib_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, case SQLMONEYN: case SQLFLT4: case SQLFLT8: + case SQLINT8: case SQLINT4: case SQLINT2: case SQLINT1: @@ -351,22 +354,28 @@ static int pdo_dblib_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, break; } + case SQLINT8: { + zv = emalloc(sizeof(zval)); + ZVAL_LONG(zv, *(DBBIGINT *) data); + + break; + } case SQLINT4: { zv = emalloc(sizeof(zval)); - ZVAL_LONG(zv, (long) ((int) *(DBINT *) data)); + ZVAL_LONG(zv, *(DBINT *) data); break; } case SQLINT2: { zv = emalloc(sizeof(zval)); - ZVAL_LONG(zv, (long) ((int) *(DBSMALLINT *) data)); + ZVAL_LONG(zv, *(DBSMALLINT *) data); break; } case SQLINT1: case SQLBIT: { zv = emalloc(sizeof(zval)); - ZVAL_LONG(zv, (long) ((int) *(DBTINYINT *) data)); + ZVAL_LONG(zv, *(DBTINYINT *) data); break; } diff --git a/ext/pdo_dblib/php_pdo_dblib_int.h b/ext/pdo_dblib/php_pdo_dblib_int.h index 01c538eed7..0b2c3a5dd0 100644 --- a/ext/pdo_dblib/php_pdo_dblib_int.h +++ b/ext/pdo_dblib/php_pdo_dblib_int.h @@ -53,6 +53,7 @@ # define SQLINT1 SYBINT1 # define SQLINT2 SYBINT2 # define SQLINT4 SYBINT4 +# define SQLINT8 SYBINT8 # define SQLINTN SYBINTN # define SQLBIT SYBBIT # define SQLFLT4 SYBREAL diff --git a/ext/pdo_dblib/tests/bug_73396.phpt b/ext/pdo_dblib/tests/bug_73396.phpt new file mode 100644 index 0000000000..909e1194c0 --- /dev/null +++ b/ext/pdo_dblib/tests/bug_73396.phpt @@ -0,0 +1,20 @@ +--TEST-- +PDO_DBLIB: bigint columns are returned as strings +--SKIPIF-- + +--FILE-- +query('SELECT CAST(1 AS bigint)'); +var_dump($stmt->fetchColumn() === $expected); +?> +--EXPECT-- +bool(true)