#22897 [Asn->Csd]: ODBC fixes & new feature

From: Date: Fri, 11 Jul 2003 13:13:48 +0000
Subject: #22897 [Asn->Csd]: ODBC fixes & new feature
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-43753@lists.php.net to get a copy of this message
ID: 22897 Updated by: kalowsky@php.net Reported By: rich at kastle dot com -Status: Assigned +Status: Closed Bug Type: Feature/Change Request Operating System: Windows NT 4.0 SP6 PHP Version: 4.3.2RC1 Assigned To: kalowsky New Comment: bug fix applied, new functionality not applied (yet). Previous Comments: ------------------------------------------------------------------------ [2003-04-09 06:20:37] rich at kastle dot com We are using php as a general purpose scripting language, not for web page generation. (We really like the syntax and plentiful features.) We've written scripts to automate and speed up some database maintenance, and we're using a combination of PHP and some existing C/C++ code which uses ODBC. What we've done is make OLE automation bindings for the existing code, and using PHP's COM interface to call them. odbc_get_handle allows us to make and use the ODBC connection in PHP, and share this connection (thereby sharing it's transaciton context) with the OLE objects. The alternatives to odbc_get_handle we explored are (a) re-writing the existing code to use ADO, which we deemed too painful (especially for the C code - furthermore we would still need to maintain the ODBC version), and (b) having the C code make it's own connection and share the transaction context using sp_bindtoken (which is much slower than what we're doing, and speed is a concern). If odbc_get_handle doesn't get integrated, then I'll just continue to patch future PHP releases as we adopt them - but it would sure be nice if I didn't have to. :-) ------------------------------------------------------------------------ [2003-04-08 00:28:42] kalowsky@php.net While most of these look good (I hope to incorporate them into potential 4.x releases), what is the purpose of adding the odbc_get_handle function? Assinging to self ------------------------------------------------------------------------ [2003-03-26 07:32:58] rich at kastle dot com 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 this bug report at http://bugs.php.net/?id=22897&edit=1

« previous php.bugs (#43753) next »