Hi Wez,

I've tested a snapshot 23th and it still crashes. See my comment in http://bugs.php.net/bug.php?id=35552 .

Thanks and mery christman,
- Markus

Wez Furlong wrote:
wez             Wed Dec 14 04:56:22 2005 EDT

  Modified files:              (Branch: PHP_5_1)
/php-src/ext/pdo_odbc odbc_driver.c Log:
  Possible fixes for #35552, #35592 and #35620.
http://cvs.php.net/viewcvs.cgi/php-src/ext/pdo_odbc/odbc_driver.c?r1=1.27.2.1&r2=1.27.2.2&diff_format=u
Index: php-src/ext/pdo_odbc/odbc_driver.c
diff -u php-src/ext/pdo_odbc/odbc_driver.c:1.27.2.1 
php-src/ext/pdo_odbc/odbc_driver.c:1.27.2.2
--- php-src/ext/pdo_odbc/odbc_driver.c:1.27.2.1 Mon Sep 26 21:37:33 2005
+++ php-src/ext/pdo_odbc/odbc_driver.c  Wed Dec 14 04:56:22 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
-/* $Id: odbc_driver.c,v 1.27.2.1 2005/09/26 21:37:33 wez Exp $ */
+/* $Id: odbc_driver.c,v 1.27.2.2 2005/12/14 04:56:22 wez Exp $ */
#ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -58,8 +58,10 @@
void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, char *what, const char *file, int line TSRMLS_DC) /* {{{ */
 {
-       RETCODE rc;
-       SWORD   errmsgsize = 0;
+       SQLRETURN rc;
+       SQLSMALLINT     errmsgsize = 0;
+       SQLHANDLE eh;
+       SQLSMALLINT htype, recno = 1;
        pdo_odbc_db_handle *H = (pdo_odbc_db_handle*)dbh->driver_data;
        pdo_odbc_errinfo *einfo = &H->einfo;
        pdo_odbc_stmt *S = NULL;
@@ -75,8 +77,19 @@
        if (statement == SQL_NULL_HSTMT && S) {
                statement = S->stmt;
        }
-       
-       rc = SQLError(H->env, H->dbc, statement, einfo->last_state, 
&einfo->last_error,
+
+       if (statement) {
+               htype = SQL_HANDLE_STMT;
+               eh = statement;
+       } else if (H->dbc) {
+               htype = SQL_HANDLE_DBC;
+               eh = H->dbc;
+       } else {
+               htype = SQL_HANDLE_ENV;
+               eh = H->env;
+       }
+
+       rc = SQLGetDiagRec(htype, eh, recno++, einfo->last_state, 
&einfo->last_error,
                        einfo->last_err_msg, sizeof(einfo->last_err_msg)-1, 
&errmsgsize);
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
@@ -94,6 +107,20 @@
                zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, 
"SQLSTATE[%s] %s: %d %s",
                                *pdo_err, what, einfo->last_error, 
einfo->last_err_msg);
        }
+
+       /* just like a cursor, once you start pulling, you need to keep
+        * going until the end; SQL Server (at least) will mess with the
+        * actual cursor state if you don't finish retrieving all the
+        * diagnostic records (which can be generated by PRINT statements
+        * in the query, for instance). */
+       while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
+               char discard_state[5];
+               char discard_buf[1024];
+               SQLINTEGER code;
+               rc = SQLGetDiagRec(htype, eh, recno++, discard_state, &code,
+                               discard_buf, sizeof(discard_buf)-1, 
&errmsgsize);
+       }
+
 }
 /* }}} */
@@ -175,14 +202,12 @@
                pdo_odbc_stmt_error("SQLPrepare");
        }
+ stmt->driver_data = S;
+       stmt->methods = &odbc_stmt_methods;
+
        if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
-               SQLFreeHandle(SQL_HANDLE_STMT, S->stmt);
                return 0;
        }
-
-       stmt->driver_data = S;
-       stmt->methods = &odbc_stmt_methods;
-       
        return 1;
 }

--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to