mirror of
https://github.com/danog/ext-pq.git
synced 2024-11-29 20:09:14 +01:00
fix Statement::descAsync; add Result::desc()
This commit is contained in:
parent
de42b70bed
commit
a4dced008a
@ -90,6 +90,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
||||
<file role="test" name="async004.phpt" />
|
||||
<file role="test" name="async005.phpt" />
|
||||
<file role="test" name="async006.phpt" />
|
||||
<file role="test" name="async007.phpt" />
|
||||
<file role="test" name="basic001.phpt" />
|
||||
<file role="test" name="basic002.phpt" />
|
||||
<file role="test" name="bound001.phpt" />
|
||||
@ -114,6 +115,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
||||
<file role="test" name="reset001.phpt" />
|
||||
<file role="test" name="savepoint001.phpt" />
|
||||
<file role="test" name="stm_desc001.phpt" />
|
||||
<file role="test" name="stm_desc002.phpt" />
|
||||
<file role="test" name="trans001.phpt" />
|
||||
<file role="test" name="trans002.phpt" />
|
||||
<file role="test" name="types001.phpt" />
|
||||
|
@ -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}
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
41
tests/async007.phpt
Normal file
41
tests/async007.phpt
Normal file
@ -0,0 +1,41 @@
|
||||
--TEST--
|
||||
async statement
|
||||
--SKIPIF--
|
||||
<?php include "_skipif.inc"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
echo "Test\n";
|
||||
include "_setup.inc";
|
||||
|
||||
function complete($c) {
|
||||
do {
|
||||
while ($c->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
|
22
tests/stm_desc002.phpt
Normal file
22
tests/stm_desc002.phpt
Normal file
@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
desc statement
|
||||
--SKIPIF--
|
||||
<?php include "_skipif.inc"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
echo "Test\n";
|
||||
include "_setup.inc";
|
||||
|
||||
$c = new pq\Connection(PQ_DSN);
|
||||
$s = new pq\Statement($c, "test1", "SELECT NOW() - \$1");
|
||||
$r = $s->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
|
Loading…
Reference in New Issue
Block a user