1--TEST--
2PostgreSQL async prepared 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');
14
15$db = pg_connect($conn_str);
16
17$version = pg_version($db);
18if ($version['protocol'] >= 3) {
19    if (!pg_send_prepare($db, 'php_test', "SELECT * FROM ".$table_name." WHERE num > \$1;")) {
20        echo "pg_send_prepare() error\n";
21    }
22    while(pg_connection_busy($db));  // busy wait: intended
23    if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
24        echo "pg_connection_status() error\n";
25    }
26    if (!($result = pg_get_result($db)))
27    {
28        echo "pg_get_result() error\n";
29    }
30    pg_free_result($result);
31
32    if (!pg_send_execute($db, 'php_test', array(100))) {
33        echo "pg_send_execute() error\n";
34    }
35    while(pg_connection_busy($db));  // busy wait: intended
36    if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
37        echo "pg_connection_status() error\n";
38    }
39    if (!($result = pg_get_result($db)))
40    {
41        echo "pg_get_result() error\n";
42    }
43
44    if (!($rows = pg_num_rows($result))) {
45        echo "pg_num_rows() error\n";
46    }
47    for ($i=0; $i < $rows; $i++)
48    {
49        pg_fetch_array($result, $i, PGSQL_NUM);
50    }
51    for ($i=0; $i < $rows; $i++)
52    {
53        pg_fetch_object($result);
54    }
55    for ($i=0; $i < $rows; $i++)
56    {
57        pg_fetch_row($result, $i);
58    }
59    for ($i=0; $i < $rows; $i++)
60    {
61        pg_fetch_result($result, $i, 0);
62    }
63
64    pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
65    pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
66    pg_field_name($result, 0);
67    pg_field_num($result, $field_name);
68    pg_field_size($result, 0);
69    pg_field_type($result, 0);
70    pg_field_prtlen($result, 0);
71    pg_field_is_null($result, 0);
72
73    if (!pg_send_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);"))
74    {
75        echo "pg_send_prepare() error\n";
76    }
77    while(pg_connection_busy($db));  // busy wait: intended
78    if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
79        echo "pg_connection_status() error\n";
80    }
81    if (!($result = pg_get_result($db)))
82    {
83        echo "pg_get_result() error\n";
84    }
85    pg_free_result($result);
86
87    if (!pg_send_execute($db, "php_test2", array(9999, "A'BC")))
88    {
89        echo "pg_send_execute() error\n";
90    }
91    while(pg_connection_busy($db));  // busy wait: intended
92    if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
93        echo "pg_connection_status() error\n";
94    }
95    if (!($result = pg_get_result($db)))
96    {
97        echo "pg_get_result() error\n";
98    }
99
100    pg_last_oid($result);
101    pg_free_result($result);
102}
103pg_close($db);
104
105echo "OK";
106?>
107--EXPECT--
108OK
109