[pgh-pm] Trying to use DBI:CSV

Greg Akins angrygreg at gmail.com
Mon Feb 16 12:04:31 PST 2009


I installed the modules from cpan.  SQL:Statement was up to date.

Still getting the same error messages.  I'm wondering if I still have
some incompatible versions.  I'm going to try to remove some of the
packages that I installed using the tarballs and see if cpan will deal
with dependencies better (if that's the problem)

This is the code I'm trying to run. The output from running the file
is appended below.

#!/usr/bin/perl -w
#
# ch04/listdsns: Enumerates all data sources and all
# installed drivers
#

use DBI;
my $dbh = DBI->connect("DBI:CSV:f_dir=.");
$table = "test_table" ;
$dbh->do("create table $table (id INTEGER, name CHAR(64))") ;

$dbh->do("INSERT INTO $table VALUES (1, "
	 . $dbh->quote("foobar") . ")");

$dbh->do("INSERT INTO $table VALUES (?, ?)", undef,
	 2, "It's a string!");

my($query) = "SELECT * FROM $table WHERE id > 1 ORDER BY id";
my($sth) = $dbh->prepare($query);
$sth->execute();
while (my $row = $sth->fetchrow_hashref) {
    print("Found result row: id = ", $row->{'id'},
	  ", name = ", $row->{'name'});
}
$sth->finish();


exit ;

########### OUTPUT #################
DBD::CSV::db do failed: Can't locate object method "command" via
package "DBD::CSV::Statement" at /Library/Perl/5.8.8/DBD/CSV.pm line
156.
 [for Statement "INSERT INTO test_table VALUES (1, 'foobar')"] at
test.pl line 12.
DBD::CSV::db do failed: Can't locate object method "command" via
package "DBD::CSV::Statement" at /Library/Perl/5.8.8/DBD/CSV.pm line
156.
 [for Statement "INSERT INTO test_table VALUES (?, ?)"] at test.pl line 15.
DBD::CSV::st execute failed: Can't locate object method "command" via
package "DBD::CSV::Statement" at /Library/Perl/5.8.8/DBD/CSV.pm line
156.
 [for Statement "SELECT * FROM test_table WHERE id > 1 ORDER BY id"]
at test.pl line 20.
DBD::CSV::st fetchrow_hashref failed: Attempt to fetch row without a
preceeding execute() call or from a non-SELECT statement [for
Statement "SELECT * FROM test_table WHERE id > 1 ORDER BY id"] at
test.pl line 21.



On Mon, Feb 16, 2009 at 2:17 PM, Sterling Hanenkamp
<sterling at hanenkamp.com> wrote:
> Welcome to Perl! I'm not actually familiar with DBD::CSV, but a bit of
> Googling showed me that others seem to have this problem if the
> SQL::Statement module is not installed. You might try installing the latest
> SQL::Statement and possibly upgrading DBI for good measure. You can do this
> from the Console in Mac OS X by running:
>
> sudo cpan SQL::Statement
> sudo cpan DBI
>
> I use Perl on Mac OS X 10.5 (as well as on Linux) daily and it works very
> well for me.
>
> If you don't need to work with SQL, you might consider using Text::CSV_XS
> directly, which I do use pretty regularly. Here's a link showing how to use
> it:
>
> http://search.cpan.org/dist/Text-CSV_XS/CSV_XS.pm
>
> Cheers,
> Sterling
>
> On Mon, Feb 16, 2009 at 12:40 PM, Greg Akins <angrygreg at gmail.com> wrote:
>>
>> First, I'm a perl newbie.. so I'm sorry if I'm asking really stupid
>> questions.
>>
>> I'm trying to use DBI:CSV
>>
>> I can create a table so at least part of the packages are installed
>> correctly.
>>
>> However when I try to insert into it, I get the following message
>>
>> DBD::CSV::db do failed: Can't locate object method "command" via
>> package "DBD::CSV::Statement" at /Library/Perl/5.8.8/DBD/CSV.pm line
>> 156.
>>  [for Statement "INSERT INTO test_table VALUES (1, 'foobar')"] at
>> test.pl line 12.
>>
>> I'm running perl 5.8.8 on Mac OS 10.5 ; probably not the OS X version
>> since 'which perl' shows it's executing from the /usr/bin directory (I
>> believe the Mac install is in System)
>>
>> I got started by following the directions here
>> (http://www.mathematik.uni-ulm.de/help/perl5/doc/DBD/CSV.html)
>>
>>
>> --
>> Greg Akins
>>
>> http://www.pghcodingdojo.org
>> http://pittjug.dev.java.net
>> _______________________________________________
>> pgh-pm mailing list
>> pgh-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/pgh-pm
>
>



-- 
Greg Akins

http://www.pghcodingdojo.org
http://pittjug.dev.java.net


More information about the pgh-pm mailing list