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