1--TEST--
2PostgreSQL non-blocking async queries
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("inc/skipif.inc");
8?>
9--FILE--
10<?php
11
12include('inc/config.inc');
13include('inc/nonblocking.inc');
14$table_name = "table_32nb_async_query";
15
16$db = pg_connect($conn_str);
17pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
18pg_query($db, "INSERT INTO {$table_name} DEFAULT VALUES");
19
20$db_socket = pg_socket($db);
21stream_set_blocking($db_socket, false);
22
23$nb_send =  pg_send_query($db, "SELECT * FROM ".$table_name.";");
24if ($nb_send === FALSE) {
25    echo "pg_send_query() error\n";
26} elseif ($nb_send === 0) {
27    nb_flush($db, $db_socket);
28}
29
30nb_consume($db, $db_socket);
31
32if (!($result = pg_get_result($db))) {
33    echo "pg_get_result() error\n";
34}
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($db, "SELECT * FROM ".$table_name.";"));
53pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
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$nb_send = pg_send_query($db, "INSERT INTO ".$table_name." VALUES (8888, 'GGG');");
62if ($nb_send === FALSE) {
63    echo "pg_send_query() error\n";
64} elseif ($nb_send === 0) {
65    nb_flush($db, $db_socket);
66}
67
68nb_consume($db, $db_socket);
69
70if (!($result = pg_get_result($db))) {
71    echo "pg_get_result() error\n";
72}
73
74pg_last_oid($result);
75pg_free_result($result);
76pg_close($db);
77
78echo "OK";
79?>
80--CLEAN--
81<?php
82include('inc/config.inc');
83$table_name = "table_32nb_async_query";
84
85$db = pg_connect($conn_str);
86pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
87?>
88--EXPECT--
89OK
90