📄 php_sybase_ct.c
字号:
} 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); for (i=0; i<result->num_fields; i++) { ALLOC_ZVAL(field_content); *field_content = result->data[result->store ? result->cur_row : 0][i]; INIT_PZVAL(field_content); zval_copy_ctor(field_content); zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *) &field_content, sizeof(zval* ), NULL); } result->cur_row++;}/* }}} */static void php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int numerics){ zval **sybase_result_index; sybase_result *result; int i, j; zval *tmp; char name[32]; 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 ? Fetch next row */ 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); *tmp = result->data[result->store ? result->cur_row : 0][i]; INIT_PZVAL(tmp); if (PG(magic_quotes_runtime) && Z_TYPE_P(tmp) == IS_STRING) { Z_STRVAL_P(tmp) = php_addslashes(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), &Z_STRLEN_P(tmp), 0 TSRMLS_CC); } else { zval_copy_ctor(tmp); } if (numerics) { 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); j++; } zend_hash_update(Z_ARRVAL_P(return_value), result->fields[i].name, strlen(result->fields[i].name)+1, (void *) &tmp, sizeof(zval *), NULL); } result->cur_row++;}/* {{{ proto object sybase_fetch_object(int result [, mixed object]) Fetch row as object */PHP_FUNCTION(sybase_fetch_object){ 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); break; case IS_NULL: break; default: { convert_to_string_ex(object); zend_str_tolower(Z_STRVAL_PP(object), Z_STRLEN_PP(object)); if (zend_hash_find(EG(class_table), Z_STRVAL_PP(object), Z_STRLEN_PP(object)+1, (void **)&ce) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Sybase: Class %s has not been declared", Z_STRVAL_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, Z_ARRVAL_P(return_value) ); }}/* }}} *//* {{{ proto array sybase_fetch_array(int result) Fetch row as array */PHP_FUNCTION(sybase_fetch_array){ php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);}/* }}} *//* {{{ proto array sybase_fetch_assoc(int result) Fetch row as array without numberic indices */PHP_FUNCTION(sybase_fetch_assoc){ php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);}/* }}} *//* {{{ proto bool sybase_data_seek(int result, int offset) Move internal row pointer */PHP_FUNCTION(sybase_data_seek){ zval **sybase_result_index, **offset; sybase_result *result; if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &sybase_result_index, &offset)==FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(result, sybase_result *, sybase_result_index, -1, "Sybase result", le_result); convert_to_long_ex(offset); /* Unbuffered ? */ 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; } result->cur_row = Z_LVAL_PP(offset); RETURN_TRUE;}/* }}} */static char *php_sybase_get_field_name(CS_INT type){ switch (type) { case CS_CHAR_TYPE: case CS_VARCHAR_TYPE: case CS_TEXT_TYPE: return "string"; break; case CS_IMAGE_TYPE: return "image"; break; case CS_BINARY_TYPE: case CS_VARBINARY_TYPE: return "blob"; break; case CS_BIT_TYPE: return "bit"; break; case CS_TINYINT_TYPE: case CS_SMALLINT_TYPE: case CS_INT_TYPE: return "int"; break; case CS_REAL_TYPE: case CS_FLOAT_TYPE: case CS_NUMERIC_TYPE: case CS_DECIMAL_TYPE: return "real"; break; case CS_MONEY_TYPE: case CS_MONEY4_TYPE: return "money"; break; case CS_DATETIME_TYPE: case CS_DATETIME4_TYPE: return "datetime"; break; default: return "unknown"; break; }}/* {{{ proto object sybase_fetch_field(int result [, int offset]) Get field information */PHP_FUNCTION(sybase_fetch_field){ zval **sybase_result_index, **offset; int field_offset; sybase_result *result; switch (ZEND_NUM_ARGS()) { case 1: if (zend_get_parameters_ex(1, &sybase_result_index) == FAILURE) { RETURN_FALSE; } field_offset=-1; break; case 2: if (zend_get_parameters_ex(2, &sybase_result_index, &offset) == FAILURE) { RETURN_FALSE; } convert_to_long_ex(offset); field_offset = Z_LVAL_PP(offset); break; default: WRONG_PARAM_COUNT; break; } ZEND_FETCH_RESOURCE(result, sybase_result *, sybase_result_index, -1, "Sybase result", le_result); if (field_offset==-1) { field_offset = result->cur_field; result->cur_field++; } if (field_offset<0 || field_offset >= result->num_fields) { if (ZEND_NUM_ARGS()==2) { /* field specified explicitly */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Bad column offset"); } RETURN_FALSE; } object_init(return_value); add_property_string(return_value, "name", result->fields[field_offset].name, 1); add_property_long(return_value, "max_length", result->fields[field_offset].max_length); add_property_string(return_value, "column_source", result->fields[field_offset].column_source, 1); add_property_long(return_value, "numeric", result->fields[field_offset].numeric); add_property_string(return_value, "type", php_sybase_get_field_name(Z_TYPE(result->fields[field_offset])), 1);}/* }}} *//* {{{ proto bool sybase_field_seek(int result, int offset) Set field offset */PHP_FUNCTION(sybase_field_seek){ zval **sybase_result_index, **offset; int field_offset; sybase_result *result; if (ZEND_NUM_ARGS() !=2 || zend_get_parameters_ex(2, &sybase_result_index, &offset) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(result, sybase_result *, sybase_result_index, -1, "Sybase result", le_result); convert_to_long_ex(offset); field_offset = Z_LVAL_PP(offset); /* Unbuffered ? */ 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); } if (field_offset<0 || field_offset >= result->num_fields) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Bad column offset"); RETURN_FALSE; } result->cur_field = field_offset; RETURN_TRUE;}/* }}} *//* {{{ proto string sybase_result(int result, int row, mixed field) Get result data */PHP_FUNCTION(sybase_result){ zval **row, **field, **sybase_result_index; int field_offset=0; sybase_result *result; if (ZEND_NUM_ARGS() !=3 || zend_get_parameters_ex(3, &sybase_result_index, &row, &field)==FAILURE) { WRONG_PARAM_COUNT; } 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)); } if (Z_LVAL_PP(row) < 0 || Z_LVAL_PP(row) >= result->num_rows) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Bad row offset (%ld)", Z_LVAL_PP(row)); RETURN_FALSE; } switch(Z_TYPE_PP(field)) { case IS_STRING: { int i; for (i=0; i<result->num_fields; i++) { if (!strcasecmp(result->fields[i].name, Z_STRVAL_PP(field))) { field_offset = i; break; } } if (i>=result->num_fields) { /* no match found */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: %s field not found in result", Z_STRVAL_PP(field)); RETURN_FALSE; } break; } default: convert_to_long_ex(field); field_offset = Z_LVAL_PP(field); if (field_offset<0 || field_offset>=result->num_fields) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Bad column offset specified"); RETURN_FALSE; } break; } *return_value = result->data[Z_LVAL_PP(row)][field_offset]; zval_copy_ctor(return_value);}/* }}} *//* {{{ proto int sybase_affected_rows([int link_id]) Get number of affected rows in last query */PHP_FUNCTION(sybase_affected_rows){ zval **sybase_link_index; sybase_link *sybase_ptr; int id; switch(ZEND_NUM_ARGS()) { case 0: id = php_sybase_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU); break; case 1: if (zend_get_parameters_ex(1, &sybase_link_index) == FAILURE) { RETURN_FALSE; } id = -1; break; default: WRONG_PARAM_COUNT; break; } ZEND_FETCH_RESOURCE2(sybase_ptr, sybase_link *, sybase_link_index, id, "Sybase-Link", le_link, le_plink); Z_LVAL_P(return_value) = sybase_ptr->affected_rows; Z_TYPE_P(return_value) = IS_LONG;}/* }}} */PHP_MINFO_FUNCTION(sybase){ char buf[32]; php_info_print_table_start(); php_info_print_table_header(2, "Sybase_CT Support", "enabled" ); sprintf(buf, "%ld", SybCtG(num_persistent)); php_info_print_table_row(2, "Active Persistent Links", buf); sprintf(buf, "%ld", SybCtG(num_links)); php_info_print_table_row(2, "Active Links", buf); 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, "Application Name", SybCtG(appname)); sprintf(buf, "%ld", SybCtG(deadlock_retry_count)); php_info_print_table_row(2, "Deadlock retry count", buf); php_info_print_table_end(); DISPLAY_INI_ENTRIES();}/* {{{ proto void sybase_min_client_severity(int severity) Sets minimum client severity */PHP_FUNCTION(sybase_min_client_severity){ zval **severity; if (ZEND_NUM_ARGS() !=1 || zend_get_parameters_ex(1, &severity) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long_ex(severity); SybCtG(min_client_severity) = Z_LVAL_PP(severity);}/* }}} *//* {{{ proto void sybase_min_server_severity(int severity) Sets minimum server severity */PHP_FUNCTION(sybase_min_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -