Re: [PATCH] notify support for DBD::Pg

From: Benjamin(dot)Feinstein(at)guardent(dot)com
To: pgsql-interfaces(at)postgresql(dot)org
Cc: alex(at)pilosoft(dot)com, E(dot)Mergl(at)bawue(dot)de, pgman(at)candle(dot)pha(dot)pa(dot)us
Subject: Re: [PATCH] notify support for DBD::Pg
Date: 2002-01-10 03:40:01
Message-ID: 397E0659AA2DD411843500508B64F1CE0287DE20@USBOSMX01
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hey ya'll,

Sorry for any confusion. Here is the diff in context format.

Cheers,
Ben

diff -c -r DBD-Pg-1.01/Pg.pm DBD-Pg-1.01.ben/Pg.pm
*** DBD-Pg-1.01/Pg.pm Wed Jun 27 13:54:58 2001
--- DBD-Pg-1.01.ben/Pg.pm Wed Jan 9 18:40:04 2002
***************
*** 629,634 ****
--- 629,643 ----
dump a complete table. See test.pl for an example on how to use
this function.

+ $ret = $dbh->func('notifies');
+
+ Returns either undef or a reference to two-element array
+ [ $table, $backend_pid ] of asynchronous notifications received.
+
+ $fd = $dbh->func('getfd');
+
+ Returns fd of the actual connection to server. Can be used with
+ select() and func('notifies').

=back

diff -c -r DBD-Pg-1.01/Pg.xs DBD-Pg-1.01.ben/Pg.xs
*** DBD-Pg-1.01/Pg.xs Mon Jul 10 13:47:51 2000
--- DBD-Pg-1.01.ben/Pg.xs Wed Jan 9 18:40:04 2002
***************
*** 83,88 ****
--- 83,106 ----
}

void
+ getfd(dbh)
+ SV * dbh
+ CODE:
+ int ret;
+ D_imp_dbh(dbh);
+
+ ret = dbd_db_getfd(dbh, imp_dbh);
+ ST(0) = sv_2mortal( newSViv( ret ) );
+
+ void
+ notifies(dbh)
+ SV * dbh
+ CODE:
+ D_imp_dbh(dbh);
+
+ ST(0) = dbd_db_notifies(dbh, imp_dbh);
+
+ void
commit(dbh)
SV * dbh
CODE:
diff -c -r DBD-Pg-1.01/dbdimp.c DBD-Pg-1.01.ben/dbdimp.c
*** DBD-Pg-1.01/dbdimp.c Wed Jun 27 13:54:58 2001
--- DBD-Pg-1.01.ben/dbdimp.c Wed Jan 9 18:40:04 2002
***************
*** 197,202 ****
--- 197,243 ----
}


+ int
+ dbd_db_getfd (dbh, imp_dbh)
+ SV *dbh;
+ imp_dbh_t *imp_dbh;
+ {
+ char id;
+ SV* retsv;
+
+ if (dbis->debug >= 1) { fprintf(DBILOGFP, "dbd_db_getfd\n"); }
+
+ return PQsocket(imp_dbh->conn);
+ }
+
+ SV *
+ dbd_db_notifies (dbh, imp_dbh)
+ SV *dbh;
+ imp_dbh_t *imp_dbh;
+ {
+ char id;
+ PGnotify* notify;
+ AV* ret;
+ SV* retsv;
+
+ if (dbis->debug >= 1) { fprintf(DBILOGFP, "dbd_db_notifies\n"); }
+
+ PQconsumeInput(imp_dbh->conn);
+
+ notify = PQnotifies(imp_dbh->conn);
+
+ if (!notify) return &sv_undef;
+
+ ret=newAV();
+
+ av_push(ret, newSVpv(notify->relname,0) );
+ av_push(ret, newSViv(notify->be_pid) );
+
+ retsv = newRV(sv_2mortal((SV*)ret));
+
+ return retsv;
+ }
+
int
dbd_db_ping (dbh)
SV *dbh;
diff -c -r DBD-Pg-1.01/dbdimp.h DBD-Pg-1.01.ben/dbdimp.h
*** DBD-Pg-1.01/dbdimp.h Mon Apr 9 13:44:18 2001
--- DBD-Pg-1.01.ben/dbdimp.h Wed Jan 9 18:40:04 2002
***************
*** 70,73 ****
--- 70,75 ----
};


+ SV * dbd_db_notifies (SV *dbh, imp_dbh_t *imp_dbh);
+
/* end of dbdimp.h */
diff -c -r DBD-Pg-1.01/test.pl DBD-Pg-1.01.ben/test.pl
*** DBD-Pg-1.01/test.pl Sun May 27 10:10:13 2001
--- DBD-Pg-1.01.ben/test.pl Wed Jan 9 18:40:04 2002
***************
*** 40,46 ****
my $dsn_main = "dbi:Pg:dbname=$dbmain";
my $dsn_test = "dbi:Pg:dbname=$dbtest";

