Backslash quoting - Bug in DBI:CSV driver?
From: Steffen G. (steffen_at_konzeptloses.de)
Date: 10/24/04
- Previous message: Ron Savage: "Re: binding multiple values and retain blanks"
- Next in thread: Jeff: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Reply: Jeff: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: dbi-users@perl.org Date: Sun, 24 Oct 2004 11:28:33 +0200
Hi there,
I have a problem with quoting of backslashes when using DBI:CSV.
To be precise:
I insert a string containing a backslash into my database, and when I read
it out again, the backslash is doubled.
Please have a look at this sample code:
~~~~~
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh=DBI->connect("DBI:CSV:f_dir=./",'','');
$dbh->do('drop table test');
$dbh->do('create table test ( col1 text )');
my $val='backslash\\'; print "Input : $val\n";
$val=$dbh->quote($val); print "Quoted Input: $val\n";
$dbh->do('insert into test (col1) values ('.$val.')') or die 'Didn\'t
work!';
print "Output : ".$dbh->selectrow_array('select * from test')."\n";
~~~~~
(Attention: "drop table test" will remove the file "test"! AND it will
produce a warning if the file doesn't exist, but that doesn't matter.)
It produces the following output:
Input : backslash\
Quoted Input: 'backslash\\'
Output : backslash\\
I my opinion, the second backslash in the last line should not be there.
Indeed, when using MySQL as database (change line 4 into something like
my $dbh=DBI->connect('DBI:mysql:test','<USER>','<PASSWD>');
), the output looks like this:
Input : backslash\
Quoted Input: 'backslash\\'
Output : backslash\
Is this a bug in the DBI:CSV driver (DBD::File, DBD::CSV, Text::CSV_XS ?) -
or what am I doing wrong?
Thanks
Steffen
- Previous message: Ron Savage: "Re: binding multiple values and retain blanks"
- Next in thread: Jeff: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Reply: Jeff: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|