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

index dff1e56bcf0aa05d49ddf05738f50d114e20f7ff..a7bc24566adc44672234c4ed1955960e2a47098f 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.");
+               }
+       }
 }
 /* }}} */