[DBD::Pg] Make sure CREATE TABLE .. AS SELECT returns rows in non do() cases. Per dicsussion on #postgresql
dbdpg-commits-gENoVmVU/[email protected] Fri, 7 Dec 2012 17:42:59 -0500
| Newsgroups | gmane.comp.db.postgresql.dbdpg.cvs |
|---|---|
| Message-ID | <[email protected]> |
Committed by Greg Sabino Mullane <greg-O9fzpki4YnJWk0Htik3J/[email protected]> Make sure CREATE TABLE .. AS SELECT returns rows in non do() cases. Per dicsussion on #postgresql --- Changes | 2 ++ dbdimp.c | 9 ++++++--- t/03dbmethod.t | 13 +++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 0232a36..86a410b 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,8 @@ Version ??? + - Make sure CREATE TABLE .. AS SELECT returns rows in non do() cases. [GSM] + - Spelling fix per CPAN bug #78168 diff --git a/dbdimp.c b/dbdimp.c index ec84e46..d8f4f88 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -3313,7 +3313,8 @@ int dbd_st_execute (SV * sth, imp_sth_t * imp_sth) gotrows = DBDPG_TRUE; } else if (0 == strncmp(cmdStatus, "DELETE", 6) - || 0 == strncmp(cmdStatus, "UPDATE", 6)) { + || 0 == strncmp(cmdStatus, "UPDATE", 6) + || 0 == strncmp(cmdStatus, "SELECT", 6)) { ret = atoi(cmdStatus + 7); gotrows = DBDPG_TRUE; } @@ -3393,8 +3394,9 @@ AV * dbd_st_fetch (SV * sth, imp_sth_t * imp_sth) if (TEND_slow) TRC(DBILOGFP, "%sEnd dbd_st_fetch (error: no statement)\n", THEADER_slow); return Nullav; } - + TRACE_PQNTUPLES; + if (imp_sth->cur_tuple == imp_sth->rows) { if (TRACE5_slow) TRC(DBILOGFP, "%sFetched the last tuple (%d)\n", THEADER_slow, imp_sth->cur_tuple); @@ -4705,7 +4707,8 @@ int pg_db_result (SV *h, imp_dbh_t *imp_dbh) rows = atoi(cmdStatus + 5); } else if (0 == strncmp(cmdStatus, "DELETE", 6) - || 0 == strncmp(cmdStatus, "UPDATE", 6)) { + || 0 == strncmp(cmdStatus, "UPDATE", 6) + || 0 == strncmp(cmdStatus, "SELECT", 6)) { rows = atoi(cmdStatus + 7); } break; diff --git a/t/03dbmethod.t b/t/03dbmethod.t index 9bcb2ba..fd35d4a 100644 --- a/t/03dbmethod.t +++ b/t/03dbmethod.t @@ -26,7 +26,7 @@ my $dbh = connect_database(); if (! $dbh) { plan skip_all => 'Connection to database failed, cannot continue testing'; } -plan tests => 534; +plan tests => 535; isnt ($dbh, undef, 'Connect to database for database handle method testing'); @@ -103,9 +103,18 @@ eval { }; like ($@, qr{last_insert_id}, $t); +$SQL = 'CREATE TEMP TABLE foobar AS SELECT * FROM pg_class LIMIT 3'; + $t='DB handle method "do" returns correct count with CREATE AS SELECT'; $dbh->rollback(); -$result = $dbh->do('CREATE TEMP TABLE foobar AS SELECT * FROM pg_class LIMIT 3'); +$result = $dbh->do($SQL); +$expected = $pgversion >= 90000 ? 3 : '0E0'; +is ($result, $expected, $t); + +$t='DB handle method "execute" returns correct count with CREATE AS SELECT'; +$dbh->rollback(); +$sth = $dbh->prepare($SQL); +$result = $sth->execute(); $expected = $pgversion >= 90000 ? 3 : '0E0'; is ($result, $expected, $t); -- 1.7.1