Through some experimenting, I've determined that when you pass a string to DBD::Oracle, it uses Perl's internal representation of the string. For example:
use DBI;
my $dbi = DBI->connect(...);
sub select_scalar {
my ($dbi, $sql) = @_;
my $sth = $dbi->prepare($sql);
$sth->execute();
my $r = $sth->fetch_row_array();
return $r->[0];
}
my $q1 = "select 1 from dual where 'ä' = chr(228)";
my $q2 = $q1.chr(1024);
chop($q2);
print "q1 eq q2? ", ($q1 eq $q2 ? "yes" : "no"), "\n";
my $r1 = select_scalar($dbi, $q1);
print "r1 = $r1\n";
my $r2 = select_scalar($dbi, $q2);
print "r2 = $r2\n";
This will emit:
q1 eq q2? yes
r1 = 1
r2 =
So, even though q1 and q2 are the same Perl string (character by character), they are different when passed to DBD::Oracle. A fix would be to use Encode::encode('iso-8859-1', ...) on every string passed to DBD::Oracle (query strings as well as values for ? place holders.)
My question: is there another (read 'better') way to do this? I'm using perl 5.8.0 and OCI version 8.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.