Author: turnstep
Date: Sun Mar 18 08:47:12 2007
New Revision: 9270

Modified:
   DBD-Pg/trunk/Pg.pm
   DBD-Pg/trunk/TODO

Log:
Add example and warnings to pg_notifies docs.


Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm  (original)
+++ DBD-Pg/trunk/Pg.pm  Sun Mar 18 08:47:12 2007
@@ -1909,7 +1909,27 @@
   $ret = $dbh->func('pg_notifies');
 
 Returns either C<undef> or a reference to two-element array [ $table,
-$backend_pid ] of asynchronous notifications received.
+$backend_pid ] of asynchronous notifications received. Note that this does
+not check if the connection to the database is still valid - for that, 
+use the c<ping> method. Also note that you may need to commit if not in 
+autocommit mode - new notices will not be picked up while in the middle of 
+a transation. An example:
+
+  $dbh->do("LISTEN abc");
+  $dbh->do("LISTEN def");
+
+  ## Hang around until we get the message we want
+  LISTENLOOP: {
+    while (my $notify = $dbh->func('pg_notifies')) {
+      my ($name, $pid) = @$notify;
+      print qq{I received notice "$name" from PID $pid\n};
+      ## Do something based on the notice received
+    }
+    $dbh->ping() or die qq{Ping failed!};
+    $dbh->commit();
+    sleep(5);
+    redo;
+  }
 
 =item getfd
 

Modified: DBD-Pg/trunk/TODO
==============================================================================
--- DBD-Pg/trunk/TODO   (original)
+++ DBD-Pg/trunk/TODO   Sun Mar 18 08:47:12 2007
@@ -1,6 +1,5 @@
 TODO: 
 
-- Better documentation for listen/notify.
 - Start testing with a thread-enabled Perl.
 - Add array OID types
 - Quoting/dequoting of arrays.

Reply via email to