Re: Backslash quoting - Bug in DBI:CSV driver?

From: Jeff (jeff_at_vpservices.com)
Date: 10/24/04


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
>
>
>  
>


Relevant Pages

  • Re: any regex gurus out there?
    ... > No matter what number or combination of backslashes I used it didn't work. ... - The compiler wouldn't take it otherwise. ... or escape each backslash with a backslash, ... > French language, the letter A may have three different accents. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Detect illconditioned backslash () solution
    ... You could set the warning state to empty before the backslash and then ... To check for an actual error just use a try-catch block. ... No, a try-catch will not catch a warning, only an error. ...
    (comp.soft-sys.matlab)
  • Re: trying out escape characters
    ... > prints a backslash followed by a space ... Yeah, but it emits a warning. ...
    (comp.lang.perl)
  • Backslash quoting - Bug in DBI:CSV driver?
    ... I insert a string containing a backslash into my database, ... Quoted Input: 'backslash\\' ...
    (perl.dbi.users)
  • Re: subjective feelings about actions?
    ... On this occasion I thought it was worth trying unicode - but it didn't make any useful ... appears to be extremely transient no matter where it comes ... symbol onto the backslash was a good idea and say a few things>_< ...
    (sci.lang.japan)