1
0
mirror of https://github.com/danog/ext-pq.git synced 2025-01-22 05:41:25 +01:00

Merge branch 'v1.1.x'

This commit is contained in:
Michael Wallner 2016-05-18 14:26:04 +02:00
commit 75f3b1b8e2
No known key found for this signature in database
GPG Key ID: 480E3E14B0A4C7C7
3 changed files with 102 additions and 1 deletions

View File

@ -48,6 +48,7 @@
<notes><![CDATA[
* Added public readonly array pq\Result::$diag property, listing PQresultErrorField details (gh-issue #14)
* Restore listeners and prepared statements after a connection reset (gh-issue #15)
* Added pq\Connection::$nonblocking and pq\Connection::flush() to support non-blocking writes (gh-issue #16)
]]></notes>
<contents>
<dir name="/">
@ -127,6 +128,7 @@
<file role="test" name="exceptions001.phpt" />
<file role="test" name="exceptions002.phpt" />
<file role="test" name="fetch001.phpt" />
<file role="test" name="flush001.phpt" />
<file role="test" name="gh-issue015_listeners.phpt" />
<file role="test" name="gh-issue015_statements.phpt" />
<file role="test" name="info001.phpt" />

View File

@ -216,6 +216,20 @@ static void php_pqconn_object_write_unbuffered(zval *object, void *o, zval *valu
obj->intern->unbuffered = z_is_true(value);
}
static void php_pqconn_object_read_nonblocking(zval *object, void *o, zval *return_value)
{
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)
{
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)
{
php_pqconn_object_t *obj = o;
@ -1047,6 +1061,40 @@ static PHP_METHOD(pqconn, poll) {
}
}
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();
@ -1902,6 +1950,7 @@ static zend_function_entry php_pqconn_methods[] = {
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)
@ -1959,7 +2008,7 @@ PHP_MINIT_FUNCTION(pqconn)
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, 22, NULL, php_pq_object_prophandler_dtor, 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;
@ -1993,6 +2042,12 @@ PHP_MINIT_FUNCTION(pqconn)
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));

44
tests/flush001.phpt Normal file
View File

@ -0,0 +1,44 @@
--TEST--
flush
--SKIPIF--
<?php include "_skipif.inc"; ?>
--FILE--
<?php
echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN);
$c->nonblocking = true;
var_dump($c->nonblocking);
$c->execAsync("SELECT '".str_repeat("a", 6e7)."'", function($r) {
$r->fetchCol($s);
var_dump(strlen($s));
});
var_dump($flushed = $c->flush());
do {
while (!$flushed || $c->busy) {
$r = $c->busy ? [$c->socket] : null;
$w = !$flushed ?[$c->socket] : null;
if (stream_select($r, $w, $e, null)) {
if ($r) {
printf("P%d", $c->poll());
}
if ($w) {
printf("F%d", $flushed = $c->flush());
}
}
}
echo "\n";
} while ($c->getResult());
?>
===DONE===
--EXPECTF--
Test
bool(true)
bool(%s)
%r(F0)*(F1)*(P3)+%r
int(60000000)
===DONE===