Thanks for the reply, Tim. On Tuesday, November 26, 2002, at 04:53 PM, Tim Bunce wrote:
Didn't even need to. I have no idea why I thought it wasn't working this morning, but now it is. Only think I can think of is that I didn't run make again before running the tests. To which I say, "duh."$dbh->quote($val, DBI_SQL_BINARY);(Which is correct per the spec.)(Which is wrong.)But only by $dbh->quote($val, { TYPE => DBI_SQL_BINARY });
Check again. It makes no sense that they would invoke different methods.
Use trace.
The error handling is wrong. Replace the whole unless(){} with just
$h->DBI::set_err(1, "Use of SQL_BINARY invalid in quote()");
As per "Error handling" section of DBI::DBD docs.
(Generaly if you write a chunk of code and think "this ought to be
easier" it generally is. Or if it isn't then I'll make it so :-)
Oh, duh again! I've even used that before, but forgot all about it,
borrowing instead from the patch I just sent. Thanks for the tip.I'm committing the enclosed patch.
Regards,
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.12
diff -u -r1.12 Pg.pm
--- Pg.pm 26 Nov 2002 17:15:41 -0000 1.12
+++ Pg.pm 27 Nov 2002 01:40:14 -0000
@@ -114,6 +114,7 @@
{ package DBD::Pg::db; # ====== DATABASE ======
use strict;
+ use Carp ();
sub prepare {
my($dbh, $statement, @attribs)= @_;
@@ -752,14 +753,18 @@
);
# 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];
+ return $str if $data_type && $no_escape{$data_type};
+
+ $dbh->DBI::set_err(1, "Use of SQL_BINARY invalid in quote()")
+ if $data_type && $data_type == DBI::SQL_BINARY;
+
$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 27 Nov 2002 01:40:18 -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 27 Nov 2002 01:40:18 -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 27 Nov 2002 01:40:18 -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,
+PrintError => 0});
print "ok $n\n"; $n++;
for (@tests) {
@@ -42,6 +42,12 @@
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 $@ && $@ =~ /Use of SQL_BINARY invalid in quote/ ?
+ "ok $n\n" : "not ok $n\n"; $n++;
+
$dbh->disconnect();
print "ok $n\n"; $n++;
