Subject: | DBD::Oracle Bug: ora_charset lost in second database connection |
Date: | Mon, 12 Dec 2011 20:05:24 +0100 |
To: | bug-DBD-Oracle [...] rt.cpan.org |
From: | Peter Albrecht <peter [...] crazymonkeys.de> |
Hello developers,
++ Brief problem description
ora_charset lost in second database connection
++ Detailed problem description
I connect to a database, using a certain character set (AL32UTF8) at
client side. Then I execute a SELECT-statement and process the results.
Everything fine so far.
Then I disconnect and immediately do the same connect again. A following
SELECT (same statement as above) returns successfully, but the german
"Umlaute" in my case are broken:
Instead of "München" I get "Munchen". Value "0x75" instead of "U+00FC".
++ Reproduce
+++ Prepare DB
---------------------------------- 8< ----------------------------------
CREATE TABLE CITIES ( ID NUMBER, TEXT VARCHAR2(64) );
INSERT INTO "CITIES" (ID, TEXT) VALUES ('1', 'Berlin');
INSERT INTO "CITIES" (ID, TEXT) VALUES ('2', 'München');
INSERT INTO "CITIES" (ID, TEXT) VALUES ('3', 'Hamburg');
---------------------------------- >8 ----------------------------------
+++ Test-program
---------------------------------- 8< ----------------------------------
#!/bin/perl
use Devel::Peek;
use DBI;
getData();
getData();
sub getData{
# TODO: set connection parameters for your db
my $dbh = DBI->connect(
"dbi:Oracle:host=$host;sid=$sid;port=$port", $dbUser, $dbPassword,
{
ora_charset => 'AL32UTF8',
# ora_verbose => 6,
}
);
my $sth = $dbh->prepare("SELECT TEXT FROM CITIES WHERE id = '2'");
$sth->execute();
my $data = $sth->fetchrow_hashref();
Dump($data->{TEXT});
# SELECT should find one data record, so this second fetch should close $sth
$sth->fetchrow_hashref();
$dbh->disconnect();
}
---------------------------------- >8 ----------------------------------
+++ Test-program output
Actual output:
---------------------------------- 8< ----------------------------------
SV = PV(0x8429c7c) at 0x84406b4
REFCNT = 1
FLAGS = (POK,pPOK,UTF8)
PV = 0x854f574 "M\303\274nchen"\0 [UTF8 "M\x{fc}nchen"]
CUR = 8
LEN = 12
SV = PV(0x8429c7c) at 0x84406e4
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x854f614 "Munchen"\0
CUR = 7
LEN = 8
---------------------------------- >8 ----------------------------------
Expected output:
---------------------------------- 8< ----------------------------------
...
PV = 0x854f574 "M\303\274nchen"\0 [UTF8 "M\x{fc}nchen"]
...
PV = 0x854f574 "M\303\274nchen"\0 [UTF8 "M\x{fc}nchen"]
...
---------------------------------- >8 ----------------------------------
+++ Additional Debug Output
Setting "ora_verbose = 6" at connect time show the following output:
at first connect
...
OCIAttrGet(##adr##,OCI_HTYPE_ENV,b744348e,0,262,##adr##)=SUCCESS
charset id=873, name=AL32UTF8, ncharset id=1, name=US7ASCII (csid: utf8=871 al32utf8=873)
...
at second connect
...
OCIAttrSet(0,OCI_HTYPE_SESSION, b7439dd2,7,Attr=OCI_ATTR_DRIVER_NAME,0)=INVALID_HANDLE
...
OCIAttrGet(##adr##,OCI_HTYPE_ENV,b744348e,0,262,##adr##)=SUCCESS
charset id=1, name=US7ASCII, ncharset id=1, name=US7ASCII (csid: utf8=871 al32utf8=873)
...
++ Used components and versions
DBD::Oracle: v1.34 (also broken in v1.28; worked in v1.27)
Perl: v5.10.0 built for i586-linux-thread-multi
Operation System: SUSE Linux Enterprise Server 11 (i586), PL 1
Oracle Instant Client:
oracle-instantclient11.2-sqlplus-11.2.0.1.0-1
oracle-instantclient11.2-devel-11.2.0.1.0-1
oracle-instantclient11.2-basic-11.2.0.1.0-1
Oracle database: 11g (11.2.0.1.0)
Kind regards,
Peter Albrecht