Index: ext/sybase_ct/php_sybase_ct.c
===================================================================
RCS file: /repository/php-src/ext/sybase_ct/php_sybase_ct.c,v
retrieving revision 1.88
diff -u -r1.88 php_sybase_ct.c
--- ext/sybase_ct/php_sybase_ct.c	18 Jan 2004 16:01:02 -0000	1.88
+++ ext/sybase_ct/php_sybase_ct.c	18 Jan 2004 17:03:55 -0000
@@ -935,9 +935,9 @@
 
 /* }}} */
 
-static void php_sybase_finish_results (sybase_result *result) 
+static int php_sybase_finish_results (sybase_result *result) 
 {
-	int i;
+	int i, fail;
 	CS_RETCODE retcode;
 	CS_INT restype;
 	TSRMLS_FETCH();
@@ -962,6 +962,7 @@
 	 * want to return a failure in this case because the application
 	 * won't be getting all the results it asked for.
 	 */
+	fail = 0;
 	while ((retcode = ct_results(result->sybase_ptr->cmd, &restype))==CS_SUCCEED) {
 		switch ((int) restype) {
 			case CS_CMD_SUCCEED:
@@ -969,8 +970,8 @@
 				break;
 
 			case CS_CMD_FAIL:
-				_free_sybase_result(result);
-				result = NULL;
+				php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Sybase:  Command failed, return code %d", retcode);
+				fail = 1;
 				break;
 
 			case CS_COMPUTE_RESULT:
@@ -988,6 +989,10 @@
 				ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL);
 				break;
 		}
+
+		if (fail) {
+			break;
+		}
 	}
 
 	switch (retcode) {
@@ -1012,8 +1017,11 @@
 		default:
 			_free_sybase_result(result);
 			result = NULL;
+			retcode = CS_FAIL;
 			break;
 	}
+
+	return retcode;
 }
 
 static int php_sybase_fetch_result_row (sybase_result *result, int numrows) 
@@ -1070,7 +1078,7 @@
 	
 	switch (retcode) {
 		case CS_END_DATA:
-			php_sybase_finish_results(result);
+			retcode = php_sybase_finish_results(result);
 			break;
 			
 		case CS_ROW_FAIL:
@@ -1080,6 +1088,7 @@
 		default:
 			_free_sybase_result(result);
 			result = NULL;
+			retcode = CS_FAIL;		/* Just to be sure */
 			break;
 	}
 	
@@ -1203,6 +1212,9 @@
 	}
 
 	retcode= php_sybase_fetch_result_row(result, buffered ? 1 : -1);
+	if (retcode == CS_FAIL) {
+		return NULL;
+	}
 
 	return result;
 }
@@ -1332,7 +1344,7 @@
 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase:  Cannot read results");
 			RETURN_FALSE;
 		}
-    
+
 		switch ((int) restype) {
 			case CS_CMD_FAIL:
 			default:
@@ -1361,7 +1373,6 @@
 				result = php_sybase_fetch_result_set(sybase_ptr, buffered, store);
 				if (result == NULL) {
 					ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL);
-					sybase_ptr->dead = 1;
 					RETURN_FALSE;
 				}
 				status = Q_RESULT;
@@ -1476,7 +1487,7 @@
 	}
 
 	/* Indicate we have data in case of buffered queries */
-    id= ZEND_REGISTER_RESOURCE(return_value, result, le_result);
+	id= ZEND_REGISTER_RESOURCE(return_value, result, le_result);
 	sybase_ptr->active_result_index= buffered ? id : 0;
 }
 
