Author: turnstep
Date: Sun Oct 12 17:13:00 2008
New Revision: 11972
Modified:
DBD-Pg/trunk/.perlcriticrc
DBD-Pg/trunk/Changes
DBD-Pg/trunk/Pg.pm
DBD-Pg/trunk/dbdimp.c
DBD-Pg/trunk/t/02attribs.t
DBD-Pg/trunk/t/99_spellcheck.t
Log:
Make $sth->{ParamTypes} conform to the spec.
Modified: DBD-Pg/trunk/.perlcriticrc
==============================================================================
--- DBD-Pg/trunk/.perlcriticrc (original)
+++ DBD-Pg/trunk/.perlcriticrc Sun Oct 12 17:13:00 2008
@@ -2,7 +2,7 @@
profile-strictness = quiet
[Documentation::PodSpelling]
-stop_words = ActiveKids AutoCommit boolean Bunce CachedKids ChildHandles
ChopBlanks CompatMode CursorName DBD DBI Datatype dbdpg enum ErrCount
FetchHashKeyName HandleError HandleSetErr InactiveDestroy LongReadLen
LongTruncOk Mergl Momjian Mullane NULLABLE OID ParamValues ParamTypes PgBouncer
pgend pglibpq pglogin pgprefix pgquote pgstart PGSERVICE PGSYSCONFDIR perl
Postgres PostgreSQL PrintError PrintWarn README RaiseError RowCache
RowCacheSize RowsInCache SQL SQLSTATE SSL STDIN STDERR STDOUT Sabino Savepoints
ShowErrorStatement TaintIn TaintOut TraceLevel UTF Username afterwards
arrayrefs attr autocommit backend bitmask bytea cancelled datatype dbd dbh
errstr fd filename getfd getline hashref largeobject len libpq lseg pgbuiltin
pgsql runtime savepoint savepoints schemas sslmode tablename tablespace
tablespaces tuple typename username varchar undef Perlish arrayref datatypes
bool func PID dr ReadOnly nullable
+stop_words = ActiveKids AutoCommit boolean Bunce CachedKids ChildHandles
ChopBlanks CompatMode CursorName DBD DBI Datatype dbdpg enum ErrCount
FetchHashKeyName HandleError HandleSetErr InactiveDestroy LongReadLen
LongTruncOk Mergl Momjian Mullane NULLABLE OID ParamValues ParamTypes PgBouncer
pgend pglibpq pglogin pgprefix pgquote pgstart PGSERVICE PGSYSCONFDIR perl
Postgres PostgreSQL PrintError PrintWarn README RaiseError RowCache
RowCacheSize RowsInCache SQL SQLSTATE SSL STDIN STDERR STDOUT Sabino Savepoints
ShowErrorStatement TaintIn TaintOut TraceLevel UTF Username afterwards
arrayrefs attr autocommit backend bitmask bytea cancelled datatype dbd dbh
errstr fd filename getfd getline hashref largeobject len libpq lseg pgbuiltin
pgsql runtime savepoint savepoints schemas sslmode tablename tablespace
tablespaces tuple typename username varchar undef Perlish arrayref datatypes
bool func PID dr ReadOnly nullable hashrefs
[-Bangs::ProhibitCommentedOutCode]
[-Bangs::ProhibitFlagComments]
Modified: DBD-Pg/trunk/Changes
==============================================================================
--- DBD-Pg/trunk/Changes (original)
+++ DBD-Pg/trunk/Changes Sun Oct 12 17:13:00 2008
@@ -1,7 +1,8 @@
('GSM' is Greg Sabino Mullane, [EMAIL PROTECTED])
-2.10.8
+2.11.0 Released October, 2008
+ - $sth->{ParamTypes} now returns a hashref per the DBI docs. [GSM]
- Adjustment of Makefile.PL to fix problem with Strawberry Perl.
Thanks to Martin Evan ([EMAIL PROTECTED]) and Brian
([EMAIL PROTECTED]) on the dbi-users list.
Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm (original)
+++ DBD-Pg/trunk/Pg.pm Sun Oct 12 17:13:00 2008
@@ -3237,7 +3237,7 @@
use DBI qw(:sql_types);
This will import some constants into your script. You can plug those
-directly into the C<bind_param> call. Some common ones that you will
+directly into the L</bind_param> call. Some common ones that you will
encounter are:
SQL_INTEGER
@@ -3247,7 +3247,7 @@
use DBD::Pg qw(:pg_types);
You can then set the data types by setting the value of the C<pg_type>
-key in the hash passed to C<bind_param>.
+key in the hash passed to L</bind_param>.
The current list of Postgres data types exported is:
PG_ABSTIME PG_ABSTIMEARRAY PG_ACLITEM PG_ACLITEMARRAY PG_ANY PG_ANYARRAY
@@ -3628,8 +3628,10 @@
=head3 B<ParamTypes> (hash ref, read-only)
Returns a reference to a hash containing the type names currently bound to
placeholders. The keys
-are the same as returned by the ParamValues method. Placeholders that have not
yet been bound will return
-undef as the value.
+are the same as returned by the ParamValues method. The values are hashrefs
containing a single key value
+pair, in which the key is always 'pg_type' and the value is the internal
number corresponding to the
+type originally passed in. (Placeholders that have not yet been bound will
return undef as the value). This
+allows the output of ParamTypes to be passed back to the L</bind_param> method.
=head3 B<Statement> (string, read-only)
Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c (original)
+++ DBD-Pg/trunk/dbdimp.c Sun Oct 12 17:13:00 2008
@@ -921,9 +921,11 @@
newSV(0), 0);
}
else {
+ HV *pvhv2 = newHV();
+ (void)hv_store(pvhv2, "pg_type", 7,
newSViv(currph->bind_type->type_id), 0);
(void)hv_store_ent
(pvhv,
(3==imp_sth->placeholder_type ? newSVpv(currph->fooname,0) : newSViv(i+1)),
-
newSVpv(currph->bind_type->type_name,0),0);
+ newRV_noinc((SV*)pvhv2), 0);
}
}
retsv = newRV_noinc((SV*)pvhv);
Modified: DBD-Pg/trunk/t/02attribs.t
==============================================================================
--- DBD-Pg/trunk/t/02attribs.t (original)
+++ DBD-Pg/trunk/t/02attribs.t Sun Oct 12 17:13:00 2008
@@ -18,7 +18,7 @@
if (! defined $dbh) {
plan skip_all => 'Connection to database failed, cannot continue
testing';
}
-plan tests => 245;
+plan tests => 248;
isnt ($dbh, undef, 'Connect to database for handle attributes testing');
@@ -846,19 +846,46 @@
# Test of the statement handle attribute "ParamTypes"
#
+
$t='Statement handle attribute "ParamTypes" works before execute';
$sth = $dbh->prepare('SELECT id FROM dbd_pg_test WHERE id=? AND val=? AND
lii=?');
$sth->bind_param(1, 1, SQL_INTEGER);
$sth->bind_param(2, 'TMW', SQL_VARCHAR);
$attrib = $sth->{ParamTypes};
-$expected = {1 => 'int4', 2 => 'varchar', 3 => undef};
+$expected = {1 => {pg_type => 23}, 2 => {pg_type => 1043}, 3 => undef};
+is_deeply ($attrib, $expected, $t);
+
+$t='Statement handle attributes "ParamValues" and "ParamTypes" can be pased
back to bind_param';
+eval {
+ my $vals = $sth->{ParamValues};
+ my $types = $sth->{ParamTypes};
+ $sth->bind_param($_, $vals->{$_}, $types->{$_} )
+ for keys %$types;
+};
+is( $@, q{}, $t);
+
+$t='Statement handle attribute "ParamTypes" works before execute with named
placeholders';
+$sth = $dbh->prepare('SELECT id FROM dbd_pg_test WHERE id=:foobar AND
val=:foobar2 AND lii=:foobar3');
+$sth->bind_param(':foobar', 1, SQL_INTEGER);
+$sth->bind_param(':foobar2', 'TMW', SQL_VARCHAR);
+$attrib = $sth->{ParamTypes};
+$expected = {':foobar' => {pg_type => 23}, ':foobar2' => {pg_type => 1043},
':foobar3' => undef};
is_deeply ($attrib, $expected, $t);
+$t='Statement handle attributes "ParamValues" and "ParamTypes" can be passed
back to bind_param';
+eval {
+ my $vals = $sth->{ParamValues};
+ my $types = $sth->{ParamTypes};
+ $sth->bind_param($_, $vals->{$_}, $types->{$_} )
+ for keys %$types;
+};
+is( $@, q{}, $t);
+
$t='Statement handle attribute "ParamTypes" works after execute';
-$sth->bind_param(3, 3, {pg_type => PG_INT4});
+$sth->bind_param(':foobar3', 3, {pg_type => PG_INT4});
$sth->execute();
$attrib = $sth->{ParamTypes};
-$expected->{3} = 'int4';
+$expected->{':foobar3'} = {pg_type => 23};
is_deeply ($attrib, $expected, $t);
#
Modified: DBD-Pg/trunk/t/99_spellcheck.t
==============================================================================
--- DBD-Pg/trunk/t/99_spellcheck.t (original)
+++ DBD-Pg/trunk/t/99_spellcheck.t Sun Oct 12 17:13:00 2008
@@ -612,6 +612,7 @@
## Pg.pm:
lseg
afterwards
+hashrefs
PGSYSCONFDIR
PGSERVICE
@@ -704,6 +705,7 @@
## types.c:
ASYNC
Autogenerate
+basename
BIGINT
BOOLOID
DESCR