X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=src%2Fphp_pqstm.c;h=1eb943bea1b4cac83db2d29c41c353f9fa28c5f0;hb=a015d26134e7d557fee53eb12a945c45de2ec890;hp=f6da0672f40ceac17de684aef0b8cb51abd03599;hpb=17e598e884de8653f13fe6450e348ed7d30ea8f5;p=m6w6%2Fext-pq diff --git a/src/php_pqstm.c b/src/php_pqstm.c index f6da067..1eb943b 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, cmd.c))) { - PHP_PQclear(res); + if ((res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c))) { + php_pqres_clear(res); } else if (!silent) { throw_exce(EX_RUNTIME TSRMLS_CC, "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_del(&obj->intern->conn->intern->statements, obj->intern->name, strlen(obj->intern->name)+1); } } @@ -79,6 +80,7 @@ static void php_pqstm_object_free(void *o TSRMLS_DC) php_pq_object_delref(obj->intern->conn TSRMLS_CC); } efree(obj->intern->name); + efree(obj->intern->query); zend_hash_destroy(&obj->intern->bound); if (obj->intern->params) { php_pq_params_free(&obj->intern->params); @@ -139,19 +141,12 @@ static void php_pqstm_object_read_query(zval *object, void *o, zval *return_valu RETVAL_STRING(obj->intern->query, 1); } -static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value) +static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value TSRMLS_DC) { int i; - HashTable *ht; - php_pqstm_object_t *obj; - - obj = (php_pqstm_object_t *)o; - ht = (HashTable *)emalloc(sizeof(HashTable)); - - zend_hash_init(ht, obj->intern->params->type.count, NULL, ZVAL_PTR_DTOR, 0); - Z_TYPE_P(return_value) = IS_ARRAY; - Z_ARRVAL_P(return_value) = ht; + php_pqstm_object_t *obj = o; + array_init_size(return_value, obj->intern->params->type.count); for (i = 0; i < obj->intern->params->type.count; i++) { add_next_index_long(return_value, (long)obj->intern->params->type.oids[i]); } @@ -170,6 +165,8 @@ php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const c ZEND_INIT_SYMTABLE(&stm->bound); + zend_hash_add(&conn->intern->statements, name, strlen(name)+1, &stm, sizeof(stm), NULL); + return stm; } @@ -186,7 +183,7 @@ static PHP_METHOD(pqstm, __construct) { char *name_str, *query_str; int name_len, *query_len; zend_bool async = 0; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Oss|a/!b", &zconn, php_pqconn_class_entry, &name_str, &name_len, &query_str, &query_len, &ztypes, &async); @@ -223,7 +220,7 @@ static PHP_METHOD(pqstm, bind) { long param_no; zval **param_ref; zend_error_handling zeh; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lZ", ¶m_no, ¶m_ref); @@ -251,7 +248,7 @@ ZEND_END_ARG_INFO(); static PHP_METHOD(pqstm, exec) { zend_error_handling zeh; zval *zparams = NULL; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &zparams); @@ -268,7 +265,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) { @@ -289,7 +286,7 @@ static PHP_METHOD(pqstm, execAsync) { zend_error_handling zeh; zval *zparams = NULL; php_pq_callback_t resolver = {{0}}; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!f", &zparams, &resolver.fci, &resolver.fcc); @@ -329,7 +326,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(pqstm, desc) { zend_error_handling zeh; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters_none(); @@ -356,7 +353,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 TSRMLS_CC); } } @@ -369,7 +366,7 @@ ZEND_END_ARG_INFO(); static PHP_METHOD(pqstm, descAsync) { zend_error_handling zeh; php_pq_callback_t resolver = {{0}}; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &resolver.fci, &resolver.fcc); @@ -395,7 +392,7 @@ static PHP_METHOD(pqstm, descAsync) { static zend_always_inline void php_pqstm_deallocate_handler(INTERNAL_FUNCTION_PARAMETERS, zend_bool async) { zend_error_handling zeh; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters_none(); @@ -426,10 +423,10 @@ 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; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters_none(); @@ -449,6 +446,9 @@ static zend_always_inline void php_pqstm_prepare_handler(INTERNAL_FUNCTION_PARAM if (SUCCESS == rv) { obj->intern->allocated = 1; + + zend_hash_add(&obj->intern->conn->intern->statements, + obj->intern->name, strlen(obj->intern->name)+1, &obj->intern, sizeof(obj->intern), NULL); } } }