[DBD::Pg] Add tests and attribute handlers for $h->{switch_prepared}
dbdpg-commits-gENoVmVU/[email protected] Mon, 25 Nov 2013 21:34:49 -0500
| Newsgroups | gmane.comp.db.postgresql.dbdpg.cvs |
|---|---|
| Message-ID | <[email protected]> |
Committed by Greg Sabino Mullane <greg-O9fzpki4YnJWk0Htik3J/[email protected]> Add tests and attribute handlers for $h->{switch_prepared} --- dbdimp.c | 32 +++++++++++++++++++++++++++++++- t/02attribs.t | 1 + t/03smethod.t | 45 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/dbdimp.c b/dbdimp.c index beb07ca..dc680b2 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -785,6 +785,12 @@ SV * dbd_db_FETCH_attrib (SV * dbh, imp_dbh_t * imp_dbh, SV * keysv) retsv = newSViv((IV)imp_dbh->pg_server_version); break; + case 18: /* pg_switch_prepared */ + + if (strEQ("pg_switch_prepared", key)) + retsv = newSViv((IV)imp_dbh->switch_prepared); + break; + case 25: /* pg_placeholder_dollaronly */ if (strEQ("pg_placeholder_dollaronly", key)) @@ -938,6 +944,16 @@ int dbd_db_STORE_attrib (SV * dbh, imp_dbh_t * imp_dbh, SV * keysv, SV * valuesv } break; + case 18: /* pg_switch_prepared */ + + if (strEQ("pg_switch_prepared", key)) { + if (SvOK(valuesv)) { + imp_dbh->switch_prepared = (unsigned)SvIV(valuesv); + retval = 1; + } + } + break; + case 25: /* pg_placeholder_dollaronly */ if (strEQ("pg_placeholder_dollaronly", key)) { @@ -1091,6 +1107,12 @@ SV * dbd_st_FETCH_attrib (SV * sth, imp_sth_t * imp_sth, SV * keysv) retsv = newSViv((IV)imp_sth->server_prepare); break; + case 18: /* pg_switch_prepared */ + + if (strEQ("pg_switch_prepared", key)) + retsv = newSViv((IV)imp_sth->switch_prepared); + break; + case 25: /* pg_placeholder_dollaronly */ if (strEQ("pg_placeholder_dollaronly", key)) @@ -1352,7 +1374,7 @@ int dbd_st_STORE_attrib (SV * sth, imp_sth_t * imp_sth, SV * keysv, SV * valuesv } break; - case 17: /* pg_server_prepare*/ + case 17: /* pg_server_prepare */ if (strEQ("pg_server_prepare", key)) { imp_sth->server_prepare = strEQ(value,"0") ? DBDPG_FALSE : DBDPG_TRUE; @@ -1360,6 +1382,14 @@ int dbd_st_STORE_attrib (SV * sth, imp_sth_t * imp_sth, SV * keysv, SV * valuesv } break; + case 18: /* pg_switch_prepared */ + + if (strEQ("pg_switch_prepared", key)) { + imp_sth->switch_prepared = (int)SvIV(valuesv); + retval = 1; + } + break; + case 25: /* pg_placeholder_dollaronly */ if (strEQ("pg_placeholder_dollaronly", key)) { diff --git a/t/02attribs.t b/t/02attribs.t index 5daa333..89cd943 100644 --- a/t/02attribs.t +++ b/t/02attribs.t @@ -60,6 +60,7 @@ d Warn d pg_prepare_now - tested in 03smethod.t d pg_server_prepare - tested in 03smethod.t +d pg_switch_prepared - tested in 03smethod.t d pg_prepare_now - tested in 03smethod.t d pg_placeholder_dollaronly - tested in 12placeholders.t diff --git a/t/03smethod.t b/t/03smethod.t index f3ad929..24a18e1 100644 --- a/t/03smethod.t +++ b/t/03smethod.t @@ -21,7 +21,7 @@ my $dbh = connect_database(); if (! $dbh) { plan skip_all => 'Connection to database failed, cannot continue testing'; } -plan tests => 97; +plan tests => 122; isnt ($dbh, undef, 'Connect to database for statement handle method testing'); @@ -53,6 +53,49 @@ $sth = $dbh->prepare($SQL); $sth->execute(1); ok ($sth->execute, $t); +$t='Setting database attribute pg_switch_prepared to 7 works'; +$dbh->{pg_switch_prepared} = 7; +is ($dbh->{pg_switch_prepared}, 7, $t); + +$t='Statement handle inherits pg_switch_prepared setting'; +$sth = $dbh->prepare($SQL); +is ($sth->{pg_switch_prepared}, 7, $t); + +$t='Setting statement attribute pg_switch_prepared to 6 works'; +$sth->{pg_switch_prepared} = 6; +is ($sth->{pg_switch_prepared}, 6, $t); + +$t='Running with statement attribute pg_switch_prepared at 6 works'; +for (1..10) { + $sth->execute(1); + my $it = "$t (run $_ of 10)"; + ok ($sth->execute, $it); +} + +$t='Running with statement attribute pg_switch_prepared at -1 works'; +$sth->{pg_switch_prepared} = -1; +for (1..4) { + $sth->execute(1); + my $it = "$t (run $_ of 4)"; + ok ($sth->execute, $it); +} + +$t='Running with statement attribute pg_switch_prepared at 0 works'; +$sth->{pg_switch_prepared} = 0; +for (1..4) { + $sth->execute(1); + my $it = "$t (run $_ of 4)"; + ok ($sth->execute, $it); +} + +$t='Running with statement attribute pg_switch_prepared at 1 works'; +$sth->{pg_switch_prepared} = 1; +for (1..4) { + $sth->execute(1); + my $it = "$t (run $_ of 4)"; + ok ($sth->execute, $it); +} + ## 7.4 does not have a full SSP implementation, so we simply skip these tests. if ($pglibversion < 80000) { SKIP: { -- 1.8.4