mirror of
https://github.com/danog/ext-pq.git
synced 2025-01-22 13:51:20 +01:00
unregister eventhandler
This commit is contained in:
parent
7e633cc0dd
commit
c5e31d5d4f
1
TODO
1
TODO
@ -1,7 +1,6 @@
|
||||
* COPY: getAsync & putAsync
|
||||
* CURSOR: *Async()
|
||||
* fetchInto/fetchCtor?
|
||||
* unregister event handler?
|
||||
* binary protocol?
|
||||
* parse explicit array dimension information in front of arrays
|
||||
* compat for box arrays
|
||||
|
@ -428,7 +428,7 @@ static void php_pqconn_wakeup(php_persistent_handle_factory_t *f, void **handle
|
||||
// FIXME: ping server
|
||||
}
|
||||
|
||||
static inline PGresult *unlisten(php_pqconn_t *conn, const char *channel_str, size_t channel_len TSRMLS_DC)
|
||||
static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t channel_len TSRMLS_DC)
|
||||
{
|
||||
char *quoted_channel = PQescapeIdentifier(conn, channel_str, channel_len);
|
||||
PGresult *res = NULL;
|
||||
@ -440,7 +440,7 @@ static inline PGresult *unlisten(php_pqconn_t *conn, const char *channel_str, si
|
||||
smart_str_appends(&cmd, quoted_channel);
|
||||
smart_str_0(&cmd);
|
||||
|
||||
res = PQexec(conn, cmd);
|
||||
res = PQexec(conn, cmd.c);
|
||||
|
||||
smart_str_free(&cmd);
|
||||
PQfreemem(quoted_channel);
|
||||
@ -1655,6 +1655,30 @@ static PHP_METHOD(pqconn, trace) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
STATUS 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)
|
||||
@ -1758,6 +1782,7 @@ static zend_function_entry php_pqconn_methods[] = {
|
||||
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)
|
||||
{0}
|
||||
|
@ -11,14 +11,13 @@ include "_setup.inc";
|
||||
$c = new pq\Connection(PQ_DSN);
|
||||
$c->exec("DROP TABLE IF EXISTS test");
|
||||
$c->on(pq\Connection::EVENT_NOTICE, function($c, $notice) {
|
||||
if ($notice !== 'CREATE TABLE will create implicit sequence "test_id_seq" for serial column "test.id"') {
|
||||
echo "Got notice: $notice\n";
|
||||
}
|
||||
echo "Got notice: $notice\n";
|
||||
});
|
||||
var_dump($c->transactionStatus == pq\Connection::TRANS_IDLE);
|
||||
$t = new pq\Transaction($c);
|
||||
var_dump($t->connection->transactionStatus == pq\Connection::TRANS_INTRANS);
|
||||
$c->exec("DROP TABLE IF EXISTS test");
|
||||
$c->off(pq\Connection::EVENT_NOTICE);
|
||||
$c->exec("CREATE TABLE test (id serial, data text)");
|
||||
$s = $c->prepare("test_insert", "INSERT INTO test (data) VALUES (\$1)", array((new pq\Types($c))["text"]->oid));
|
||||
$s->exec(array("a"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user