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