Skip to content

Commit 8c5e2e6

Browse files
committed
Fixed bug #68199 (PDO::pgsqlGetNotify doesn't support NOTIFY payloads)
1 parent d748c9f commit 8c5e2e6

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ PHP NEWS
5252
. Add CURL_SSLVERSION_TLSv1_0, CURL_SSLVERSION_TLSv1_1, and
5353
CURL_SSLVERSION_TLSv1_2 constants if supported by libcurl (Rasmus)
5454

55+
- PDO_pgsql:
56+
. Fixed bug #68199 (PDO::pgsqlGetNotify doesn't support NOTIFY payloads)
57+
(Matteo, Alain Laporte)
58+
5559
16 Oct 2014, PHP 5.6.2
5660

5761
- Core:

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,10 +1058,16 @@ static PHP_METHOD(PDO, pgsqlGetNotify)
10581058
if (result_type == PDO_FETCH_NUM || result_type == PDO_FETCH_BOTH) {
10591059
add_index_string(return_value, 0, pgsql_notify->relname, 1);
10601060
add_index_long(return_value, 1, pgsql_notify->be_pid);
1061+
if (pgsql_notify->extra && pgsql_notify->extra[0]) {
1062+
add_index_string(return_value, 2, pgsql_notify->extra, 1);
1063+
}
10611064
}
10621065
if (result_type == PDO_FETCH_ASSOC || result_type == PDO_FETCH_BOTH) {
10631066
add_assoc_string(return_value, "message", pgsql_notify->relname, 1);
10641067
add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
1068+
if (pgsql_notify->extra && pgsql_notify->extra[0]) {
1069+
add_assoc_string(return_value, "payload", pgsql_notify->extra, 1);
1070+
}
10651071
}
10661072

10671073
PQfreemem(pgsql_notify);

ext/pdo_pgsql/tests/bug68199.phpt

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
--TEST--
2+
Bug #68199 (PDO::pgsqlGetNotify doesn't support NOTIFY payloads)
3+
--SKIPIF--
4+
<?php # vim:se ft=php:
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8+
PDOTest::skip();
9+
10+
$db = PDOTest::factory();
11+
if (version_compare($db->getAttribute(PDO::ATTR_SERVER_VERSION), '9.0.0') < 0) {
12+
die("skip Requires 9.0+");
13+
}
14+
15+
?>
16+
--FILE--
17+
<?php
18+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
19+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
20+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
21+
22+
// pgsqlGetPid should return something meaningful
23+
$pid = $db->pgsqlGetPid();
24+
var_dump($pid > 0);
25+
26+
// No listen, no notifies
27+
var_dump($db->pgsqlGetNotify());
28+
29+
// Listen started, no notifies
30+
$db->exec("LISTEN notifies_phpt");
31+
var_dump($db->pgsqlGetNotify());
32+
33+
// No parameters with payload, use default PDO::FETCH_NUM
34+
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_NUM);
35+
$db->exec("NOTIFY notifies_phpt, 'payload'");
36+
$notify = $db->pgsqlGetNotify();
37+
var_dump(count($notify));
38+
var_dump($notify[0]);
39+
var_dump($notify[1] == $pid);
40+
var_dump($notify[2]);
41+
42+
// No parameters with payload, use default PDO::FETCH_ASSOC
43+
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
44+
$db->exec("NOTIFY notifies_phpt, 'payload'");
45+
$notify = $db->pgsqlGetNotify();
46+
var_dump(count($notify));
47+
var_dump($notify['message']);
48+
var_dump($notify['pid'] == $pid);
49+
var_dump($notify['payload']);
50+
51+
// Test PDO::FETCH_NUM as parameter with payload
52+
$db->exec("NOTIFY notifies_phpt, 'payload'");
53+
$notify = $db->pgsqlGetNotify(PDO::FETCH_NUM);
54+
var_dump(count($notify));
55+
var_dump($notify[0]);
56+
var_dump($notify[1] == $pid);
57+
var_dump($notify[2]);
58+
59+
// Test PDO::FETCH_ASSOC as parameter with payload
60+
$db->exec("NOTIFY notifies_phpt, 'payload'");
61+
$notify = $db->pgsqlGetNotify(PDO::FETCH_ASSOC);
62+
var_dump(count($notify));
63+
var_dump($notify['message']);
64+
var_dump($notify['pid'] == $pid);
65+
var_dump($notify['payload']);
66+
67+
// Test PDO::FETCH_BOTH as parameter with payload
68+
$db->exec("NOTIFY notifies_phpt, 'payload'");
69+
$notify = $db->pgsqlGetNotify(PDO::FETCH_BOTH);
70+
var_dump(count($notify));
71+
var_dump($notify['message']);
72+
var_dump($notify['pid'] == $pid);
73+
var_dump($notify['payload']);
74+
var_dump($notify[0]);
75+
var_dump($notify[1] == $pid);
76+
var_dump($notify[2]);
77+
78+
// Verify that there are no notifies queued
79+
var_dump($db->pgsqlGetNotify());
80+
81+
?>
82+
--EXPECT--
83+
bool(true)
84+
bool(false)
85+
bool(false)
86+
int(3)
87+
string(13) "notifies_phpt"
88+
bool(true)
89+
string(7) "payload"
90+
int(3)
91+
string(13) "notifies_phpt"
92+
bool(true)
93+
string(7) "payload"
94+
int(3)
95+
string(13) "notifies_phpt"
96+
bool(true)
97+
string(7) "payload"
98+
int(3)
99+
string(13) "notifies_phpt"
100+
bool(true)
101+
string(7) "payload"
102+
int(6)
103+
string(13) "notifies_phpt"
104+
bool(true)
105+
string(7) "payload"
106+
string(13) "notifies_phpt"
107+
bool(true)
108+
string(7) "payload"
109+
bool(false)

0 commit comments

Comments
 (0)