-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 In reference to: http://archives.postgresql.org/message-id/6534f7ae0811181547v1dc1f096g6222e8273b461...@mail.gmail.com
Had to fix a lot of bit rot, but otherwise looks good. My updated patch attached. Will commit in a day or so if no objections. BTW, some commitfest procedural comments/questions: 1) I couldn't figure out how to attach my patch to the commitfest page short of cut-n-paste into the small comment text box -- is that my only choice? 2) It would be nice if the mail archive web page of the original message had a "Reply To" button. Otherwise I guess I can do what I've done above. 3) I couldn't see any way to assign myself as the committer. Joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iQIcBAEBCAAGBQJKd5K8AAoJEDfy90M199hlDbIQAIYeLR1B3JKkXvoBCZUkzVNj hkj67d38ygU/Q4RDsnPT0N96PbPvzBJGCueaCLfwzbdpEQb4Si37R8xBMXPzT/df SEoWrx/2r1/cERyImxHVGlj0kBWBa7K42hcEotD0mNqWqX6rqByLDpVTSlpZZdfM a/b04iXfPcIvOLSpX6PJOb047SeHQrzOmcnurBqc1HE81XiiBNQlJjOd0Zi+y+pT zGJChGSRO1lXriOI1Pu2K18daqY8vLLZA0LlaZ3SD6UeS7Uayeo+8cOpAk6N1b7H EKqYAwWfmRrSO6bUCmgkqlHa/TiaIL0uJb0me68YcUy08DAt1O8iRmUnAE+cxXU5 HeZgGqJI2G19Ts5i9R2YaHVe8kTmPD88zztv8giiAw01m9h6azkiM342CzNuyQTw 8TbZnjWdCkb4KuH9en4C/puIWUpCOd2OkVju3ZUJCvzaO/jS/HVf2fc08K9TddPK OWpsytXCNS6ojM/Em5lZzfsZZ9sDcrP29dSHZEJqOIkMhFoEGqq4DVqtJnLMHsLw 3PtSfgz0SbXcuAA0vv/VJSDm+cAl+aJN93hbwNybwrT14XEotllFdhyJrSPqFgYm 4b7P29dFKP+aF90C6klxr5Mq/nRYiJVdTepqjfyikVBsdZoMwQXvG+ROiwbzjl9g eEmht8ysuxn2Ju8FcDYc =AJfk -----END PGP SIGNATURE-----
Index: contrib/dblink/dblink.c =================================================================== RCS file: /opt/src/cvs/pgsql/contrib/dblink/dblink.c,v retrieving revision 1.82 diff -c -r1.82 dblink.c *** contrib/dblink/dblink.c 11 Jun 2009 14:48:50 -0000 1.82 --- contrib/dblink/dblink.c 4 Aug 2009 01:05:49 -0000 *************** *** 1635,1640 **** --- 1635,1681 ---- PG_RETURN_DATUM(current_query(fcinfo)); } + /* + * Retrieve async notifications for a connection. + * + * Returns an array of notifications, or NULL if none recieved. + * Can optionally take a named connection as parameter, but uses the unnamed connection per default. + * + */ + PG_FUNCTION_INFO_V1(dblink_get_notify); + Datum + dblink_get_notify(PG_FUNCTION_ARGS) + { + PGconn *conn = NULL; + remoteConn *rconn = NULL; + ArrayBuildState *astate = NULL; + PGnotify *notify; + + DBLINK_INIT; + if (PG_NARGS() == 1) + DBLINK_GET_NAMED_CONN; + else + conn = pconn->conn; + + PQconsumeInput(conn); + + while ((notify = PQnotifies(conn)) != NULL) + { + /* stash away current value */ + astate = accumArrayResult(astate, + PointerGetDatum(cstring_to_text(notify->relname)), + false, TEXTOID, CurrentMemoryContext); + PQfreemem(notify); + PQconsumeInput(conn); + } + + if (astate) + PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate, + CurrentMemoryContext)); + else + PG_RETURN_NULL(); + } + /************************************************************* * internal functions */ Index: contrib/dblink/dblink.h =================================================================== RCS file: /opt/src/cvs/pgsql/contrib/dblink/dblink.h,v retrieving revision 1.22 diff -c -r1.22 dblink.h *** contrib/dblink/dblink.h 9 Jun 2009 17:41:02 -0000 1.22 --- contrib/dblink/dblink.h 4 Aug 2009 00:56:56 -0000 *************** *** 57,61 **** --- 57,62 ---- extern Datum dblink_build_sql_delete(PG_FUNCTION_ARGS); extern Datum dblink_build_sql_update(PG_FUNCTION_ARGS); extern Datum dblink_current_query(PG_FUNCTION_ARGS); + extern Datum dblink_get_notify(PG_FUNCTION_ARGS); #endif /* DBLINK_H */ Index: contrib/dblink/dblink.sql.in =================================================================== RCS file: /opt/src/cvs/pgsql/contrib/dblink/dblink.sql.in,v retrieving revision 1.18 diff -c -r1.18 dblink.sql.in *** contrib/dblink/dblink.sql.in 9 Jun 2009 17:41:02 -0000 1.18 --- contrib/dblink/dblink.sql.in 4 Aug 2009 00:58:52 -0000 *************** *** 202,204 **** --- 202,214 ---- RETURNS text AS 'MODULE_PATHNAME', 'dblink_error_message' LANGUAGE C STRICT; + + CREATE OR REPLACE FUNCTION dblink_get_notify() + RETURNS text[] + AS 'MODULE_PATHNAME', 'dblink_get_notify' + LANGUAGE C STRICT; + + CREATE OR REPLACE FUNCTION dblink_get_notify(conname text) + RETURNS text[] + AS 'MODULE_PATHNAME', 'dblink_get_notify' + LANGUAGE C STRICT; Index: contrib/dblink/uninstall_dblink.sql =================================================================== RCS file: /opt/src/cvs/pgsql/contrib/dblink/uninstall_dblink.sql,v retrieving revision 1.7 diff -c -r1.7 uninstall_dblink.sql *** contrib/dblink/uninstall_dblink.sql 5 Apr 2008 02:26:14 -0000 1.7 --- contrib/dblink/uninstall_dblink.sql 4 Aug 2009 00:56:56 -0000 *************** *** 76,78 **** --- 76,82 ---- DROP FUNCTION dblink_is_busy(text); DROP FUNCTION dblink_send_query(text, text); + + DROP FUNCTION dblink_get_notify(); + + DROP FUNCTION dblink_get_notify(text); Index: contrib/dblink/expected/dblink.out =================================================================== RCS file: /opt/src/cvs/pgsql/contrib/dblink/expected/dblink.out,v retrieving revision 1.25 diff -c -r1.25 dblink.out *** contrib/dblink/expected/dblink.out 6 Jun 2009 21:27:56 -0000 1.25 --- contrib/dblink/expected/dblink.out 4 Aug 2009 01:20:09 -0000 *************** *** 827,829 **** --- 827,864 ---- DROP USER MAPPING FOR public SERVER fdtest; DROP SERVER fdtest; DROP FOREIGN DATA WRAPPER postgresql; + -- test asynchronous notifications + SELECT dblink_connect('dbname=contrib_regression'); + dblink_connect + ---------------- + OK + (1 row) + + --should return listen + SELECT dblink_exec('LISTEN regression'); + dblink_exec + ------------- + LISTEN + (1 row) + + NOTIFY regression; + --should return {regression} + SELECT dblink_get_notify(); + dblink_get_notify + ------------------- + {regression} + (1 row) + + --should return null + SELECT dblink_get_notify(); + dblink_get_notify + ------------------- + + (1 row) + + SELECT dblink_disconnect(); + dblink_disconnect + ------------------- + OK + (1 row) + Index: contrib/dblink/sql/dblink.sql =================================================================== RCS file: /opt/src/cvs/pgsql/contrib/dblink/sql/dblink.sql,v retrieving revision 1.21 diff -c -r1.21 dblink.sql *** contrib/dblink/sql/dblink.sql 6 Jun 2009 21:27:56 -0000 1.21 --- contrib/dblink/sql/dblink.sql 4 Aug 2009 01:19:48 -0000 *************** *** 389,391 **** --- 389,407 ---- DROP USER MAPPING FOR public SERVER fdtest; DROP SERVER fdtest; DROP FOREIGN DATA WRAPPER postgresql; + + -- test asynchronous notifications + SELECT dblink_connect('dbname=contrib_regression'); + + --should return listen + SELECT dblink_exec('LISTEN regression'); + + NOTIFY regression; + + --should return {regression} + SELECT dblink_get_notify(); + + --should return null + SELECT dblink_get_notify(); + + SELECT dblink_disconnect(); Index: doc/src/sgml/dblink.sgml =================================================================== RCS file: /opt/src/cvs/pgsql/doc/src/sgml/dblink.sgml,v retrieving revision 1.8 diff -c -r1.8 dblink.sgml *** doc/src/sgml/dblink.sgml 18 Jun 2009 14:34:36 -0000 1.8 --- doc/src/sgml/dblink.sgml 4 Aug 2009 00:52:09 -0000 *************** *** 1260,1265 **** --- 1260,1339 ---- </refsect1> </refentry> + <refentry id="CONTRIB-DBLINK-GET-NOTIFY"> + <refnamediv> + <refname>dblink_get_notify</refname> + <refpurpose>retrieve async notifications on a connection</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <synopsis> + dblink_get_notify() returns text[] + dblink_get_notify(text connname) returns text[] + </synopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para> + <function>dblink_get_notify</> retrieves notifications on either + the unnamed connection, or on a named connection if specified. + To receive notifications via dblink, <function>LISTEN</> must + first be issued, using <function>dblink_exec</>. + For details see <xref linkend="sql-listen"> and <xref linkend="sql-notify">. + </para> + + </refsect1> + + <refsect1> + <title>Arguments</title> + + <variablelist> + <varlistentry> + <term><parameter>conname</parameter></term> + <listitem> + <para> + The name of a named connection to get notifications on. + </para> + </listitem> + </varlistentry> + </variablelist> + </refsect1> + + <refsect1> + <title>Return Value</title> + <para>Returns a text array of notification names, or NULL if none.</para> + </refsect1> + + <refsect1> + <title>Example</title> + + <programlisting> + test=# SELECT dblink_exec('LISTEN virtual'); + dblink_exec + ------------- + LISTEN + (1 row) + + test=# SELECT dblink_get_notify(); + dblink_get_notify + ------------------- + + (1 row) + + test=# NOTIFY virtual; + NOTIFY + + test=# SELECT dblink_get_notify(); + dblink_get_notify + ------------------- + {virtual} + (1 row) + </programlisting> + </refsect1> + </refentry> + <refentry id="CONTRIB-DBLINK-GET-RESULT"> <refmeta> <refentrytitle>dblink_get_result</refentrytitle>
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers