php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #69526
Patch odbc_diff.txt revision 2015-04-27 13:39 UTC by einavitamar at gmail dot com

Patch odbc_diff.txt for ODBC related Bug #69526

Patch version 2015-04-27 13:39 UTC

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

Developer: einavitamar@gmail.com

diff -u odbc_old/php_odbc.c odbc/php_odbc.c
--- C:\php-sdk\phpdev\vc11\x86\php-5.6.8-src\ext\odbc_old\php_odbc.c	2015-04-24 16:29:29.440000000 +0300
+++ C:\php-sdk\phpdev\vc11\x86\php-5.6.8-src\ext\odbc\php_odbc.c	2015-04-26 11:29:03.998000000 +0300
@@ -1167,6 +1167,7 @@
 	odbc_result *result = NULL;
 	odbc_connection *conn;
 	RETCODE rc;
+	int i;
 #ifdef HAVE_SQL_EXTENDED_FETCH
 	SQLUINTEGER      scrollopts;
 #endif
@@ -1236,6 +1237,19 @@
 	zend_list_addref(conn->id);
 	result->conn_ptr = conn;
 	result->fetched = 0;
+	
+	result->param_info = (param_info_t *) safe_emalloc(sizeof(param_info_t), result->numparams, 0);
+	for (i=0;i<result->numparams;i++) {
+		rc = SQLDescribeParam(result->stmt, (SQLUSMALLINT)(i+1), &result->param_info[i].sqltype, &result->param_info[i].precision, 
+													&result->param_info[i].scale, &result->param_info[i].nullable);
+		if (rc == SQL_ERROR) {
+			odbc_sql_error(result->conn_ptr, result->stmt, "SQLDescribeParameter");	
+			SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
+			efree(result->param_info);
+			efree(result);
+			RETURN_FALSE;
+		}
+	}	
 	ZEND_REGISTER_RESOURCE(return_value, result, le_result);  
 }
 /* }}} */
@@ -1256,9 +1270,10 @@
 	params_t *params = NULL;
 	char *filename;
 	unsigned char otype;
-   	SQLSMALLINT sqltype, ctype, scale;
-	SQLSMALLINT nullable;
-	SQLULEN precision;
+	SQLSMALLINT ctype;
+   	//SQLSMALLINT sqltype, scale;
+	//SQLSMALLINT nullable;
+	//SQLULEN precision;
    	odbc_result *result;
 	int numArgs, i, ne;
 	RETCODE rc;
@@ -1316,22 +1331,10 @@
 				RETURN_FALSE;
 			}
 			
-			rc = SQLDescribeParam(result->stmt, (SQLUSMALLINT)i, &sqltype, &precision, &scale, &nullable);
 			params[i-1].vallen = Z_STRLEN_PP(tmp);
 			params[i-1].fp = -1;
-			if (rc == SQL_ERROR) {
-				odbc_sql_error(result->conn_ptr, result->stmt, "SQLDescribeParameter");	
-				SQLFreeStmt(result->stmt, SQL_RESET_PARAMS);
-				for (i = 0; i < result->numparams; i++) {
-					if (params[i].fp != -1) {
-						close(params[i].fp);
-					}
-				}
-				efree(params);
-				RETURN_FALSE;
-			}
 
-			if (IS_SQL_BINARY(sqltype)) {
+			if (IS_SQL_BINARY(result->param_info[i-1].sqltype)) {
 				ctype = SQL_C_BINARY;
 			} else {
 				ctype = SQL_C_CHAR;
@@ -1378,7 +1381,7 @@
 				params[i-1].vallen = SQL_LEN_DATA_AT_EXEC(0);
 
 				rc = SQLBindParameter(result->stmt, (SQLUSMALLINT)i, SQL_PARAM_INPUT,
-									  ctype, sqltype, precision, scale,
+									  ctype, result->param_info[i-1].sqltype, result->param_info[i-1].precision, result->param_info[i-1].scale,
 									  (void *)params[i-1].fp, 0,
 									  &params[i-1].vallen);
 			} else {
@@ -1390,7 +1393,7 @@
 				}
 
 				rc = SQLBindParameter(result->stmt, (SQLUSMALLINT)i, SQL_PARAM_INPUT,
-									  ctype, sqltype, precision, scale,
+									  ctype, result->param_info[i-1].sqltype, result->param_info[i-1].precision, result->param_info[i-1].scale,
 									  Z_STRVAL_PP(tmp), 0,
 									  &params[i-1].vallen);
 			}
diff -u odbc_old/php_odbc_includes.h odbc/php_odbc_includes.h
--- C:\php-sdk\phpdev\vc11\x86\php-5.6.8-src\ext\odbc_old\php_odbc_includes.h	2015-04-24 16:29:29.456000000 +0300
+++ C:\php-sdk\phpdev\vc11\x86\php-5.6.8-src\ext\odbc\php_odbc_includes.h	2015-04-24 23:01:38.451000000 +0300
@@ -233,6 +233,13 @@
 	SQLLEN coltype;
 } odbc_result_value;
 
+typedef struct param_info_t {
+	SQLSMALLINT sqltype;
+	SQLSMALLINT scale;
+	SQLSMALLINT nullable;
+	SQLULEN precision;
+} param_info_t;
+
 typedef struct odbc_result {
 	ODBC_SQL_STMT_T stmt;
 	odbc_result_value *values;
@@ -244,6 +251,7 @@
 	long longreadlen;
 	int binmode;
 	int fetched;
+	param_info_t * param_info;
 	odbc_connection *conn_ptr;
 } odbc_result;
 
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Feb 16 03:01:24 2019 UTC