From: rich at kastle dot com
Operating system: Windows NT 4.0 SP6
PHP version: 4.3.2RC1
PHP Bug Type: ODBC related
Bug description: ODBC fixes & new feature
Things I have attempted to fix and are illustrated by the enclosed diff (if
I were more expert I'd call it a patch but I've done virtually no patch
files and so make no such claim):
1. odbc_next_result calls SQLMoreResults but does not properly report an
error resturned from the call (anything but SQL_SUCCESS is treated like
SQL_NO_MORE_DATA). This defeats attempts to detect errors in mid-batch.
2. PHP documentation claims that odbc_error and odbc_errormsg are blank if
no error has occured, but in reality they are uninitialized until an error
occurs.
3. I also blank odbc_error and odbc_errormsg in odbc_exec so that (among
other things) upon a FALSE return from odbc_next_result, an error can be
distinguished from normal no-more-data.
4. Microsoft documentation claims that callers to SQLDriverConnect should
provide at least a 1024 byte buffer.
5. I added a function odbc_get_handle which yeilds the underlying HDBC as
a long, for a given $dbid resource.
diff -r temp/php-4.3.2RC1\ext\odbc\php_odbc.c
php-4.3.2RC1\ext\odbc\php_odbc.c
113a114
> PHP_FE(odbc_get_handle, NULL)
1344a1346,1348
> // No error
> conn->laststate[0] = conn->lasterrormsg[0] = 0;
>
2081a2086,2088
> (*conn)->laststate[0] = 0;
> (*conn)->lasterrormsg[0] = 0;
>
2115c2122
< char dsnbuf[300];
---
> char dsnbuf[1024];
2133c2140
< rc = SQLDriverConnect((*conn)->hdbc, NULL, ldb, strlen(ldb),
dsnbuf,
300,
---
> rc = SQLDriverConnect((*conn)->hdbc, NULL, ldb, strlen(ldb),
> dsnbuf,
sizeof(dsnbuf),
2410a2418,2435
> /* {{{ proto int odbc_handle(int connection_id)
> Returns the basic ODBC HDBC for a connection */
> PHP_FUNCTION(odbc_get_handle)
> {
> odbc_connection *conn;
> pval **pv_conn;
> int is_pconn = 0;
>
> if (zend_get_parameters_ex(1, &pv_conn) == FAILURE) {
> WRONG_PARAM_COUNT;
> }
>
> ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link",
le_conn, le_pconn);
>
> RETURN_LONG((long)conn->hdbc);
> }
> /* }}} */
>
2454c2479,2480
< else {
---
> else if(rc == SQL_NO_DATA_FOUND)
> {
2456a2483,2485
>
> odbc_sql_error(result->conn_ptr, result->stmt, " SQLMoreResults");
> RETURN_FALSE;
diff -r temp/php-4.3.2RC1\ext\odbc\php_odbc.h
php-4.3.2RC1\ext\odbc\php_odbc.h
94a95
> PHP_FUNCTION(odbc_get_handle);
--
Edit bug report at http://bugs.php.net/?id=22897&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=22897&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=22897&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=22897&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=22897&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=22897&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=22897&r=support
Expected behavior: http://bugs.php.net/fix.php?id=22897&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=22897&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=22897&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=22897&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22897&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=22897&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=22897&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=22897&r=gnused