Hello All,
I am trying to insert data in TEXT field in Latin1 PostgreSQL database using
Perl 5.8.4, DBI 1.48, DBD::Pg 1.42 on Debian (kernel 2.6.8).
The table name ($tblname) I get from XML parser and it has UTF8 flag turned
on. This causes the whole statement ($insdata1, $insdata2) to have the UTF8
flag on (data itself as a variable has the utf8 flag off).
When I use :
---------------------------------------------------------------------------------------------------------------
my $insdata2="Insert into $tblname (ext_name, last_change_dt) values (?,?)";
my $sth2=$dbh->prepare($insdata2);
$sth2->execute($arr[0],$apiis->now);
---------------------------------------------------------------------------------------------------------------
data is correctly entered into the database, (ext_name: "Höl|Hölty").
However, when I use the following code:
---------------------------------------------------------------------------------------------------------------
my $data=$dbh->quote($arr[0]);
my $now=$dbh->quote($apiis->now);
my $insdata1="Insert into $tblname (ext_name,last_change_dt) values ($data,
$now)";
my $sth1=$dbh->prepare($insdata1);
$sth1->execute;
---------------------------------------------------------------------------------------------------------------
I get into database ext_name: "Höl|Hölty", which looks like byte sequence.
Shouldn't both snippets produce the same result?
What is the best practice in case I get data from utf8 and Latin1 sources- to
use Encode::encode_utf8($tblname)?
Bellow are the Dumps of the $insdata1:
---------------------------------------------------------------------------------------------------------------
SV = PVMG(0x8b3d828) at 0x863af68
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8)
IV = 0
NV = 0
PV = 0x8b84468 "Insert into naming (ext_name,last_change_dt) values
('H\303\266l|H\303\266lty','2005-10-10 15:26:43')"\0 [UTF8 "Insert into
naming (ext_name,last_change_dt) values ('H\x{f6}l|H\x{f6}lty','2005-10-10
15:26:43')"]
CUR = 89
LEN = 90
MAGIC = 0x8b29570
MG_VIRTUAL = &PL_vtbl_utf8
MG_TYPE = PERL_MAGIC_utf8(w)
MG_LEN = 87
---------------------------------------------------------------------------------------------------------------
and $insdata2:
---------------------------------------------------------------------------------------------------------------
SV = PVMG(0x8b85778) at 0x863b088
REFCNT = 1
FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8)
IV = 0
NV = 0
PV = 0x8b39d28 "Insert into naming (ext_name, last_change_dt) values
(?,?)"\0 [UTF8 "Insert into naming (ext_name, last_change_dt) values (?,?)"]
CUR = 58
LEN = 59
MAGIC = 0x8b343f0
MG_VIRTUAL = &PL_vtbl_utf8
MG_TYPE = PERL_MAGIC_utf8(w)
MG_LEN = 58
---------------------------------------------------------------------------------------------------------------
and $arr[0]:
---------------------------------------------------------------------------------------------------------------
SV = PV(0x8b616f4) at 0x8b5c4e4
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x8b2b568 "H\366l|H\366lty"\0
CUR = 9
LEN = 10
---------------------------------------------------------------------------------------------------------------
Thanks in advance
Zhivko Duchev