RE: Any DBD::Pg Committers out there?
"Eric Simon" <[email protected]> Tue, 16 Nov 2010 17:01:11 -0600
| Newsgroups | gmane.comp.db.postgresql.dbdpg |
|---|---|
| Message-ID | <A4CA169E981340FCB4C2647C0009B6F9@Masterchief> |
Here you go. I also patched the 04misc test because it was failing under Perl 5.12. If you'd like me to break that out into a separate patch, let me know. -- Eric Simon The IQ Group, Inc. -----Original Message----- From: David E. Wheeler [mailto:[email protected]] Sent: Tuesday, November 16, 2010 3:36 PM To: Eric Simon Cc: [email protected] Subject: Re: Any DBD::Pg Committers out there? On Nov 16, 2010, at 11:27 AM, Eric Simon wrote: > I have a small patch for DBD::Pg that implements the cancel() method for a > statement handle (different than pg_cancel() which is for an asynchronous > cancel). Are there any committers out that have some time to apply it > (Greg's currently in a busy season)? I'm a committer. Let's see the patch. David
dbd-pg-cancel-patch.diff
(application/octet-stream, 2.7 KB)
Index: dbdimp.c
===================================================================
--- dbdimp.c (revision 14516)
+++ dbdimp.c (working copy)
@@ -4909,7 +4909,40 @@
} /* end of handle_old_async */
+/* ================================================================== */
+/* Attempt to cancel a synchronous query
+ Returns true if the cancel succeeded, and false if it did not */
+int dbd_st_cancel(SV *sth, imp_sth_t *imp_sth)
+{
+ dTHX;
+ D_imp_dbh_from_sth;
+ PGcancel *cancel;
+ char errbuf[256];
+ if (TSTART) TRC(DBILOGFP, "%sBegin dbd_st_cancel\n", THEADER);
+
+ /* Get the cancel structure */
+ TRACE_PQGETCANCEL;
+ cancel = PQgetCancel(imp_dbh->conn);
+
+ /* This almost always works. If not, free our structure and complain loudly */
+ TRACE_PQGETCANCEL;
+ if (!PQcancel(cancel, errbuf, sizeof(errbuf))) {
+ TRACE_PQFREECANCEL;
+ PQfreeCancel(cancel);
+ if (TRACEWARN) TRC(DBILOGFP, "%sPQcancel failed: %s\n", THEADER, errbuf);
+ pg_error(aTHX_ sth, PGRES_FATAL_ERROR, "PQcancel failed");
+ if (TEND) TRC(DBILOGFP, "%sEnd dbd_st_cancel (error: cancel failed)\n", THEADER);
+ return DBDPG_FALSE;
+ }
+ TRACE_PQFREECANCEL;
+ PQfreeCancel(cancel);
+
+ if (TEND) TRC(DBILOGFP, "%sEnd dbd_st_cancel\n", THEADER);
+ return DBDPG_TRUE;
+
+} /* end of dbd_st_cancel */
+
/*
Some information to keep you sane:
typedef enum
Index: dbdimp.h
===================================================================
--- dbdimp.h (revision 14516)
+++ dbdimp.h (working copy)
@@ -166,9 +166,12 @@
#define dbd_st_rows pg_st_rows
int dbd_st_rows (SV * sth, imp_sth_t * imp_sth);
-#define dbd_st_finish pg_st_finidh
+#define dbd_st_finish pg_st_finish
int dbd_st_finish (SV * sth, imp_sth_t * imp_sth);
+#define dbd_st_cancel pg_st_cancel
+int dbd_st_cancel (SV * sth, imp_sth_t * imp_sth);
+
#define dbd_st_destroy pg_st_destroy
void dbd_st_destroy (SV * sth, imp_sth_t * imp_sth);
Index: Pg.xs
===================================================================
--- Pg.xs (revision 14516)
+++ Pg.xs (working copy)
@@ -796,6 +796,13 @@
D_imp_sth(sth);
ST(0) = pg_db_cancel_sth(sth, imp_sth) ? &PL_sv_yes : &PL_sv_no;
+void
+cancel(sth)
+ SV *sth
+ CODE:
+ D_imp_sth(sth);
+ ST(0) = dbd_st_cancel(sth, imp_sth) ? &PL_sv_yes : &PL_sv_no;
+
#if PGLIBVERSION >= 80000
void
Index: t/04misc.t
===================================================================
--- t/04misc.t (revision 14516)
+++ t/04misc.t (working copy)
@@ -284,7 +284,7 @@
$t='The "data_sources" method returns undef when fed a bogus second argument';
@result = DBI->data_sources('Pg','foobar');
-is_deeply (@result, undef, $t);
+is (scalar @result, 0, $t);
$t='The "data_sources" method returns information when fed a valid port as the second arg';
my $port = $dbh->{pg_port};