A. you probably want to write "use utf8;" in your perl program whenever
you deal with utf8 texts. I would guess that your use of binmode forces
reading of utf8 characters properly from the file, but when you embed
them in a string for the DBD access, it can get messed up.
B. using parameterized queries instead of directly embedding the texts
into your SQL statement may also help, in addition to being safe against
SQL injection attacks.

On Mon, 2009-08-03 at 13:39 +0300, Nicky Pappo wrote: 
> Hi, 
> I am trying to read a file (Hebrew characters), and store data from it
> thought DBI into SQL server. 
> Characters are garbaged after the Insert command. 
> Any ideas? 
> 
> Thanks Nicky Pappo
> [email protected]
> 
> 
> Here the relevant piece from the code: 
> 
> 
> #!/usr/bin/perl
> 
> use strict;
> use DBI;
> 
> 
> my $dbconnect="SQLEXPRESS";  #the odbc connection
> my $paramvalue = "";
> my $filename="1";
> my $paramtype="type"; 
> my $sqlstatement;
> 
> open(DAT, "test.txt" ) || die("Could not open file!");
> binmode DAT, ":utf8";
> while (<DAT>){
>     $paramvalue .= $_;
> }
> 
> 
> my $dbh = DBI->connect("dbi:ODBC:$dbconnect");
> 
> 
> $sqlstatement= "insert into parameters
> (filename,ParameterType,ParameterValue)
> values('$filename','$paramtype',N'$paramvalue')"; 
> #setUTF8($sqlstatement);
> my $sth = $dbh->prepare($sqlstatement);
> $sth->execute();


_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to