From:             [EMAIL PROTECTED]
Operating system: All
PHP version:      4.0 Latest CVS (2001-06-13)
PHP Bug Type:     Sybase-ct (ctlib) related
Bug description:  stored procedure processing

We have some Sybase stored procedures that don't work with php - they return 1 instead 
of a result set.  Stepping through the code, I found that the proc was returning an 
empty status result before the real results, which confuses the php code that loops 
through the Sybase results, as it expects to see a result set first.

I've made the following change to that code (diff -u format)that processes all of the 
results, and doesn't treat a status result in the same way as a real result.

--- php_sybase_ct.c.orig        Mon Jun 11 17:17:22 2001
+++ php_sybase_ct.c     Mon Jun 11 17:17:31 2001
@@ -1079,36 +1079,32 @@
                 * properly read or cancel them or the connection will become
                 * unusable.
                 */
-               if (ct_results(sybase_ptr->cmd, &restype)!=CS_SUCCEED) {
-                       ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL);
-                       sybase_ptr->dead = 1;
-                       RETURN_FALSE;
-               }
+               while ((retcode = ct_results(sybase_ptr->cmd, &restype))==CS_SUCCEED) {
 
-               switch ((int) restype) {
+                   switch ((int) restype) {
                        case CS_CMD_FAIL:
                        default:
                                status = Q_FAILURE;
                                break;
                        case CS_CMD_SUCCEED:
                        case CS_CMD_DONE: {
-                                       CS_INT row_count;
-                                       if (ct_res_info(sybase_ptr->cmd, CS_ROW_COUNT, 
&row_count, CS_UNUSED, NULL)==CS_SUCCEED) {
-                                               sybase_ptr->affected_rows = 
(long)row_count;
-                                       }
+                               CS_INT row_count;
+                               if (ct_res_info(sybase_ptr->cmd, CS_ROW_COUNT, 
+&row_count, CS_UNUSED, NULL)==CS_SUCCEED) {
+                                       sybase_ptr->affected_rows = (long)row_count;
                                }
+                       }
                                /* Fall through */
                        case CS_COMPUTEFMT_RESULT:
                        case CS_ROWFMT_RESULT:
                        case CS_DESCRIBE_RESULT:
                        case CS_MSG_RESULT:
-                               status = Q_SUCCESS;
+                               if (status != Q_RESULT) /* if we don't already have a 
+result */
+                                       status = Q_SUCCESS;
                                break;
                        case CS_COMPUTE_RESULT:
                        case CS_CURSOR_RESULT:
                        case CS_PARAM_RESULT:
                        case CS_ROW_RESULT:
-                       case CS_STATUS_RESULT:
                                result = php_sybase_fetch_result_set(sybase_ptr);
                                if (result == NULL) {
                                        ct_cancel(NULL, sybase_ptr->cmd, 
CS_CANCEL_ALL);
@@ -1117,41 +1113,11 @@
                                }
                                status = Q_RESULT;
                                break;
-               }
-
-               /* The only restype we should get now is CS_CMD_DONE, possibly
-                * followed by a CS_STATUS_RESULT/CS_CMD_SUCCEED/CS_CMD_DONE
-                * sequence if the command was a stored procedure call.  But we
-                * still need to read and discard unexpected results.  We might
-                * want to return a failure in this case because the application
-                * won't be getting all the results it asked for.
-                */
-               while ((retcode = ct_results(sybase_ptr->cmd, &restype))==CS_SUCCEED) {
-                       switch ((int) restype) {
-                               case CS_CMD_SUCCEED:
-                               case CS_CMD_DONE:
-                                       break;
-
-                               case CS_CMD_FAIL:
-                                       status = Q_FAILURE;
-                                       break;
-                       
-                               case CS_COMPUTE_RESULT:
-                               case CS_CURSOR_RESULT:
-                               case CS_PARAM_RESULT:
-                               case CS_ROW_RESULT:
-                                       /* Unexpected results, cancel them. */
-                               case CS_STATUS_RESULT:
-                                       ct_cancel(NULL, sybase_ptr->cmd, 
CS_CANCEL_CURRENT);
-                                       break;
-                       
-                               default:
-                                       status = Q_FAILURE;
-                                       break;
-                       }
-                       if (status == Q_FAILURE) {
-                               ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL);
-                       }
+                       /* nothing to read for STATUS_RESULT */
+                       case CS_STATUS_RESULT:
+                               ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_CURRENT);
+                               break;
+                   }
                }
 
                switch (retcode) {





-- 
Edit Bug report at: http://bugs.php.net/?id=11475&edit=1



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to