]> granicus.if.org Git - php/commitdiff
Fixed bug #17291 (mssql_query does not update get_last_message) (patch by: mgruetzner...
authorfoobar <sniper@php.net>
Fri, 11 Jul 2003 02:08:14 +0000 (02:08 +0000)
committerfoobar <sniper@php.net>
Fri, 11 Jul 2003 02:08:14 +0000 (02:08 +0000)
ext/sybase/php_sybase_db.c

index 8f2a76b1c729cdc3edd797e11387e6e3de624d6d..96ac666234c317bb9b1b3649a0f9b16e94940de6 100644 (file)
@@ -766,6 +766,7 @@ PHP_FUNCTION(sybase_query)
        int blocks_initialized=1;
        int i,j;
        int *column_types;
+       RETCODE dbresults_retval;
 
        switch(ZEND_NUM_ARGS()) {
                case 1:
@@ -797,7 +798,14 @@ PHP_FUNCTION(sybase_query)
                /*php_error_docref(NULL TSRMLS_CC, E_WARNING,"Sybase:  Unable to set query");*/
                RETURN_FALSE;
        }
-       if (dbsqlexec(sybase_ptr->link)==FAIL || dbresults(sybase_ptr->link)==FAIL) {
+
+       if (dbsqlexec(sybase_ptr->link)==FAIL) {
+               /*php_error(E_WARNING,"Sybase:  Query failed");*/
+               RETURN_FALSE;
+       }
+
+       dbresults_retval = dbresults(sybase_ptr->link);
+       if (dbresults_retval==FAIL) {
                /*php_error_docref(NULL TSRMLS_CC, E_WARNING,"Sybase:  Query failed");*/
                RETURN_FALSE;
        }
@@ -895,6 +903,37 @@ PHP_FUNCTION(sybase_query)
        efree(column_types);
        Z_LVAL_P(return_value) = zend_list_insert(result,php_sybase_module.le_result);
        Z_TYPE_P(return_value) = IS_LONG;
+
+       /**
+        * mgruetzner@rw3.com -- 3-6/2003
+        *
+        * If you do a query that calls a stored procedure which returns
+        * data AND calls raiserror to generated a user-defined error message,
+        * then after retrieving the first set of results above, the call
+        * to dbresults will have returned SUCCESS, instead of NO_MORE_RESULTS
+        * which indicates that the message generated by raiserror is still 
+        * waiting to be read.  If this is the case, then call dbresults
+        * again to force the reading of the message.  This will ensure the 
+        * get_last_message call will return the message properly if called
+        * after mssql_query, like it should.
+        *
+        * One thing to note, we are assuming that no more data should follow
+        * in this case--only the message will be read.  To make sure, I have
+        * added a call to dbnextrow.  The assumption is that it will return
+        * NO_MORE_ROWS in this case.  If the assumption is false, generate
+        * a PHP error so we can debug this case.
+        *
+        */
+       if (dbresults_retval != NO_MORE_RESULTS) {
+               /* Call dbresults again to read message */
+               dbresults_retval = dbresults(sybase_ptr->link);
+
+               /* Check assumption that dbnextrow returns NO_MORE_ROWS */
+               retvalue = dbnextrow(sybase_ptr->link);
+               if (retvalue != NO_MORE_ROWS) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING,"Expected dbnextrow() to return NO_MORE_ROWS.");
+               }
+       }
 }
 /* }}} */