Hello,

I'm having two problems with DBD::CSV.  I am working with two comma
delimited files and to start out on the small project I need to match
names from one file to a name in the other file.  Here is the block of
code that I am using to get an idea of how many matches I have and what
is not matching:

  my $dir = "/path/to/files/";
  my $dbh = DBI->connect("DBI:CSV:f_dir=$dir;csv_eol=\n;csv_sep_char=,;")
      or die "Cannot connect: " . $DBI::errstr;

  my $sql = "Select fname, lname from customer_info";
  my $sth = $dbh->prepare($sql)
        or die "Cannot prepare $sql: " . $DBI::errstr;
  my $rc = $sth->execute
        or die "Cannot execute SQL Statement: " . $DBI::errstr;

  my ($yes,$no);

  while (my ($fname,$lname) = $sth->fetchrow)
  {
    my $name = "$fname $lname";
    my $sql2 = "Select email from order_info where name = '$name'";
                print "$sql2\n";
    my $sth2 = $dbh->prepare($sql2)
        or die "Cannot prepare $sql2: " . $DBI::errstr;
    my $rc2 = $sth2->execute
        or die "Cannot execute SQL Statement: " . $DBI::errstr;

    my $rows = $sth2->rows;

    if ($rows > 0) {
        $yes++;
        print "1\n";
    } else {
        $no++;
        print "$name\n";
    }
  }
  print "\nyes: $yes\no: $no\n";
  $sth->finish if $sth;
  $dbh->disconnect if $dbh;

On the first run I found I have one Irish man to contend with.  The
error follows but the name has been changed to protect the innocent:


Select email from order_info where name = 'Tim O'Reilly'
DBD::CSV::db prepare failed: Mismatched single quote before: 'Reilly'
Cannot prepare Select email from order_info where name = 'Tim O'Reilly':
Mismatched single quote before: 'Reilly'


So I changed the single quotes to escaped double quotes (\") as it
likely should have been in the first place but found my self with a new
error:


Select email from order_info where name = "George W. Bush"
SQL ERROR: Table '"George W' in WHERE clause not in FROM clause!

SQL ERROR: Couldn't find predicate!

SV = PVIV(0x83b86c0) at 0x82cbd48
  REFCNT = 1
  FLAGS = (PADBUSY,PADMY,ROK)
  IV = 0
  RV = 0x81eefd8
DBD::CSV::st execute failed: dbih_getcom handle
DBD::CSV::Statement=HASH(0x81eefd8) is not a DBI handle (has no magic)
at /usr/lib/perl5/site_perl/5.6.0/SQL/Statement.pm line 164.
Cannot execute SQL Statement: dbih_getcom handle
DBD::CSV::Statement=HASH(0x81eefd8) is not a DBI handle (has no magic)
at /usr/lib/perl5/site_perl/5.6.0/SQL/Statement.pm line 164.


Well, it seems that DBD::CSV thinks anything in double quote should be a
table/file. Also if I remove the or die statements from the prepare and
execute I will find that I still get an error from our Irish friend.


  Select email from order_info where name = "Tim O'Reilly"
DBD::CSV::db prepare failed: Mismatched single quote before: 'Select
email from order_info where name = "Tim O'Reilly"


I'm I doing something wrong or is the world against me? =) Thanks for
any help in advance!

-- 
David Steinbrunner
mailto:[EMAIL PROTECTED]
MFM Communications Software, Inc.
http://www.mfm.com

Reply via email to