From: Michael Wallner Date: Tue, 14 May 2013 12:30:53 +0000 (+0200) Subject: fix Statement::descAsync; add Result::desc() X-Git-Tag: v0.4.0~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a4dced008a651f8850669a527987239c9b87f7d3;p=m6w6%2Fext-pq fix Statement::descAsync; add Result::desc() --- diff --git a/package.xml b/package.xml index 741cddc..4956eda 100644 --- a/package.xml +++ b/package.xml @@ -90,6 +90,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -114,6 +115,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/src/php_pqres.c b/src/php_pqres.c index addeab3..de33fd2 100644 --- a/src/php_pqres.c +++ b/src/php_pqres.c @@ -883,6 +883,25 @@ static PHP_METHOD(pqres, count) { } } +ZEND_BEGIN_ARG_INFO_EX(ai_pqres_desc, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(pqres, desc) { + if (SUCCESS == zend_parse_parameters_none()) { + php_pqres_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); + + if (!obj->intern) { + throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Result not initialized"); + } else { + int p, params; + + array_init(return_value); + for (p = 0, params = PQnparams(obj->intern->res); p < params; ++p) { + add_next_index_long(return_value, PQparamtype(obj->intern->res, p)); + } + } + } +} + static zend_function_entry php_pqres_methods[] = { PHP_ME(pqres, bind, ai_pqres_bind, ZEND_ACC_PUBLIC) PHP_ME(pqres, fetchBound, ai_pqres_fetch_bound, ZEND_ACC_PUBLIC) @@ -891,6 +910,7 @@ static zend_function_entry php_pqres_methods[] = { PHP_ME(pqres, fetchAll, ai_pqres_fetch_all, ZEND_ACC_PUBLIC) PHP_ME(pqres, count, ai_pqres_count, ZEND_ACC_PUBLIC) PHP_ME(pqres, map, ai_pqres_map, ZEND_ACC_PUBLIC) + PHP_ME(pqres, desc, ai_pqres_desc, ZEND_ACC_PUBLIC) {0} }; diff --git a/src/php_pqstm.c b/src/php_pqstm.c index a0ae249..6be580c 100644 --- a/src/php_pqstm.c +++ b/src/php_pqstm.c @@ -113,7 +113,7 @@ static void php_pqstm_object_read_connection(zval *object, void *o, zval *return ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_construct, 0, 0, 3) ZEND_ARG_OBJ_INFO(0, Connection, pq\\Connection, 0) - ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, query) ZEND_ARG_ARRAY_INFO(0, types, 1) ZEND_ARG_INFO(0, async) @@ -293,14 +293,16 @@ static PHP_METHOD(pqstm, desc) { } } -ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc_async, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc_async, 0, 0, 1) + ZEND_ARG_INFO(0, callable) ZEND_END_ARG_INFO(); static PHP_METHOD(pqstm, descAsync) { zend_error_handling zeh; + php_pq_callback_t resolver = {{0}}; STATUS rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); - rv = zend_parse_parameters_none(); + rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &resolver.fci, &resolver.fcc); zend_restore_error_handling(&zeh TSRMLS_CC); if (SUCCESS == rv) { @@ -311,6 +313,11 @@ static PHP_METHOD(pqstm, descAsync) { } else if (!PQsendDescribePrepared(obj->intern->conn->intern->conn, obj->intern->name)) { throw_exce(EX_IO TSRMLS_CC, "Failed to describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn)); } else { + php_pq_callback_dtor(&obj->intern->conn->intern->onevent); + if (resolver.fci.size > 0) { + obj->intern->conn->intern->onevent = resolver; + php_pq_callback_addref(&obj->intern->conn->intern->onevent); + } obj->intern->conn->intern->poller = PQconsumeInput; php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC); } diff --git a/tests/async007.phpt b/tests/async007.phpt new file mode 100644 index 0000000..c2a59f6 --- /dev/null +++ b/tests/async007.phpt @@ -0,0 +1,41 @@ +--TEST-- +async statement +--SKIPIF-- + +--FILE-- +busy) { + $r = array($c->socket); + $w = $e = null; + if (stream_select($r, $w, $e, null)) { + $c->poll(); + } + } + } while ($c->getResult()); +} + +$c = new pq\Connection(PQ_DSN); +$t = new pq\Types($c); +$s = new pq\Statement($c, "test1", "SELECT NOW() - \$1", null, true); +complete($s->connection); + +$s->execAsync(array("2012-12-12 12:12:12")); +complete($s->connection); + +$s->descAsync(function($r) use ($t) { + list($typeOid) = $r->desc(); + printf("%s\n", $t[$typeOid]->typname); +}); +complete($s->connection); + +?> +DONE +--EXPECT-- +Test +timestamptz +DONE diff --git a/tests/stm_desc002.phpt b/tests/stm_desc002.phpt new file mode 100644 index 0000000..32ab8b2 --- /dev/null +++ b/tests/stm_desc002.phpt @@ -0,0 +1,22 @@ +--TEST-- +desc statement +--SKIPIF-- + +--FILE-- +exec(array("2012-12-12 12:12:12")); +$d = $s->desc(); + +printf("%s\n", (new pq\Types($c))[$d[0]]->typname); + +?> +DONE +--EXPECT-- +Test +timestamptz +DONE