php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #9397 odbc_setoption() cannot accept string value (patch included)
Submitted: 2001-02-22 04:55 UTC Modified: 2017-01-08 05:57 UTC
From: clin at lion dot syscom dot com dot tw Assigned: krakjoe (profile)
Status: Closed Package: ODBC related
PHP Version: 4.0.4pl1 OS: Linux
Private report: No CVE-ID: None
 [2001-02-22 04:55 UTC] clin at lion dot syscom dot com dot tw
When I tried to use odbc_setoption() to set file extension
name:

odbc_setoption($sth, 2, 2001, "JPG"); /*2001 means SQL_EXTENSION_NAME*/

php will hang.

The patch followed:

****** BEGIN PATCH ***********

--- php_odbc.c.old	Wed Jan  3 23:04:50 2001
+++ php_odbc.c	Thu Feb 22 10:29:52 2001
@@ -2393,6 +2393,7 @@
 	odbc_result	*result;
 	RETCODE rc;
 	pval **pv_handle, **pv_which, **pv_opt, **pv_val;
+	UDWORD val;
 
  	if ( zend_get_parameters_ex(4, &pv_handle, &pv_which, &pv_opt, &pv_val) == FAILURE) {
 		WRONG_PARAM_COUNT;
@@ -2400,7 +2401,20 @@
  
 	convert_to_long_ex(pv_which);
 	convert_to_long_ex(pv_opt);
+	switch (Z_TYPE_PP(pv_val)) {
+		case IS_LONG:
 	convert_to_long_ex(pv_val);
+			val = (*pv_val)->value.lval;
+			break;
+		case IS_STRING:
+			convert_to_string_ex(pv_val); 
+			val = (UDWORD) (*pv_val)->value.str.val;
+			break;
+		default:
+			php_error(E_WARNING, "Unknown param type");
+			RETURN_FALSE;
+			break;
+	}
 
 	switch ((*pv_which)->value.lval) {
 		case 1:		/* SQLSetConnectOption */
@@ -2409,7 +2423,7 @@
 				php_error(E_WARNING, "Can't set option for persistent connection");
 				RETURN_FALSE;
 			}
-			rc = SQLSetConnectOption(conn->hdbc, (unsigned short)((*pv_opt)->value.lval), (*pv_val)->value.lval);
+			rc = SQLSetConnectOption(conn->hdbc, (unsigned short)((*pv_opt)->value.lval), val);
 			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
 				odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SetConnectOption");
 				RETURN_FALSE;
@@ -2418,7 +2432,7 @@
 		case 2:		/* SQLSetStmtOption */
 			ZEND_FETCH_RESOURCE(result, odbc_result *, pv_handle, -1, "ODBC result", le_result);
 			
-			rc = SQLSetStmtOption(result->stmt, (unsigned short)((*pv_opt)->value.lval), ((*pv_val)->value.lval));
+			rc = SQLSetStmtOption(result->stmt, (unsigned short)((*pv_opt)->value.lval), val);
 
 			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
 				odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SetStmtOption");


****** END PATCH ***********

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-22 11:35 UTC] kara@php.net
In ODBC 2.x it is not possible to pass string values to
SQLSetStmtOption(). It is possible with ODBC 3,
SQLSetStmtAttr() has an additional parameter to specify the
string length. 
By the way: I couldn't find SQL_EXTENSION_NAME as possible
attribute to SQLSetStmtAttr(). What's it's pupose?

 [2001-03-05 00:37 UTC] clin at lion dot syscom dot com dot tw
Dear kara,

I am sorry for not specifying it clearly last time. SQL_EXTENSION_NAME is used specifically for our database, DBMaker.

We are developers for this database and we have also have developed php driver for our database. Because of some specific features of our database, we really need to let users who use our database be able to set this kind of options. Unfortunately, ODBC 2.x does not allow setting attributes with string-type values.

Since the ODBC version currently used in php is, as you can see from the source code, 2.x. We really cannot use SQLSetStmtAttr() provided by ODBC 3.

We didn't use HAVE_DBMAKER ifdefs because we think other databases might be glad to see this, too.



 [2001-04-18 21:49 UTC] kalowsky@php.net
Changing this to a feature request as it seems to be more a request to update PHP/ODBC to ODBC3 compliancy.  
 [2010-12-29 10:42 UTC] jani@php.net
-Package: Feature/Change Request +Package: ODBC related
 [2017-01-08 05:57 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2017-01-08 05:57 UTC] krakjoe@php.net
16 years is a long time to wait for an answer, sorry about that.

This having been open for so long with very little activity seems to indicate that there is no appetite for this change, so I'm closing this bug report.

If anybody reading disagrees, I encourage them to open a pull request on github with a patch against 7.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC