diff options
author | Marc Boeren <mboeren@php.net> | 2001-06-05 13:39:09 +0000 |
---|---|---|
committer | Marc Boeren <mboeren@php.net> | 2001-06-05 13:39:09 +0000 |
commit | 98eed02fd7fb4495c1df97efe510684a1be66cd8 (patch) | |
tree | 786668e756cf2060b959389b27910d9b84bb3ebf | |
parent | 25c3a3a39d7aebdce95825e6af2ad8c62905b7cc (diff) | |
download | php-git-98eed02fd7fb4495c1df97efe510684a1be66cd8.tar.gz |
Replaced dbx_cmp_asc and dbx_cmp_desc with dbx_compare function and
DBX_CMP_ASC, DBX_CMP_DESC flags.
Default comparison changed from DBX_CMP_TEXT to new DBX_CMP_NATIVE.
Solved bug in associative fields when using mssql
Cleaned up comments (/*/ ... /*/ to /* ... */)
dbx_connect now always return false if the database is not found.
Optimized dbx_query field-info retrieval loop
-rw-r--r-- | ext/dbx/dbx.c | 358 | ||||
-rw-r--r-- | ext/dbx/dbx.h | 17 | ||||
-rw-r--r-- | ext/dbx/dbx_mssql.c | 55 | ||||
-rw-r--r-- | ext/dbx/dbx_mssql.h | 18 | ||||
-rw-r--r-- | ext/dbx/dbx_mysql.c | 55 | ||||
-rw-r--r-- | ext/dbx/dbx_mysql.h | 18 | ||||
-rw-r--r-- | ext/dbx/dbx_odbc.c | 37 | ||||
-rw-r--r-- | ext/dbx/dbx_odbc.h | 18 | ||||
-rw-r--r-- | ext/dbx/dbx_pgsql.c | 16 | ||||
-rw-r--r-- | ext/dbx/dbx_pgsql.h | 18 | ||||
-rw-r--r-- | ext/dbx/php_dbx.h | 7 |
11 files changed, 325 insertions, 292 deletions
diff --git a/ext/dbx/dbx.c b/ext/dbx/dbx.c index f587e16072..af7e5be955 100644 --- a/ext/dbx/dbx.c +++ b/ext/dbx/dbx.c @@ -29,20 +29,20 @@ #include "php_dbx.h" #include "ext/standard/info.h" -/*/ defines for supported databases /*/ +/* defines for supported databases */ #define DBX_UNKNOWN 0 #define DBX_MYSQL 1 #define DBX_ODBC 2 #define DBX_PGSQL 3 #define DBX_MSSQL 4 -/*/ includes for supported databases /*/ +/* includes for supported databases */ #include "dbx.h" #include "dbx_mysql.h" #include "dbx_odbc.h" #include "dbx_pgsql.h" #include "dbx_mssql.h" -/*/ support routines /*/ +/* support routines */ int module_exists(char * module_name) { zend_module_entry * zme; int r; @@ -78,7 +78,7 @@ int split_dbx_handle_object(zval ** dbx_object, zval *** pdbx_handle, zval *** p return 1; } -/*/ from dbx.h, to be used in support-files (dbx_mysql.c etc...) /*/ +/* from dbx.h, to be used in support-files (dbx_mysql.c etc...) */ void dbx_call_any_function(INTERNAL_FUNCTION_PARAMETERS, char * function_name, zval ** returnvalue, int number_of_arguments, zval *** params) { zval * zval_function_name; MAKE_STD_ZVAL(zval_function_name); @@ -86,36 +86,36 @@ void dbx_call_any_function(INTERNAL_FUNCTION_PARAMETERS, char * function_name, z if (call_user_function_ex(EG(function_table), NULL, zval_function_name, returnvalue, number_of_arguments, params, 0, NULL) == FAILURE) { zend_error(E_ERROR, "function '%s' not found", zval_function_name->value.str.val); } - zval_dtor(zval_function_name); /*/ to free stringvalue memory /*/ + zval_dtor(zval_function_name); /* to free stringvalue memory */ FREE_ZVAL(zval_function_name); } -/*/ switch_dbx functions declarations -/ / each must be supported in the x/dbx_module files as dbx_module_function, -/ / e.g. switch_dbx_connect expects a dbx_mysql_connect in de x/dbx_mysql files -/ / all params except the dbx_module param are passed on -/ / each must return the expected zval * 's in the rv parameter, which are passed on unmodified -/ / do NOT use the return_value parameter from INTERNAL_FUNCTION_PARAMETERS -/ / you can additionally return 0 or 1 for failure or success which will also be returned by the switches -/*/ +/* switch_dbx functions declarations + * each must be supported in the dbx_module files as dbx_module_function, + * e.g. switch_dbx_connect expects a dbx_mysql_connect in de dbx_mysql files + * all params except the dbx_module param are passed on + * each must return the expected zval * 's in the rv parameter, which are passed on unmodified + * do NOT use the return_value parameter from INTERNAL_FUNCTION_PARAMETERS + * you can additionally return 0 or 1 for failure or success which will also be returned by the switches + */ int switch_dbx_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int switch_dbx_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns persistent connection handle as resource on success or 0 as long on failure /*/ + /* returns persistent connection handle as resource on success or 0 as long on failure */ int switch_dbx_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns 1 as long or result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or result identifier as resource on success or 0 as long on failure */ int switch_dbx_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ int switch_dbx_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ int switch_dbx_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ int switch_dbx_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int switch_dbx_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module); - /*/ returns string /*/ + /* returns string */ /* Every user visible function must have an entry in dbx_functions[]. */ @@ -126,8 +126,7 @@ function_entry dbx_functions[] = { ZEND_FE(dbx_error, NULL) ZEND_FE(dbx_sort, NULL) - ZEND_FE(dbx_cmp_asc, NULL) - ZEND_FE(dbx_cmp_desc, NULL) + ZEND_FE(dbx_compare, NULL) {NULL, NULL, NULL} /* Must be the last line in dbx_functions[] */ }; @@ -149,26 +148,28 @@ ZEND_GET_MODULE(dbx) ZEND_MINIT_FUNCTION(dbx) { -/*/ REGISTER_INI_ENTRIES(); /*/ - REGISTER_LONG_CONSTANT("DBX_MYSQL", DBX_MYSQL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DBX_ODBC", DBX_ODBC, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DBX_PGSQL", DBX_PGSQL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DBX_MSSQL", DBX_MSSQL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DBX_PERSISTENT", DBX_PERSISTENT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBX_RESULT_INFO", DBX_RESULT_INFO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DBX_RESULT_INDEX", DBX_RESULT_INDEX, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DBX_RESULT_ASSOC", DBX_RESULT_ASSOC, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("DBX_CMP_NATIVE", DBX_CMP_NATIVE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DBX_CMP_TEXT", DBX_CMP_TEXT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DBX_CMP_NUMBER", DBX_CMP_NUMBER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBX_CMP_ASC", DBX_CMP_ASC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBX_CMP_DESC", DBX_CMP_DESC, CONST_CS | CONST_PERSISTENT); return SUCCESS; } ZEND_MSHUTDOWN_FUNCTION(dbx) { -/*/ UNREGISTER_INI_ENTRIES(); /*/ return SUCCESS; } @@ -186,23 +187,19 @@ ZEND_MINFO_FUNCTION(dbx) { php_info_print_table_start(); php_info_print_table_row(2, "dbx support", "enabled"); - php_info_print_table_row(2, "dbx support for MySQL", "enabled"); - php_info_print_table_row(2, "dbx support for ODBC", "enabled"); - php_info_print_table_row(2, "dbx support for PostgreSQL", "enabled"); - php_info_print_table_row(2, "dbx support for Microsoft SQL Server", "enabled"); + php_info_print_table_row(2, "dbx version", "1.0.0"); + php_info_print_table_row(2, "supported databases", "MySQL<br />ODBC<br />PostgreSQL<br />Microsoft SQL Server"); php_info_print_table_end(); -/*/ DISPLAY_INI_ENTRIES(); /*/ } -/*/ -/ / -/ / actual implementation of the dbx functions -/ / -/ / -/ / -/ / -/*/ -/* {{{ proto dbx_handle_object dbx_connect(string module_name, string host, string db, string username, string password [, bool persistent]) - returns a dbx_handle_object on success + +/* + + actual implementation of the dbx functions + +*/ + +/* {{{ proto dbx_link_object dbx_connect(string module_name, string host, string db, string username, string password [, bool persistent]) + returns a dbx_link_object on success returns 0 on failure */ ZEND_FUNCTION(dbx_connect) @@ -263,6 +260,7 @@ ZEND_FUNCTION(dbx_connect) } if (!result) { FREE_ZVAL(dbx_module); + zval_dtor(db_name); /* to free stringvalue memory */ FREE_ZVAL(db_name); FREE_ZVAL(rv_dbx_handle); RETURN_LONG(0); @@ -271,6 +269,7 @@ ZEND_FUNCTION(dbx_connect) if (object_init(return_value) != SUCCESS) { zend_error(E_ERROR, "dbx: unable to create resulting object..."); FREE_ZVAL(dbx_module); + zval_dtor(db_name); /* to free stringvalue memory */ FREE_ZVAL(db_name); FREE_ZVAL(rv_dbx_handle); RETURN_LONG(0); @@ -282,8 +281,9 @@ ZEND_FUNCTION(dbx_connect) } /* }}} */ -/* {{{ proto bool dbx_close(dbx_handle_object dbx_handle) - Returns success or failure */ +/* {{{ proto bool dbx_close(dbx_link_object dbx_link) + Returns success or failure +*/ ZEND_FUNCTION(dbx_close) { int number_of_arguments=1; @@ -316,11 +316,10 @@ ZEND_FUNCTION(dbx_close) } /* }}} */ -/* {{{ proto data[rowinfo+rows][colinfo+cols] dbx_query(dbx_handle_object dbx_handle, string sql_statement [, long flags]) - Returns results combined with query-information or false for failure or true for success on execution query - flags parameters is not implemented yet and if specified generates a WRONG_PARAM_COUNT - it will be used to indicate what column info should be returned, and if fieldnames should be used - as assoc column indicators in the result-set */ +/* {{{ proto dbx_result_object dbx_query(dbx_link_object dbx_link, string sql_statement [, long flags]) + returns a dbx_link_object on success + returns 0 on failure +*/ ZEND_FUNCTION(dbx_query) { int min_number_of_arguments=2; @@ -338,6 +337,9 @@ ZEND_FUNCTION(dbx_query) zval * info; long info_flags; zval * data; + zval * dummy; + zval ** row_ptr; + zval ** inforow_ptr; if (ZEND_NUM_ARGS()<min_number_of_arguments || ZEND_NUM_ARGS()>number_of_arguments || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) { WRONG_PARAM_COUNT; @@ -346,13 +348,13 @@ ZEND_FUNCTION(dbx_query) zend_error(E_WARNING, "dbx_query: not a valid dbx_handle-object..."); RETURN_LONG(0); } - /*/ default values /*/ + /* default values */ info_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | DBX_RESULT_ASSOC; - /*/ parameter overrides /*/ + /* parameter overrides */ if (ZEND_NUM_ARGS()>2) { convert_to_long_ex(arguments[2]); info_flags = (*arguments[2])->value.lval; - /*/ fieldnames are needed for association! /*/ + /* fieldnames are needed for association! */ if (info_flags & DBX_RESULT_ASSOC) { info_flags |= DBX_RESULT_INFO; } @@ -361,24 +363,24 @@ ZEND_FUNCTION(dbx_query) ZVAL_LONG(rv_result_handle, 0); convert_to_string_ex(arguments[1]); result = switch_dbx_query(&rv_result_handle, dbx_handle, dbx_database, arguments[1], INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module); - /*/ boolean return value means either failure for any query or success for queries that don't return anything /*/ + /* boolean return value means either failure for any query or success for queries that don't return anything */ if (!result || (rv_result_handle && rv_result_handle->type==IS_BOOL)) { result = (result && rv_result_handle->value.lval)?1:0; FREE_ZVAL(rv_result_handle); RETURN_LONG(result?1:0); } - /*/ if you get here, the query succeeded and returned results, so we'll return them - / / rv_result_handle holds a resource - /*/ - /*/ init return_value as object (of rows) /*/ + /* if you get here, the query succeeded and returned results, so we'll return them + * rv_result_handle holds a resource + */ + /* init return_value as object (of rows) */ if (object_init(return_value) != SUCCESS) { zend_error(E_ERROR, "dbx_query: unable to create resulting object..."); FREE_ZVAL(rv_result_handle); RETURN_LONG(0); } - /*/ add result_handle property to return_value /*/ + /* add result_handle property to return_value */ zend_hash_update(return_value->value.obj.properties, "handle", 7, (void *)&(rv_result_handle), sizeof(zval *), NULL); - /*/ init info property as array and add to return_value as a property /*/ + /* init info property as array and add to return_value as a property */ if (info_flags & DBX_RESULT_INFO) { MAKE_STD_ZVAL(info); if (array_init(info) != SUCCESS) { @@ -388,7 +390,7 @@ ZEND_FUNCTION(dbx_query) } zend_hash_update(return_value->value.obj.properties, "info", 5, (void *)&(info), sizeof(zval *), NULL); } - /*/ init data property as array and add to return_value as a property /*/ + /* init data property as array and add to return_value as a property */ MAKE_STD_ZVAL(data); if (array_init(data) != SUCCESS) { zend_error(E_ERROR, "dbx_query: unable to create data-array for results..."); @@ -396,7 +398,7 @@ ZEND_FUNCTION(dbx_query) RETURN_LONG(0); } zend_hash_update(return_value->value.obj.properties, "data", 5, (void *)&(data), sizeof(zval *), NULL); - /*/ get columncount and add to returnvalue as property /*/ + /* get columncount and add to returnvalue as property */ MAKE_STD_ZVAL(rv_column_count); ZVAL_LONG(rv_column_count, 0); result = switch_dbx_getcolumncount(&rv_column_count, &rv_result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module); @@ -406,53 +408,52 @@ ZEND_FUNCTION(dbx_query) RETURN_LONG(0); } zend_hash_update(return_value->value.obj.properties, "cols", 5, (void *)&(rv_column_count), sizeof(zval *), NULL); - /*/ fill the info array with columnnames (only indexed (maybe assoc)) /*/ + /* fill the info array with columnnames and types (indexed and assoc) */ if (info_flags & DBX_RESULT_INFO) { - zval * info_row; - MAKE_STD_ZVAL(info_row); - if (array_init(info_row) != SUCCESS) { - zend_error(E_ERROR, "dbx_query: unable to create info_row-array for results..."); - FREE_ZVAL(info_row); + zval * info_row_name; + zval * info_row_type; + MAKE_STD_ZVAL(info_row_name); + MAKE_STD_ZVAL(info_row_type); + if (array_init(info_row_name) != SUCCESS) { + zend_error(E_ERROR, "dbx_query: unable to create info_row_name-array for results..."); + FREE_ZVAL(info_row_name); + FREE_ZVAL(info_row_type); + RETURN_LONG(0); + } + if (array_init(info_row_type) != SUCCESS) { + zend_error(E_ERROR, "dbx_query: unable to create info_row_type-array for results..."); + FREE_ZVAL(info_row_name); + FREE_ZVAL(info_row_type); RETURN_LONG(0); } for (col_index=0; col_index<rv_column_count->value.lval; ++col_index) { zval * rv_column_name; + zval * rv_column_type; + /* get name */ MAKE_STD_ZVAL(rv_column_name); ZVAL_LONG(rv_column_name, 0); result = switch_dbx_getcolumnname(&rv_column_name, &rv_result_handle, col_index, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module); if (result) { - zend_hash_index_update(info_row->value.ht, col_index, (void *)&(rv_column_name), sizeof(zval *), NULL); + zend_hash_index_update(info_row_name->value.ht, col_index, (void *)&(rv_column_name), sizeof(zval *), NULL); } else { FREE_ZVAL(rv_column_name); } - } - zend_hash_update(info->value.ht, "name", 5, (void *) &info_row, sizeof(zval *), NULL); - } - /*/ fill the info array with columntypes (indexed and assoc) /*/ - if (info_flags & DBX_RESULT_INFO) { - zval * info_row; - MAKE_STD_ZVAL(info_row); - if (array_init(info_row) != SUCCESS) { - zend_error(E_ERROR, "dbx_query: unable to create info_row-array for results..."); - FREE_ZVAL(info_row); - RETURN_LONG(0); - } - for (col_index=0; col_index<rv_column_count->value.lval; ++col_index) { - zval * rv_column_type; + /* get type */ MAKE_STD_ZVAL(rv_column_type); ZVAL_LONG(rv_column_type, 0); result = switch_dbx_getcolumntype(&rv_column_type, &rv_result_handle, col_index, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module); if (result) { - zend_hash_index_update(info_row->value.ht, col_index, (void *)&(rv_column_type), sizeof(zval *), NULL); + zend_hash_index_update(info_row_type->value.ht, col_index, (void *)&(rv_column_type), sizeof(zval *), NULL); } else { FREE_ZVAL(rv_column_type); } } - zend_hash_update(info->value.ht, "type", 5, (void *) &info_row, sizeof(zval *), NULL); + zend_hash_update(info->value.ht, "name", 5, (void *) &info_row_name, sizeof(zval *), (void **) &inforow_ptr); + zend_hash_update(info->value.ht, "type", 5, (void *) &info_row_type, sizeof(zval *), NULL); } - /*/ fill each row array with fieldvalues (indexed and assoc) /*/ + /* fill each row array with fieldvalues (indexed (and assoc)) */ row_count=0; result=1; while (result) { @@ -461,36 +462,44 @@ ZEND_FUNCTION(dbx_query) ZVAL_LONG(rv_row, 0); result = switch_dbx_getrow(&rv_row, &rv_result_handle, row_count, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module); if (result) { - zval ** row_ptr; - zend_hash_index_update(data->value.ht, row_count, (void *)&(rv_row), sizeof(zval *), (void **) &row_ptr); - /*/ associate results with fieldnames /*/ - if (info_flags & DBX_RESULT_ASSOC) { - zval **columnname_ptr, **actual_ptr, **reference_ptr; - zval *dummy, **inforow_ptr; - ALLOC_ZVAL(dummy); - INIT_ZVAL(*dummy); - zend_hash_find(info->value.ht, "name", 5, (void **) &inforow_ptr); - for (col_index=0; col_index<rv_column_count->value.lval; ++col_index) { - zend_hash_index_find((*inforow_ptr)->value.ht, col_index, (void **) &columnname_ptr); - zend_hash_index_find((*row_ptr)->value.ht, col_index, (void **) &actual_ptr); - zend_hash_update((*row_ptr)->value.ht, (*columnname_ptr)->value.str.val, (*columnname_ptr)->value.str.len + 1, &dummy, sizeof(zval *), (void **) &reference_ptr); - zend_assign_to_variable_reference(NULL, reference_ptr, actual_ptr, NULL ELS_CC); - } + zend_hash_index_update(data->value.ht, row_count, (void *)&(rv_row), sizeof(zval *), (void **) &row_ptr); + /* associate results with fieldnames */ + if (info_flags & DBX_RESULT_ASSOC) { + zval **columnname_ptr, **actual_ptr, **reference_ptr; + for (col_index=0; col_index<rv_column_count->value.lval; ++col_index) { + MAKE_STD_ZVAL(dummy); + zend_hash_index_find((*inforow_ptr)->value.ht, col_index, (void **) &columnname_ptr); + zend_hash_index_find((*row_ptr)->value.ht, col_index, (void **) &actual_ptr); + zend_hash_update((*row_ptr)->value.ht, (*columnname_ptr)->value.str.val, (*columnname_ptr)->value.str.len + 1, &dummy, sizeof(zval *), (void **) &reference_ptr); + zend_assign_to_variable_reference(NULL, reference_ptr, actual_ptr, NULL ELS_CC); } + } ++row_count; } else { FREE_ZVAL(rv_row); } } - /*/ add row_count property /*/ + /* add row_count property */ add_property_long(return_value, "rows", row_count); - /*/ thank you for watching. /*/ + /* free original resultset / + { + int number_of_arguments=1; + zval ** arguments[1]; + zval * returned_zval=NULL; + + arguments[0]=&rv_result_handle; + dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_free_result", &returned_zval, number_of_arguments, arguments); + if (!returned_zval || returned_zval->type!=IS_RESOURCE) { + if (returned_zval) zval_ptr_dtor(&returned_zval); + } + }*/ } /* }}} */ -/* {{{ proto void dbx_error() - Returns success or failure */ +/* {{{ proto void dbx_error(dbx_link_object dbx_link) + Returns success or failure +*/ ZEND_FUNCTION(dbx_error) { int number_of_arguments=1; @@ -521,18 +530,20 @@ ZEND_FUNCTION(dbx_error) } /* }}} */ -/*/ -/ / dbx functions that are database independent... like sorting result_objects! -/*/ -/* {{{ proto long dbx_cmp_asc(array row_x, array row_y, string columnname) - returns row_x[columnname] - row_y[columnname], converted to -1, 0 or 1 +/* + * dbx functions that are database independent... like sorting result_objects! + */ + +/* {{{ proto long dbx_compare(array row_x, array row_y, string columnname [, flags]) + returns row_y[columnname] - row_x[columnname], converted to -1, 0 or 1 */ -ZEND_FUNCTION(dbx_cmp_asc) +ZEND_FUNCTION(dbx_compare) { int min_number_of_arguments=3; int max_number_of_arguments=4; int number_of_arguments=-1; - long comparison_type; + long comparison_direction=DBX_CMP_ASC; + long comparison_type=DBX_CMP_NATIVE; double dtemp; long ltemp; zval ** arguments[4]; @@ -549,11 +560,28 @@ ZEND_FUNCTION(dbx_cmp_asc) zend_error(E_WARNING, "Wrong argument type for compare"); RETURN_LONG(0); } - convert_to_string_ex(arguments[2]); /*/ field name /*/ - comparison_type = DBX_CMP_TEXT; + convert_to_string_ex(arguments[2]); /* field name */ + comparison_type = DBX_CMP_NATIVE; + comparison_direction = DBX_CMP_ASC; if (number_of_arguments>3) { - convert_to_long_ex(arguments[3]); /*/ comparison type /*/ - comparison_type=(*arguments[3])->value.lval; + convert_to_long_ex(arguments[3]); /* comparison type and direction*/ + /* direction */ + if ((*arguments[3])->value.lval & DBX_CMP_DESC) { + comparison_direction=DBX_CMP_DESC; + } + if ((*arguments[3])->value.lval & DBX_CMP_ASC) { + comparison_direction=DBX_CMP_ASC; + } + /* type */ + if ((*arguments[3])->value.lval & DBX_CMP_NUMBER) { + comparison_type=DBX_CMP_NUMBER; + } + if ((*arguments[3])->value.lval & DBX_CMP_TEXT) { + comparison_type=DBX_CMP_TEXT; + } + if ((*arguments[3])->value.lval & DBX_CMP_NATIVE) { + comparison_type=DBX_CMP_NATIVE; + } } if (zend_hash_find((*arguments[0])->value.ht, (*arguments[2])->value.str.val, (*arguments[2])->value.str.len+1, (void **) &zv_a)==FAILURE @@ -566,83 +594,39 @@ ZEND_FUNCTION(dbx_cmp_asc) case DBX_CMP_TEXT: convert_to_string_ex(zv_a); convert_to_string_ex(zv_b); - ltemp = strcmp((*zv_a)->value.str.val, (*zv_b)->value.str.val); - result = (ltemp==0?0: (ltemp>0?1:-1)); break; case DBX_CMP_NUMBER: convert_to_double_ex(zv_a); convert_to_double_ex(zv_b); - dtemp = ((*zv_a)->value.dval - (*zv_b)->value.dval); - result = (dtemp==0?0: (dtemp>0?1:-1)); break; - default: + } + switch ((*zv_a)->type) { + case IS_NULL: result=0; break; - } - - RETURN_LONG(result); -} - -/* {{{ proto long dbx_cmp_desc(array row_x, array row_y, string columnname) - returns row_y[columnname] - row_x[columnname], converted to -1, 0 or 1 -*/ -ZEND_FUNCTION(dbx_cmp_desc) -{ - int min_number_of_arguments=3; - int max_number_of_arguments=4; - int number_of_arguments=-1; - long comparison_type; - double dtemp; - long ltemp; - zval ** arguments[4]; - zval ** zv_a; - zval ** zv_b; - int result=0; - number_of_arguments=ZEND_NUM_ARGS(); - if (number_of_arguments<min_number_of_arguments || number_of_arguments>max_number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if ((*arguments[0])->type != IS_ARRAY - || (*arguments[1])->type != IS_ARRAY) { - zend_error(E_WARNING, "Wrong argument type for compare"); - RETURN_LONG(0); - } - convert_to_string_ex(arguments[2]); /*/ field name /*/ - comparison_type = DBX_CMP_TEXT; - if (number_of_arguments>3) { - convert_to_long_ex(arguments[3]); /*/ comparison type /*/ - comparison_type=(*arguments[3])->value.lval; - } - - if (zend_hash_find((*arguments[0])->value.ht, (*arguments[2])->value.str.val, (*arguments[2])->value.str.len+1, (void **) &zv_a)==FAILURE - || zend_hash_find((*arguments[1])->value.ht, (*arguments[2])->value.str.val, (*arguments[2])->value.str.len+1, (void **) &zv_b)==FAILURE) { - zend_error(E_WARNING, "Field '%s' not available in result-object", (*arguments[2])->value.str.val); - RETURN_LONG(0); - } - - switch (comparison_type) { - case DBX_CMP_TEXT: - convert_to_string_ex(zv_a); - convert_to_string_ex(zv_b); - ltemp = strcmp((*zv_b)->value.str.val, (*zv_a)->value.str.val); + case IS_BOOL: + case IS_LONG: + case IS_CONSTANT: + ltemp = (*zv_a)->value.lval - (*zv_b)->value.lval; result = (ltemp==0?0: (ltemp>0?1:-1)); break; - case DBX_CMP_NUMBER: - convert_to_double_ex(zv_a); - convert_to_double_ex(zv_b); - dtemp = ((*zv_b)->value.dval - (*zv_a)->value.dval); + case IS_DOUBLE: + dtemp = ((*zv_a)->value.dval - (*zv_b)->value.dval); result = (dtemp==0?0: (dtemp>0?1:-1)); break; - default: - result=0; + case IS_STRING: + ltemp = strcmp((*zv_a)->value.str.val, (*zv_b)->value.str.val); + result = (ltemp==0?0: (ltemp>0?1:-1)); break; + default: result=0; } + if (comparison_direction==DBX_CMP_DESC) RETURN_LONG(-result); RETURN_LONG(result); } -/* {{{ proto long dbx_sort(dbx_result_object stn_search_keywords_result, string compare_function_name) + +/* {{{ proto long dbx_sort(dbx_result_object dbx_result, string compare_function_name) returns 0 on failure, 1 on success */ ZEND_FUNCTION(dbx_sort) @@ -678,11 +662,11 @@ ZEND_FUNCTION(dbx_sort) /***********************************/ -/*/ -/ / switch_dbx functions -/*/ +/* + * switch_dbx functions + */ int switch_dbx_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -694,7 +678,7 @@ int switch_dbx_connect(zval ** rv, zval ** host, zval ** db, zval ** username, z } int switch_dbx_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns persistent connection handle as resource on success or 0 as long on failure /*/ + /* returns persistent connection handle as resource on success or 0 as long on failure */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -706,7 +690,7 @@ int switch_dbx_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, } int switch_dbx_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -718,7 +702,7 @@ int switch_dbx_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETER } int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns 1 as long or result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or result identifier as resource on success or 0 as long on failure */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -730,7 +714,7 @@ int switch_dbx_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sq } int switch_dbx_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -742,7 +726,7 @@ int switch_dbx_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTI } int switch_dbx_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -754,7 +738,7 @@ int switch_dbx_getcolumnname(zval ** rv, zval ** result_handle, long column_inde } int switch_dbx_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -766,7 +750,7 @@ int switch_dbx_getcolumntype(zval ** rv, zval ** result_handle, long column_inde } int switch_dbx_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -778,7 +762,7 @@ int switch_dbx_getrow(zval ** rv, zval ** result_handle, long row_number, INTERN } int switch_dbx_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval ** dbx_module) { - /*/ returns string /*/ + /* returns string */ switch ((*dbx_module)->value.lval) { case DBX_MYSQL: return dbx_mysql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU); case DBX_ODBC: return dbx_odbc_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU); diff --git a/ext/dbx/dbx.h b/ext/dbx/dbx.h index c0f6b3ee2c..927d366286 100644 --- a/ext/dbx/dbx.h +++ b/ext/dbx/dbx.h @@ -29,12 +29,17 @@ #include "php.h" -#define DBX_PERSISTENT 1 -#define DBX_RESULT_INFO 1 -#define DBX_RESULT_INDEX 2 -#define DBX_RESULT_ASSOC 4 -#define DBX_CMP_TEXT 0 -#define DBX_CMP_NUMBER 1 +#define DBX_PERSISTENT (1<<0) + +#define DBX_RESULT_INFO (1<<0) +#define DBX_RESULT_INDEX (1<<1) +#define DBX_RESULT_ASSOC (1<<2) + +#define DBX_CMP_NATIVE (1<<0) +#define DBX_CMP_TEXT (1<<1) +#define DBX_CMP_NUMBER (1<<2) +#define DBX_CMP_ASC (1<<3) +#define DBX_CMP_DESC (1<<4) #define MOVE_RETURNED_TO_RV(rv, returned_zval) { **rv = *returned_zval; zval_copy_ctor(*rv); zval_ptr_dtor(&returned_zval); } diff --git a/ext/dbx/dbx_mssql.c b/ext/dbx/dbx_mssql.c index b0582fbb4a..5568ee2b53 100644 --- a/ext/dbx/dbx_mssql.c +++ b/ext/dbx/dbx_mssql.c @@ -27,7 +27,7 @@ #define MSSQL_NUM 1<<1 int dbx_mssql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int number_of_arguments=3; zval ** arguments[3]; zval * returned_zval=NULL; @@ -41,19 +41,30 @@ int dbx_mssql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zv if (returned_zval) zval_ptr_dtor(&returned_zval); return 0; } - MOVE_RETURNED_TO_RV(rv, returned_zval); number_of_arguments=2; arguments[0]=db; - arguments[1]=rv; + arguments[1]=&returned_zval; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mssql_select_db", &select_db_zval, number_of_arguments, arguments); + if (!select_db_zval || (select_db_zval->type==IS_BOOL && select_db_zval->value.lval==0) ) { + if (select_db_zval) zval_ptr_dtor(&select_db_zval); + /* also close connection */ + number_of_arguments=1; + arguments[0]=&returned_zval; + dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mssql_close", &select_db_zval, number_of_arguments, arguments); + if (select_db_zval) zval_ptr_dtor(&select_db_zval); + zval_ptr_dtor(&returned_zval); + return 0; + } zval_ptr_dtor(&select_db_zval); + MOVE_RETURNED_TO_RV(rv, returned_zval); + return 1; } int dbx_mssql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns persistent connection handle as resource on success or 0 as long on failure /*/ + /* returns persistent connection handle as resource on success or 0 as long on failure */ int number_of_arguments=3; zval ** arguments[3]; zval * returned_zval=NULL; @@ -67,19 +78,30 @@ int dbx_mssql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, z if (returned_zval) zval_ptr_dtor(&returned_zval); return 0; } - MOVE_RETURNED_TO_RV(rv, returned_zval); number_of_arguments=2; arguments[0]=db; - arguments[1]=rv; + arguments[1]=&returned_zval; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mssql_select_db", &select_db_zval, number_of_arguments, arguments); + if (!select_db_zval || (select_db_zval->type==IS_BOOL && select_db_zval->value.lval==0) ) { + if (select_db_zval) zval_ptr_dtor(&select_db_zval); + /* also close connection */ + number_of_arguments=1; + arguments[0]=&returned_zval; + dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mssql_close", &select_db_zval, number_of_arguments, arguments); + if (select_db_zval) zval_ptr_dtor(&select_db_zval); + zval_ptr_dtor(&returned_zval); + return 0; + } zval_ptr_dtor(&select_db_zval); + MOVE_RETURNED_TO_RV(rv, returned_zval); + return 1; } int dbx_mssql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; @@ -95,7 +117,7 @@ int dbx_mssql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS } int dbx_mssql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns 1 as long or a result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or a result identifier as resource on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * returned_zval=NULL; @@ -111,7 +133,7 @@ int dbx_mssql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql arguments[0]=sql_statement; arguments[1]=dbx_handle; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mssql_query", &returned_zval, number_of_arguments, arguments); - /*/ mssql_query returns a bool for success or failure, or a result_identifier for select statements /*/ + /* mssql_query returns a bool for success or failure, or a result_identifier for select statements */ if (!returned_zval || (returned_zval->type!=IS_BOOL && returned_zval->type!=IS_RESOURCE)) { if (returned_zval) zval_ptr_dtor(&returned_zval); return 0; @@ -121,7 +143,7 @@ int dbx_mssql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql } int dbx_mssql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; @@ -137,7 +159,7 @@ int dbx_mssql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTIO } int dbx_mssql_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * zval_column_index; @@ -148,7 +170,7 @@ int dbx_mssql_getcolumnname(zval ** rv, zval ** result_handle, long column_index arguments[0]=result_handle; arguments[1]=&zval_column_index; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mssql_field_name", &returned_zval, number_of_arguments, arguments); - /*/ mssql_field_name returns a string /*/ + /* mssql_field_name returns a string */ if (!returned_zval || returned_zval->type!=IS_STRING) { if (returned_zval) zval_ptr_dtor(&returned_zval); FREE_ZVAL(zval_column_index); @@ -160,7 +182,7 @@ int dbx_mssql_getcolumnname(zval ** rv, zval ** result_handle, long column_index } int dbx_mssql_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * zval_column_index; @@ -171,19 +193,20 @@ int dbx_mssql_getcolumntype(zval ** rv, zval ** result_handle, long column_index arguments[0]=result_handle; arguments[1]=&zval_column_index; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mssql_field_type", &returned_zval, number_of_arguments, arguments); - /*/ mssql_field_name returns a string /*/ + /* mssql_field_name returns a string */ if (!returned_zval || returned_zval->type!=IS_STRING) { if (returned_zval) zval_ptr_dtor(&returned_zval); FREE_ZVAL(zval_column_index); return 0; } FREE_ZVAL(zval_column_index); + MOVE_RETURNED_TO_RV(rv, returned_zval); return 1; } int dbx_mssql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; @@ -199,7 +222,7 @@ int dbx_mssql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNA } int dbx_mssql_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns string /*/ + /* returns string */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; diff --git a/ext/dbx/dbx_mssql.h b/ext/dbx/dbx_mssql.h index c7e2bd57ba..4854eb9020 100644 --- a/ext/dbx/dbx_mssql.h +++ b/ext/dbx/dbx_mssql.h @@ -30,23 +30,23 @@ #include "php.h" int dbx_mssql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int dbx_mssql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns persistent connection handle as resource on success or 0 as long on failure /*/ + /* returns persistent connection handle as resource on success or 0 as long on failure */ int dbx_mssql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ int dbx_mssql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns 1 as long or a result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or a result identifier as resource on success or 0 as long on failure */ int dbx_mssql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ int dbx_mssql_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ int dbx_mssql_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ int dbx_mssql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int dbx_mssql_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns string /*/ + /* returns string */ #endif /* ZEND_DBX_MSSQL_H */ diff --git a/ext/dbx/dbx_mysql.c b/ext/dbx/dbx_mysql.c index 3366be3c2d..d11b2accc9 100644 --- a/ext/dbx/dbx_mysql.c +++ b/ext/dbx/dbx_mysql.c @@ -27,7 +27,7 @@ #define MYSQL_NUM 1<<1 int dbx_mysql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int number_of_arguments=3; zval ** arguments[3]; zval * returned_zval=NULL; @@ -41,19 +41,30 @@ int dbx_mysql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zv if (returned_zval) zval_ptr_dtor(&returned_zval); return 0; } - MOVE_RETURNED_TO_RV(rv, returned_zval); number_of_arguments=2; arguments[0]=db; - arguments[1]=rv; + arguments[1]=&returned_zval; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_select_db", &select_db_zval, number_of_arguments, arguments); + if (!select_db_zval || (select_db_zval->type==IS_BOOL && select_db_zval->value.lval==0) ) { + if (select_db_zval) zval_ptr_dtor(&select_db_zval); + /* also close connection */ + number_of_arguments=1; + arguments[0]=&returned_zval; + dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_close", &select_db_zval, number_of_arguments, arguments); + if (select_db_zval) zval_ptr_dtor(&select_db_zval); + zval_ptr_dtor(&returned_zval); + return 0; + } zval_ptr_dtor(&select_db_zval); + MOVE_RETURNED_TO_RV(rv, returned_zval); + return 1; } int dbx_mysql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns persistent connection handle as resource on success or 0 as long on failure /*/ + /* returns persistent connection handle as resource on success or 0 as long on failure */ int number_of_arguments=3; zval ** arguments[3]; zval * returned_zval=NULL; @@ -67,19 +78,30 @@ int dbx_mysql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, z if (returned_zval) zval_ptr_dtor(&returned_zval); return 0; } - MOVE_RETURNED_TO_RV(rv, returned_zval); number_of_arguments=2; arguments[0]=db; - arguments[1]=rv; + arguments[1]=&returned_zval; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_select_db", &select_db_zval, number_of_arguments, arguments); + if (!select_db_zval || (select_db_zval->type==IS_BOOL && select_db_zval->value.lval==0) ) { + if (select_db_zval) zval_ptr_dtor(&select_db_zval); + /* also close connection */ + number_of_arguments=1; + arguments[0]=&returned_zval; + dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_close", &select_db_zval, number_of_arguments, arguments); + if (select_db_zval) zval_ptr_dtor(&select_db_zval); + zval_ptr_dtor(&returned_zval); + return 0; + } zval_ptr_dtor(&select_db_zval); + MOVE_RETURNED_TO_RV(rv, returned_zval); + return 1; } int dbx_mysql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; @@ -95,7 +117,7 @@ int dbx_mysql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS } int dbx_mysql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns 1 as long or a result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or a result identifier as resource on success or 0 as long on failure */ int number_of_arguments=3; zval ** arguments[3]; zval * returned_zval=NULL; @@ -104,7 +126,7 @@ int dbx_mysql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql arguments[1]=sql_statement; arguments[2]=dbx_handle; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_db_query", &returned_zval, number_of_arguments, arguments); - /*/ mysql_query returns a bool for success or failure, or a result_identifier for select statements /*/ + /* mysql_query returns a bool for success or failure, or a result_identifier for select statements */ if (!returned_zval || (returned_zval->type!=IS_BOOL && returned_zval->type!=IS_RESOURCE)) { if (returned_zval) zval_ptr_dtor(&returned_zval); return 0; @@ -114,7 +136,7 @@ int dbx_mysql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql } int dbx_mysql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; @@ -130,7 +152,7 @@ int dbx_mysql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTIO } int dbx_mysql_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * zval_column_index; @@ -141,7 +163,7 @@ int dbx_mysql_getcolumnname(zval ** rv, zval ** result_handle, long column_index arguments[0]=result_handle; arguments[1]=&zval_column_index; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_field_name", &returned_zval, number_of_arguments, arguments); - /*/ mysql_field_name returns a string /*/ + /* mysql_field_name returns a string */ if (!returned_zval || returned_zval->type!=IS_STRING) { if (returned_zval) zval_ptr_dtor(&returned_zval); FREE_ZVAL(zval_column_index); @@ -153,7 +175,7 @@ int dbx_mysql_getcolumnname(zval ** rv, zval ** result_handle, long column_index } int dbx_mysql_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * zval_column_index; @@ -164,19 +186,20 @@ int dbx_mysql_getcolumntype(zval ** rv, zval ** result_handle, long column_index arguments[0]=result_handle; arguments[1]=&zval_column_index; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "mysql_field_type", &returned_zval, number_of_arguments, arguments); - /*/ mysql_field_name returns a string /*/ + /* mysql_field_name returns a string */ if (!returned_zval || returned_zval->type!=IS_STRING) { if (returned_zval) zval_ptr_dtor(&returned_zval); FREE_ZVAL(zval_column_index); return 0; } FREE_ZVAL(zval_column_index); + MOVE_RETURNED_TO_RV(rv, returned_zval); return 1; } int dbx_mysql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * zval_resulttype=NULL; @@ -198,7 +221,7 @@ int dbx_mysql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNA } int dbx_mysql_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns string /*/ + /* returns string */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; diff --git a/ext/dbx/dbx_mysql.h b/ext/dbx/dbx_mysql.h index 4a3b49aafb..c9bc0b5d39 100644 --- a/ext/dbx/dbx_mysql.h +++ b/ext/dbx/dbx_mysql.h @@ -30,23 +30,23 @@ #include "php.h" int dbx_mysql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int dbx_mysql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns persistent connection handle as resource on success or 0 as long on failure /*/ + /* returns persistent connection handle as resource on success or 0 as long on failure */ int dbx_mysql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ int dbx_mysql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns 1 as long or a result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or a result identifier as resource on success or 0 as long on failure */ int dbx_mysql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ int dbx_mysql_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ int dbx_mysql_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ int dbx_mysql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int dbx_mysql_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns string /*/ + /* returns string */ #endif /* ZEND_DBX_MYSQL_H */ diff --git a/ext/dbx/dbx_odbc.c b/ext/dbx/dbx_odbc.c index 3e4d0ef39a..ca5ad9ff5c 100644 --- a/ext/dbx/dbx_odbc.c +++ b/ext/dbx/dbx_odbc.c @@ -27,7 +27,7 @@ #define ODBC_NUM 2 int dbx_odbc_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int number_of_arguments=3; zval ** arguments[3]; zval * returned_zval=NULL; @@ -45,7 +45,7 @@ int dbx_odbc_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zva } int dbx_odbc_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int number_of_arguments=3; zval ** arguments[3]; zval * returned_zval=NULL; @@ -63,7 +63,7 @@ int dbx_odbc_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zv } int dbx_odbc_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; @@ -79,17 +79,17 @@ int dbx_odbc_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) } int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns 1 as long or a result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or a result identifier as resource on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * queryresult_zval=NULL; zval * num_fields_zval=NULL; - // db_name is not used in this function + /* db_name is not used in this function */ arguments[0]=dbx_handle; arguments[1]=sql_statement; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_exec", &queryresult_zval, number_of_arguments, arguments); - /*/ odbc_query returns a bool for failure, or a result_identifier for success /*/ + /* odbc_query returns a bool for failure, or a result_identifier for success */ if (!queryresult_zval || queryresult_zval->type!=IS_RESOURCE) { if (queryresult_zval) zval_ptr_dtor(&queryresult_zval); return 0; @@ -103,7 +103,7 @@ int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_ } if (num_fields_zval->value.lval==0) { (*rv)->type=IS_BOOL; - (*rv)->value.lval=1; /*/ success, but no data /*/ + (*rv)->value.lval=1; /* success, but no data */ FREE_ZVAL(num_fields_zval); if (queryresult_zval) zval_ptr_dtor(&queryresult_zval); return 1; @@ -114,7 +114,7 @@ int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_ } int dbx_odbc_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ int number_of_arguments=1; zval ** arguments[1]; zval * returned_zval=NULL; @@ -130,7 +130,7 @@ int dbx_odbc_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION } int dbx_odbc_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * zval_column_index; @@ -141,7 +141,7 @@ int dbx_odbc_getcolumnname(zval ** rv, zval ** result_handle, long column_index, arguments[0]=result_handle; arguments[1]=&zval_column_index; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_field_name", &returned_zval, number_of_arguments, arguments); - /*/ odbc_field_name returns a string /*/ + /* odbc_field_name returns a string */ if (!returned_zval || returned_zval->type!=IS_STRING) { if (returned_zval) zval_ptr_dtor(&returned_zval); FREE_ZVAL(zval_column_index); @@ -153,7 +153,7 @@ int dbx_odbc_getcolumnname(zval ** rv, zval ** result_handle, long column_index, } int dbx_odbc_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ int number_of_arguments=2; zval ** arguments[2]; zval * zval_column_index; @@ -164,19 +164,20 @@ int dbx_odbc_getcolumntype(zval ** rv, zval ** result_handle, long column_index, arguments[0]=result_handle; arguments[1]=&zval_column_index; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_field_type", &returned_zval, number_of_arguments, arguments); - /*/ odbc_field_name returns a string /*/ + /* odbc_field_name returns a string */ if (!returned_zval || returned_zval->type!=IS_STRING) { if (returned_zval) zval_ptr_dtor(&returned_zval); FREE_ZVAL(zval_column_index); return 0; } FREE_ZVAL(zval_column_index); + MOVE_RETURNED_TO_RV(rv, returned_zval); return 1; } int dbx_odbc_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int number_of_arguments; zval ** arguments[2]; zval * num_fields_zval=NULL; @@ -187,7 +188,7 @@ int dbx_odbc_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL long field_index; long field_count=-1; - /*/ get # fields /*/ + /* get # fields */ MAKE_STD_ZVAL(num_fields_zval); ZVAL_LONG(num_fields_zval, 0); if (!dbx_odbc_getcolumncount(&num_fields_zval, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU)) { @@ -195,7 +196,7 @@ int dbx_odbc_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL } field_count=num_fields_zval->value.lval; FREE_ZVAL(num_fields_zval); - /*/ fetch row /*/ + /* fetch row */ number_of_arguments=1; arguments[0]=result_handle; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "odbc_fetch_row", &fetch_row_result_zval, number_of_arguments, arguments); @@ -205,12 +206,12 @@ int dbx_odbc_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL } if (fetch_row_result_zval->value.lval==0) { (*rv)->type=IS_LONG; - (*rv)->value.lval=0; /*/ ok, no more rows /*/ + (*rv)->value.lval=0; /* ok, no more rows */ zval_ptr_dtor(&fetch_row_result_zval); return 0; } zval_ptr_dtor(&fetch_row_result_zval); - /*/ fill array with field results... /*/ + /* fill array with field results... */ MAKE_STD_ZVAL(returned_zval); if (array_init(returned_zval) != SUCCESS) { zend_error(E_ERROR, "dbx_odbc_getrow: unable to create result-array..."); @@ -234,7 +235,7 @@ int dbx_odbc_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL } int dbx_odbc_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS) { - /*/ returns empty string, no equivalent in odbc module (yet???) /*/ + /* returns empty string, no equivalent in odbc module (yet???) */ ZVAL_EMPTY_STRING((*rv)); return 1; } diff --git a/ext/dbx/dbx_odbc.h b/ext/dbx/dbx_odbc.h index 895545e5f8..38625ca1e7 100644 --- a/ext/dbx/dbx_odbc.h +++ b/ext/dbx/dbx_odbc.h @@ -30,23 +30,23 @@ #include "php.h" int dbx_odbc_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int dbx_odbc_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns persisten connection handle as resource on success or 0 as long on failure /*/ + /* returns persisten connection handle as resource on success or 0 as long on failure */ int dbx_odbc_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ int dbx_odbc_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns 1 as long or a result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or a result identifier as resource on success or 0 as long on failure */ int dbx_odbc_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ int dbx_odbc_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ int dbx_odbc_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ int dbx_odbc_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int dbx_odbc_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns string /*/ + /* returns string */ #endif /* ZEND_DBX_ODBC_H */ diff --git a/ext/dbx/dbx_pgsql.c b/ext/dbx/dbx_pgsql.c index 4c4dce79b8..e945bc06b6 100644 --- a/ext/dbx/dbx_pgsql.c +++ b/ext/dbx/dbx_pgsql.c @@ -25,8 +25,7 @@ #define PGSQL_NUM 1<<1 int dbx_pgsql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) { - /* returns connection handle as resource on success or 0 - as long on failure */ + /* returns connection handle as resource on success or 0 as long on failure */ int nargs=5; char *port="5432", *connstring=NULL; zval **args[5], *rarg = NULL; @@ -71,8 +70,7 @@ int dbx_pgsql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zv } int dbx_pgsql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS) { - /* returns persistent connection handle as resource on success or 0 - as long on failure */ + /* returns persistent connection handle as resource on success or 0 as long on failure */ int nargs=5; char *port="5432", *connstring=NULL; zval **args[5], *rarg = NULL; @@ -139,7 +137,7 @@ int dbx_pgsql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql zval **args[2]; zval *returned_zval=NULL, *num_rows_zval=NULL; - // db_name is not used in this function + /* db_name is not used in this function */ args[0]=dbx_handle; args[1]=sql_statement; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_exec", &returned_zval, nargs, args); @@ -182,7 +180,7 @@ int dbx_pgsql_getcolumnname(zval ** rv, zval ** result_handle, long column_index arguments[0]=result_handle; arguments[1]=&zval_column_index; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_fieldname", &returned_zval, number_of_arguments, arguments); - /*/ pgsql_field_name returns a string /*/ + /* pg_fieldname returns a string */ if (!returned_zval || returned_zval->type!=IS_STRING) { if (returned_zval) zval_ptr_dtor(&returned_zval); FREE_ZVAL(zval_column_index); @@ -205,20 +203,20 @@ int dbx_pgsql_getcolumntype(zval ** rv, zval ** result_handle, long column_index arguments[0]=result_handle; arguments[1]=&zval_column_index; dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "pg_fieldtype", &returned_zval, number_of_arguments, arguments); - /* pgsql_field_name returns a string */ + /* pg_fieldtype returns a string */ if (!returned_zval || returned_zval->type!=IS_STRING) { if (returned_zval) zval_ptr_dtor(&returned_zval); FREE_ZVAL(zval_column_index); return 0; } FREE_ZVAL(zval_column_index); + MOVE_RETURNED_TO_RV(rv, returned_zval); return 1; } int dbx_pgsql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS) { - /* returns array[0..columncount-1] as strings on success or 0 - as long on failure */ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int number_of_arguments=2; int save_error_reporting=0; zval ** arguments[2]; diff --git a/ext/dbx/dbx_pgsql.h b/ext/dbx/dbx_pgsql.h index 80668c9bb4..795ac752c3 100644 --- a/ext/dbx/dbx_pgsql.h +++ b/ext/dbx/dbx_pgsql.h @@ -26,23 +26,23 @@ #include "php.h" int dbx_pgsql_connect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns connection handle as resource on success or 0 as long on failure /*/ + /* returns connection handle as resource on success or 0 as long on failure */ int dbx_pgsql_pconnect(zval ** rv, zval ** host, zval ** db, zval ** username, zval ** password, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns persistent connection handle as resource on success or 0 as long on failure /*/ + /* returns persistent connection handle as resource on success or 0 as long on failure */ int dbx_pgsql_close(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns 1 as long on success or 0 as long on failure /*/ + /* returns 1 as long on success or 0 as long on failure */ int dbx_pgsql_query(zval ** rv, zval ** dbx_handle, zval ** db_name, zval ** sql_statement, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns 1 as long or a result identifier as resource on success or 0 as long on failure /*/ + /* returns 1 as long or a result identifier as resource on success or 0 as long on failure */ int dbx_pgsql_getcolumncount(zval ** rv, zval ** result_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-count as long on success or 0 as long on failure /*/ + /* returns column-count as long on success or 0 as long on failure */ int dbx_pgsql_getcolumnname(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-name as string on success or 0 as long on failure /*/ + /* returns column-name as string on success or 0 as long on failure */ int dbx_pgsql_getcolumntype(zval ** rv, zval ** result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns column-type as string on success or 0 as long on failure /*/ + /* returns column-type as string on success or 0 as long on failure */ int dbx_pgsql_getrow(zval ** rv, zval ** result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns array[0..columncount-1] as strings on success or 0 as long on failure /*/ + /* returns array[0..columncount-1] as strings on success or 0 as long on failure */ int dbx_pgsql_error(zval ** rv, zval ** dbx_handle, INTERNAL_FUNCTION_PARAMETERS); - /*/ returns string /*/ + /* returns string */ #endif /* ZEND_DBX_PGSQL_H */ diff --git a/ext/dbx/php_dbx.h b/ext/dbx/php_dbx.h index 80300e7402..08d753d648 100644 --- a/ext/dbx/php_dbx.h +++ b/ext/dbx/php_dbx.h @@ -38,8 +38,8 @@ extern zend_module_entry dbx_module_entry; ZEND_MINIT_FUNCTION(dbx); ZEND_MSHUTDOWN_FUNCTION(dbx); -/*/ ZEND_RINIT_FUNCTION(dbx); /*/ -/*/ ZEND_RSHUTDOWN_FUNCTION(dbx); /*/ +/* ZEND_RINIT_FUNCTION(dbx); */ +/* ZEND_RSHUTDOWN_FUNCTION(dbx); */ ZEND_MINFO_FUNCTION(dbx); @@ -49,8 +49,7 @@ ZEND_FUNCTION(dbx_query); ZEND_FUNCTION(dbx_error); ZEND_FUNCTION(dbx_sort); -ZEND_FUNCTION(dbx_cmp_asc); -ZEND_FUNCTION(dbx_cmp_desc); +ZEND_FUNCTION(dbx_compare); /* Declare any global variables you may need between the BEGIN |