X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pqstm.c;h=f421b81b8da8e7362a3b37ff12f821b5b50c02fd;hp=dff5375d973e61f5b40b1ac29190537e06e01279;hb=HEAD;hpb=cb69b6218d9d6e789527b3bd62c3cc37686547a3 diff --git a/src/php_pqstm.c b/src/php_pqstm.c index dff5375..f421b81 100644 --- a/src/php_pqstm.c +++ b/src/php_pqstm.c @@ -51,8 +51,8 @@ static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_ } else { PGresult *res; - if ((res = PQexec(obj->intern->conn->intern->conn, smart_str_v(&cmd)))) { - PHP_PQclear(res); + if ((res = php_pq_exec(obj->intern->conn->intern->conn, smart_str_v(&cmd)))) { + php_pqres_clear(res); } else if (!silent) { throw_exce(EX_RUNTIME, "Failed to deallocate statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn)); } @@ -63,6 +63,7 @@ static void php_pqstm_deallocate(php_pqstm_object_t *obj, zend_bool async, zend_ } obj->intern->allocated = 0; + zend_hash_str_del(&obj->intern->conn->intern->statements, obj->intern->name, strlen(obj->intern->name)); } } @@ -101,21 +102,21 @@ static zend_object *php_pqstm_create_object(zend_class_entry *class_type) return &php_pqstm_create_object_ex(class_type, NULL)->zo; } -static void php_pqstm_object_read_name(zval *object, void *o, zval *return_value) +static void php_pqstm_object_read_name(void *o, zval *return_value) { php_pqstm_object_t *obj = o; RETVAL_STRING(obj->intern->name); } -static void php_pqstm_object_read_connection(zval *object, void *o, zval *return_value) +static void php_pqstm_object_read_connection(void *o, zval *return_value) { php_pqstm_object_t *obj = o; php_pq_object_to_zval(obj->intern->conn, return_value); } -static void php_pqstm_object_gc_connection(zval *object, void *o, zval *return_value) +static void php_pqstm_object_gc_connection(void *o, zval *return_value) { php_pqstm_object_t *obj = o; zval zconn; @@ -124,14 +125,14 @@ static void php_pqstm_object_gc_connection(zval *object, void *o, zval *return_v add_next_index_zval(return_value, &zconn); } -static void php_pqstm_object_read_query(zval *object, void *o, zval *return_value) +static void php_pqstm_object_read_query(void *o, zval *return_value) { php_pqstm_object_t *obj = o; RETVAL_STRING(obj->intern->query); } -static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value) +static void php_pqstm_object_read_types(void *o, zval *return_value) { int i; php_pqstm_object_t *obj = o; @@ -155,6 +156,8 @@ php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const c ZEND_INIT_SYMTABLE(&stm->bound); + zend_hash_str_add_ptr(&conn->intern->statements, name, strlen(name), stm); + return stm; } @@ -252,7 +255,7 @@ static PHP_METHOD(pqstm, exec) { PGresult *res; php_pq_params_set_params(obj->intern->params, zparams ? Z_ARRVAL_P(zparams) : &obj->intern->bound); - res = PQexecPrepared(obj->intern->conn->intern->conn, obj->intern->name, obj->intern->params->param.count, (const char *const*) obj->intern->params->param.strings, NULL, NULL, 0); + res = php_pq_exec_prepared(obj->intern->conn->intern->conn, obj->intern->name, obj->intern->params->param.count, (const char *const*) obj->intern->params->param.strings, NULL, NULL, 0); php_pq_params_set_params(obj->intern->params, NULL); if (!res) { @@ -272,7 +275,7 @@ ZEND_END_ARG_INFO(); static PHP_METHOD(pqstm, execAsync) { zend_error_handling zeh; zval *zparams = NULL; - php_pq_callback_t resolver = {{0}}; + php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT; ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh); @@ -340,7 +343,7 @@ static PHP_METHOD(pqstm, desc) { add_next_index_long(return_value, PQparamtype(res, p)); } } - PHP_PQclear(res); + php_pqres_clear(res); php_pqconn_notify_listeners(obj->intern->conn); } } @@ -352,7 +355,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc_async, 0, 0, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(pqstm, descAsync) { zend_error_handling zeh; - php_pq_callback_t resolver = {{0}}; + php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT; ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh); @@ -410,7 +413,7 @@ static PHP_METHOD(pqstm, deallocateAsync) php_pqstm_deallocate_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } -static zend_always_inline void php_pqstm_prepare_handler(INTERNAL_FUNCTION_PARAMETERS, zend_bool async) +static inline void php_pqstm_prepare_handler(INTERNAL_FUNCTION_PARAMETERS, zend_bool async) { zend_error_handling zeh; ZEND_RESULT_CODE rv; @@ -433,6 +436,9 @@ static zend_always_inline void php_pqstm_prepare_handler(INTERNAL_FUNCTION_PARAM if (SUCCESS == rv) { obj->intern->allocated = 1; + + zend_hash_str_add_ptr(&obj->intern->conn->intern->statements, + obj->intern->name, strlen(obj->intern->name), obj->intern); } } } @@ -453,7 +459,7 @@ static PHP_METHOD(pqstm, prepareAsync) } static zend_function_entry php_pqstm_methods[] = { - PHP_ME(pqstm, __construct, ai_pqstm_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(pqstm, __construct, ai_pqstm_construct, ZEND_ACC_PUBLIC) PHP_ME(pqstm, bind, ai_pqstm_bind, ZEND_ACC_PUBLIC) PHP_ME(pqstm, deallocate, ai_pqstm_deallocate, ZEND_ACC_PUBLIC) PHP_ME(pqstm, deallocateAsync, ai_pqstm_deallocate_async, ZEND_ACC_PUBLIC) @@ -487,7 +493,7 @@ PHP_MINIT_FUNCTION(pqstm) php_pqstm_object_handlers.read_property = php_pq_object_read_prop; php_pqstm_object_handlers.write_property = php_pq_object_write_prop; php_pqstm_object_handlers.clone_obj = NULL; - php_pqstm_object_handlers.get_property_ptr_ptr = NULL; + php_pqstm_object_handlers.get_property_ptr_ptr = php_pq_object_get_prop_ptr_null; php_pqstm_object_handlers.get_gc = php_pq_object_get_gc; php_pqstm_object_handlers.get_properties = php_pq_object_properties; php_pqstm_object_handlers.get_debug_info = php_pq_object_debug_info;