static zend_object_handlers php_pqconn_object_handlers;
static HashTable php_pqconn_object_prophandlers;
+static void php_pq_callback_hash_dtor(zval *p)
+{
+ php_pq_callback_dtor(Z_PTR_P(p));
+ efree(Z_PTR_P(p));
+}
+
/*
-static void php_pqconn_del_eventhandler(php_pqconn_object_t *obj, const char *type_str, size_t type_len, ulong id TSRMLS_DC)
+static void php_pqconn_del_eventhandler(php_pqconn_object_t *obj, const char *type_str, size_t type_len, unsigned long id)
{
zval **evhs;
}
*/
-static ulong php_pqconn_add_eventhandler(php_pqconn_object_t *obj, const char *type_str, size_t type_len, php_pq_callback_t *cb TSRMLS_DC)
+static zend_long php_pqconn_add_eventhandler(php_pqconn_object_t *obj, const char *type_str, size_t type_len, php_pq_callback_t *cb)
{
- ulong h;
- HashTable *evhs;
+ zend_long h;
+ zval *zevhs;
+
+ if (!(zevhs = zend_hash_str_find(&obj->intern->eventhandlers, type_str, type_len))) {
+ HashTable *evhs;
+ zval tmp;
- if (!(evhs = zend_hash_str_find_ptr(&obj->intern->eventhandlers, type_str, type_len))) {
- HashTable evh;
+ ALLOC_HASHTABLE(evhs);
+ zend_hash_init(evhs, 1, NULL, php_pq_callback_hash_dtor, 0);
- zend_hash_init(&evh, 1, NULL, (dtor_func_t) php_pq_callback_dtor, 0);
- evhs = zend_hash_str_add_mem(&obj->intern->eventhandlers, type_str, type_len, (void *) &evh, sizeof(evh));
+ ZVAL_ARR(&tmp, evhs);
+ zevhs = zend_hash_str_add(&obj->intern->eventhandlers, type_str, type_len, &tmp);
}
php_pq_callback_addref(cb);
- h = zend_hash_next_free_element(evhs);
- zend_hash_index_update_ptr(evhs, h, (void *) cb);
+ h = zend_hash_next_free_element(Z_ARRVAL_P(zevhs));
+ zend_hash_index_update_mem(Z_ARRVAL_P(zevhs), h, (void *) cb, sizeof(*cb));
return h;
}
{
php_pqconn_object_t *obj = PHP_PQ_OBJ(NULL, o);
#if DBG_GC
- fprintf(stderr, "FREE conn(#%d) %p\n", obj->zv.handle, obj);
+ fprintf(stderr, "FREE conn(#%d) %p\n", obj->zo.handle, obj);
#endif
if (obj->intern) {
php_pq_callback_dtor(&obj->intern->onevent);
php_resource_factory_handle_dtor(&obj->intern->factory, obj->intern->conn);
php_resource_factory_dtor(&obj->intern->factory);
zend_hash_destroy(&obj->intern->listeners);
+ zend_hash_destroy(&obj->intern->statements);
zend_hash_destroy(&obj->intern->converters);
zend_hash_destroy(&obj->intern->eventhandlers);
efree(obj->intern);
obj->intern = NULL;
}
- zend_object_std_dtor(o);
- efree(obj);
+ php_pq_object_dtor(o);
}
php_pqconn_object_t *php_pqconn_create_object_ex(zend_class_entry *ce, php_pqconn_t *intern)
{
- php_pqconn_object_t *o;
-
- o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
- zend_object_std_init(&o->zo, ce);
- object_properties_init(&o->zo, ce);
- o->prophandler = &php_pqconn_object_prophandlers;
-
- if (intern) {
- o->intern = intern;
- }
-
- o->zo.handlers = &php_pqconn_object_handlers;
-
- return o;
+ return php_pq_object_create(ce, intern, sizeof(php_pqconn_object_t),
+ &php_pqconn_object_handlers, &php_pqconn_object_prophandlers);
}
static zend_object *php_pqconn_create_object(zend_class_entry *class_type)
return &php_pqconn_create_object_ex(class_type, NULL)->zo;
}
-static void php_pqconn_object_read_status(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_status(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_LONG(PQstatus(obj->intern->conn));
}
-static void php_pqconn_object_read_transaction_status(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_transaction_status(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_LONG(PQtransactionStatus(obj->intern->conn));
}
-static void php_pqconn_object_read_error_message(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_error_message(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
char *error = PHP_PQerrorMessage(obj->intern->conn);
zend_fcall_info_argn(&listener->fci, 3, &zchannel, &zmessage, &zpid);
zend_fcall_info_call(&listener->fci, &listener->fcc, NULL, NULL);
+ zend_fcall_info_args_clear(&listener->fci, 0);
zval_ptr_dtor(&zchannel);
zval_ptr_dtor(&zmessage);
}
}
-static void php_pqconn_object_read_busy(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_busy(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_BOOL(PQisBusy(obj->intern->conn));
}
-static void php_pqconn_object_read_encoding(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_encoding(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_STRING(pg_encoding_to_char(PQclientEncoding(obj->intern->conn)));
}
-static void php_pqconn_object_write_encoding(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_encoding(void *o, zval *value)
{
php_pqconn_object_t *obj = o;
zend_string *zenc = zval_get_string(value);
zend_string_release(zenc);
}
-static void php_pqconn_object_read_unbuffered(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_unbuffered(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_BOOL(obj->intern->unbuffered);
}
-static void php_pqconn_object_write_unbuffered(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_unbuffered(void *o, zval *value)
{
php_pqconn_object_t *obj = o;
obj->intern->unbuffered = z_is_true(value);
}
-static void php_pqconn_object_read_db(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_nonblocking(void *o, zval *return_value)
+{
+ php_pqconn_object_t *obj = o;
+
+ RETVAL_BOOL(PQisnonblocking(obj->intern->conn));
+}
+
+static void php_pqconn_object_write_nonblocking(void *o, zval *value)
+{
+ php_pqconn_object_t *obj = o;
+
+ PQsetnonblocking(obj->intern->conn, z_is_true(value));
+}
+
+static void php_pqconn_object_read_db(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
char *db = PQdb(obj->intern->conn);
}
}
-static void php_pqconn_object_read_user(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_user(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
char *user = PQuser(obj->intern->conn);
}
}
-static void php_pqconn_object_read_pass(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_pass(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
char *pass = PQpass(obj->intern->conn);
}
}
-static void php_pqconn_object_read_host(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_host(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
char *host = PQhost(obj->intern->conn);
}
}
-static void php_pqconn_object_read_port(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_port(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
char *port = PQport(obj->intern->conn);
}
#if HAVE_PQCONNINFO
-static void php_pqconn_object_read_params(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_params(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
PQconninfoOption *ptr, *params = PQconninfo(obj->intern->conn);
}
#endif
-static void php_pqconn_object_read_options(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_options(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
char *options = PQoptions(obj->intern->conn);
}
}
-static int apply_read_event_handler_ex(zval *p, void *arg)
+static int apply_read_callback_ex(zval *p, void *arg)
{
HashTable *rv = arg;
zval zcb;
return ZEND_HASH_APPLY_KEEP;
}
-static int apply_read_event_handlers(zval *p, int argc, va_list argv, zend_hash_key *key)
+static int apply_read_callbacks(zval *p, int argc, va_list argv, zend_hash_key *key)
{
- HashTable *evhs = Z_PTR_P(p), *rv = va_arg(argv, HashTable *);
+ HashTable *evhs = Z_ARRVAL_P(p), *rv = va_arg(argv, HashTable *);
zval entry, *entry_ptr;
array_init_size(&entry, zend_hash_num_elements(evhs));
entry_ptr = zend_hash_index_update(rv, key->h, &entry);
}
- zend_hash_apply_with_argument(evhs, apply_read_event_handler_ex, Z_ARRVAL_P(entry_ptr));
+ zend_hash_apply_with_argument(evhs, apply_read_callback_ex, Z_ARRVAL_P(entry_ptr));
return ZEND_HASH_APPLY_KEEP;
}
-static void php_pqconn_object_read_event_handlers(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_event_handlers(void *o, zval *return_value)
+{
+ php_pqconn_object_t *obj = o;
+
+ array_init(return_value);
+ zend_hash_apply_with_arguments(&obj->intern->eventhandlers, apply_read_callbacks, 1, Z_ARRVAL_P(return_value));
+}
+
+static void php_pqconn_object_gc_event_handlers(void *o, zval *return_value)
+{
+ php_pqconn_object_t *obj = o;
+ zval *evhs;
+
+ ZEND_HASH_FOREACH_VAL(&obj->intern->eventhandlers, evhs)
+ {
+ zval *evh;
+
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(evhs), evh)
+ {
+ zval zcb;
+
+ add_next_index_zval(return_value, php_pq_callback_to_zval_no_addref(Z_PTR_P(evh), &zcb));
+ }
+ ZEND_HASH_FOREACH_END();
+ }
+ ZEND_HASH_FOREACH_END();
+}
+
+static void php_pqconn_object_read_listeners(void *o, zval *return_value)
+{
+ php_pqconn_object_t *obj = o;
+
+ array_init(return_value);
+ zend_hash_apply_with_arguments(&obj->intern->listeners, apply_read_callbacks, 1, Z_ARRVAL_P(return_value));
+}
+
+static void php_pqconn_object_gc_listeners(void *o, zval *return_value)
+{
+ php_pqconn_object_t *obj = o;
+ zval *listeners;
+
+ ZEND_HASH_FOREACH_VAL(&obj->intern->listeners, listeners)
+ {
+ zval *listener;
+
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(listeners), listener)
+ {
+ zval zcb;
+
+ add_next_index_zval(return_value, php_pq_callback_to_zval_no_addref(Z_PTR_P(listener), &zcb));
+ }
+ ZEND_HASH_FOREACH_END();
+ }
+ ZEND_HASH_FOREACH_END();
+}
+
+static void php_pqconn_object_read_converters(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
array_init(return_value);
- zend_hash_apply_with_arguments(&obj->intern->eventhandlers, apply_read_event_handlers, 1, Z_ARRVAL_P(return_value) TSRMLS_CC);
+ zend_hash_copy(Z_ARRVAL_P(return_value), &obj->intern->converters, zval_add_ref);
}
-static void php_pqconn_object_read_def_fetch_type(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_gc_converters(void *o, zval *return_value)
+{
+ php_pqconn_object_t *obj = o;
+ zval *converter;
+
+ ZEND_HASH_FOREACH_VAL(&obj->intern->converters, converter)
+ {
+ add_next_index_zval(return_value, converter);
+ }
+ ZEND_HASH_FOREACH_END();
+}
+
+static void php_pqconn_object_read_def_fetch_type(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_LONG(obj->intern->default_fetch_type);
}
-static void php_pqconn_object_write_def_fetch_type(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_def_fetch_type(void *o, zval *value)
{
php_pqconn_object_t *obj = o;
obj->intern->default_fetch_type = zval_get_long(value) & 0x3; /* two bits only */
}
-static void php_pqconn_object_read_def_txn_isolation(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_txn_isolation(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_LONG(obj->intern->default_txn_isolation);
}
-static void php_pqconn_object_write_def_txn_isolation(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_def_txn_isolation(void *o, zval *value)
{
php_pqconn_object_t *obj = o;
obj->intern->default_txn_isolation = zval_get_long(value) & 0x3; /* two bits only */
}
-static void php_pqconn_object_read_def_txn_readonly(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_txn_readonly(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_BOOL(obj->intern->default_txn_readonly);
}
-static void php_pqconn_object_write_def_txn_readonly(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_def_txn_readonly(void *o, zval *value)
{
php_pqconn_object_t *obj = o;
obj->intern->default_txn_readonly = z_is_true(value);
}
-static void php_pqconn_object_read_def_txn_deferrable(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_txn_deferrable(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_BOOL(obj->intern->default_txn_deferrable);
}
-static void php_pqconn_object_write_def_txn_deferrable(zval *object, void *o, zval *value)
+static void php_pqconn_object_write_def_txn_deferrable(void *o, zval *value)
{
php_pqconn_object_t *obj = o;
obj->intern->default_txn_deferrable = zend_is_true(value);
}
-static void php_pqconn_object_read_def_auto_conv(zval *object, void *o, zval *return_value)
+static void php_pqconn_object_read_def_auto_conv(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
RETVAL_LONG(obj->intern->default_auto_convert);
}
-static void php_pqconn_object_write_def_auto_conv(zval*object, void *o, zval *value)
+static void php_pqconn_object_write_def_auto_conv(void *o, zval *value)
{
php_pqconn_object_t *obj = o;
obj->intern->default_auto_convert = zval_get_long(value) & PHP_PQRES_CONV_ALL;
}
+#ifdef HAVE_PQLIBVERSION
+static void php_pqconn_object_read_lib_version(void *o, zval *return_value)
+{
+ char ver[16];
+
+ php_pq_version_to_string(PQlibVersion(), ver, sizeof(ver));
+ RETVAL_STRING(ver);
+}
+#endif
+#ifdef HAVE_PQPROTOCOLVERSION
+static void php_pqconn_object_read_protocol_version(void *o, zval *return_value)
+{
+ php_pqconn_object_t *obj = o;
+
+ RETVAL_LONG(PQprotocolVersion(obj->intern->conn));
+}
+#endif
+#ifdef HAVE_PQSERVERVERSION
+static void php_pqconn_object_read_server_version(void *o, zval *return_value)
+{
+ php_pqconn_object_t *obj = o;
+ char ver[16];
+
+ php_pq_version_to_string(PQserverVersion(obj->intern->conn), ver, sizeof(ver));
+ RETVAL_STRING(ver);
+}
+#endif
+
static ZEND_RESULT_CODE php_pqconn_update_socket(zval *zobj, php_pqconn_object_t *obj)
{
zval zsocket, zmember;
ZVAL_NULL(&zsocket);
retval = FAILURE;
}
- zend_get_std_object_handlers()->write_property(zobj, &zmember, &zsocket, NULL);
+#if PHP_VERSION_ID >= 80000
+ zend_std_write_property(Z_OBJ_P(zobj), Z_STR(zmember), &zsocket, NULL);
+#else
+ zend_std_write_property(zobj, &zmember, &zsocket, NULL);
+#endif
zval_ptr_dtor(&zsocket);
+ zval_ptr_dtor(&zmember);
return retval;
}
static void php_pqconn_wakeup(php_persistent_handle_factory_t *f, void **handle)
{
PGresult *res = PQexec(*handle, "");
- PHP_PQclear(res);
+ php_pqres_clear(res);
if (CONNECTION_OK != PQstatus(*handle)) {
PQreset(*handle);
smart_str_appends(&cmd, quoted_channel);
smart_str_0(&cmd);
- res = PQexec(conn, smart_str_v(&cmd));
+ res = php_pq_exec(conn, smart_str_v(&cmd));
smart_str_free(&cmd);
PQfreemem(quoted_channel);
PGresult *res = unlisten(obj->intern->conn, key->key->val, key->key->len);
if (res) {
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
return ZEND_HASH_APPLY_REMOVE;
}
/* clean up async results */
while ((res = PQgetResult(*handle))) {
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
/* clean up transaction & session */
}
if (res) {
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
if (evdata) {
zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &dsn_str, &dsn_len, &flags);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
if (SUCCESS == rv) {
php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
obj->intern->default_auto_convert = PHP_PQRES_CONV_ALL;
zend_hash_init(&obj->intern->listeners, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_init(&obj->intern->statements, 0, NULL, NULL, 0);
zend_hash_init(&obj->intern->converters, 0, NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_init(&obj->intern->eventhandlers, 0, NULL, (dtor_func_t) zend_hash_destroy, 0);
+ zend_hash_init(&obj->intern->eventhandlers, 0, NULL, ZVAL_PTR_DTOR, 0);
if (flags & PHP_PQCONN_PERSISTENT) {
zend_string *dsn = zend_string_init(dsn_str, dsn_len, 0);
php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
if (!obj->intern) {
- throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
} else {
if (!PQresetStart(obj->intern->conn)) {
- throw_exce(EX_IO TSRMLS_CC, "Failed to start connection reset (%s)", PHP_PQerrorMessage(obj->intern->conn));
+ throw_exce(EX_IO, "Failed to start connection reset (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
obj->intern->poller = (int (*)(PGconn*)) PQresetPoll;
}
if (res) {
php_pqres_success(res);
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
}
}
static void php_pqconn_add_listener(php_pqconn_object_t *obj, const char *channel_str, size_t channel_len, php_pq_callback_t *listener)
{
- zval *existing, tmp;
+ zval *existing;
php_pq_callback_addref(listener);
if ((existing = zend_hash_str_find(&obj->intern->listeners, channel_str, channel_len))) {
zend_hash_next_index_insert_mem(Z_ARRVAL_P(existing), (void *) listener, sizeof(*listener));
} else {
- ZVAL_NEW_ARR(&tmp);
- zend_hash_next_index_insert_mem(Z_ARRVAL(tmp), (void *) listener, sizeof(*listener));
+ zval tmp;
+ HashTable *ht;
+
+ ALLOC_HASHTABLE(ht);
+ zend_hash_init(ht, 0, NULL, php_pq_callback_hash_dtor, 0);
+ zend_hash_next_index_insert_mem(ht, (void *) listener, sizeof(*listener));
+
+ ZVAL_ARR(&tmp, ht);
zend_hash_str_add(&obj->intern->listeners, channel_str, channel_len, &tmp);
}
}
zend_error_handling zeh;
char *channel_str = NULL;
size_t channel_len = 0;
- php_pq_callback_t listener = {{0}};
+ php_pq_callback_t listener = PHP_PQ_CALLBACK_INIT;
ZEND_RESULT_CODE rv;
zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
smart_str_appends(&cmd, quoted_channel);
smart_str_0(&cmd);
- res = PQexec(obj->intern->conn, smart_str_v(&cmd));
+ res = php_pq_exec(obj->intern->conn, smart_str_v(&cmd));
smart_str_free(&cmd);
PQfreemem(quoted_channel);
obj->intern->poller = PQconsumeInput;
php_pqconn_add_listener(obj, channel_str, channel_len, &listener);
}
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
php_pqconn_notify_listeners(obj);
zend_error_handling zeh;
char *channel_str = NULL;
size_t channel_len = 0;
- php_pq_callback_t listener = {{0}};
+ php_pq_callback_t listener = PHP_PQ_CALLBACK_INIT;
ZEND_RESULT_CODE rv;
zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
if (!obj->intern) {
- throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
} else {
char *quoted_channel = PQescapeIdentifier(obj->intern->conn, channel_str, channel_len);
if (!quoted_channel) {
- throw_exce(EX_ESCAPE TSRMLS_CC, "Failed to escape channel identifier (%s)", PHP_PQerrorMessage(obj->intern->conn));
+ throw_exce(EX_ESCAPE, "Failed to escape channel identifier (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
smart_str cmd = {0};
PGresult *res;
char *params[2] = {channel_str, message_str};
- res = PQexecParams(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0);
+ res = php_pq_exec_params(obj->intern->conn, "select pg_notify($1, $2)", 2, NULL, (const char *const*) params, NULL, NULL, 0);
if (!res) {
throw_exce(EX_RUNTIME, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
php_pqres_success(res);
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
php_pqconn_notify_listeners(obj);
}
}
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_flush, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqconn, flush) {
+ zend_error_handling zeh;
+ ZEND_RESULT_CODE rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
+ } else if (!obj->intern->poller) {
+ throw_exce(EX_RUNTIME, "No asynchronous operation active");
+ } else {
+ switch (PQflush(obj->intern->conn)) {
+ case -1:
+ default:
+ throw_exce(EX_RUNTIME, "Failed to flush connection: %s", PHP_PQerrorMessage(obj->intern->conn));
+ break;
+ case 0:
+ RETVAL_TRUE;
+ break;
+ case 1:
+ RETVAL_FALSE;
+ break;
+ }
+ }
+ }
+}
+
ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_exec, 0, 0, 1)
ZEND_ARG_INFO(0, query)
ZEND_END_ARG_INFO();
if (!obj->intern) {
throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
} else {
- PGresult *res = PQexec(obj->intern->conn, query_str);
+ PGresult *res = php_pq_exec(obj->intern->conn, query_str);
if (!res) {
throw_exce(EX_RUNTIME, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else if (SUCCESS == php_pqres_success(res)) {
php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), return_value);
} else {
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
php_pqconn_notify_listeners(obj);
throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
} else {
PGresult *res = PQgetResult(obj->intern->conn);
+ php_pq_object_t *res_obj;
- if (!res) {
- RETVAL_NULL();
+ if (res && (res_obj = PQresultInstanceData(res, php_pqconn_event))) {
+ php_pq_object_to_zval_no_addref(res_obj, return_value);
} else {
- php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), return_value);
+ RETVAL_NULL();
}
php_pqconn_notify_listeners(obj);
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, execAsync) {
zend_error_handling zeh;
- php_pq_callback_t resolver = {{0}};
+ php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT;
char *query_str;
size_t query_len;
ZEND_RESULT_CODE rv;
php_pq_params_t *params;
params = php_pq_params_init(&obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, Z_ARRVAL_P(zparams));
- res = PQexecParams(obj->intern->conn, query_str, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
+ res = php_pq_exec_params(obj->intern->conn, query_str, params->param.count, params->type.oids, (const char *const*) params->param.strings, NULL, NULL, 0);
php_pq_params_free(¶ms);
if (!res) {
if (SUCCESS == php_pqres_success(res)) {
php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), return_value);
} else {
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
php_pqconn_notify_listeners(obj);
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, execParamsAsync) {
zend_error_handling zeh;
- php_pq_callback_t resolver = {{0}};
+ php_pq_callback_t resolver = PHP_PQ_CALLBACK_INIT;
char *query_str;
size_t query_len;
zval *zparams;
obj = PHP_PQ_OBJ(object, NULL);
}
- res = PQprepare(obj->intern->conn, name, query, params->type.count, params->type.oids);
+ res = php_pq_prepare(obj->intern->conn, name, query, params->type.count, params->type.oids);
if (!res) {
rv = FAILURE;
throw_exce(EX_RUNTIME, "Failed to prepare statement (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
rv = php_pqres_success(res);
- PHP_PQclear(res);
+ php_pqres_clear(res);
php_pqconn_notify_listeners(obj);
}
}
}
-ZEND_RESULT_CODE php_pqconn_prepare_async(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_prepare_async(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params)
{
ZEND_RESULT_CODE rv;
obj = PHP_PQ_OBJ(object, NULL);
}
- res = PQexec(obj->intern->conn, decl);
+ res = php_pq_exec(obj->intern->conn, decl);
if (!res) {
rv = FAILURE;
throw_exce(EX_RUNTIME, "Failed to declare cursor (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
rv = php_pqres_success(res);
- PHP_PQclear(res);
+ php_pqres_clear(res);
php_pqconn_notify_listeners(obj);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, escapeBytea) {
char *str;
- int len;
+ size_t len;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len)) {
php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
}
if (!conn_obj->intern) {
- throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
} else {
PGresult *res;
smart_str cmd = {0};
smart_str_appends(&cmd, " DEFERRABLE");
smart_str_0(&cmd);
- res = PQexec(conn_obj->intern->conn, smart_str_v(&cmd));
+ res = php_pq_exec(conn_obj->intern->conn, smart_str_v(&cmd));
if (!res) {
throw_exce(EX_RUNTIME, "Failed to start transaction (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
} else {
rv = php_pqres_success(res);
- PHP_PQclear(res);
+ php_pqres_clear(res);
php_pqconn_notify_listeners(conn_obj);
}
zend_error_handling zeh;
char *type_str;
size_t type_len;
- php_pq_callback_t cb = {{0}};
+ php_pq_callback_t cb = PHP_PQ_CALLBACK_INIT;
ZEND_RESULT_CODE rv;
zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh);
php_pqconn_object_t *obj = PHP_PQ_OBJ(getThis(), NULL);
if (!obj->intern) {
- throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ throw_exce(EX_UNINITIALIZED, "pq\\Connection not initialized");
} else {
RETVAL_LONG(php_pqconn_add_eventhandler(obj, type_str, type_len, &cb));
}
struct apply_set_converter_arg arg = {NULL};
ZVAL_NULL(&zoids);
- zend_call_method_with_0_params(zcnv, NULL, NULL, "converttypes", &zoids);
+ php_pq_call_method(zcnv, "converttypes", 0, &zoids);
ZVAL_DUP(&tmp, &zoids);
convert_to_array(&tmp);
struct apply_set_converter_arg arg = {NULL};
ZVAL_NULL(&zoids);
- zend_call_method_with_0_params(zcnv, NULL, NULL, "converttypes", &zoids);
+ php_pq_call_method(zcnv, "converttypes", 0, &zoids);
ZVAL_DUP(&tmp, &zoids);
convert_to_array(&tmp);
}
static zend_function_entry php_pqconn_methods[] = {
- PHP_ME(pqconn, __construct, ai_pqconn_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+ PHP_ME(pqconn, __construct, ai_pqconn_construct, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, reset, ai_pqconn_reset, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, resetAsync, ai_pqconn_reset_async, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, poll, ai_pqconn_poll, ZEND_ACC_PUBLIC)
+ PHP_ME(pqconn, flush, ai_pqconn_flush, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, exec, ai_pqconn_exec, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, execAsync, ai_pqconn_exec_async, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, execParams, ai_pqconn_exec_params, ZEND_ACC_PUBLIC)
php_pqconn_object_handlers.read_property = php_pq_object_read_prop;
php_pqconn_object_handlers.write_property = php_pq_object_write_prop;
php_pqconn_object_handlers.clone_obj = NULL;
- php_pqconn_object_handlers.get_property_ptr_ptr = NULL;
- php_pqconn_object_handlers.get_gc = NULL;
+ php_pqconn_object_handlers.get_property_ptr_ptr = php_pq_object_get_prop_ptr_null;
+ php_pqconn_object_handlers.get_gc = php_pq_object_get_gc;
php_pqconn_object_handlers.get_properties = php_pq_object_properties;
php_pqconn_object_handlers.get_debug_info = php_pq_object_debug_info;
- zend_hash_init(&php_pqconn_object_prophandlers, 20, NULL, NULL, 1);
+ zend_hash_init(&php_pqconn_object_prophandlers, 23, NULL, php_pq_object_prophandler_dtor, 1);
zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("status"), CONNECTION_BAD, ZEND_ACC_PUBLIC);
ph.read = php_pqconn_object_read_status;
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "unbuffered", sizeof("unbuffered")-1, (void *) &ph, sizeof(ph));
ph.write = NULL;
+ zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("nonblocking"), 0, ZEND_ACC_PUBLIC);
+ ph.read = php_pqconn_object_read_nonblocking;
+ ph.write = php_pqconn_object_write_nonblocking;
+ zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "nonblocking", sizeof("nonblocking")-1, (void *) &ph, sizeof(ph));
+ ph.write = NULL;
+
zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("db"), ZEND_ACC_PUBLIC);
ph.read = php_pqconn_object_read_db;
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "db", sizeof("db")-1, (void *) &ph, sizeof(ph));
zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("eventHandlers"), ZEND_ACC_PUBLIC);
ph.read = php_pqconn_object_read_event_handlers;
+ ph.gc = php_pqconn_object_gc_event_handlers;
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "eventHandlers", sizeof("eventHandlers")-1, (void *) &ph, sizeof(ph));
+ ph.gc = NULL;
+
+ zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("listeners"), ZEND_ACC_PUBLIC);
+ ph.read = php_pqconn_object_read_listeners;
+ ph.gc = php_pqconn_object_gc_listeners;
+ zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "listeners", sizeof("listeners")-1, (void *) &ph, sizeof(ph));
+ ph.gc = NULL;
+
+ zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("converters"), ZEND_ACC_PUBLIC);
+ ph.read = php_pqconn_object_read_converters;
+ ph.gc = php_pqconn_object_gc_converters;
+ zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "converters", sizeof("converters")-1, (void *) &ph, sizeof(ph));
+ ph.gc = NULL;
zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultFetchType"), 0, ZEND_ACC_PUBLIC);
ph.read = php_pqconn_object_read_def_fetch_type;
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultTransactionReadonly", sizeof("defaultTransactionReadonly")-1, (void *) &ph, sizeof(ph));
ph.write = NULL;
- zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("defaultTransactionDeferrable"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("defaultTransactionDeferrable"), 0, ZEND_ACC_PUBLIC);
ph.read = php_pqconn_object_read_def_txn_deferrable;
ph.write = php_pqconn_object_write_def_txn_deferrable;
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultTransactionDeferrable", sizeof("defaultTransactionDeferrable")-1, (void *) &ph, sizeof(ph));
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultAutoConvert", sizeof("defaultAutoConvert")-1, (void *) &ph, sizeof(ph));
ph.write = NULL;
+#ifdef HAVE_PQLIBVERSION
+ zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("libraryVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY);
+ ph.read = php_pqconn_object_read_lib_version;
+ zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("libraryVersion"), (void *) &ph, sizeof(ph));
+#endif
+
+#ifdef HAVE_PQPROTOCOLVERSION
+ zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("protocolVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY);
+ ph.read = php_pqconn_object_read_protocol_version;
+ zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("protocolVersion"), (void *) &ph, sizeof(ph));
+#endif
+
+#ifdef HAVE_PQSERVERVERSION
+ zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("serverVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY);
+ ph.read = php_pqconn_object_read_server_version;
+ zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("serverVersion"), (void *) &ph, sizeof(ph));
+#endif
+
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("STARTED"), CONNECTION_STARTED);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("AUTH_OK"), CONNECTION_AUTH_OK);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("SSL_STARTUP"), CONNECTION_SSL_STARTUP);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("SETENV"), CONNECTION_SETENV);
+#ifdef HAVE_CONNECTION_CHECK_WRITABLE
+ zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("CHECK_WRITABLE"), CONNECTION_CHECK_WRITABLE);
+#endif
+#ifdef HAVE_CONNECTION_CONSUME
+ zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("CONSUME"), CONNECTION_CONSUME);
+#endif
+#ifdef HAVE_CONNECTION_GSS_STARTUP
+ zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("GSS_STARTUP"), CONNECTION_GSS_STARTUP);
+#endif
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_IDLE"), PQTRANS_IDLE);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("TRANS_ACTIVE"), PQTRANS_ACTIVE);