! my ($dbh0, $dbh, $sth);

#DBI->trace(3); # make your choice

--- 40,46 ----
my $dsn_main = "dbi:Pg:dbname=$dbmain";
my $dsn_test = "dbi:Pg:dbname=$dbtest";

! my ($dbh0, $dbh, $dbh1, $sth);

#DBI->trace(3); # make your choice

***************
*** 445,460 ****
# end transaction
$dbh->{AutoCommit} = 1;

( $dbh->func($lobjId, 'lo_unlink') )
and print "\$dbh->func(lo_unlink) ...... ok\n"
or print "\$dbh->func(lo_unlink) ...... not ok\n";

- # compare large objects
-
( $pgin cmp $buf and $pgin cmp $blob )
and print "compare blobs .............. not ok\n"
or print "compare blobs .............. ok\n";

######################### disconnect and drop test database

# disconnect
--- 445,500 ----
# end transaction
$dbh->{AutoCommit} = 1;

+ # compare large objects
+
( $dbh->func($lobjId, 'lo_unlink') )
and print "\$dbh->func(lo_unlink) ...... ok\n"
or print "\$dbh->func(lo_unlink) ...... not ok\n";

( $pgin cmp $buf and $pgin cmp $blob )
and print "compare blobs .............. not ok\n"
or print "compare blobs .............. ok\n";

+ my $fd;
+ ( $fd=$dbh->func( 'getfd') )
+ and print "\$dbh->func(getfd) .......... ok\n"
+ or print "\$dbh->func(getfd) .......... not ok\n";
+
+ ( $dbh->do( 'LISTEN test ') )
+ and print "\$dbh->do('LISTEN test') .... ok\n"
+ or print "\$dbh->do('LISTEN test') .... not ok\n";
+
+ ( $dbh1 = DBI->connect("$dsn_test", '', '', { AutoCommit => 1 }) )
+ and print "DBI->connect (for notify)... ok\n"
+ or die "DBI->connect (for notify)... not ok: ", $DBI::errstr;
+
+ # there should be no data for read on $fd , until we send a notify
+
+ my $rout;
+ my $rin = '';
+ vec($rin,$fd,1) = 1;
+ my $nfound = select( $rout=$rin, undef, undef, 0);
+
+ ( $nfound==0 )
+ and print "select(\$fd) returns no data. ok\n"
+ or die "select(\$fd) returns no data. not ok\n";
+
+ ( $dbh1->do( 'NOTIFY test ') )
+ and print "\$dbh1->do('NOTIFY test') ... ok\n"
+ or print "\$dbh1->do('NOTIFY test') ... not ok\n";
+
+ my $nfound2 = select( $rout=$rin, undef, undef, 1);
+
+ ( $nfound2==1 )
+ and print "select(\$fd) returns data.... ok\n"
+ or die "select(\$fd) returns data.... not ok\n";
+
+ my $notify_r;
+
+ ( $notify_r = $dbh->func('notifies') )
+ and print "\$dbh->func('notifies')...... ok\n"
+ or die "\$dbh->func('notifies')...... not ok\n";
+
######################### disconnect and drop test database

# disconnect
***************
*** 463,468 ****
--- 503,512 ----
and print "\$dbh->disconnect ........... ok\n"
or die "\$dbh->disconnect ........... not ok: ", $DBI::errstr;

+ ( $dbh1->disconnect )
+ and print "\$dbh1->disconnect .......... ok\n"
+ or die "\$dbh1->disconnect .......... not ok: ", $DBI::errstr;
+
$dbh0->do("DROP DATABASE $dbtest");
$dbh0->disconnect;

-----Original Message-----
From: Bruce Momjian [mailto:pgman(at)candle(dot)pha(dot)pa(dot)us]
Sent: Wednesday, January 09, 2002 7:29 PM
To: Ben Feinstein
Cc: pgsql-interfaces(at)postgresql(dot)org; alex(at)pilosoft(dot)com; E(dot)Mergl(at)bawue(dot)de
Subject: Re: [INTERFACES] [PATCH] notify support for DBD::Pg

Benjamin(dot)Feinstein(at)guardent(dot)com wrote:
> Hey ya'll,
>
> Attached is a patch to add support for asynchronous client notifications
to
> the DBD::Pg interface. The original patch was written by Alex Pilosov
> <alex(at)pilosoft(dot)com> and sent to this list on 10 Jun 2001. This is an
updated
> version that fixes some problems I encountered when running Alex's patch
> against DBD-Pg-1.01. Alex's original patch was generated from a diff of
> DBD-Pg-1.00.

We really need a context diff, diff -c.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

Browse pgsql-interfaces by date

  From Date Subject
Next Message Christof Petig 2002-01-10 07:41:20 Re: dynamic sql in ecpg
Previous Message Tom Lane 2002-01-10 01:16:04 Re: [PATCH] notify support for DBD::Pg