X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pq.c;h=6223ef95c74f90a47194102be28773dbe6be1006;hp=c716a6156e60dd1bf34d17f29eb16ba3602dd2ce;hb=610b4a3a7a4a14a5bb0996f0f0871eb79e46b8e5;hpb=8c6b701bbd00db448d04be4a6a059641f299130d diff --git a/src/php_pq.c b/src/php_pq.c index c716a61..6223ef9 100644 --- a/src/php_pq.c +++ b/src/php_pq.c @@ -14,9 +14,12 @@ # include "config.h" #endif +#define SMART_STR_PREALLOC 256 + #include #include #include +#include #include #include @@ -52,7 +55,6 @@ static int php_pqconn_event(PGEventId id, void *e, void *data); ZEND_DECLARE_MODULE_GLOBALS(pq) */ - /* {{{ PHP_INI */ /* Remove comments and fill if you need to have entries in php.ini @@ -527,13 +529,6 @@ static void php_pqconn_object_free(void *o TSRMLS_DC) php_pqconn_object_t *obj = o; if (obj->intern) { - php_pqconn_event_data_t *evdata = PQinstanceData(obj->intern->conn, php_pqconn_event); - - if (evdata) { - efree(evdata); - PQsetInstanceData(obj->intern->conn, php_pqconn_event, NULL); - } - php_resource_factory_handle_dtor(&obj->intern->factory, obj->intern->conn TSRMLS_CC); php_resource_factory_dtor(&obj->intern->factory); php_pq_callback_dtor(&obj->intern->onevent); @@ -1584,6 +1579,7 @@ static STATUS php_pqconn_update_socket(zval *this_ptr, php_pqconn_object_t *obj if ((CONNECTION_BAD != PQstatus(obj->intern->conn)) && (-1 < (socket = PQsocket(obj->intern->conn))) && (stream = php_stream_fopen_from_fd(socket, "r+b", NULL))) { + stream->flags |= PHP_STREAM_FLAG_NO_CLOSE; php_stream_to_zval(stream, zsocket); retval = SUCCESS; } else { @@ -1618,20 +1614,24 @@ static int apply_event(void *p, void *a TSRMLS_DC) return ZEND_HASH_APPLY_KEEP; } -static void php_pqconn_event_connreset(PGEventConnReset *event, php_pqconn_event_data_t *data) +static void php_pqconn_event_connreset(PGEventConnReset *event) { - zval **evhs; - TSRMLS_DF(data); + php_pqconn_event_data_t *data = PQinstanceData(event->conn, php_pqconn_event); + + if (data) { + zval **evhs; + TSRMLS_DF(data); - if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("reset"), (void *) &evhs)) { - zval *args, *connection = NULL; + if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("reset"), (void *) &evhs)) { + zval *args, *connection = NULL; - MAKE_STD_ZVAL(args); - array_init(args); - php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); - add_next_index_zval(args, connection); - zend_hash_apply_with_argument(Z_ARRVAL_PP(evhs), apply_event, args TSRMLS_CC); - zval_ptr_dtor(&args); + MAKE_STD_ZVAL(args); + array_init(args); + php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); + add_next_index_zval(args, connection); + zend_hash_apply_with_argument(Z_ARRVAL_PP(evhs), apply_event, args TSRMLS_CC); + zval_ptr_dtor(&args); + } } } @@ -1655,31 +1655,35 @@ static zval *result_instance_zval(PGresult *res TSRMLS_DC) return rid; } -static void php_pqconn_event_resultcreate(PGEventResultCreate *event, php_pqconn_event_data_t *data) +static void php_pqconn_event_resultcreate(PGEventResultCreate *event) { - zval **evhs; - TSRMLS_DF(data); - - /* event listener */ - if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("result"), (void *) &evhs)) { - zval *args, *connection = NULL, *res = result_instance_zval(event->result TSRMLS_CC); - - MAKE_STD_ZVAL(args); - array_init(args); - php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); - add_next_index_zval(args, connection); - add_next_index_zval(args, res); - zend_hash_apply_with_argument(Z_ARRVAL_PP(evhs), apply_event, args TSRMLS_CC); - zval_ptr_dtor(&args); - } + php_pqconn_event_data_t *data = PQinstanceData(event->conn, php_pqconn_event); + + if (data) { + zval **evhs; + TSRMLS_DF(data); + + /* event listener */ + if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("result"), (void *) &evhs)) { + zval *args, *connection = NULL, *res = result_instance_zval(event->result TSRMLS_CC); + + MAKE_STD_ZVAL(args); + array_init(args); + php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); + add_next_index_zval(args, connection); + add_next_index_zval(args, res); + zend_hash_apply_with_argument(Z_ARRVAL_PP(evhs), apply_event, args TSRMLS_CC); + zval_ptr_dtor(&args); + } - /* async callback */ - if (data->obj->intern->onevent.fci.size > 0) { - zval *res = result_instance_zval(event->result TSRMLS_CC); + /* async callback */ + if (data->obj->intern->onevent.fci.size > 0) { + zval *res = result_instance_zval(event->result TSRMLS_CC); - zend_fcall_info_argn(&data->obj->intern->onevent.fci TSRMLS_CC, 1, &res); - zend_fcall_info_call(&data->obj->intern->onevent.fci, &data->obj->intern->onevent.fcc, NULL, NULL TSRMLS_CC); - zval_ptr_dtor(&res); + zend_fcall_info_argn(&data->obj->intern->onevent.fci TSRMLS_CC, 1, &res); + zend_fcall_info_call(&data->obj->intern->onevent.fci, &data->obj->intern->onevent.fcc, NULL, NULL TSRMLS_CC); + zval_ptr_dtor(&res); + } } } @@ -1687,10 +1691,10 @@ static int php_pqconn_event(PGEventId id, void *e, void *data) { switch (id) { case PGEVT_CONNRESET: - php_pqconn_event_connreset(e, data); + php_pqconn_event_connreset(e); break; case PGEVT_RESULTCREATE: - php_pqconn_event_resultcreate(e, data); + php_pqconn_event_resultcreate(e); break; default: break; @@ -1712,19 +1716,22 @@ static php_pqconn_event_data_t *php_pqconn_event_data_init(php_pqconn_object_t * static void php_pqconn_notice_recv(void *p, const PGresult *res) { php_pqconn_event_data_t *data = p; - zval **evhs; - TSRMLS_DF(data); - if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("notice"), (void *) &evhs)) { - zval *args, *connection = NULL; + if (data) { + zval **evhs; + TSRMLS_DF(data); + + if (SUCCESS == zend_hash_find(&data->obj->intern->eventhandlers, ZEND_STRS("notice"), (void *) &evhs)) { + zval *args, *connection = NULL; - MAKE_STD_ZVAL(args); - array_init(args); - php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); - add_next_index_zval(args, connection); - add_next_index_string(args, PHP_PQresultErrorMessage(res), 1); - zend_hash_apply_with_argument(Z_ARRVAL_PP(evhs), apply_event, args TSRMLS_CC); - zval_ptr_dtor(&args); + MAKE_STD_ZVAL(args); + array_init(args); + php_pq_object_to_zval(data->obj, &connection TSRMLS_CC); + add_next_index_zval(args, connection); + add_next_index_string(args, PHP_PQresultErrorMessage(res), 1); + zend_hash_apply_with_argument(Z_ARRVAL_PP(evhs), apply_event, args TSRMLS_CC); + zval_ptr_dtor(&args); + } } } @@ -1733,37 +1740,35 @@ typedef struct php_pqconn_resource_factory_data { long flags; } php_pqconn_resource_factory_data_t; -static php_pqconn_resource_factory_data_t *php_pqconn_resource_factory_data_init(const char *dsn, long flags) -{ - php_pqconn_resource_factory_data_t *data = emalloc(sizeof(*data)); - - data->dsn = estrdup(dsn); - data->flags = flags; - - return data; -} - -static void php_pqconn_resource_factory_data_dtor(void *d) -{ - php_pqconn_resource_factory_data_t *data = d; - - efree(data->dsn); - efree(data); -} - static void *php_pqconn_resource_factory_ctor(void *data, void *init_arg TSRMLS_DC) { php_pqconn_resource_factory_data_t *o = init_arg; + PGconn *conn = NULL;; if (o->flags & PHP_PQCONN_ASYNC) { - return PQconnectStart(o->dsn); + conn = PQconnectStart(o->dsn); } else { - return PQconnectdb(o->dsn); + conn = PQconnectdb(o->dsn); + } + + if (conn) { + PQregisterEventProc(conn, php_pqconn_event, "ext-pq", NULL); } + + return conn; } static void php_pqconn_resource_factory_dtor(void *opaque, void *handle TSRMLS_DC) { + php_pqconn_event_data_t *evdata = PQinstanceData(handle, php_pqconn_event); + + /* we don't care for anthing, except free'ing evdata */ + if (evdata) { + PQsetInstanceData(handle, php_pqconn_event, NULL); + memset(evdata, 0, sizeof(*evdata)); + efree(evdata); + } + PQfinish(handle); } @@ -1773,6 +1778,75 @@ static php_resource_factory_ops_t php_pqconn_resource_factory_ops = { php_pqconn_resource_factory_dtor }; +static void php_pqconn_wakeup(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC) +{ +} + +static int apply_unlisten(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) +{ + php_pqconn_object_t *obj = va_arg(argv, php_pqconn_object_t *); + char *quoted_channel = PQescapeIdentifier(obj->intern->conn, key->arKey, key->nKeyLength - 1); + + if (quoted_channel) { + PGresult *res; + char *cmd; + + spprintf(&cmd, 0, "UNLISTEN %s", quoted_channel); + if ((res = PQexec(obj->intern->conn, cmd))) { + PHP_PQclear(res); + } + + efree(cmd); + PQfreemem(quoted_channel); + } + + return ZEND_HASH_APPLY_REMOVE; +} + +static void php_pqconn_notice_ignore(void *p, const PGresult *res) +{ +} + +static void php_pqconn_retire(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC) +{ + php_pqconn_event_data_t *evdata = PQinstanceData(*handle, php_pqconn_event); + PGresult *res; + + /* go away */ + PQsetInstanceData(*handle, php_pqconn_event, NULL); + + /* ignore notices */ + PQsetNoticeReceiver(*handle, php_pqconn_notice_ignore, NULL); + + /* clean up async results */ + while ((res = PQgetResult(*handle))) { + PHP_PQclear(res); + } + + /* clean up transaction & session */ + switch (PQtransactionStatus(*handle)) { + case PQTRANS_IDLE: + res = PQexec(*handle, "RESET ALL"); + break; + default: + res = PQexec(*handle, "ROLLBACK; RESET ALL"); + break; + } + + if (res) { + PHP_PQclear(res); + } + + if (evdata) { + /* clean up notify listeners */ + zend_hash_apply_with_arguments(&evdata->obj->intern->listeners TSRMLS_CC, apply_unlisten, 1, evdata->obj); + + /* release instance data */ + memset(evdata, 0, sizeof(*evdata)); + efree(evdata); + } +} + ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_construct, 0, 0, 1) ZEND_ARG_INFO(0, dsn) ZEND_ARG_INFO(0, async) @@ -1795,19 +1869,18 @@ static PHP_METHOD(pqconn, __construct) { zend_hash_init(&obj->intern->eventhandlers, 0, NULL, ZVAL_PTR_DTOR, 0); if (flags & PHP_PQCONN_PERSISTENT) { - php_persistent_handle_factory_t *phf = php_persistent_handle_concede(NULL, ZEND_STRL("pq\\Connection"), dsn_str, dsn_len TSRMLS_CC); + php_persistent_handle_factory_t *phf = php_persistent_handle_concede(NULL, ZEND_STRL("pq\\Connection"), dsn_str, dsn_len, php_pqconn_wakeup, php_pqconn_retire TSRMLS_CC); php_resource_factory_init(&obj->intern->factory, php_persistent_handle_get_resource_factory_ops(), phf, (void (*)(void*)) php_persistent_handle_abandon); - } else{ + } else { php_resource_factory_init(&obj->intern->factory, &php_pqconn_resource_factory_ops, NULL, NULL); } + if (flags & PHP_PQCONN_ASYNC) { obj->intern->poller = (int (*)(PGconn*)) PQconnectPoll; } obj->intern->conn = php_resource_factory_handle_ctor(&obj->intern->factory, &rfdata TSRMLS_CC); - PQregisterEventProc(obj->intern->conn, php_pqconn_event, "ext-pq", evdata); - /* the connection might be persistent, so reset event_proc instance data */ PQsetInstanceData(obj->intern->conn, php_pqconn_event, evdata); PQsetNoticeReceiver(obj->intern->conn, php_pqconn_notice_recv, evdata); @@ -1893,7 +1966,7 @@ static PHP_METHOD(pqconn, listen) { PGresult *res; char *cmd; - spprintf(&cmd, 0, "LISTEN %s", channel_str); + spprintf(&cmd, 0, "LISTEN %s", quoted_channel); res = PQexec(obj->intern->conn, cmd); efree(cmd); @@ -1923,6 +1996,51 @@ static PHP_METHOD(pqconn, listen) { } } +ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_listen_async, 0, 0, 0) + ZEND_ARG_INFO(0, channel) + ZEND_ARG_INFO(0, callable) +ZEND_END_ARG_INFO(); +static PHP_METHOD(pqconn, listenAsync) { + char *channel_str = NULL; + int channel_len = 0; + php_pq_callback_t listener; + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sf", &channel_str, &channel_len, &listener.fci, &listener.fcc)) { + php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + + obj->intern->poller = PQconsumeInput; + + if (obj->intern) { + char *quoted_channel = PQescapeIdentifier(obj->intern->conn, channel_str, channel_len); + + if (quoted_channel) { + char *cmd; + + obj->intern->poller = PQconsumeInput; + + spprintf(&cmd, 0, "LISTEN %s", channel_str); + if (PQsendQuery(obj->intern->conn, cmd)) { + php_pqconn_add_listener(obj, channel_str, channel_len, &listener TSRMLS_CC); + RETVAL_TRUE; + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not install listener (%s)", PHP_PQerrorMessage(obj->intern->conn)); + RETVAL_FALSE; + } + + efree(cmd); + PQfreemem(quoted_channel); + + php_pqconn_notify_listeners(obj TSRMLS_CC); + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not escape channel identifier (%s)", PHP_PQerrorMessage(obj->intern->conn)); + } + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "pq\\Connection not initialized"); + RETVAL_FALSE; + } + } +} + ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_notify, 0, 0, 2) ZEND_ARG_INFO(0, channel) ZEND_ARG_INFO(0, message) @@ -1961,6 +2079,38 @@ static PHP_METHOD(pqconn, notify) { } } +ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_notify_async, 0, 0, 2) + ZEND_ARG_INFO(0, channel) + ZEND_ARG_INFO(0, message) +ZEND_END_ARG_INFO(); +static PHP_METHOD(pqconn, notifyAsync) { + char *channel_str, *message_str; + int channel_len, message_len; + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &channel_str, &channel_len, &message_str, &message_len)) { + php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + + if (obj->intern) { + char *params[2] = {channel_str, message_str}; + + obj->intern->poller = PQconsumeInput; + + if (PQsendQueryParams(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0)) { + RETVAL_TRUE; + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn)); + RETVAL_FALSE; + } + + php_pqconn_notify_listeners(obj TSRMLS_CC); + + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "pq\\Connection not initialized"); + RETVAL_FALSE; + } + } +} + ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_poll, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(pqconn, poll) { @@ -2145,7 +2295,7 @@ static int php_pq_types_to_array(HashTable *ht, Oid **types TSRMLS_DC) Oid *tmp; /* +1 for when less types than params are specified */ - *types = tmp = ecalloc(count + 1, sizeof(Oid)); + *types = tmp = ecalloc(count + 1, sizeof(**types)); zend_hash_apply_with_argument(ht, apply_to_oid, &tmp TSRMLS_CC); } @@ -2167,7 +2317,26 @@ static int php_pq_params_to_array(HashTable *ht, char ***params, HashTable *zdto return count; } +/* +static Oid *php_pq_ntypes_to_array(zend_bool fill, int argc, ...) +{ + int i; + Oid *oids = ecalloc(argc + 1, sizeof(*oids)); + va_list argv; + + va_start(argv, argc); + for (i = 0; i < argc; ++i) { + if (!fill || !i) { + oids[i] = va_arg(argv, Oid); + } else { + oids[i] = oids[0]; + } + } + va_end(argv); + return oids; +} +*/ ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_exec_params, 0, 0, 2) ZEND_ARG_INFO(0, query) ZEND_ARG_ARRAY_INFO(0, params, 0) @@ -2732,7 +2901,9 @@ static zend_function_entry php_pqconn_methods[] = { PHP_ME(pqconn, prepare, ai_pqconn_prepare, ZEND_ACC_PUBLIC) PHP_ME(pqconn, prepareAsync, ai_pqconn_prepare_async, ZEND_ACC_PUBLIC) PHP_ME(pqconn, listen, ai_pqconn_listen, ZEND_ACC_PUBLIC) + PHP_ME(pqconn, listenAsync, ai_pqconn_listen_async, ZEND_ACC_PUBLIC) PHP_ME(pqconn, notify, ai_pqconn_notify, ZEND_ACC_PUBLIC) + PHP_ME(pqconn, notifyAsync, ai_pqconn_notify_async, ZEND_ACC_PUBLIC) PHP_ME(pqconn, getResult, ai_pqconn_get_result, ZEND_ACC_PUBLIC) PHP_ME(pqconn, quote, ai_pqconn_quote, ZEND_ACC_PUBLIC) PHP_ME(pqconn, quoteName, ai_pqconn_quote_name, ZEND_ACC_PUBLIC) @@ -2746,13 +2917,14 @@ static zend_function_entry php_pqconn_methods[] = { ZEND_BEGIN_ARG_INFO_EX(ai_pqtypes_construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, connection, pq\\Connection, 0) + ZEND_ARG_ARRAY_INFO(0, namespaces, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(pqtypes, __construct) { zend_error_handling zeh; - zval *zconn; + zval *zconn, *znsp = NULL; zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zconn, php_pqconn_class_entry)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|a!", &zconn, php_pqconn_class_entry, &znsp)) { php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC); if (conn_obj->intern) { @@ -2764,7 +2936,11 @@ static PHP_METHOD(pqtypes, __construct) { php_pq_object_addref(conn_obj TSRMLS_CC); zend_hash_init(&obj->intern->types, 300, NULL, ZVAL_PTR_DTOR, 0); - zend_call_method_with_0_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", &retval); + if (znsp) { + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", &retval, znsp); + } else { + zend_call_method_with_0_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "refresh", &retval); + } if (retval) { zval_ptr_dtor(&retval); } @@ -2779,17 +2955,52 @@ static PHP_METHOD(pqtypes, __construct) { "select t.oid, t.* " \ "from pg_type t join pg_namespace n on t.typnamespace=n.oid " \ "where typisdefined " \ - "and typrelid=0 " \ - "and nspname in ('public', 'pg_catalog')" + "and typrelid=0" +#define PHP_PQ_OID_TEXT 25 ZEND_BEGIN_ARG_INFO_EX(ai_pqtypes_refresh, 0, 0, 0) + ZEND_ARG_ARRAY_INFO(0, namespaces, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(pqtypes, refresh) { - if (SUCCESS == zend_parse_parameters_none()) { + HashTable *nsp = NULL; + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H/!", &nsp)) { php_pqtypes_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); if (obj->intern) { - PGresult *res = PQexec(obj->intern->conn->intern->conn, PHP_PQ_TYPES_QUERY); + PGresult *res; + + if (nsp && zend_hash_num_elements(nsp)) { + int i, count; + Oid *oids; + char **params = NULL; + HashTable zdtor; + smart_str str = {0}; + + smart_str_appends(&str, PHP_PQ_TYPES_QUERY " and nspname in("); + zend_hash_init(&zdtor, 0, NULL, ZVAL_PTR_DTOR, 0); + count = php_pq_params_to_array(nsp, ¶ms, &zdtor TSRMLS_CC); + oids = ecalloc(count + 1, sizeof(*oids)); + for (i = 0; i < count; ++i) { + oids[i] = PHP_PQ_OID_TEXT; + if (i) { + smart_str_appendc(&str, ','); + } + smart_str_appendc(&str, '$'); + smart_str_append_unsigned(&str, i+1); + } + smart_str_appendc(&str, ')'); + smart_str_0(&str); + + res = PQexecParams(obj->intern->conn->intern->conn, str.c, count, oids, (const char *const*) params, NULL, NULL, 0); + + smart_str_free(&str); + efree(oids); + efree(params); + zend_hash_destroy(&zdtor); + } else { + res = PQexec(obj->intern->conn->intern->conn, PHP_PQ_TYPES_QUERY " and nspname in ('public', 'pg_catalog')"); + } php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC); @@ -3464,12 +3675,44 @@ static PHP_METHOD(pqstm, desc) { zend_restore_error_handling(&zeh TSRMLS_CC); } +ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc_async, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(pqstm, descAsync) { + zend_error_handling zeh; + + zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC); + if (SUCCESS == zend_parse_parameters_none()) { + php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + + if (obj->intern) { + + obj->intern->conn->intern->poller = PQconsumeInput; + + if (PQsendDescribePrepared(obj->intern->conn->intern->conn, obj->intern->name)) { + RETVAL_TRUE; + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn)); + RETVAL_FALSE; + } + + php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC); + + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement not initialized"); + RETVAL_FALSE; + } + } + zend_restore_error_handling(&zeh TSRMLS_CC); +} + + static zend_function_entry php_pqstm_methods[] = { PHP_ME(pqstm, __construct, ai_pqstm_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_ME(pqstm, bind, ai_pqstm_bind, ZEND_ACC_PUBLIC) PHP_ME(pqstm, exec, ai_pqstm_exec, ZEND_ACC_PUBLIC) PHP_ME(pqstm, desc, ai_pqstm_desc, ZEND_ACC_PUBLIC) PHP_ME(pqstm, execAsync, ai_pqstm_exec_async, ZEND_ACC_PUBLIC) + PHP_ME(pqstm, descAsync, ai_pqstm_desc_async, ZEND_ACC_PUBLIC) {0} }; @@ -4856,7 +5099,7 @@ static PHP_MINIT_FUNCTION(pq) zend_declare_class_constant_long(php_pqcopy_class_entry, ZEND_STRL("FROM_STDIN"), PHP_PQCOPY_FROM_STDIN TSRMLS_CC); zend_declare_class_constant_long(php_pqcopy_class_entry, ZEND_STRL("TO_STDOUT"), PHP_PQCOPY_TO_STDOUT TSRMLS_CC); - php_persistent_handle_provide(ZEND_STRL("pq\\Connection"), &php_pqconn_resource_factory_ops, NULL, NULL); + php_persistent_handle_provide(ZEND_STRL("pq\\Connection"), &php_pqconn_resource_factory_ops, NULL, NULL TSRMLS_CC); /* REGISTER_INI_ENTRIES(); @@ -4912,6 +5155,7 @@ const zend_function_entry pq_functions[] = { static zend_module_dep pq_module_deps[] = { ZEND_MOD_REQUIRED("raphf") + ZEND_MOD_REQUIRED("spl") ZEND_MOD_END };