PHP 4.0 Bug #9397 Updated: odbc_setoption() cannot accept string value (patch included)
| From: | clin at lion dot syscom dot com dot tw | Date: | Mon, 05 Mar 2001 05:37:22 +0000 |
| Subject: | PHP 4.0 Bug #9397 Updated: odbc_setoption() cannot accept string value (patch included) | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-47953@lists.php.net to get a copy of this message | ||
ID: 9397
User Update by: clin@lion.syscom.com.tw
Old-Status: Feedback
Status: Open
Bug Type: ODBC related
Description: odbc_setoption() cannot accept string value (patch included)
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.
Previous Comments:
---------------------------------------------------------------------------
[2001-02-22 11:35:25] 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-02-22 04:55:38] clin@lion.syscom.com.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 ***********
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=9397