amonotod wrote:

Everything works fine, provided that I my input data is not the exact
length of the destination field while containing non-printable chars.
I have for example, a varchar (255) field, into which I want to put a
string that contains 253 chars (including spaces) and two bell
characters.

I tried to replicate your problem with the script below and couldn't. The script manually creates a CSV file containing a field with an embedded bell character, then uses DBD::CSV to add another field with an embedded bell character, then uses DBD::CSV to retrieve the fields and compares their length to the original field and they're all three (original,manual insert,DBD insert) the same length and the bell character occupies only one char in all with no translation of the bell character. Does this script work for you? If not, please send me the output of perl -MDBI -e "DBI->installed_versions" if you have a new DBI or version numbers and OS info if you don't.


#!perl
use strict;
my $old = "b \7 b";
my $tbl = 'bell_csv';
my $str = <<"";
c1|c2|c3
hasbell|$old|c
nobell|d|e

open(O,">$tbl") or die $!;
print O $str;
close O;
use DBI;
my $dbh=DBI->connect('dbi:CSV(RaiseError=1):csv_sep_char=\|');
my $insert=$dbh->prepare("INSERT INTO $tbl VALUES(?,?,?)");
$insert->execute('hasbell',$old,'f');
my $query  = $dbh->prepare("SELECT c2 FROM $tbl WHERE c1='hasbell'");
$query->execute;
my $new='';
while (my $r=$query->fetch) {
    $new.=join('|',@$r)
}
printf "before : %d\nafter  : %d\n",length $old,length $new;
__END__

--
Jeff

Reply via email to