com php-src: Fix for bug #68087 (ODBC not reading DATE columns correctly): ext/odbc/php_odbc.c ext/odbc/tests/bug68087.p hpt
| From: | Keyur Govande | Date: | Tue, 07 Oct 2014 21:17:36 +0000 |
| Subject: | com php-src: Fix for bug #68087 (ODBC not reading DATE columns correctly): ext/odbc/php_odbc.c ext/odbc/tests/bug68087.p hpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-82182@lists.php.net to get a copy of this message | ||
Commit: df9078ea55e2bd60d718c6e6948b70311650fe39
Author: Keyur Govande <keyur@php.net> Tue, 7 Oct 2014 21:17:36 +0000
Parents: d21602c07288283e680941c0c0f963715fed0337
Branches: PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=df9078ea55e2bd60d718c6e6948b70311650fe39
Log:
Fix for bug #68087 (ODBC not reading DATE columns correctly)
Temporary variable indicating column field type ID should be
reset to default for loop iteration (i.e. every column in the
record set. The old buggy code made it persist across all columns
leading to invalid reads from the buffer, if for example a DATE
column was preceded by a VARCHAR column.
Bugs:
https://bugs.php.net/68087
Changed paths:
M ext/odbc/php_odbc.c
A ext/odbc/tests/bug68087.phpt
Diff:
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index 19f9fe4..b9bee96 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -951,14 +951,15 @@ int odbc_bindcols(odbc_result *result TSRMLS_DC)
SQLUSMALLINT colfieldid;
int charextraalloc;
- colfieldid = SQL_COLUMN_DISPLAY_SIZE;
- charextraalloc = 0;
result->values = (odbc_result_value *) safe_emalloc(sizeof(odbc_result_value),
result->numcols, 0);
result->longreadlen = ODBCG(defaultlrl);
result->binmode = ODBCG(defaultbinmode);
for(i = 0; i < result->numcols; i++) {
+ charextraalloc = 0;
+ colfieldid = SQL_COLUMN_DISPLAY_SIZE;
+
rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_NAME,
result->values[i].name, sizeof(result->values[i].name), &colnamelen, 0);
rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_TYPE,
diff --git a/ext/odbc/tests/bug68087.phpt b/ext/odbc/tests/bug68087.phpt
new file mode 100644
index 0000000..3bc1812
--- /dev/null
+++ b/ext/odbc/tests/bug68087.phpt
@@ -0,0 +1,57 @@
+--TEST--
+odbc_exec(): Getting accurate date data from query
+--SKIPIF--
+<?php include 'skipif.inc'; ?>
+--FILE--
+<?php
+
+include 'config.inc';
+
+$id_1_date = '2014-09-23';
+$id_2_date = '2014-09-24';
+
+$conn = odbc_connect($dsn, $user, $pass);
+
+@odbc_exec($conn, 'CREATE DATABASE odbcTEST');
+
+odbc_exec($conn, 'CREATE TABLE FOO (ID INT, VARCHAR_COL VARCHAR(100), DATE_COL DATE)');
+
+odbc_exec($conn, "INSERT INTO FOO(ID, VARCHAR_COL, DATE_COL) VALUES (1, 'hello',
'$id_1_date')");
+odbc_exec($conn, "INSERT INTO FOO(ID, VARCHAR_COL, DATE_COL) VALUES (2,
'helloagain', '$id_2_date')");
+
+$res = odbc_exec($conn, 'SELECT * FROM FOO ORDER BY ID ASC');
+
+while(odbc_fetch_row($res)) {
+ $id = odbc_result($res, "ID");
+ $varchar_col = odbc_result($res, "VARCHAR_COL");
+ $date = odbc_result($res, "DATE_COL");
+
+ if ($id == 1) {
+ if ($date != $id_1_date) {
+ print "Date_1 mismatched\n";
+ } else {
+ print "Date_1 matched\n";
+ }
+ } else {
+ if ($date != $id_2_date) {
+ print "Date_2 mismatched\n";
+ } else {
+ print "Date_2 matched\n";
+ }
+ }
+}
+
+?>
+--EXPECT--
+Date_1 matched
+Date_2 matched
+--CLEAN--
+<?php
+include 'config.inc';
+
+$conn = odbc_connect($dsn, $user, $pass);
+
+odbc_exec($conn, 'DROP TABLE FOO');
+odbc_exec($conn, 'DROP DATABASE odbcTEST');
+
+?>