Dear monks,
I'm desperately hoping you can help me with this problem. I'm new to the module, but am attempting to manipulate a CSV file with this module:
CSV file (file.csv):
"field1";"field2";"field3";"field4";"field5";"field6";"field7";
"5/7/2005 6:50:43 AM";1;1;0;"some text 1";"some text 5";"some text 9."
"5/7/2005 5:55:44 AM";1;1;0;"some text 2";"some text 6";"some text 10"
"5/7/2005 5:20:03 AM";1;1;0;"some text 3";"some text 7";"some text 11"
"5/7/2005 5:06:07 AM";1;1;0;"some text 4";"some text 8";"some text 12"
I'm using the following code to attemp to simply create a virtual SQL table with it, and then use a select statement to pull the data from the virtual table...
my $dbh = DBI->connect(qq{DBI:CSV:csv_sep_char=\\;});
$dbh->{'csv_tables'}->{'info'} = { 'file' => 'test.csv' } or die "Prob
+lem creating table";
my $sth = $dbh->prepare("select * from info") or die "Can't prepare st
+h: $dbh->errstr\n";
$sth->execute or die "Can't execute the query: $sth->errstr";
my $count = 0;
while (my @row = $sth->fetchrow_array) {
print "Row: $count ";
print $row[0] . " ";
print $row[1] . " ";
print $row[2] . " ";
print $row[3] . " ";
print $row[4] . " ";
print $row[5] . " ";
print $row[6] . " ";
$count++;
}
$sth->finish;
However, I'm encountering the following error:
"Execution ERROR: Missing first row at c:/apache/Perl/site/lib/DBD/CSV.pm line 165, line 1. . DBD::CSV::st fetchrow_array failed: Attempt to fetch row from a Non-SELECT statement
for statement ``select * from info'') at /apache/htdocs/test.cgi line 35."
I've tried a number of different things, but without any luck.
Could anyone advise me of what I'm doing wrong?
Thanks a ton!
Regards,
Stenyj
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.