Re: Backslash quoting - Bug in DBI:CSV driver?
From: Jeff (jeff_at_vpservices.com)
Date: 10/24/04
- Next message: Steffen G.: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Previous message: Steffen G.: "Backslash quoting - Bug in DBI:CSV driver?"
- In reply to: Steffen G.: "Backslash quoting - Bug in DBI:CSV driver?"
- Next in thread: Steffen G.: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Reply: Steffen G.: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 24 Oct 2004 10:43:52 +0000 To: "Steffen G." <steffen@konzeptloses.de>
Steffen G. wrote:
> (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.)
I think that is as it should be. Attempting to drop a non-existant table should produce an error. If you don't want to see the error, then either use the MySQL-like syntax "DROP TABLE IF EXISTS foo" or else wrap the DROP statement in an eval.
> I my opinion, the second backslash in the last line should not be there.
> ...
> Is this a bug in the DBI:CSV driver (DBD::File, DBD::CSV, Text::CSV_XS ?) -
> or what am I doing wrong?
LOL, you're right there is a bug, and those are good guesses about where it occurs, but all wrong :-). The bug is acutally in SQL::Parser!
Adding this line before line 1748 of SQL::Parser should fix it. I'll add it to the next version.
@$fields = map { s/\\\\/\\/g; $_ } @$fields;
Thanks for finding this.
--
Jeff
>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
>
>
>
>
- Next message: Steffen G.: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Previous message: Steffen G.: "Backslash quoting - Bug in DBI:CSV driver?"
- In reply to: Steffen G.: "Backslash quoting - Bug in DBI:CSV driver?"
- Next in thread: Steffen G.: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Reply: Steffen G.: "Re: Backslash quoting - Bug in DBI:CSV driver?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|