[DBD::Pg] Don't return quick on a ping() if we are inside a transaction but idle: do a SELECT to the server as we do with an active session. Per bug report #100648
[email protected] Tue, 2 Dec 2014 00:47:48 +0000
| Newsgroups | perl.dbd.pg.changes |
|---|---|
| Message-ID | <[email protected]> |
Committed by Greg Sabino Mullane <[email protected]> Don't return quick on a ping() if we are inside a transaction but idle: do a SELECT to the server as we do with an active session. Per bug report #100648 --- dbdimp.c | 2 +- t/03dbmethod.t | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dbdimp.c b/dbdimp.c index 28882a5..1fa422e 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -472,7 +472,7 @@ int dbd_db_ping (SV * dbh) return -2; } - if (tstatus != 0) {/* 2=active, 3=intrans, 4=inerror */ + if (tstatus != 0 && tstatus != 2) {/* 0=idle, 1=active, 2=intrans, 3=error 4=unknown */ if (TEND_slow) TRC(DBILOGFP, "%sEnd dbd_pg_ping (result: %d)\n", THEADER_slow, 1+tstatus); return 1+tstatus; } diff --git a/t/03dbmethod.t b/t/03dbmethod.t index 57da55b..f37f16f 100644 --- a/t/03dbmethod.t +++ b/t/03dbmethod.t @@ -1882,9 +1882,9 @@ $dbh2->disconnect(); $t='DB handle method "ping" returns 1 on an idle connection'; is ($dbh->ping(), 1, $t); -$t='DB handle method "ping" returns 3 for a good connection inside a transaction'; +$t='DB handle method "ping" returns 1 for a good connection inside a transaction'; $dbh->do('SELECT 123'); -$result = 3; +$result = 1; is ($result, $dbh->ping(), $t); $t='DB handle method "ping" returns 1 on an idle connection'; @@ -1902,9 +1902,9 @@ $dbh->do('COPY dbd_pg_test(id,pname) TO STDOUT'); is ($dbh->ping(), 2, $t); 1 while $dbh->pg_getline($mtvar,1000); -$t='DB handle method "ping" returns 3 for a good connection inside a transaction'; +$t='DB handle method "ping" returns 1 for a good connection inside a transaction'; $dbh->do('SELECT 123'); -is ($dbh->ping(), 3, $t); +is ($dbh->ping(), 1, $t); $t='DB handle method "ping" returns a 4 when inside a failed transaction'; eval { @@ -1927,9 +1927,9 @@ isnt ($dbh, undef, $t); $t='DB handle method "pg_ping" returns 1 on an idle connection'; is ($dbh->pg_ping(), 1, $t); -$t='DB handle method "pg_ping" returns 3 for a good connection inside a transaction'; +$t='DB handle method "pg_ping" returns 1 for a good connection inside a transaction'; $dbh->do('SELECT 123'); -is ($dbh->pg_ping(), 3, $t); +is ($dbh->pg_ping(), 1, $t); $t='DB handle method "pg_ping" returns 1 on an idle connection'; $dbh->commit(); @@ -1944,9 +1944,9 @@ $t='DB handle method "pg_ping" returns 2 immediately after COPY IN state'; 1 while $dbh->pg_getline($mtvar,1000); is ($dbh->pg_ping(), 2, $t); -$t='DB handle method "pg_ping" returns 3 for a good connection inside a transaction'; +$t='DB handle method "pg_ping" returns 1 for a good connection inside a transaction'; $dbh->do('SELECT 123'); -is ($dbh->pg_ping(), 3, $t); +is ($dbh->pg_ping(), 1, $t); $t='DB handle method "pg_ping" returns a 4 when inside a failed transaction'; eval { -- 1.8.4