com php-src: Handle SQLDECIMAL/SQLNUMERIC types, which are used by later TDS versions: ext/pdo_dblib/README ext/pdo_dblib/dblib_ stmt.c
ext/pdo_dblib/tests/config.inc ext/pdo_dblib /tests/types.phpt

From: Date: Tue, 13 Sep 2016 20:32:37 +0000
Subject: com php-src: Handle SQLDECIMAL/SQLNUMERIC types, which are used by later TDS versions: ext/pdo_dblib/README ext/pdo_dblib/dblib_ stmt.c
ext/pdo_dblib/tests/config.inc ext/pdo_dblib /tests/types.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-94498@lists.php.net to get a copy of this message
Commit: 91c49c4ab0632116760d9beeddb0ec26ddc61ca7 Author: Adam Baratz <adambaratz@php.net> Tue, 13 Sep 2016 16:26:38 -0400 Parents: 9cdf2042bd3e1a34c15e120cba85a76ef54eb854 Branches: PHP-7.0 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=91c49c4ab0632116760d9beeddb0ec26ddc61ca7 Log: Handle SQLDECIMAL/SQLNUMERIC types, which are used by later TDS versions Changed paths: M ext/pdo_dblib/README M ext/pdo_dblib/dblib_stmt.c M ext/pdo_dblib/tests/config.inc M ext/pdo_dblib/tests/types.phpt Diff: diff --git a/ext/pdo_dblib/README b/ext/pdo_dblib/README index 15f8d14..e833c74 100644 --- a/ext/pdo_dblib/README +++ b/ext/pdo_dblib/README @@ -9,4 +9,15 @@ The following database products are free for testing: - Microsoft SQL Server Express (Windows Only) - Sybase Adaptive Server (Windows, Linux, *NIX) - Microsoft SQL Server Azure (One Month Trial Cloud Service) - + +You must set the following environment variables to run the tests: + - PDO_DBLIB_TEST_DSN - DSN (e.g., dblib:host=localhost;dbname=test) + - PDO_DBLIB_TEST_USER - database user + - PDO_DBLIB_TEST_PASS - database user password + +This extension supports multiple versions of the TDS protocol. There are +behavioral differences between versions. When making changes, it's recommended +to test across all supported versions. You can specify a version using a version +parameter in the DSN. See dblib_driver.c:pdo_dblib_handle_factory() for valid +values. Some tests check version-specific behavior by parsing this string, so +it's best to use the DSN (rather than freetds.conf, etc.) to set the version. diff --git a/ext/pdo_dblib/dblib_stmt.c b/ext/pdo_dblib/dblib_stmt.c index 8ec4f78..311d856 100644 --- a/ext/pdo_dblib/dblib_stmt.c +++ b/ext/pdo_dblib/dblib_stmt.c @@ -266,6 +266,11 @@ static int pdo_dblib_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, if (data_len != 0 || data != NULL) { if (stmt->dbh->stringify) { switch (coltype) { + case SQLDECIMAL: + case SQLNUMERIC: + case SQLMONEY: + case SQLMONEY4: + case SQLMONEYN: case SQLFLT4: case SQLFLT8: case SQLINT4: @@ -361,18 +366,16 @@ static int pdo_dblib_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, break; } + case SQLDECIMAL: + case SQLNUMERIC: case SQLMONEY: case SQLMONEY4: case SQLMONEYN: { - DBFLT8 money_value; - dbconvert(NULL, coltype, data, 8, SQLFLT8, (LPBYTE)&money_value, -1); + DBFLT8 float_value; + dbconvert(NULL, coltype, data, 8, SQLFLT8, (LPBYTE)&float_value, -1); zv = emalloc(sizeof(zval)); - ZVAL_DOUBLE(zv, money_value); - - if (stmt->dbh->stringify) { - convert_to_string(zv); - } + ZVAL_DOUBLE(zv, float_value); break; } diff --git a/ext/pdo_dblib/tests/config.inc b/ext/pdo_dblib/tests/config.inc index 5b7b4d4..346de0f 100644 --- a/ext/pdo_dblib/tests/config.inc +++ b/ext/pdo_dblib/tests/config.inc @@ -1,5 +1,21 @@ <?php +function get_tds_version() { + global $dsn; + + $dsn_parts = explode(':', $dsn, 2); + if ($dsn_parts[0] == 'dblib') { // uri is an option, which we'll ignore + foreach (explode(';', $dsn_parts[1]) as $arg) { + $arg = explode('=', $arg); + if ($arg[0] == 'version') { + return $arg[1]; + } + } + } + + return null; +} + if (false !== getenv('PDO_DBLIB_TEST_DSN')) $dsn = getenv('PDO_DBLIB_TEST_DSN'); else diff --git a/ext/pdo_dblib/tests/types.phpt b/ext/pdo_dblib/tests/types.phpt index dd849ad..04b8568 100644 --- a/ext/pdo_dblib/tests/types.phpt +++ b/ext/pdo_dblib/tests/types.phpt @@ -9,14 +9,28 @@ require __DIR__ . '/config.inc'; <?php require __DIR__ . '/config.inc'; +function get_expected_float_string() { + switch (get_tds_version()) { + case '5.0': + case '6.0': + case '7.0': + case '7.1': + case '7.2': + case '8.0': + return '10.500'; + default: + return '10.5'; + } +} + $sql = " SELECT 'foo' AS [char], CAST('2030-01-01 23:59:59' AS DATETIME) AS [datetime], CAST(0 AS BIT) AS [false], - 10.5 AS [float], + 10.500 AS [float], 1000 AS [int], - CAST(10.5 AS MONEY) AS [money], + CAST(10.500 AS MONEY) AS [money], CAST('1950-01-18 23:00:00' AS SMALLDATETIME) as [smalldatetime], CAST(1 AS BIT) AS [true] "; @@ -40,9 +54,9 @@ $row = $stmt->fetch(PDO::FETCH_ASSOC); var_dump($row['char'] === 'foo'); var_dump($row['datetime'] === '2030-01-01 23:59:59'); var_dump($row['false'] === '0'); -var_dump($row['float'] === '10.5'); +var_dump($row['float'] === get_expected_float_string()); var_dump($row['int'] === '1000'); -var_dump($row['money'] === '10.5'); +var_dump($row['money'] === '10.50'); var_dump($row['smalldatetime'] === '1950-01-18 23:00:00'); var_dump($row['true'] === '1');

« previous php.cvs (#94498) next »