php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #68199
Patch payload_support revision 2014-10-09 12:54 UTC by alain dot laporte12345 at gmail dot com

Patch payload_support for PDO PgSQL Bug #68199

Patch version 2014-10-09 12:54 UTC

Return to Bug #68199 | Download this patch
Patch Revisions:

Developer: alain.laporte12345@gmail.com

commit ff221849d4ff3de718fd2f1dd899ad93caf02e22
Author: Alain Laporte <alaporte@anevia.com>
Date:   Thu Oct 9 10:07:54 2014 +0200

    DEVEL : Add payload support

diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index 96f6fa7..d20b0bb 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -1058,10 +1058,16 @@ static PHP_METHOD(PDO, pgsqlGetNotify)
 	if (result_type == PDO_FETCH_NUM || result_type == PDO_FETCH_BOTH) {
 		add_index_string(return_value, 0, pgsql_notify->relname, 1);
 		add_index_long(return_value, 1, pgsql_notify->be_pid);
+		if (PG_VERSION_NUM > 74000 && strlen(pgsql_notify->extra) > 0) {
+			add_index_string(return_value, 2, pgsql_notify->extra, 1);
+		}
 	}
 	if (result_type == PDO_FETCH_ASSOC || result_type == PDO_FETCH_BOTH) {
 		add_assoc_string(return_value, "message", pgsql_notify->relname, 1);
 		add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
+		if (PG_VERSION_NUM > 74000 && strlen(pgsql_notify->extra) > 0) {
+			add_assoc_string(return_value, "payload", pgsql_notify->extra, 1);
+		}
 	}
 
 	PQfreemem(pgsql_notify);
diff --git a/ext/pdo_pgsql/tests/getnotify.phpt b/ext/pdo_pgsql/tests/getnotify.phpt
index c093e03..b8807b2 100644
--- a/ext/pdo_pgsql/tests/getnotify.phpt
+++ b/ext/pdo_pgsql/tests/getnotify.phpt
@@ -63,6 +63,51 @@ var_dump($notify['pid'] == $pid);
 var_dump($notify[0]);
 var_dump($notify[1] == $pid);
 
+// No parameters with payload, use default PDO::FETCH_NUM
+$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_NUM);
+$db->exec("NOTIFY notifies_phpt, payload");
+$notify = $db->pgsqlGetNotify();
+var_dump(count($notify));
+var_dump($notify[0]);
+var_dump($notify[1] == $pid);
+var_dump($notify[2]);
+
+// No parameters with payload, use default PDO::FETCH_ASSOC
+$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
+$db->exec("NOTIFY notifies_phpt, payload");
+$notify = $db->pgsqlGetNotify();
+var_dump(count($notify));
+var_dump($notify['message']);
+var_dump($notify['pid'] == $pid);
+var_dump($notify['payload']);
+
+// Test PDO::FETCH_NUM as parameter with payload
+$db->exec("NOTIFY notifies_phpt, payload");
+$notify = $db->pgsqlGetNotify(PDO::FETCH_NUM);
+var_dump(count($notify));
+var_dump($notify[0]);
+var_dump($notify[1] == $pid);
+var_dump($notify[2]);
+
+// Test PDO::FETCH_ASSOC as parameter with payload
+$db->exec("NOTIFY notifies_phpt, payload");
+$notify = $db->pgsqlGetNotify(PDO::FETCH_ASSOC);
+var_dump(count($notify));
+var_dump($notify['message']);
+var_dump($notify['pid'] == $pid);
+var_dump($notify['payload']);
+
+// Test PDO::FETCH_BOTH as parameter with payload
+$db->exec("NOTIFY notifies_phpt, payload");
+$notify = $db->pgsqlGetNotify(PDO::FETCH_BOTH);
+var_dump(count($notify));
+var_dump($notify['message']);
+var_dump($notify['pid'] == $pid);
+var_dump($notify['payload']);
+var_dump($notify[0]);
+var_dump($notify[1] == $pid);
+var_dump($notify[2]);
+
 // Verify that there are no notifies queued
 var_dump($db->pgsqlGetNotify());
 
@@ -102,6 +147,29 @@ string(13) "notifies_phpt"
 bool(true)
 string(13) "notifies_phpt"
 bool(true)
+int(3)
+string(13) "notifies_phpt"
+bool(true)
+string(7) "payload"
+int(3)
+string(13) "notifies_phpt"
+bool(true)
+string(7) "payload"
+int(3)
+string(13) "notifies_phpt"
+bool(true)
+string(7) "payload"
+int(3)
+string(13) "notifies_phpt"
+bool(true)
+string(7) "payload"
+int(6)
+string(13) "notifies_phpt"
+bool(true)
+string(7) "payload"
+string(13) "notifies_phpt"
+bool(true)
+string(7) "payload"
 bool(false)
 bool(true)
 bool(false)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC