php_resource_factory_handle_dtor(&obj->intern->factory, obj->intern->conn TSRMLS_CC);
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);
}
if (0 > PQsetClientEncoding(obj->intern->conn, Z_STRVAL_P(zenc))) {
- zend_error(E_NOTICE, "Unrecognized encoding '%s'", Z_STRVAL_P(zenc));
+ php_error(E_NOTICE, "Unrecognized encoding '%s'", Z_STRVAL_P(zenc));
}
if (zenc != value) {
{
php_pqconn_object_t *obj = o;
- obj->intern->unbuffered = zend_is_true(value);
+ obj->intern->unbuffered = z_is_true(value);
+}
+
+static void php_pqconn_object_read_nonblocking(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+
+ RETVAL_BOOL(PQisnonblocking(obj->intern->conn));
+}
+
+static void php_pqconn_object_write_nonblocking(zval *object, void *o, zval *value TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+
+ PQsetnonblocking(obj->intern->conn, z_is_true(value));
}
static void php_pqconn_object_read_db(zval *object, void *o, zval *return_value TSRMLS_DC)
}
}
+#if HAVE_PQCONNINFO
+static void php_pqconn_object_read_params(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+ PQconninfoOption *ptr, *params = PQconninfo(obj->intern->conn);
+
+ array_init(return_value);
+
+ if (params) {
+ for (ptr = params; ptr->keyword; ++ptr) {
+ if (ptr->val) {
+ add_assoc_string(return_value, ptr->keyword, ptr->val, 1);
+ } else {
+ add_assoc_null(return_value, ptr->keyword);
+ }
+ }
+ PQconninfoFree(params);
+ }
+}
+#endif
+
static void php_pqconn_object_read_options(zval *object, void *o, zval *return_value TSRMLS_DC)
{
php_pqconn_object_t *obj = o;
zend_hash_apply_with_arguments(&obj->intern->eventhandlers TSRMLS_CC, apply_read_event_handlers, 1, Z_ARRVAL_P(return_value) TSRMLS_CC);
}
-static STATUS php_pqconn_update_socket(zval *this_ptr, php_pqconn_object_t *obj TSRMLS_DC)
+static void php_pqconn_object_read_def_fetch_type(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ 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 TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+ zval *zft = value;
+
+ if (Z_TYPE_P(zft) != IS_LONG) {
+ if (Z_REFCOUNT_P(zft) > 1) {
+ zval *tmp;
+ MAKE_STD_ZVAL(tmp);
+ ZVAL_ZVAL(tmp, zft, 1, 0);
+ convert_to_long(tmp);
+ zft = tmp;
+ } else {
+ convert_to_long_ex(&zft);
+ }
+ }
+
+ obj->intern->default_fetch_type = Z_LVAL_P(zft) & 0x3; /* two bits only */
+
+ if (zft != value) {
+ zval_ptr_dtor(&zft);
+ }
+}
+
+static void php_pqconn_object_read_def_txn_isolation(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ 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 TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+ zval *zti = value;
+
+ if (Z_TYPE_P(zti) != IS_LONG) {
+ if (Z_REFCOUNT_P(zti) > 1) {
+ zval *tmp;
+ MAKE_STD_ZVAL(tmp);
+ ZVAL_ZVAL(tmp, zti, 1, 0);
+ convert_to_long(tmp);
+ zti = tmp;
+ } else {
+ convert_to_long_ex(&zti);
+ }
+ }
+
+ obj->intern->default_txn_isolation = Z_LVAL_P(zti) & 0x3; /* two bits only */
+
+ if (zti != value) {
+ zval_ptr_dtor(&zti);
+ }
+}
+
+static void php_pqconn_object_read_def_txn_readonly(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ 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 TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+
+ obj->intern->default_txn_readonly = zend_is_true(value);
+}
+
+static void php_pqconn_object_read_def_txn_deferrable(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ 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 TSRMLS_DC)
+{
+ 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 TSRMLS_DC)
+{
+ 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 TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+ zval *zac = value;
+
+ if (Z_TYPE_P(zac) != IS_LONG) {
+ if (Z_REFCOUNT_P(zac) > 1) {
+ zval *tmp;
+ MAKE_STD_ZVAL(tmp);
+ ZVAL_ZVAL(tmp, zac, 1, 0);
+ convert_to_long(tmp);
+ zac = tmp;
+ } else {
+ convert_to_long_ex(&zac);
+ }
+ }
+
+ obj->intern->default_auto_convert = Z_LVAL_P(zac) & PHP_PQRES_CONV_ALL;
+
+ if (zac != value) {
+ zval_ptr_dtor(&zac);
+ }
+}
+
+static ZEND_RESULT_CODE php_pqconn_update_socket(zval *this_ptr, php_pqconn_object_t *obj TSRMLS_DC)
{
zval *zsocket, zmember;
php_stream *stream;
- STATUS retval;
+ ZEND_RESULT_CODE retval;
int socket;
if (!obj) {
static void php_pqconn_wakeup(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC)
{
- // FIXME: ping server
+ PGresult *res = PQexec(*handle, "");
+ php_pqres_clear(res);
+
+ if (CONNECTION_OK != PQstatus(*handle)) {
+ PQreset(*handle);
+ }
}
-static int apply_unlisten(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t channel_len TSRMLS_DC)
{
- php_pqconn_object_t *obj = va_arg(argv, php_pqconn_object_t *);
- char *quoted_channel = PQescapeIdentifier(obj->intern->conn, key->arKey, key->nKeyLength - 1);
+ char *quoted_channel = PQescapeIdentifier(conn, channel_str, channel_len);
+ PGresult *res = NULL;
if (quoted_channel) {
- PGresult *res;
- char *cmd;
+ smart_str cmd = {0};
- spprintf(&cmd, 0, "UNLISTEN %s", quoted_channel);
- if ((res = PQexec(obj->intern->conn, cmd))) {
- PHP_PQclear(res);
- }
+ smart_str_appends(&cmd, "UNLISTEN ");
+ smart_str_appends(&cmd, quoted_channel);
+ smart_str_0(&cmd);
- efree(cmd);
+ res = PQexec(conn, cmd.c);
+
+ smart_str_free(&cmd);
PQfreemem(quoted_channel);
}
+ return res;
+}
+
+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 *);
+ PGresult *res = unlisten(obj->intern->conn, key->arKey, key->nKeyLength - 1 TSRMLS_CC);
+
+ if (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_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)
+ ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, __construct) {
zend_error_handling zeh;
char *dsn_str = "";
int dsn_len = 0;
long flags = 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, "|sl", &dsn_str, &dsn_len, &flags);
obj->intern = ecalloc(1, sizeof(*obj->intern));
+ obj->intern->default_auto_convert = PHP_PQRES_CONV_ALL;
+
zend_hash_init(&obj->intern->listeners, 0, NULL, (dtor_func_t) zend_hash_destroy, 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);
if (flags & PHP_PQCONN_PERSISTENT) {
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);
+ php_persistent_handle_resource_factory_init(&obj->intern->factory, phf);
} else {
php_resource_factory_init(&obj->intern->factory, &php_pqconn_resource_factory_ops, NULL, NULL);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, reset) {
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();
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, resetAsync) {
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();
}
}
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_unlisten, 0, 0, 1)
+ ZEND_ARG_INFO(0, channel)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqconn, unlisten)
+{
+ zend_error_handling zeh;
+ char *channel_str;
+ int channel_len;
+ 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, "s", &channel_str, &channel_len);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else if (SUCCESS == zend_hash_del(&obj->intern->listeners, channel_str, channel_len + 1)) {
+ PGresult *res = unlisten(obj->intern->conn, channel_str, channel_len TSRMLS_CC);
+
+ if (res) {
+ php_pqres_success(res TSRMLS_CC);
+ php_pqres_clear(res);
+ }
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_unlisten_async, 0, 0, 1)
+ ZEND_ARG_INFO(0, channel)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqconn, unlistenAsync) {
+ zend_error_handling zeh;
+ char *channel_str;
+ int channel_len;
+ 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, "s", &channel_str, &channel_len);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "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));
+ } else {
+ smart_str cmd = {0};
+
+ smart_str_appends(&cmd, "UNLISTEN ");
+ smart_str_appends(&cmd, quoted_channel);
+ smart_str_0(&cmd);
+
+ if (!PQsendQuery(obj->intern->conn, cmd.c)) {
+ throw_exce(EX_IO TSRMLS_CC, "Failed to uninstall listener (%s)", PHP_PQerrorMessage(obj->intern->conn));
+ } else {
+ obj->intern->poller = PQconsumeInput;
+ zend_hash_del(&obj->intern->listeners, channel_str, channel_len + 1);
+ }
+
+ smart_str_free(&cmd);
+ PQfreemem(quoted_channel);
+ php_pqconn_notify_listeners(obj TSRMLS_CC);
+ }
+ }
+ }
+}
+
static void php_pqconn_add_listener(php_pqconn_object_t *obj, const char *channel_str, size_t channel_len, php_pq_callback_t *listener TSRMLS_DC)
{
HashTable ht, *existing_listeners;
}
}
-ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_listen, 0, 0, 0)
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_listen, 0, 0, 2)
ZEND_ARG_INFO(0, channel)
ZEND_ARG_INFO(0, callable)
ZEND_END_ARG_INFO();
char *channel_str = NULL;
int channel_len = 0;
php_pq_callback_t listener = {{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, "sf", &channel_str, &channel_len, &listener.fci, &listener.fcc);
smart_str_appends(&cmd, quoted_channel);
smart_str_0(&cmd);
- res = PQexec(obj->intern->conn, cmd.c);
+ res = php_pq_exec(obj->intern->conn, cmd.c);
smart_str_free(&cmd);
PQfreemem(quoted_channel);
obj->intern->poller = PQconsumeInput;
php_pqconn_add_listener(obj, channel_str, channel_len, &listener TSRMLS_CC);
}
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
php_pqconn_notify_listeners(obj TSRMLS_CC);
char *channel_str = NULL;
int channel_len = 0;
php_pq_callback_t listener = {{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, "sf", &channel_str, &channel_len, &listener.fci, &listener.fcc);
zend_error_handling zeh;
char *channel_str, *message_str;
int channel_len, message_len;
- 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, "ss", &channel_str, &channel_len, &message_str, &message_len);
throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to notify listeners (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
php_pqres_success(res TSRMLS_CC);
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
php_pqconn_notify_listeners(obj TSRMLS_CC);
zend_error_handling zeh;
char *channel_str, *message_str;
int channel_len, message_len;
- 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, "ss", &channel_str, &channel_len, &message_str, &message_len);
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, poll) {
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();
}
}
+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 TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else if (!obj->intern->poller) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "No asynchronous operation active");
+ } else {
+ switch (PQflush(obj->intern->conn)) {
+ case -1:
+ default:
+ throw_exce(EX_RUNTIME TSRMLS_CC, "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();
zend_error_handling zeh;
char *query_str;
int query_len;
- 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, "s", &query_str, &query_len);
if (!obj->intern) {
throw_exce(EX_UNINITIALIZED TSRMLS_CC, "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 TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), &return_value TSRMLS_CC);
} else {
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
php_pqconn_notify_listeners(obj TSRMLS_CC);
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, getResult) {
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();
php_pq_callback_t resolver = {{0}};
char *query_str;
int query_len;
- 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, "s|f", &query_str, &query_len, &resolver.fci, &resolver.fcc);
throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
} else if (!PQsendQuery(obj->intern->conn, query_str)) {
throw_exce(EX_IO TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
+#if HAVE_PQSETSINGLEROWMODE
} else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) {
throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn));
+#endif
} else {
+ php_pq_callback_recurse(&obj->intern->onevent, &resolver TSRMLS_CC);
obj->intern->poller = PQconsumeInput;
- php_pq_callback_dtor(&obj->intern->onevent);
- if (resolver.fci.size > 0) {
- obj->intern->onevent = resolver;
- php_pq_callback_addref(&obj->intern->onevent);
- }
php_pqconn_notify_listeners(obj TSRMLS_CC);
}
}
int query_len;
zval *zparams;
zval *ztypes = 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, "sa/|a/!", &query_str, &query_len, &zparams, &ztypes);
if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), &return_value TSRMLS_CC);
} else {
- PHP_PQclear(res);
+ php_pqres_clear(res);
}
php_pqconn_notify_listeners(obj TSRMLS_CC);
int query_len;
zval *zparams;
zval *ztypes = 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, "sa/|a/!f", &query_str, &query_len, &zparams, &ztypes, &resolver.fci, &resolver.fcc);
if (!rc) {
throw_exce(EX_IO TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn));
+#if HAVE_PQSETSINGLEROWMODE
} else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) {
throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn));
+#endif
} else {
+ php_pq_callback_recurse(&obj->intern->onevent, &resolver TSRMLS_CC);
obj->intern->poller = PQconsumeInput;
- php_pq_callback_dtor(&obj->intern->onevent);
- if (resolver.fci.size > 0) {
- obj->intern->onevent = resolver;
- php_pq_callback_addref(&obj->intern->onevent);
- }
php_pqconn_notify_listeners(obj TSRMLS_CC);
}
}
zend_restore_error_handling(&zeh TSRMLS_CC);
}
-STATUS php_pqconn_prepare(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(zval *object, php_pqconn_object_t *obj, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC)
{
PGresult *res;
- STATUS rv;
+ ZEND_RESULT_CODE rv;
if (!obj) {
obj = zend_object_store_get_object(object TSRMLS_CC);
}
- 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 TSRMLS_CC, "Failed to prepare statement (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
rv = php_pqres_success(res TSRMLS_CC);
- PHP_PQclear(res);
+ php_pqres_clear(res);
php_pqconn_notify_listeners(obj TSRMLS_CC);
}
zval *ztypes = NULL;
char *name_str, *query_str;
int name_len, *query_len;
- 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, "ss|a/!", &name_str, &name_len, &query_str, &query_len, &ztypes);
if (SUCCESS != php_pqconn_prepare(getThis(), obj, name_str, query_str, params TSRMLS_CC)) {
php_pq_params_free(¶ms);
} else {
- php_pqstm_t *stm = ecalloc(1, sizeof(*stm));
-
- php_pq_object_addref(obj TSRMLS_CC);
- stm->conn = obj;
- stm->name = estrdup(name_str);
- stm->params = params;
- ZEND_INIT_SYMTABLE(&stm->bound);
+ php_pqstm_t *stm = php_pqstm_init(obj, name_str, query_str, params TSRMLS_CC);
return_value->type = IS_OBJECT;
return_value->value.obj = php_pqstm_create_object_ex(php_pqstm_class_entry, stm, NULL TSRMLS_CC);
}
}
-STATUS 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 TSRMLS_DC)
{
- STATUS rv;
+ ZEND_RESULT_CODE rv;
if (!obj) {
obj = zend_object_store_get_object(object TSRMLS_CC);
if (!PQsendPrepare(obj->intern->conn, name, query, params->type.count, params->type.oids)) {
rv = FAILURE;
throw_exce(EX_IO TSRMLS_CC, "Failed to prepare statement (%s)", PHP_PQerrorMessage(obj->intern->conn));
- } else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) {
- rv = FAILURE;
- throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
rv = SUCCESS;
obj->intern->poller = PQconsumeInput;
zval *ztypes = NULL;
char *name_str, *query_str;
int name_len, *query_len;
- 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, "ss|a/!", &name_str, &name_len, &query_str, &query_len, &ztypes);
if (SUCCESS != php_pqconn_prepare_async(getThis(), obj, name_str, query_str, params TSRMLS_CC)) {
php_pq_params_free(¶ms);
} else {
- php_pqstm_t *stm = ecalloc(1, sizeof(*stm));
-
- php_pq_object_addref(obj TSRMLS_CC);
- stm->conn = obj;
- stm->name = estrdup(name_str);
- stm->params = params;
- ZEND_INIT_SYMTABLE(&stm->bound);
+ php_pqstm_t *stm = php_pqstm_init(obj, name_str, query_str, params TSRMLS_CC);
return_value->type = IS_OBJECT;
return_value->value.obj = php_pqstm_create_object_ex(php_pqstm_class_entry, stm, NULL TSRMLS_CC);
}
}
-static inline char *declare_str(const char *name_str, size_t name_len, unsigned flags, const char *query_str, size_t query_len)
-{
- size_t decl_len = name_len + query_len + sizeof("DECLARE BINARY INSENSITIVE NO SCROLL CURSOR WITHOUT HOLD FOR ");
- char *decl_str;
-
- decl_str = emalloc(decl_len);
- decl_len = slprintf(decl_str, decl_len, "DECLARE %s %s %s %s CURSOR %s FOR %s",
- name_str,
- (flags & PHP_PQ_DECLARE_BINARY) ? "BINARY" : "",
- (flags & PHP_PQ_DECLARE_INSENSITIVE) ? "INSENSITIVE" : "",
- (flags & PHP_PQ_DECLARE_NO_SCROLL) ? "NO SCROLL" :
- (flags & PHP_PQ_DECLARE_SCROLL) ? "SCROLL" : "",
- (flags & PHP_PQ_DECLARE_WITH_HOLD) ? "WITH HOLD" : "",
- query_str
- );
- return decl_str;
-}
-
-STATUS php_pqconn_declare(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_declare(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC)
{
PGresult *res;
- STATUS rv;
+ ZEND_RESULT_CODE rv;
if (!obj) {
obj = zend_object_store_get_object(object TSRMLS_CC);
}
- res = PQexec(obj->intern->conn, decl);
+ res = php_pq_exec(obj->intern->conn, decl);
if (!res) {
rv = FAILURE;
throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to declare cursor (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
rv = php_pqres_success(res TSRMLS_CC);
- PHP_PQclear(res);
+ php_pqres_clear(res);
php_pqconn_notify_listeners(obj TSRMLS_CC);
}
char *name_str, *query_str;
int name_len, query_len;
long flags;
- 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, "sls", &name_str, &name_len, &flags, &query_str, &query_len);
if (!obj->intern) {
throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
} else {
- char *decl = declare_str(name_str, name_len, flags, query_str, query_len);
+ int query_offset;
+ char *decl = php_pqcur_declare_str(name_str, name_len, flags, query_str, query_len, &query_offset);
if (SUCCESS != php_pqconn_declare(getThis(), obj, decl TSRMLS_CC)) {
efree(decl);
} else {
- php_pqcur_t *cur = ecalloc(1, sizeof(*cur));
-
- php_pq_object_addref(obj TSRMLS_CC);
- cur->conn = obj;
- cur->open = 1;
- cur->name = estrdup(name_str);
- cur->decl = decl;
+ php_pqcur_t *cur = php_pqcur_init(obj, name_str, decl, query_offset, flags TSRMLS_CC);
return_value->type = IS_OBJECT;
return_value->value.obj = php_pqcur_create_object_ex(php_pqcur_class_entry, cur, NULL TSRMLS_CC);
}
}
-STATUS php_pqconn_declare_async(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_declare_async(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC)
{
- STATUS rv;
+ ZEND_RESULT_CODE rv;
if (!obj) {
obj = zend_object_store_get_object(object TSRMLS_CC);
if (!PQsendQuery(obj->intern->conn, decl)) {
rv = FAILURE;
throw_exce(EX_IO TSRMLS_CC, "Failed to declare cursor (%s)", PHP_PQerrorMessage(obj->intern->conn));
- } else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) {
- rv = FAILURE;
- throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn));
} else {
rv = SUCCESS;
obj->intern->poller = PQconsumeInput;
char *name_str, *query_str;
int name_len, query_len;
long flags;
- 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, "sls", &name_str, &name_len, &flags, &query_str, &query_len);
if (!obj->intern) {
throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
} else {
- char *decl = declare_str(name_str, name_len, flags, query_str, query_len);
+ int query_offset;
+ char *decl = php_pqcur_declare_str(name_str, name_len, flags, query_str, query_len, &query_offset);
if (SUCCESS != php_pqconn_declare_async(getThis(), obj, decl TSRMLS_CC)) {
efree(decl);
} else {
- php_pqcur_t *cur = ecalloc(1, sizeof(*cur));
-
- php_pq_object_addref(obj TSRMLS_CC);
- cur->conn = obj;
- cur->open = 1;
- cur->name = estrdup(name_str);
- cur->decl = decl;
+ php_pqcur_t *cur = php_pqcur_init(obj, name_str, decl, query_offset, flags TSRMLS_CC);
return_value->type = IS_OBJECT;
return_value->value.obj = php_pqcur_create_object_ex(php_pqcur_class_entry, cur, NULL TSRMLS_CC);
}
}
-STATUS php_pqconn_start_transaction(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_start_transaction(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable TSRMLS_DC)
{
- STATUS rv = FAILURE;
+ ZEND_RESULT_CODE rv = FAILURE;
if (!conn_obj) {
conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
} else {
PGresult *res;
smart_str cmd = {0};
- const char *il = isolation_level(&isolation);
+ const char *il = php_pq_isolation_level(&isolation);
smart_str_appends(&cmd, "START TRANSACTION ISOLATION LEVEL ");
smart_str_appends(&cmd, il);
smart_str_appends(&cmd, " DEFERRABLE");
smart_str_0(&cmd);
- res = PQexec(conn_obj->intern->conn, cmd.c);
+ res = php_pq_exec(conn_obj->intern->conn, cmd.c);
if (!res) {
throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to start transaction (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
} else {
rv = php_pqres_success(res TSRMLS_CC);
- PHP_PQclear(res);
+ php_pqres_clear(res);
php_pqconn_notify_listeners(conn_obj TSRMLS_CC);
}
return rv;
}
-STATUS php_pqconn_start_transaction_async(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable TSRMLS_DC)
+ZEND_RESULT_CODE php_pqconn_start_transaction_async(zval *zconn, php_pqconn_object_t *conn_obj, long isolation, zend_bool readonly, zend_bool deferrable TSRMLS_DC)
{
- STATUS rv = FAILURE;
+ ZEND_RESULT_CODE rv = FAILURE;
if (!conn_obj) {
conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
} else {
smart_str cmd = {0};
- const char *il = isolation_level(&isolation);
+ const char *il = php_pq_isolation_level(&isolation);
smart_str_appends(&cmd, "START TRANSACTION ISOLATION LEVEL ");
smart_str_appends(&cmd, il);
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, startTransaction) {
zend_error_handling zeh;
- long isolation = PHP_PQTXN_READ_COMMITTED;
- zend_bool readonly = 0, deferrable = 0;
- STATUS rv;
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ long isolation = obj->intern ? obj->intern->default_txn_isolation : PHP_PQTXN_READ_COMMITTED;
+ zend_bool readonly = obj->intern ? obj->intern->default_txn_readonly : 0;
+ zend_bool deferrable = obj->intern ? obj->intern->default_txn_deferrable : 0;
+ 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, "|lbb", &isolation, &readonly, &deferrable);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (SUCCESS == rv) {
- php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
rv = php_pqconn_start_transaction(getThis(), obj, isolation, readonly, deferrable TSRMLS_CC);
if (SUCCESS == rv) {
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, startTransactionAsync) {
zend_error_handling zeh;
- long isolation = PHP_PQTXN_READ_COMMITTED;
- zend_bool readonly = 0, deferrable = 0;
- STATUS rv;
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ long isolation = obj->intern ? obj->intern->default_txn_isolation : PHP_PQTXN_READ_COMMITTED;
+ zend_bool readonly = obj->intern ? obj->intern->default_txn_readonly : 0;
+ zend_bool deferrable = obj->intern ? obj->intern->default_txn_deferrable : 0;
+ 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, "|lbb", &isolation, &readonly, &deferrable);
zend_restore_error_handling(&zeh TSRMLS_CC);
- if (SUCCESS == rv) {
- php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == rv) {
rv = php_pqconn_start_transaction_async(getThis(), obj, isolation, readonly, deferrable TSRMLS_CC);
if (SUCCESS == rv) {
php_pq_object_addref(obj TSRMLS_CC);
txn->conn = obj;
+ txn->open = 1;
txn->isolation = isolation;
txn->readonly = readonly;
txn->deferrable = deferrable;
}
}
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_off, 0, 0, 1)
+ ZEND_ARG_INFO(0, type)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqconn, off) {
+ zend_error_handling zeh;
+ char *type_str;
+ int type_len;
+ 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, "s", &type_str, &type_len);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else {
+ RETURN_BOOL(SUCCESS == zend_hash_del(&obj->intern->eventhandlers, type_str, type_len + 1));
+ }
+ }
+}
+
ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_on, 0, 0, 2)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, callable)
char *type_str;
int type_len;
php_pq_callback_t cb = {{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, "sf", &type_str, &type_len, &cb.fci, &cb.fcc);
}
}
-static int apply_set_converter(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+struct apply_set_converter_arg {
+ HashTable *ht;
+ zval **zconv;
+ unsigned add:1;
+};
+
+static int apply_set_converter(void *p, void *a TSRMLS_DC)
{
- zval *tmp, **zoid = p, **zcnv = va_arg(argv, zval **);
- HashTable *converters = va_arg(argv, HashTable *);
+ zval *tmp, **zoid = p;
+ struct apply_set_converter_arg *arg = a;
tmp = *zoid;
+ Z_ADDREF_P(tmp);
convert_to_long_ex(&tmp);
- Z_ADDREF_PP(zcnv);
- zend_hash_index_update(converters, Z_LVAL_P(tmp), zcnv, sizeof(zval *), NULL);
- if (tmp != *zoid) {
- zval_ptr_dtor(&tmp);
+ if (arg->add) {
+ Z_ADDREF_PP(arg->zconv);
+ zend_hash_index_update(arg->ht, Z_LVAL_P(tmp), arg->zconv, sizeof(zval *), NULL);
+ } else {
+ zend_hash_index_del(arg->ht, Z_LVAL_P(tmp));
}
+ zval_ptr_dtor(&tmp);
return ZEND_HASH_APPLY_KEEP;
}
ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_set_converter, 0, 0, 1)
- ZEND_ARG_OBJ_INFO(0, converter, pq\\ConverterInterface, 0)
+ ZEND_ARG_OBJ_INFO(0, converter, pq\\Converter, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, setConverter) {
- STATUS rv;
+ ZEND_RESULT_CODE rv;
zend_error_handling zeh;
zval *zcnv;
throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
} else {
zval *tmp, *zoids = NULL;
+ struct apply_set_converter_arg arg = {NULL};
zend_call_method_with_0_params(&zcnv, NULL, NULL, "converttypes", &zoids);
tmp = zoids;
- convert_to_array_ex(&zoids);
- zend_hash_apply_with_arguments(Z_ARRVAL_P(zoids) TSRMLS_CC, apply_set_converter, 2, &zcnv, &obj->intern->converters);
- if (tmp != zoids) {
- zval_ptr_dtor(&tmp);
- }
+ Z_ADDREF_P(tmp);
+ convert_to_array_ex(&tmp);
+
+ arg.ht = &obj->intern->converters;
+ arg.zconv = &zcnv;
+ arg.add = 1;
+
+ zend_hash_apply_with_argument(Z_ARRVAL_P(tmp), apply_set_converter, &arg TSRMLS_CC);
+
+ zval_ptr_dtor(&tmp);
+ zval_ptr_dtor(&zoids);
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_unset_converter, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, converter, pq\\Converter, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqconn, unsetConverter) {
+ ZEND_RESULT_CODE rv;
+ zend_error_handling zeh;
+ zval *zcnv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zcnv, php_pqconv_class_entry);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else {
+ zval *tmp, *zoids = NULL;
+ struct apply_set_converter_arg arg = {NULL};
+
+ zend_call_method_with_0_params(&zcnv, NULL, NULL, "converttypes", &zoids);
+ tmp = zoids;
+ Z_ADDREF_P(tmp);
+ convert_to_array_ex(&tmp);
+
+ arg.ht = &obj->intern->converters;
+ arg.zconv = &zcnv;
+ arg.add = 0;
+
+ zend_hash_apply_with_argument(Z_ARRVAL_P(tmp), apply_set_converter, &arg TSRMLS_CC);
+
+ zval_ptr_dtor(&tmp);
zval_ptr_dtor(&zoids);
}
}
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_ME(pqconn, prepareAsync, ai_pqconn_prepare_async, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, declare, ai_pqconn_declare, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, declareAsync, ai_pqconn_declare_async, ZEND_ACC_PUBLIC)
+ PHP_ME(pqconn, unlisten, ai_pqconn_unlisten, ZEND_ACC_PUBLIC)
+ PHP_ME(pqconn, unlistenAsync, ai_pqconn_unlisten_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, startTransaction, ai_pqconn_start_transaction, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, startTransactionAsync, ai_pqconn_start_transaction_async, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, trace, ai_pqconn_trace, ZEND_ACC_PUBLIC)
+ PHP_ME(pqconn, off, ai_pqconn_off, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, on, ai_pqconn_on, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, setConverter, ai_pqconn_set_converter, ZEND_ACC_PUBLIC)
+ PHP_ME(pqconn, unsetConverter, ai_pqconn_unset_converter, ZEND_ACC_PUBLIC)
{0}
};
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, 14, NULL, NULL, 1);
+ zend_hash_init(&php_pqconn_object_prophandlers, 21, NULL, NULL, 1);
zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("status"), CONNECTION_BAD, ZEND_ACC_PUBLIC TSRMLS_CC);
ph.read = php_pqconn_object_read_status;
zend_hash_add(&php_pqconn_object_prophandlers, "unbuffered", sizeof("unbuffered"), (void *) &ph, sizeof(ph), NULL);
ph.write = NULL;
+ zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("nonblocking"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_nonblocking;
+ ph.write = php_pqconn_object_write_nonblocking;
+ zend_hash_add(&php_pqconn_object_prophandlers, "nonblocking", sizeof("nonblocking"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("db"), ZEND_ACC_PUBLIC TSRMLS_CC);
ph.read = php_pqconn_object_read_db;
zend_hash_add(&php_pqconn_object_prophandlers, "db", sizeof("db"), (void *) &ph, sizeof(ph), NULL);
ph.read = php_pqconn_object_read_port;
zend_hash_add(&php_pqconn_object_prophandlers, "port", sizeof("port"), (void *) &ph, sizeof(ph), NULL);
+#if HAVE_PQCONNINFO
+ zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_params;
+ zend_hash_add(&php_pqconn_object_prophandlers, "params", sizeof("params"), (void *) &ph, sizeof(ph), NULL);
+#endif
+
zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("options"), ZEND_ACC_PUBLIC TSRMLS_CC);
ph.read = php_pqconn_object_read_options;
zend_hash_add(&php_pqconn_object_prophandlers, "options", sizeof("options"), (void *) &ph, sizeof(ph), NULL);
ph.read = php_pqconn_object_read_event_handlers;
zend_hash_add(&php_pqconn_object_prophandlers, "eventHandlers", sizeof("eventHandlers"), (void *) &ph, sizeof(ph), NULL);
+ zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultFetchType"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_def_fetch_type;
+ ph.write = php_pqconn_object_write_def_fetch_type;
+ zend_hash_add(&php_pqconn_object_prophandlers, "defaultFetchType", sizeof("defaultFetchType"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
+ zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultTransactionIsolation"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_def_txn_isolation;
+ ph.write = php_pqconn_object_write_def_txn_isolation;
+ zend_hash_add(&php_pqconn_object_prophandlers, "defaultTransactionIsolation", sizeof("defaultTransactionIsolation"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
+ zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("defaultTransactionReadonly"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_def_txn_readonly;
+ ph.write = php_pqconn_object_write_def_txn_readonly;
+ zend_hash_add(&php_pqconn_object_prophandlers, "defaultTransactionReadonly", sizeof("defaultTransactionReadonly"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
+ zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("defaultTransactionDeferrable"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_def_txn_deferrable;
+ ph.write = php_pqconn_object_write_def_txn_deferrable;
+ zend_hash_add(&php_pqconn_object_prophandlers, "defaultTransactionDeferrable", sizeof("defaultTransactionDeferrable"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
+ zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultAutoConvert"), PHP_PQRES_CONV_ALL, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_def_auto_conv;
+ ph.write = php_pqconn_object_write_def_auto_conv;
+ zend_hash_add(&php_pqconn_object_prophandlers, "defaultAutoConvert", sizeof("defaultAutoConvert"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK TSRMLS_CC);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD TSRMLS_CC);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("STARTED"), CONNECTION_STARTED TSRMLS_CC);