diff -r --unified DBD-Pg-1.00/Pg.pm DBD-Pg-1.00.alex/Pg.pm --- DBD-Pg-1.00/Pg.pm Sun May 27 10:10:13 2001 +++ DBD-Pg-1.00.alex/Pg.pm Sun Jun 10 15:14:32 2001 @@ -629,6 +629,15 @@ 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 -r --unified DBD-Pg-1.00/Pg.xs DBD-Pg-1.00.alex/Pg.xs --- DBD-Pg-1.00/Pg.xs Mon Jul 10 13:47:51 2000 +++ DBD-Pg-1.00.alex/Pg.xs Sun Jun 10 15:12:35 2001 @@ -83,6 +83,24 @@ } 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 -r --unified DBD-Pg-1.00/dbdimp.c DBD-Pg-1.00.alex/dbdimp.c --- DBD-Pg-1.00/dbdimp.c Sun May 27 10:10:13 2001 +++ DBD-Pg-1.00.alex/dbdimp.c Sun Jun 10 15:12:35 2001 @@ -197,6 +197,47 @@ } +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 -r --unified DBD-Pg-1.00/dbdimp.h DBD-Pg-1.00.alex/dbdimp.h --- DBD-Pg-1.00/dbdimp.h Mon Apr 9 13:44:18 2001 +++ DBD-Pg-1.00.alex/dbdimp.h Sun Jun 10 15:12:35 2001 @@ -70,4 +70,6 @@ }; +SV * dbd_db_notifies (SV *dbh, imp_dbh_t *imp_dbh); + /* end of dbdimp.h */ diff -r --unified DBD-Pg-1.00/test.pl DBD-Pg-1.00.alex/test.pl --- DBD-Pg-1.00/test.pl Sun May 27 10:10:13 2001 +++ DBD-Pg-1.00.alex/test.pl Sun Jun 10 15:38:09 2001 @@ -40,7 +40,7 @@ my $dsn_main = "dbi:Pg:dbname=$dbmain"; my $dsn_test = "dbi:Pg:dbname=$dbtest"; -my ($dbh0, $dbh, $sth); +my ($dbh0, $dbh, $dbh1, $sth); #DBI->trace(3); # make your choice @@ -445,16 +445,56 @@ # 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"; -# compare large objects - ( $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 $nfound = select( $rout=$rin, undef, undef, 1); + +( $nfound==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 @@ -462,6 +502,10 @@ ( $dbh->disconnect ) 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;