On Fri, May 30, 2003 at 03:13:04PM +0100, Dominic Mitchell wrote:Tim Bunce wrote:On Fri, May 30, 2003 at 10:20:11AM +0100, Dominic Mitchell wrote:See, I told you I wasn't an XS guru. :-)
Actually, I looked at this, but my limited C and DBI skills couldn't work out a) what the required handle was (probably dbh)
Just whatever handle was used to call the method that's generating the warning.
and b) how to pass that into the PQsetNoticeProcessor function as data and get it out again.
Ah, different issue. For that I'd say if DBIc_WARN(imp_xxh) isn't true then disable the PQsetNoticeProcessor function.
Well, we're calling PQsetNoticeProcessor[1], from inside dbd_db_login, so I should be able to pass in imp_dbh as the "arg" argument. The bit that I wasn't sure about before was what to cast it to in order to retrieve it from a void *.
You could always cast it to a void * :-)
Right, I've tried to amend my patch to save a reference to the dbh, and only warn if DBIc_WARN(), just like all the other cases in the code.
However, it doesn't work. When the callback function pg_warn() gets called, DBI complains that I've passed in undef. Which implies that the dbh I'm using has gone out of scope somewhere, but I can't see where.
Would somebody who's more familiar with DBD::Pg mind having a look at the attached patch? I've got no idea why it isn't working. :-(
Sorry, -Dom
-- | Semantico: creators of major online resources | | URL: http://www.semantico.com/ | | Tel: +44 (1273) 722222 | | Address: 33 Bond St., Brighton, Sussex, BN1 1RD, UK. |
? .dbdimp.c.swp
? Pg.xsi
Index: dbdimp.c
===================================================================
RCS file: /usr/local/cvsroot/dbdpg/dbdpg/dbdimp.c,v
retrieving revision 1.23
diff -u -r1.23 dbdimp.c
--- dbdimp.c 29 May 2003 08:37:46 -0000 1.23
+++ dbdimp.c 2 Jun 2003 13:25:55 -0000
@@ -76,7 +76,10 @@
void *arg;
const char *message;
{
- warn( message );
+ D_imp_dbh( (SV *)arg );
+
+ if (DBIc_WARN(imp_dbh))
+ warn( message );
}
/* Database specific error handling. */
@@ -178,7 +181,7 @@
}
/* Enable warnings to go through perl */
- PQsetNoticeProcessor(imp_dbh->conn, pg_warn, NULL);
+ PQsetNoticeProcessor(imp_dbh->conn, pg_warn, (void *)dbh);
/* Quick basic version check -- not robust a'tall TODO: rewrite */
pgres_ret = PQexec(imp_dbh->conn, "SELECT version()");
