On Monday, November 25, 2002, at 03:57 PM, David Wheeler wrote:
Here's the patch. I would appreciate any feedback. I had to alter quote() quite a bit again, as it seems that DBD::Pg's quote() method is never invoked byIf it doesn't work then yes (if $h->{Warn} is set, see Driver.xst for examples).
Okay, I'll try to work up that patch tonight.
$dbh->quote($val, DBI_SQL_BINARY);
But only by
$dbh->quote($val, { TYPE => DBI_SQL_BINARY });
Tim, I had been under the impression that if a driver overrides quote() that it will always be called.
Anyway, I also added the warning to dbd_bind_ph() and I added tests for both of these changes.
I think that once this is figured out, we'll be ready to release a new rev of DBD::Pg.
Thanks,
David
--
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: [EMAIL PROTECTED]
Index: Pg.pm
===================================================================
RCS file: /usr/local/cvsroot/dbdpg/dbdpg/Pg.pm,v
retrieving revision 1.9
diff -u -r1.9 Pg.pm
--- Pg.pm 26 Nov 2002 04:22:50 -0000 1.9
+++ Pg.pm 26 Nov 2002 18:07:20 -0000
@@ -114,6 +114,7 @@
{ package DBD::Pg::db; # ====== DATABASE ======
use strict;
+ use Carp ();
sub prepare {
my($dbh, $statement, @attribs)= @_;
@@ -752,14 +753,26 @@
);
# Set up lookup for SQL types we don't want to escape.
- my @no_escape = map { $_ => 1 }
+ my %no_escape = map { $_ => 1 }
DBI::SQL_INTEGER, DBI::SQL_SMALLINT, DBI::SQL_DECIMAL,
DBI::SQL_FLOAT, DBI::SQL_REAL, DBI::SQL_DOUBLE, DBI::SQL_NUMERIC;
sub quote {
my ($dbh, $str, $data_type) = @_;
return "NULL" unless defined $str;
- return $str if $data_type && $no_escape[$data_type];
+ $data_type = $data_type->{TYPE} if defined $data_type && ref $data_type;
+ return $str if $data_type && $no_escape{$data_type};
+
+ if ($data_type && $data_type == DBI::SQL_BINARY) {
+ # We don't support SQL_BINARY.
+ my $msg = "Use of SQL_BINARY invalid in quote()";
+ unless ($dbh->FETCH('HandleError') &&
+ !$dbh->FETCH('HandleError')->($msg, $dbh)) {
+ Carp::croak($msg) if $dbh->FETCH('RaiseError');
+ Carp::carp ($msg) if $dbh->FETCH('PrintError');
+ }
+ }
+
$str =~ s/(['\\\0])/$esc{$1}/g;
return "'$str'";
}
Index: dbdimp.c
===================================================================
RCS file: /usr/local/cvsroot/dbdpg/dbdpg/dbdimp.c,v
retrieving revision 1.6
diff -u -r1.6 dbdimp.c
--- dbdimp.c 25 Nov 2002 22:52:20 -0000 1.6
+++ dbdimp.c 26 Nov 2002 18:07:24 -0000
@@ -1058,6 +1058,10 @@
}
}
if (sql_type) {
+ /* SQL_BINARY (-2) is deprecated. */
+ if (sql_type == -2 && DBIc_WARN(imp_sth)) {
+ warn("Use of SQL type SQL_BINARY (%d) is deprecated. Use { pg_type =>
+DBD::Pg::PG_BYTEA } instead.", sql_type);
+ }
phs->ftype = pg_sql_type(imp_sth, phs->name, sql_type);
}
} /* was first bind for this placeholder */
Index: t/03bind.t
===================================================================
RCS file: /usr/local/cvsroot/dbdpg/dbdpg/t/03bind.t,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 03bind.t
--- t/03bind.t 15 Oct 2002 19:20:20 -0000 1.1.1.1
+++ t/03bind.t 26 Nov 2002 18:07:24 -0000
@@ -11,7 +11,7 @@
sub main {
my ($n, $dbh, $sth);
- print "1..5\n";
+ print "1..6\n";
$n = 1;
@@ -46,7 +46,23 @@
$sth->finish();
print "ok $n\n"; $n++;
-
+
+ # Make sure that we get warnings when we try to use SQL_BINARY.
+ {
+ local $SIG{__WARN__} =
+ sub { print $_[0] =~ /^Use of SQL type SQL_BINARY/ ?
+ "ok $n\n" : "no ok $n\n"; $n++
+ };
+
+ $sth = $dbh->prepare(q{
+ SELECT id
+ , name
+ FROM test
+ WHERE id = ?
+ AND name = ?
+ });
+ $sth->bind_param(1, 'foo', DBI::SQL_BINARY);
+ }
$dbh->disconnect();
print "ok $n\n"; $n++;
Index: t/11quoting.t
===================================================================
RCS file: /usr/local/cvsroot/dbdpg/dbdpg/t/11quoting.t,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 11quoting.t
--- t/11quoting.t 15 Oct 2002 19:20:20 -0000 1.1.1.1
+++ t/11quoting.t 26 Nov 2002 18:07:24 -0000
@@ -1,3 +1,4 @@
+#!perl -w
if (!exists($ENV{DBDPG_MAINTAINER})) {
print "1..0\n";
exit;
@@ -19,12 +20,11 @@
, ["\\'?:", sprintf("'\\%03o\\%03o?:'", ord("\\"), ord("'"))]
);
- print "1..7\n";
+ print "1..8\n";
$n = 1;
-
- $dbh =
DBI->connect("dbi:Pg:dbname=$ENV{DBDPG_TEST_DB};host=$ENV{DBDPG_TEST_HOST}",
$ENV{DBDPG_TEST_USER}, $ENV{DBDPG_TEST_PASS}, {RaiseError => 1, AutoCommit => 0});
+ $dbh =
+DBI->connect("dbi:Pg:dbname=$ENV{DBDPG_TEST_DB};host=$ENV{DBDPG_TEST_HOST}",
+$ENV{DBDPG_TEST_USER}, $ENV{DBDPG_TEST_PASS}, {RaiseError => 1, AutoCommit => 0});
print "ok $n\n"; $n++;
for (@tests) {
@@ -42,6 +42,11 @@
print "ok $n\n"; $n++;
}
+ # Make sure that SQL_BINARY doesn't work.
+ eval { $dbh->quote('foo', { TYPE => DBI::SQL_BINARY })};
+# eval { $dbh->quote('foo', DBI::SQL_BINARY)};
+ print $@ ? "ok $n\n" : "not ok $n\n"; $n++;
+
$dbh->disconnect();
print "ok $n\n"; $n++;
