php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #44278
Patch varcharmax-fix-v2.diff revision 2017-11-18 11:30 UTC by chris at ocproducts dot com
Patch varcharmax-fix.diff revision 2017-11-17 03:35 UTC by chris at ocproducts dot com

Patch varcharmax-fix.diff for ODBC related Bug #44278

Patch version 2017-11-17 03:35 UTC

Return to Bug #44278 | Download this patch
Patch Revisions:

Developer: chris@ocproducts.com

diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index f432dcd..657e98b 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -972,6 +972,11 @@ int odbc_bindcols(odbc_result *result)
 		/* Don't bind LONG / BINARY columns, so that fetch behaviour can
 		 * be controlled by odbc_binmode() / odbc_longreadlen()
 		 */
+
+		if (result->values[i].vallen <= 0) {
+			// Probably SQL_NO_TOTAL (-4) or not returned (0). FreeTDS is returning this for SQL_VARCHAR, but we need the SQL_LONGVARCHAR branch triggered
+			result->values[i].coltype = SQL_LONGVARCHAR;
+		}
 		
 		switch(result->values[i].coltype) {
 			case SQL_BINARY:
@@ -1775,6 +1780,11 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
 	for(i = 0; i < result->numcols; i++) {
 		sql_c_type = SQL_C_CHAR;
 
+		if (result->values[i].vallen <= 0) {
+			// Probably SQL_NO_TOTAL (-4) or not returned (0). FreeTDS is returning this for SQL_VARCHAR, but we need the SQL_LONGVARCHAR branch triggered
+			result->values[i].coltype = SQL_LONGVARCHAR;
+		}
+		
 		switch(result->values[i].coltype) {
 			case SQL_BINARY:
 			case SQL_VARBINARY:
@@ -1929,6 +1939,11 @@ PHP_FUNCTION(odbc_fetch_into)
 	for(i = 0; i < result->numcols; i++) {
 		sql_c_type = SQL_C_CHAR;
 
+		if (result->values[i].vallen <= 0) {
+			// Probably SQL_NO_TOTAL (-4) or not returned (0). FreeTDS is returning this for SQL_VARCHAR, but we need the SQL_LONGVARCHAR branch triggered
+			result->values[i].coltype = SQL_LONGVARCHAR;
+		}
+		
 		switch(result->values[i].coltype) {
 			case SQL_BINARY:
 			case SQL_VARBINARY:
@@ -2155,6 +2170,11 @@ PHP_FUNCTION(odbc_result)
 		result->fetched++;
 	}
 
+	if (result->values[field_ind].vallen <= 0) {
+		// Probably SQL_NO_TOTAL (-4) or not returned (0). FreeTDS is returning this for SQL_VARCHAR, but we need the SQL_LONGVARCHAR branch triggered
+		result->values[field_ind].coltype = SQL_LONGVARCHAR;
+	}
+	
 	switch(result->values[field_ind].coltype) {
 		case SQL_BINARY:
 		case SQL_VARBINARY:
@@ -2320,6 +2340,11 @@ PHP_FUNCTION(odbc_result_all)
 		result->fetched++;
 		php_printf("<tr>");
 		for(i = 0; i < result->numcols; i++) {
+			if (result->values[i].vallen <= 0) {
+				// Probably SQL_NO_TOTAL (-4) or not returned (0). FreeTDS is returning this for SQL_VARCHAR, but we need the SQL_LONGVARCHAR branch triggered
+				result->values[i].coltype = SQL_LONGVARCHAR;
+			}
+		
 			sql_c_type = SQL_C_CHAR;
 			switch(result->values[i].coltype) {
 				case SQL_BINARY:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC