]> granicus.if.org Git - php/commitdiff
Fixed bug #73725 Unable to retrieve value of varchar(max) type
authorAnatol Belski <ab@php.net>
Mon, 22 Jan 2018 16:02:54 +0000 (17:02 +0100)
committerAnatol Belski <ab@php.net>
Mon, 22 Jan 2018 16:02:54 +0000 (17:02 +0100)
ext/odbc/php_odbc.c
ext/odbc/tests/bug73725.phpt [new file with mode: 0644]

index 918c7bbf97f369ebaadb6bb9cc86975e5ad6ee41..514b8de74d37a31b70058c82cba227a98bb72af9 100644 (file)
@@ -1027,6 +1027,13 @@ int odbc_bindcols(odbc_result *result)
                                        break;
                                }
 #endif
+                               /* Workaround for drivers that report VARCHAR(MAX) columns as SQL_VARCHAR (bug #73725) */
+                               if (SQL_VARCHAR == result->values[i].coltype && displaysize == 0) {
+                                       result->values[i].coltype = SQL_LONGVARCHAR;
+                                       result->values[i].value = NULL;
+                                       break;
+                               }
+
                                /* Workaround for Oracle ODBC Driver bug (#50162) when fetching TIMESTAMP column */
                                if (result->values[i].coltype == SQL_TIMESTAMP) {
                                        displaysize += 3;
diff --git a/ext/odbc/tests/bug73725.phpt b/ext/odbc/tests/bug73725.phpt
new file mode 100644 (file)
index 0000000..f0ab6cc
--- /dev/null
@@ -0,0 +1,55 @@
+--TEST--
+Bug #73725 Unable to retrieve value of varchar(max) type
+--SKIPIF--
+<?php include 'skipif.inc'; ?>
+--FILE--
+<?php
+
+include dirname(__FILE__) . "/config.inc";
+
+$conn = odbc_connect($dsn, $user, $pass);
+
+odbc_do($conn, "CREATE TABLE bug73725(i int, txt varchar(max), k int)");
+
+odbc_do($conn, "INSERT INTO bug73725 VALUES(101,'Any text', 33)");
+odbc_do($conn, "INSERT INTO bug73725 VALUES(102,'Müsliriegel', 34)");
+
+$rc = odbc_do($conn, "SELECT i, txt, k FROM bug73725");
+
+$r = odbc_fetch_array($rc);
+var_dump($r);
+
+$r = odbc_fetch_array($rc);
+var_dump($r);
+
+?>
+==DONE==
+--EXPECT--
+array(3) {
+  ["i"]=>
+  string(3) "101"
+  ["txt"]=>
+  string(8) "Any text"
+  ["k"]=>
+  string(2) "33"
+}
+array(3) {
+  ["i"]=>
+  string(3) "102"
+  ["txt"]=>
+  string(12) "Müsliriegel"
+  ["k"]=>
+  string(2) "34"
+}
+==DONE==
+--CLEAN--
+<?php
+include 'config.inc';
+
+$conn = odbc_connect($dsn, $user, $pass);
+
+odbc_exec($conn, 'DROP TABLE bug73725');
+
+odbc_close($conn);
+
+?>