Author: turnstep
Date: Sat May 24 19:27:30 2008
New Revision: 11308

Modified:
   DBD-Pg/trunk/Changes
   DBD-Pg/trunk/Pg.pm
   DBD-Pg/trunk/dbdimp.c
   DBD-Pg/trunk/t/03dbmethod.t

Log:
Added in payload strings for LISTEN/NOTIFY in 8.4 via $dbh->pg_notifies()


Modified: DBD-Pg/trunk/Changes
==============================================================================
--- DBD-Pg/trunk/Changes        (original)
+++ DBD-Pg/trunk/Changes        Sat May 24 19:27:30 2008
@@ -2,6 +2,8 @@
 
 2.7.3
 
+       - Added in payload strings for LISTEN/NOTIFY in 8.4 
+               via $dbh->pg_notifies() [GSM]
        - Fixed problem preventing some pg_type bind_arrays
                from working [GSM]
 

Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm  (original)
+++ DBD-Pg/trunk/Pg.pm  Sat May 24 19:27:30 2008
@@ -2548,12 +2548,12 @@
 
   $ret = $dbh->pg_notifies;
 
-Returns either C<undef> or a reference to two-element array [ $table,
-$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 transaction. An example:
+Looks for any asycnhronous notifications received and returns either C<undef> 
+or a reference to a three-element array consisting of an event name, the PID 
+of the backend that sent the NOTIFY command, and the optional payload string. 
+Note that this does not check if the connection to the database is still valid 
first - 
+for that, use the c<ping> method. You may need to commit if not in autocommit 
mode - 
+new notices will not be picked up while in the middle of a transaction. An 
example:
 
   $dbh->do("LISTEN abc");
   $dbh->do("LISTEN def");
@@ -2561,8 +2561,8 @@
   ## Hang around until we get the message we want
   LISTENLOOP: {
     while (my $notify = $dbh->pg_notifies) {
-      my ($name, $pid) = @$notify;
-      print qq{I received notice "$name" from PID $pid\n};
+      my ($name, $pid, $payload) = @$notify;
+      print qq{I received notice "$name" from PID $pid, payload was 
"$payload"\n};
       ## Do something based on the notice received
     }
     $dbh->ping() or die qq{Ping failed!};
@@ -2571,6 +2571,9 @@
     redo;
   }
 
+Payloads will always be an empty string unless you are connecting to a 
Postgres 
+server version 8.4 or higher.
+
 =item B<ping>
 
   $rc = $dbh->ping;

Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c       (original)
+++ DBD-Pg/trunk/dbdimp.c       Sat May 24 19:27:30 2008
@@ -1305,6 +1305,8 @@
        ret=newAV();
        av_push(ret, newSVpv(notify->relname,0) );
        av_push(ret, newSViv(notify->be_pid) );
+       av_push(ret, newSVpv(notify->extra,0) );
+       /* Think about utf-8 in payloads someday... */
        
        TRACE_PQFREEMEM;
        PQfreemem(notify);

Modified: DBD-Pg/trunk/t/03dbmethod.t
==============================================================================
--- DBD-Pg/trunk/t/03dbmethod.t (original)
+++ DBD-Pg/trunk/t/03dbmethod.t Sat May 24 19:27:30 2008
@@ -1169,13 +1169,13 @@
 $dbh->do("NOTIFY $notify_name");
 $dbh->commit();
 $info = $dbh->func('pg_notifies');
-is_deeply($info, [$notify_name, $pid], $t);
+is_deeply($info, [$notify_name, $pid, ''], $t);
 
 $t=q{DB handle method "pg_notifies" returns the correct values};
 $dbh->do("NOTIFY $notify_name");
 $dbh->commit();
 $info = $dbh->pg_notifies;;
-is_deeply($info, [$notify_name, $pid], $t);
+is_deeply($info, [$notify_name, $pid, ''], $t);
 
 #
 # Test of the "getfd" database handle method

Reply via email to