Backslash quoting - Bug in DBI:CSV driver?

From: Steffen G. (steffen_at_konzeptloses.de)
Date: 10/24/04

  • Next message: Jeff: "Re: Backslash quoting - Bug in DBI:CSV driver?"
    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


  • Next message: Jeff: "Re: Backslash quoting - Bug in DBI:CSV driver?"

    Relevant Pages

    • Re: String variable read from Mysql DB + echo = Newline problem
      ... The string already has single backslash in the database. ... And BTW - you cannot exactly control formatting on the user's browser. ...
      (comp.lang.php)
    • Re: Backslash quoting - Bug in DBI:CSV driver?
      ... > produce a warning if the file doesn't exist, but that doesn't matter.) ... >it out again, the backslash is doubled. ...
      (perl.dbi.users)
    • Re: String variable read from Mysql DB + echo = Newline problem
      ... The string already has single backslash in the database. ... Then PHP does some funkyness to the string ...
      (comp.lang.php)
    • Re: gfortran diagnostics and so on
      ... Well, in f0003, backslash is part of the standard Fortran character set. ... Because the backslash is part of the standard Fortran character set, the default behavior should be the printable character, **NOT** some kind of magic introductory character that transforms the interpretation of following character. ... The one I like best is to use one of the popular extensions to designate a particular literal string according to the C language. ...
      (comp.lang.fortran)
    • Re: Double backslashes \ in strings
      ... and the single backslash isn't ... The simplest way to specify a string is to enclose it in single quotes. ... echo ''; ...
      (comp.lang.php)