Index: ext/sybase_ct/php_sybase_ct.c
===================================================================
RCS file: /repository/php-src/ext/sybase_ct/php_sybase_ct.c,v
retrieving revision 1.90
diff -u -r1.90 php_sybase_ct.c
--- ext/sybase_ct/php_sybase_ct.c	25 Jan 2004 20:03:10 -0000	1.90
+++ ext/sybase_ct/php_sybase_ct.c	9 Feb 2004 00:03:00 -0000
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_sybase_ct.c,v 1.90 2004/01/25 20:03:10 thekid Exp $ */
+/* $Id: php_sybase_ct.c,v 1.73.2.9 2004/01/25 20:14:05 thekid Exp $ */
 
 
 #ifdef HAVE_CONFIG_H
@@ -1078,8 +1078,8 @@
 	CS_INT retcode;
 	
 	/* We've already fetched everything */
-	if (result->last_retcode == CS_END_DATA) {
-		return CS_END_DATA;
+	if (result->last_retcode == CS_END_DATA || result->last_retcode == CS_END_RESULTS) {
+		return result->last_retcode;
 	}
 	
 	if (numrows!=-1) numrows+= result->num_rows;
@@ -1130,7 +1130,6 @@
 	}
 	
 	result->last_retcode= retcode;
-	
 	switch (retcode) {
 		case CS_END_DATA:
 			retcode = php_sybase_finish_results(result);
@@ -1265,12 +1264,13 @@
 		result->fields[i].numeric = result->numerics[i];
 		Z_TYPE(result->fields[i]) = result->types[i];
 	}
-
+	
 	retcode= php_sybase_fetch_result_row(result, buffered ? 1 : -1);
 	if (retcode == CS_FAIL) {
 		return NULL;
 	}
 
+	result->last_retcode = retcode;
 	return result;
 }
 
@@ -1399,7 +1399,6 @@
 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase:  Cannot read results");
 			RETURN_FALSE;
 		}
-
 		switch ((int) restype) {
 			case CS_CMD_FAIL:
 			default:
@@ -1458,6 +1457,7 @@
 								RETURN_FALSE;
 							}
 							status = Q_RESULT;
+							retcode = result->last_retcode; 
 						} else {
 							/* Unexpected results, cancel them. */
 							ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_CURRENT);
@@ -1475,8 +1475,10 @@
 				if (status == Q_FAILURE) {
 					ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL);
 				}
+				if (retcode == CS_END_RESULTS) {
+					break;
+				}
 			}
-
 			switch (retcode) {
 				case CS_END_RESULTS:
 					/* Normal. */
@@ -1500,7 +1502,7 @@
 					break;
 			}
 		}
-		
+
 		/* Retry deadlocks up until deadlock_retry_count times */		
 		if (sybase_ptr->deadlock && SybCtG(deadlock_retry_count) != -1 && ++deadlock_count > SybCtG(deadlock_retry_count)) {
 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase:  Retried deadlock %d times [max: %ld], giving up\n", deadlock_count- 1, SybCtG(deadlock_retry_count));
@@ -1654,7 +1656,7 @@
 	ZEND_FETCH_RESOURCE(result, sybase_result *, sybase_result_index, -1, "Sybase result", le_result);
 
 	/* Unbuffered? */
-	if (result->last_retcode != CS_END_DATA) {
+	if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) {
 		php_sybase_fetch_result_row(result, 1);
 	}
 	
@@ -1691,7 +1693,7 @@
 	ZEND_FETCH_RESOURCE(result, sybase_result *, sybase_result_index, -1, "Sybase result", le_result);
 
 	/* Unbuffered ? Fetch next row */
-	if (result->last_retcode != CS_END_DATA) {
+	if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) {
 		php_sybase_fetch_result_row(result, 1);
 	}
 
@@ -1804,7 +1806,7 @@
 	convert_to_long_ex(offset);
 
 	/* Unbuffered ? */
-	if (result->last_retcode != CS_END_DATA && Z_LVAL_PP(offset)>=result->num_rows) {
+	if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS && Z_LVAL_PP(offset)>=result->num_rows) {
 		php_sybase_fetch_result_row(result, Z_LVAL_PP(offset));
 	}
 	
@@ -1932,7 +1934,7 @@
 	field_offset = Z_LVAL_PP(offset);
 	
 	/* Unbuffered ? */
-	if (result->last_retcode != CS_END_DATA && field_offset>=result->num_rows) {
+	if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS && field_offset>=result->num_rows) {
 		php_sybase_fetch_result_row(result, field_offset);
 	}
 
@@ -1965,7 +1967,7 @@
 	convert_to_long_ex(row);
 	
 	/* Unbuffered ? */
-	if (result->last_retcode != CS_END_DATA && Z_LVAL_PP(row) >= result->num_rows) {
+	if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS && Z_LVAL_PP(row) >= result->num_rows) {
 		php_sybase_fetch_result_row(result, Z_LVAL_PP(row));
 	}
 
