Author: turnstep
Date: Mon Oct 13 21:05:28 2008
New Revision: 11978
Modified:
DBD-Pg/trunk/Changes
DBD-Pg/trunk/Pg.pm
DBD-Pg/trunk/dbdimp.c
DBD-Pg/trunk/t/02attribs.t
Log:
Have ParamTypes return 'TYPE' whenever possible, and fall back to 'pg_type'.
Modified: DBD-Pg/trunk/Changes
==============================================================================
--- DBD-Pg/trunk/Changes (original)
+++ DBD-Pg/trunk/Changes Mon Oct 13 21:05:28 2008
@@ -1,5 +1,9 @@
('GSM' is Greg Sabino Mullane, [email protected])
+2.11.1 Released October 14, 2008
+
+ - $sth->{ParamTypes} returns 'TYPE' when possible.
+
2.11.0 Released October 13, 2008 (subversion r11976)
- $sth->{ParamTypes} now returns a hashref per the DBI docs. [GSM]
Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm (original)
+++ DBD-Pg/trunk/Pg.pm Mon Oct 13 21:05:28 2008
@@ -3629,9 +3629,10 @@
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. 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.
+pair, in which the key is either 'TYPE' if the type has a generic SQL equivalent, and 'pg_type' if the type can
+only be expressed by a Postgres type. 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 Mon Oct 13 21:05:28 2008
@@ -922,7 +922,12 @@
}
else {
HV *pvhv2 = newHV();
- (void)hv_store(pvhv2, "pg_type", 7, newSViv(currph->bind_type->type_id), 0);
+ if (currph->bind_type->type.sql) {
+ (void)hv_store(pvhv2, "TYPE", 4, newSViv(currph->bind_type->type.sql), 0);
+ }
+ else {
+ (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)),
newRV_noinc((SV*)pvhv2), 0);
Modified: DBD-Pg/trunk/t/02attribs.t
==============================================================================
--- DBD-Pg/trunk/t/02attribs.t (original)
+++ DBD-Pg/trunk/t/02attribs.t Mon Oct 13 21:05:28 2008
@@ -18,7 +18,7 @@
if (! defined $dbh) {
plan skip_all => 'Connection to database failed, cannot continue testing';
}
-plan tests => 248;
+plan tests => 249;
isnt ($dbh, undef, 'Connect to database for handle attributes testing');
@@ -852,7 +852,7 @@
$sth->bind_param(1, 1, SQL_INTEGER);
$sth->bind_param(2, 'TMW', SQL_VARCHAR);
$attrib = $sth->{ParamTypes};
-$expected = {1 => {pg_type => 23}, 2 => {pg_type => 1043}, 3 => undef};
+$expected = {1 => {TYPE => SQL_INTEGER}, 2 => {TYPE => SQL_VARCHAR}, 3 => undef};
is_deeply ($attrib, $expected, $t);
$t='Statement handle attributes "ParamValues" and "ParamTypes" can be pased back to bind_param';
@@ -866,10 +866,10 @@
$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);
+$sth->bind_param(':foobar', 1, {pg_type => PG_INT4});
+$sth->bind_param(':foobar2', 'TMW', {pg_type => PG_TEXT});
$attrib = $sth->{ParamTypes};
-$expected = {':foobar' => {pg_type => 23}, ':foobar2' => {pg_type => 1043}, ':foobar3' => undef};
+$expected = {':foobar' => {TYPE => SQL_INTEGER}, ':foobar2' => {TYPE => SQL_LONGVARCHAR}, ':foobar3' => undef};
is_deeply ($attrib, $expected, $t);
$t='Statement handle attributes "ParamValues" and "ParamTypes" can be passed back to bind_param';
@@ -882,10 +882,16 @@
is( $@, q{}, $t);
$t='Statement handle attribute "ParamTypes" works after execute';
-$sth->bind_param(':foobar3', 3, {pg_type => PG_INT4});
+$sth->bind_param(':foobar3', 3, {pg_type => PG_INT2});
$sth->execute();
$attrib = $sth->{ParamTypes};
-$expected->{':foobar3'} = {pg_type => 23};
+$expected->{':foobar3'} = {TYPE => SQL_SMALLINT};
+is_deeply ($attrib, $expected, $t);
+
+$t='Statement handle attribute "ParamTypes" returns correct values';
+$sth->bind_param(':foobar2', 3, {pg_type => PG_CIRCLE});
+$attrib = $sth->{ParamTypes}{':foobar2'};
+$expected = {pg_type => PG_CIRCLE};
is_deeply ($attrib, $expected, $t);
#
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.