1--TEST--
2PostgreSQL async prepared queries
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("inc/skipif.inc");
8if (!function_exists('pg_send_prepare')) die('skip function pg_send_prepare() does not exist');
9?>
10--FILE--
11<?php
12
13include('inc/config.inc');
14$table_name = "table_26async_query_prepared";
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} (num) VALUES(1000)");
19
20if (!pg_send_prepare($db, 'php_test', "SELECT * FROM ".$table_name." WHERE num > \$1;")) {
21	echo "pg_send_prepare() error\n";
22}
23while(pg_connection_busy($db));  // busy wait: intended
24if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
25	echo "pg_connection_status() error\n";
26}
27if (!($result = pg_get_result($db)))
28{
29	echo "pg_get_result() error\n";
30}
31pg_free_result($result);
32
33if (!pg_send_execute($db, 'php_test', array(100))) {
34	echo "pg_send_execute() error\n";
35}
36while(pg_connection_busy($db));  // busy wait: intended
37if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
38	echo "pg_connection_status() error\n";
39}
40if (!($result = pg_get_result($db)))
41{
42	echo "pg_get_result() error\n";
43}
44
45if (!($rows = pg_num_rows($result))) {
46	echo "pg_num_rows() error\n";
47}
48for ($i=0; $i < $rows; $i++)
49{
50	pg_fetch_array($result, $i, PGSQL_NUM);
51}
52for ($i=0; $i < $rows; $i++)
53{
54	pg_fetch_object($result);
55}
56for ($i=0; $i < $rows; $i++)
57{
58	pg_fetch_row($result, $i);
59}
60for ($i=0; $i < $rows; $i++)
61{
62	pg_fetch_result($result, $i, 0);
63}
64
65pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
66pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
67pg_field_name($result, 0);
68pg_field_num($result, "num");
69pg_field_size($result, 0);
70pg_field_type($result, 0);
71pg_field_prtlen($result, null, 0);
72pg_field_is_null($result, null, 0);
73
74if (!pg_send_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);"))
75{
76	echo "pg_send_prepare() error\n";
77}
78while(pg_connection_busy($db));  // busy wait: intended
79if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
80	echo "pg_connection_status() error\n";
81}
82if (!($result = pg_get_result($db)))
83{
84	echo "pg_get_result() error\n";
85}
86pg_free_result($result);
87
88if (!pg_send_execute($db, "php_test2", array(9999, "A'BC")))
89{
90	echo "pg_send_execute() error\n";
91}
92while(pg_connection_busy($db));  // busy wait: intended
93if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
94	echo "pg_connection_status() error\n";
95}
96if (!($result = pg_get_result($db)))
97{
98	echo "pg_get_result() error\n";
99}
100
101pg_last_oid($result);
102pg_free_result($result);
103pg_close($db);
104
105echo "OK";
106?>
107--CLEAN--
108<?php
109include('inc/config.inc');
110$table_name = "table_26async_query_prepared";
111
112$db = pg_connect($conn_str);
113pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
114?>
115--EXPECT--
116OK
117