1--TEST--
2PostgreSQL non-blocking async query params
3--SKIPIF--
4<?php
5include("skipif.inc");
6if (!function_exists('pg_send_query_params')) die('skip function pg_send_query_params() does not exist');
7?>
8--FILE--
9<?php
10
11include('config.inc');
12include('nonblocking.inc');
13
14$db = pg_connect($conn_str);
15
16$version = pg_version($db);
17if ($version['protocol'] < 3) {
18    echo "OK";
19    exit(0);
20}
21
22$db_socket = pg_socket($db);
23stream_set_blocking($db_socket, false);
24
25$sent = pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
26if ($sent === FALSE) {
27    echo "pg_send_query_params() error\n";
28} elseif ($sent === 0) {
29    nb_flush($db, $db_socket);
30}
31
32nb_consume($db, $db_socket);
33
34if (!($result = pg_get_result($db))) {
35    echo "pg_get_result() error\n";
36}
37if (!($rows = pg_num_rows($result))) {
38    echo "pg_num_rows() error\n";
39}
40for ($i=0; $i < $rows; $i++) {
41    pg_fetch_array($result, $i, PGSQL_NUM);
42}
43for ($i=0; $i < $rows; $i++) {
44    pg_fetch_object($result);
45}
46for ($i=0; $i < $rows; $i++) {
47    pg_fetch_row($result, $i);
48}
49for ($i=0; $i < $rows; $i++) {
50    pg_fetch_result($result, $i, 0);
51}
52
53pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
54pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
55pg_field_name($result, 0);
56pg_field_num($result, $field_name);
57pg_field_size($result, 0);
58pg_field_type($result, 0);
59pg_field_prtlen($result, 0);
60pg_field_is_null($result, 0);
61
62$sent = pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
63
64if ($sent === FALSE) {
65    echo "pg_send_query_params() error\n";
66} elseif ($sent === 0) {
67    nb_flush($db, $db_socket);
68}
69
70pg_last_oid($result);
71pg_free_result($result);
72
73pg_close($db);
74
75echo "OK";
76?>
77--EXPECT--
78OK
79