Skip to content

Commit

Permalink
Fix #73396: bigint columns are returned as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
adambaratz committed Oct 27, 2016
1 parent 886e721 commit 0a2c02c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions ext/pdo_dblib/dblib_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions ext/pdo_dblib/php_pdo_dblib_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions ext/pdo_dblib/tests/bug_73396.phpt
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0a2c02c

Please sign in to comment.