forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg_pipeline_sync.phpt
99 lines (81 loc) · 2.06 KB
/
pg_pipeline_sync.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
--TEST--
PostgreSQL pipeline mode
--EXTENSIONS--
pgsql
--SKIPIF--
<?php
include("skipif.inc");
if (!defined('PGSQL_PIPELINE_SYNC') || !function_exists('pg_send_query_params')) {
die('skip pipeline mode not available');
}
?>
--FILE--
<?php
include('config.inc');
include('nonblocking.inc');
if (!$db = pg_connect($conn_str, PGSQL_CONNECT_ASYNC)) {
die("pg_connect() error");
} elseif (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
die("pg_connect() error");
} elseif ($db_socket = pg_socket($db)) {
stream_set_blocking($db_socket, FALSE);
} else {
die("pg_socket() error");
}
while (true) {
switch ($status = pg_connect_poll($db)) {
case PGSQL_POLLING_READING:
nb_is_readable($db_socket);
break;
case PGSQL_POLLING_WRITING:
nb_is_writable($db_socket);
break;
case PGSQL_POLLING_FAILED:
die("async connection failed");
case PGSQL_POLLING_OK:
break 2;
default:
die("unknown poll status");
}
}
if (!pg_enter_pipeline_mode($db)) {
die('pg_enter_pipeline_mode{}');
}
if (!pg_send_query_params($db, "select $1 as index, now() + ($1||' day')::interval as time", array(1))) {
die('pg_send_query_params failed');
}
if (!pg_pipeline_sync($db)) {
die('pg_pipeline_sync failed');
}
if (pg_pipeline_status($db) !== PGSQL_PIPELINE_ON) {
die('pg_pipeline_status failed');
}
if (!($result = pg_get_result($db))) {
die('pg_get_result');
}
if (pg_result_status($result) !== PGSQL_TUPLES_OK) {
die('pg_result_status failed');
}
if (pg_num_rows($result) == -1) {
die('pg_num_rows failed');
}
if (!pg_fetch_row($result, null)) {
die('pg_fetch_row failed');
}
pg_free_result($result);
if (pg_get_result($db) !== false) {
die('pg_get_result failed');
}
if (($result = pg_get_result($db)) !== false) {
if (pg_result_status($result) !== PGSQL_PIPELINE_SYNC) {
die('pg_result_status failed');
}
}
if (!pg_exit_pipeline_mode($db)) {
die('pg_exit_pipeline_mode failed');
}
echo "OK";
pg_close($db);
?>
--EXPECT--
OK