/* }}} */
-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();
* 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:
break;
case CS_CMD_FAIL:
- _free_sybase_result(result);
- result = NULL;
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Command failed, cancelling rest");
+ ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL);
+ fail = 1;
break;
case CS_COMPUTE_RESULT:
ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL);
break;
}
+
+ if (fail) {
+ break;
+ }
}
switch (retcode) {
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)
case 1:
convert_to_long(&result->data[i][j]);
break;
- case 2:
+ case 2:
+ /* We also get numbers that are actually integers here due to the check on
+ * precision against > 9 (ranges are -1E10 to -1E9 and 1E9 to 1E10). As we
+ * cannot be sure that they "fit" into MIN_LONG <= x <= MAX_LONG, we call
+ * convert_to_double() on them. This is a small performance penalty, but
+ * ensures that "select 2147483648" will be a float and "select 2147483647"
+ * will be become an int.
+ */
convert_to_double(&result->data[i][j]);
break;
}
switch (retcode) {
case CS_END_DATA:
- php_sybase_finish_results(result);
+ retcode = php_sybase_finish_results(result);
break;
case CS_ROW_FAIL:
default:
_free_sybase_result(result);
result = NULL;
+ retcode = CS_FAIL; /* Just to be sure */
break;
}
case CS_DECIMAL_TYPE:
result->datafmt[i].maxlength = result->datafmt[i].precision + 3;
/* numeric(10) vs numeric(10, 1) */
- result->numerics[i] = (result->datafmt[i].scale == 0 && result->datafmt[i].precision <= 10) ? 1 : 2;
+ result->numerics[i] = (result->datafmt[i].scale == 0 && result->datafmt[i].precision <= 9) ? 1 : 2;
break;
default:
result->datafmt[i].maxlength++;
}
retcode= php_sybase_fetch_result_row(result, buffered ? 1 : -1);
+ if (retcode == CS_FAIL) {
+ return NULL;
+ }
return result;
}
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Cannot read results");
RETURN_FALSE;
}
-
+
switch ((int) restype) {
case CS_CMD_FAIL:
default:
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;
}
/* 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;
}
}
if (SybCtG(callback_name)) {
- zval_dtor(SybCtG(callback_name));
+ zval_ptr_dtor(&SybCtG(callback_name));
SybCtG(callback_name)= NULL;
}