]> granicus.if.org Git - php/commitdiff
Fix #73396: bigint columns are returned as strings
authorAdam Baratz <adambaratz@php.net>
Thu, 27 Oct 2016 17:52:59 +0000 (13:52 -0400)
committerAdam Baratz <adambaratz@php.net>
Thu, 27 Oct 2016 17:52:59 +0000 (13:52 -0400)
NEWS
ext/pdo_dblib/dblib_stmt.c
ext/pdo_dblib/php_pdo_dblib_int.h
ext/pdo_dblib/tests/bug_73396.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index c6a5f3e223789296b92a4bac206658147a886966..bf3d949540c306adaa2b82df55da60348c1ad97b 100644 (file)
--- 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)
index 74e91a84b1347a3fd1c7b88f4594cf7f8534518e..18e9ab65c102023cdd983c1dd9d4b35417791f17 100644 (file)
@@ -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;
                                }
index 01c538eed7ab75a0b2c2d91dce756146b18a680d..0b2c3a5dd055a3cd837a2958d43bb9379a9a834d 100644 (file)
@@ -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 (file)
index 0000000..909e119
--- /dev/null
@@ -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)