com php-src: Fix #73396: bigint columns are returned as strings: NEWS ext/pdo_dblib/dblib_stmt.c ext/pdo_dblib/php_pdo_ dblib_int.h
ext/pdo_dblib/tests/bug_73396 .phpt

From: Date: Thu, 27 Oct 2016 17:52:59 +0000
Subject: com php-src: Fix #73396: bigint columns are returned as strings: NEWS ext/pdo_dblib/dblib_stmt.c ext/pdo_dblib/php_pdo_ dblib_int.h
ext/pdo_dblib/tests/bug_73396 .phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95308@lists.php.net to get a copy of this message
Commit: 0a2c02cb57d2d2f3cb0bd762b686a45b83d129ca Author: Adam Baratz <adambaratz@php.net> Thu, 27 Oct 2016 13:52:59 -0400 Parents: 886e721356eb311fbf2dbeca91575b93d585168e Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0a2c02cb57d2d2f3cb0bd762b686a45b83d129ca Log: Fix #73396: bigint columns are returned as strings Bugs: https://bugs.php.net/73396 Changed paths: M NEWS M ext/pdo_dblib/dblib_stmt.c M ext/pdo_dblib/php_pdo_dblib_int.h A ext/pdo_dblib/tests/bug_73396.phpt Diff: diff --git a/NEWS b/NEWS index c6a5f3e..bf3d949 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 74e91a8..18e9ab6 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 01c538e..0b2c3a5 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 0000000..909e119 --- /dev/null +++ b/ext/pdo_dblib/tests/bug_73396.phpt @@ -0,0 +1,20 @@ +--TEST-- +PDO_DBLIB: bigint columns are returned as strings +--SKIPIF-- +<?php +if (!extension_loaded('pdo_dblib')) die('skip not loaded'); +require dirname(__FILE__) . '/config.inc'; +?> +--FILE-- +<?php +require dirname(__FILE__) . '/config.inc'; + +// on 64-bit machines, these columns should come back as ints +// on 32-bit machines, they will come back as strings because zend_long isn't big enough +$expected = PHP_INT_SIZE == 8 ? 1 : '1'; + +$stmt = $db->query('SELECT CAST(1 AS bigint)'); +var_dump($stmt->fetchColumn() === $expected); +?> +--EXPECT-- +bool(true)

« previous php.cvs (#95308) next »