I'm working on a test script. Right now the tests are passing because I've mocked out the routine they are testing in order to get the test script working first. I'm encountering errors from my attempts to read a .csv file that I can't find documented in DBD::CSV's documentation.

The first sign of error reads: SQL ERROR: Bad table or column name 'vasample;' has chars not alphanumeric or underscore!, and then it generally breaks down from there.

The field names from the first line are defined as follows:

"random","memberid","address1","address2","county","local","state","zip","zip4"," hod","vasenate","congress","district"

I have a sample file from the client with data and the results she produced doing my module's task manually. I need to loop through that csv file, pull arguments and expected results from each record and use those to test the code I'm working on tonight.

Any ideas would be appreciated.

-- Hugh

UPDATE:

almut takes the prize here. As soon as I deleted that semicolon "in my table name" (who knew?), I got 49 records of data come flooding by. Thanks loads.

My code reads:

#!/usr/bin/perl -w use Test::More tests => 10; use Data::Dumper; use DBI; use lib('lib'); use My::New::Module; my $vasbe = My::New::Module->new(); isa_ok($vasbe,'My::New::Module'); my $dir = "/home/hesco/sb/My-New-Module/"; my $file = 'vasample.csv'; my $table = 'vasample'; my $cols = [qw( random memberid address1 address2 county local state +zip zip4 hod vasenate congress district )]; my $sep = ','; my $dbh = DBI->connect( "DBI:CSV:f_dir=$dir;csv_eol=\n;csv_sep_char=$sep;", {RaiseError=>1}, ); print STDERR "The connection is made.\n"; $dbh->{'csv_tables'}->{'vasample'} = { 'file' => 'vasample.csv', 'col_names' => $cols, }; print STDERR "Our tables are defined.\n"; my $sql = "SELECT memberid, address1, zip, hod, vasenate, congress, di +strict FROM $table;"; my $sth = $dbh->prepare($sql) or die "Cannot prepare query: " . $sql . "|<-->|" . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); print STDERR "We've executed this query: $sql.\n"; print STDERR "Which returned " . $sth->rows() . " records.\n"; while (my $row = $sth->fetchrow_hashref) { print("Found result row: id = ", $row->{'memberid'}, ", zip = ", $ro +w->{'zip'}); } print STDERR " . . . and printed a row for each record.\n"; my %address = ( 'streetnumber' => '', 'streetname' => '', 'zipcode' => '', ); print STDERR "We've now built the \%address hash.\n"; my $result = &match_address( \%address ); END { print "And now the program is terminating.\n"; $sth->finish(); $dbh->disconnect(); } 1; # with subroutines following # STDERR / STDOUT follows: t/12_vasbe_testcases.t 1..10 ok 1 - The object isa My::New::Module The connection is made. Our tables are defined. SQL ERROR: Bad table or column name 'vasample;' has chars not alphanum +eric or underscore! We've executed this query: SELECT memberid, address1, zip, hod, vasena +te, congress, district FROM vasample;. Which returned 1 records. Use of uninitialized value in print at t/12_vasbe_testcases.t line 52. Use of uninitialized value in print at t/12_vasbe_testcases.t line 52. Found result row: id = , zip = . . . and printed a row for each recor +d. We've now built the %address hash. . . . successfully runs the mocked tests. And now the program is terminating.
if( $lal && $lol ) { $life++; }

In reply to DBD::CSV issues querying file by hesco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.