}
/* Forward declaration */
-static int php_sybase_finish_results (sybase_result *result);
+static int php_sybase_finish_results (sybase_result *result TSRMLS_DC);
static void php_free_sybase_result(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
if (result->sybase_ptr->cmd) {
ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL);
}
- php_sybase_finish_results(result);
+ php_sybase_finish_results(result TSRMLS_CC);
}
_free_sybase_result(result);
ZVAL_LONG(line, srvmsg->line);
args[3] = &line;
- MAKE_STD_ZVAL(text);
+ MAKE_STD_ZVAL(text);
ZVAL_STRING(text, srvmsg->text, 1);
args[4] = &text;
-
+
if (call_user_function_ex(EG(function_table), NULL, callback_name, &retval, 5, args, 0, NULL TSRMLS_CC) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Cannot call the messagehandler %s", Z_STRVAL_P(callback_name));
}
}
}
- /* Set the timeout, which is per context and can't be set with
- * ct_con_props(), so set it globally from the config value if
+ /* Set the timeout, which is per context and can't be set with
+ * ct_con_props(), so set it globally from the config value if
* requested. The default is CS_NO_LIMIT.
- *
+ *
* Note that despite some noise in the documentation about using
* signals to implement timeouts, they are actually implemented
* by using poll() or select() on Solaris and Linux.
}
if (appname) {
ct_con_props(sybase->connection, CS_SET, CS_APPNAME, appname, CS_NULLTERM, NULL);
- } else {
+ } else {
ct_con_props(sybase->connection, CS_SET, CS_APPNAME, SybCtG(appname), CS_NULLTERM, NULL);
}
}
}
}
-
+
if (cfg_get_long("sybct.packet_size", &packetsize) == SUCCESS) {
if (ct_con_props(sybase->connection, CS_SET, CS_PACKETSIZE, (CS_VOID *)&packetsize, CS_UNUSED, NULL) != CS_SUCCEED) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Unable to update connection packetsize.");
}
/* Set the login timeout. Actually, the login timeout is per context
- * and not per connection, but we will update the context here to
+ * and not per connection, but we will update the context here to
* allow for code such as the following:
- *
+ *
* ini_set('sybct.login_timeout', $timeout);
* sybase_connect(...)
- *
- * Note that preceding calls to sybase_connect() will now use the
+ *
+ * Note that preceding calls to sybase_connect() will now use the
* updated value and not the default one!
- *
+ *
* The default value for CS_LOGIN_TIMEOUT is 60 (1 minute).
*/
if (SybCtG(login_timeout) != -1) {
/* }}} */
-static int php_sybase_finish_results(sybase_result *result TSRMLS_DC)
+static int php_sybase_finish_results(sybase_result *result TSRMLS_DC)
{
int i, fail;
CS_RETCODE retcode;
CS_INT restype;
-
+
efree(result->datafmt);
efree(result->lengths);
efree(result->indicators);
* dead ourselves.
*/
result->sybase_ptr->dead = 1;
-
+
case CS_CANCELED:
default:
_free_sybase_result(result);
int i, j;
CS_INT retcode;
TSRMLS_FETCH();
-
+
/* We've already fetched everything */
if (result->last_retcode == CS_END_DATA || result->last_retcode == CS_END_RESULTS) {
return result->last_retcode;
}
-
+
if (numrows!=-1) numrows+= result->num_rows;
while ((retcode=ct_fetch(result->sybase_ptr->cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, NULL))==CS_SUCCEED
|| retcode==CS_ROW_FAIL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Error reading row %d", result->num_rows);
}
*/
-
+
result->num_rows++;
i= result->store ? result->num_rows- 1 : 0;
if (i >= result->blocks_initialized*SYBASE_ROWS_BLOCK) {
ZVAL_LONG(&result->data[i][j], strtol(result->tmp_buffer[j], NULL, 10));
break;
}
-
+
case 2: {
/* This indicates a float */
- RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]);
+ RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]);
break;
}
errno = 0;
Z_LVAL(result->data[i][j]) = strtol(result->tmp_buffer[j], NULL, 10);
if (errno == ERANGE) {
-
+
/* An overflow occurred, so try to fit it into a double */
- RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]);
+ RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]);
break;
}
Z_TYPE(result->data[i][j]) = IS_LONG;
break;
}
-
+
default: {
/* This indicates anything else, return it as string */
ZVAL_STRINGL(&result->data[i][j], result->tmp_buffer[j], result->lengths[j]- 1, 1);
break;
- }
+ }
}
}
}
if (numrows!=-1 && result->num_rows>=numrows) break;
}
-
+
result->last_retcode= retcode;
switch (retcode) {
case CS_END_DATA:
retcode = php_sybase_finish_results(result TSRMLS_CC);
break;
-
+
case CS_ROW_FAIL:
case CS_SUCCEED:
break;
-
+
default:
_free_sybase_result(result);
result = NULL;
retcode = CS_FAIL; /* Just to be sure */
break;
}
-
+
return retcode;
}
if (ct_res_info(sybase_ptr->cmd, CS_NUMDATA, &num_fields, CS_UNUSED, NULL)!=CS_SUCCEED) {
return NULL;
}
-
+
result = (sybase_result *) emalloc(sizeof(sybase_result));
result->data = (zval **) safe_emalloc(sizeof(zval *), SYBASE_ROWS_BLOCK, 0);
result->fields = NULL;
result->datafmt = (CS_DATAFMT *) safe_emalloc(sizeof(CS_DATAFMT), num_fields, 0);
result->numerics = (unsigned char *) safe_emalloc(sizeof(unsigned char), num_fields, 0);
result->types = (CS_INT *) safe_emalloc(sizeof(CS_INT), num_fields, 0);
-
+
for (i=0; i<num_fields; i++) {
ct_describe(sybase_ptr->cmd, i+1, &result->datafmt[i]);
result->types[i] = result->datafmt[i].datatype;
result->fields[i].numeric = result->numerics[i];
Z_TYPE(result->fields[i]) = result->types[i];
}
-
+
if (buffered) {
retcode = CS_SUCCEED;
} else {
if (sybase_ptr->dead) {
RETURN_FALSE;
}
-
+
/* Check to see if a previous sybase_unbuffered_query has read all rows */
if (sybase_ptr->active_result_index) {
zval *tmp = NULL;
-
+
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "called without first fetching all rows from a previous unbuffered query");
if (sybase_ptr->cmd) {
ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_ALL);
}
-
+
/* Get the resultset and free it */
ALLOC_ZVAL(tmp);
Z_LVAL_P(tmp)= sybase_ptr->active_result_index;
Z_TYPE_P(tmp)= IS_RESOURCE;
INIT_PZVAL(tmp);
ZEND_FETCH_RESOURCE(result, sybase_result *, &tmp, -1, "Sybase result", le_result);
-
+
/* Causes the following segfault:
Program received signal SIGSEGV, Segmentation fault.
- 0x8144380 in _efree (ptr=0x81fe024, __zend_filename=0x81841a0 "php4/ext/sybase_ct/php_sybase_ct.c",
+ 0x8144380 in _efree (ptr=0x81fe024, __zend_filename=0x81841a0 "php4/ext/sybase_ct/php_sybase_ct.c",
__zend_lineno=946, __zend_orig_filename=0x0, __zend_orig_lineno=0) at php4/Zend/zend_alloc.c:229
php4/Zend/zend_alloc.c:229:7284:beg:0x8144380
*/
php_sybase_finish_results(result TSRMLS_CC);
}
#endif
-
+
zval_ptr_dtor(&tmp);
zend_list_delete(sybase_ptr->active_result_index);
sybase_ptr->active_result_index= 0;
status = Q_RESULT;
break;
}
-
+
/* Check for left-over results */
if (!buffered && status != Q_RESULT) {
while ((retcode = ct_results(sybase_ptr->cmd, &restype))==CS_SUCCEED) {
RETURN_FALSE;
}
status = Q_RESULT;
- retcode = result->last_retcode;
+ retcode = result->last_retcode;
} else {
/* Unexpected results, cancel them. */
ct_cancel(NULL, sybase_ptr->cmd, CS_CANCEL_CURRENT);
}
}
- /* Retry deadlocks up until deadlock_retry_count times */
+ /* 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", deadlock_count- 1, SybCtG(deadlock_retry_count));
if (result != NULL) {
}
ZEND_FETCH_RESOURCE(result, sybase_result *, sybase_result_index, -1, "Sybase result", le_result);
-
+
/* Did we fetch up until the end? */
if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) {
/* php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Cancelling the rest of the results"); */
ct_cancel(NULL, result->sybase_ptr->cmd, CS_CANCEL_ALL);
php_sybase_finish_results(result TSRMLS_CC);
}
-
+
zend_list_delete(Z_LVAL_PP(sybase_result_index));
RETURN_TRUE;
}
if (ZEND_NUM_ARGS() !=1 || zend_get_parameters_ex(1, &sybase_result_index) == FAILURE) {
WRONG_PARAM_COUNT;
}
-
+
ZEND_FETCH_RESOURCE(result, sybase_result *, sybase_result_index, -1, "Sybase result", le_result);
/* Unbuffered? */
if (result->last_retcode != CS_END_DATA && result->last_retcode != CS_END_RESULTS) {
php_sybase_fetch_result_row(result, 1);
}
-
+
/* At the end? */
if (result->cur_row >= result->num_rows) {
RETURN_FALSE;
}
array_init(return_value);
-
+
j= 1;
for (i=0; i<result->num_fields; i++) {
ALLOC_ZVAL(tmp);
zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *) &tmp, sizeof(zval *), NULL);
tmp->refcount++;
}
-
+
if (zend_hash_exists(Z_ARRVAL_P(return_value), result->fields[i].name, strlen(result->fields[i].name)+1)) {
snprintf(name, 32, "%s%d", result->fields[i].name, j);
result->fields[i].name= estrdup(name);
zval **object= NULL;
zval *sybase_result_index;
zend_class_entry *ce= NULL;
-
+
/* Was a second parameter given? */
if (2 == ZEND_NUM_ARGS()) {
if (zend_get_parameters_ex(2, &sybase_result_index, &object) == FAILURE) {
WRONG_PARAM_COUNT;
}
-
+
switch (Z_TYPE_PP(object)) {
case IS_OBJECT:
ce = Z_OBJCE_PP(object);
/* Reset no. of arguments to 1 so that we can use INTERNAL_FUNCTION_PARAM_PASSTHRU */
ht= 1;
}
-
+
php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
if (Z_TYPE_P(return_value)==IS_ARRAY) {
object_and_properties_init(
- return_value,
- ce ? ce : ZEND_STANDARD_CLASS_DEF_PTR,
+ return_value,
+ ce ? ce : ZEND_STANDARD_CLASS_DEF_PTR,
Z_ARRVAL_P(return_value)
);
}
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)+ 1);
}
-
+
if (Z_LVAL_PP(offset)<0 || Z_LVAL_PP(offset)>=result->num_rows) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Bad row offset %ld, must be betweem 0 and %d", Z_LVAL_PP(offset), result->num_rows - 1);
RETURN_FALSE;
convert_to_long_ex(offset);
field_offset = Z_LVAL_PP(offset);
-
+
if (field_offset<0 || field_offset >= result->num_fields) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Bad column offset");
RETURN_FALSE;
ZEND_FETCH_RESOURCE(result, sybase_result *, sybase_result_index, -1, "Sybase result", le_result);
convert_to_long_ex(row);
-
+
/* Unbuffered ? */
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));
sprintf(buf, "%ld", SybCtG(min_server_severity));
php_info_print_table_row(2, "Min server severity", buf);
sprintf(buf, "%ld", SybCtG(min_client_severity));
- php_info_print_table_row(2, "Min client severity", buf);
+ php_info_print_table_row(2, "Min client severity", buf);
php_info_print_table_row(2, "Application Name", SybCtG(appname));
sprintf(buf, "%ld", SybCtG(deadlock_retry_count));
php_info_print_table_row(2, "Deadlock retry count", buf);
/* {{{ proto bool sybase_set_message_handler(mixed error_func [, resource connection])
- Set the error handler, to be called when a server message is raised.
+ Set the error handler, to be called when a server message is raised.
If error_func is NULL the handler will be deleted */
PHP_FUNCTION(sybase_set_message_handler)
{
case 2: /* Connection-based message handler */
if (zend_get_parameters_ex(2, ¶m, &sybase_link_index) == FAILURE) {
RETURN_FALSE;
- }
+ }
ZEND_FETCH_RESOURCE2(sybase_ptr, sybase_link *, sybase_link_index, -1, "Sybase-Link", le_link, le_plink);
callback = &sybase_ptr->callback_name;
break;
default:
WRONG_PARAM_COUNT;
}
-
+
/* Clean out old callback */
if (*callback) {
zval_ptr_dtor(callback);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argumented is expected to be either NULL, an array or string, %s given", zend_zval_type_name(*param));
RETURN_FALSE;
}
-
+
ALLOC_ZVAL(*callback);
**callback = **param;
INIT_PZVAL(*callback);