1--TEST--
2PostgreSQL non-blocking async prepared 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_31nb_async_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
20$db_socket = pg_socket($db);
21stream_set_blocking($db_socket, false);
22
23$nb_send =  pg_send_prepare($db, 'php_test', "SELECT * FROM ".$table_name." WHERE num > \$1;");
24if ($nb_send === FALSE) {
25    echo "pg_send_prepare() 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}
35pg_free_result($result);
36
37$nb_send = pg_send_execute($db, 'php_test', array(100));
38if ($nb_send === FALSE) {
39    echo "pg_send_execute() error\n";
40} elseif ($nb_send === 0) {
41    nb_flush($db, $db_socket);
42}
43
44nb_consume($db, $db_socket);
45
46if (!($result = pg_get_result($db))) {
47    echo "pg_get_result() error\n";
48}
49
50if (!($rows = pg_num_rows($result))) {
51    echo "pg_num_rows() error\n";
52}
53for ($i=0; $i < $rows; $i++) {
54    pg_fetch_array($result, $i, PGSQL_NUM);
55}
56for ($i=0; $i < $rows; $i++) {
57    pg_fetch_object($result);
58}
59for ($i=0; $i < $rows; $i++) {
60    pg_fetch_row($result, $i);
61}
62for ($i=0; $i < $rows; $i++)  {
63    pg_fetch_result($result, $i, 0);
64}
65
66pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
67pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
68pg_field_name($result, 0);
69pg_field_num($result, "num");
70pg_field_size($result, 0);
71pg_field_type($result, 0);
72pg_field_prtlen($result, 0);
73pg_field_is_null($result, 0);
74
75$nb_send = pg_send_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);");
76if ($nb_send === FALSE) {
77    echo "pg_send_prepare() error\n";
78} elseif ($nb_send === 0) {
79    nb_flush($db, $db_socket);
80}
81
82nb_consume($db, $db_socket);
83
84if (!($result = pg_get_result($db))) {
85    echo "pg_get_result() error\n";
86}
87pg_free_result($result);
88
89$nb_send = pg_send_execute($db, "php_test2", array(9999, "A'BC"));
90if ($nb_send === FALSE) {
91    echo "pg_send_execute() error\n";
92} elseif ($nb_send === 0) {
93    nb_flush($db, $db_socket);
94}
95
96nb_consume($db, $db_socket);
97
98if (!($result = pg_get_result($db))) {
99    echo "pg_get_result() error\n";
100}
101
102pg_last_oid($result);
103pg_free_result($result);
104pg_close($db);
105
106echo "OK";
107?>
108--CLEAN--
109<?php
110include('inc/config.inc');
111$table_name = "table_31nb_async_query_prepared";
112
113$db = pg_connect($conn_str);
114pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
115?>
116--EXPECTF--
117Deprecated: Calling pg_field_prtlen() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in %s on line %d
118
119Deprecated: Calling pg_field_is_null() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in %s on line %d
120OK
121