Hi
I have a problem with text containing newline characters when using DBI:CSV.
I put in a string containing a newline and I get back a string containing
"\n".
Please have a look at this sample code:
~~~
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh=DBI->connect('DBI:CSV:f_dir=./db;csv_eol='."\n",'','');
$dbh->do('create table test ( col1 text )');
my $val="New\nline"; print "Input : $val\n";
$val=$dbh->quote($val); print "Quoted Input: $val\n";
$dbh->do('insert into test (col1) values ('.$val.')');
print "Output : ".$dbh->selectrow_array('select * from test')."\n";
~~~
The ouput looks like this:
Input : New
line
Quoted Input: 'New\nline'
Output : New\nline
Using a MySQL database, it looks like it - I think - should be:
Input : New
line
Quoted Input: 'New\nline'
Output : New
line
What am I doing wrong?
As this problem is similar to a bug I've found few months ago, which Jeff
could fix by adding a line in SQL::Parser (thanks again), I looked for a
similar solution, and indeed, adding these lines...
@$fields = map { s/([^\\])\\r/$1\r/g; $_ } @$fields;
@$fields = map { s/([^\\])\\n/$1\n/g; $_ } @$fields;
... in SQL::Parser, line 1748, will work for the example above.
But as it will fail when having a string like "\\\n", its just a dirty
workaround...
Thanks
Steffen