-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
> I've been using the $dbh->quote method quite happily lately, but it raises
> some warnings which I find a bit odd. If I read the documentation correctly,
> the type which we quote is one of the :pg_types, or the :sql_types (or
> whatever) from DBI.
>
> The latter work fine, the Pg ones however will tell me this:
>
> Unknown type 1043, defaulting to UNKNOWN at wherever.pl
> Unknown type 17, defaulting to UNKNOWN at wherever.pl
> $ean = DBH->quote($ean, PG_VARCHAR);
> $artist = defined $artist ? DBH->quote($artist, PG_VARCHAR) : 'NULL';
> $title = DBH->quote($title, PG_VARCHAR);
> (Also, it would be cool if the quote function returned an apostrophe-less
> NULL
> if it encounters an undef value :) Or is there a reason why it doesn't do
>
> that?)
>
You need to let the quote method know that these are Postgres constants, and
not sql ones. Because there could be overlap in the numbers, you cannot simply
pass in the Postgres ones directly. Also, NULL quoting should work as expected.
Example follows (note using $dbh not DBH):
my $ean = 'Foobar';
my $res = $dbh->quote($ean, {pg_type => PG_VARCHAR});
print "Res is ($res)\n";
$ean = q{What's happening};
$res = $dbh->quote($ean, {pg_type => PG_VARCHAR});
print "Res is ($res)\n";
$ean = undef;
$res = $dbh->quote($ean, {pg_type => PG_VARCHAR});
print "Res is ($res)\n";
Output:
Res is ('Foobar')
Res is ('What''s happening')
Res is (NULL)
- --
Greg Sabino Mullane [email protected]
End Point Corporation
PGP Key: 0x14964AC8 200909151126
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
iEYEAREDAAYFAkqvslgACgkQvJuQZxSWSsj3IgCgxK64FVaw/28fmRh6cBKO/Wmf
ZgYAnjjxbH8RjzA4r8hTVzADQDomFOc0
=ktK1
-----END PGP SIGNATURE-----