From angrygreg at gmail.com Mon Feb 16 10:40:50 2009 From: angrygreg at gmail.com (Greg Akins) Date: Mon, 16 Feb 2009 13:40:50 -0500 Subject: [pgh-pm] Trying to use DBI:CSV Message-ID: <8526685f0902161040h54a44ea3t4ae771846fb220ea@mail.gmail.com> 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 From angrygreg at gmail.com Mon Feb 16 12:04:31 2009 From: angrygreg at gmail.com (Greg Akins) Date: Mon, 16 Feb 2009 15:04:31 -0500 Subject: [pgh-pm] Trying to use DBI:CSV In-Reply-To: References: <8526685f0902161040h54a44ea3t4ae771846fb220ea@mail.gmail.com> Message-ID: <8526685f0902161204o1f5807e5q6b73b4a711000ff6@mail.gmail.com> 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 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 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 From jkeen at verizon.net Mon Feb 16 12:41:29 2009 From: jkeen at verizon.net (James E Keenan) Date: Mon, 16 Feb 2009 15:41:29 -0500 Subject: [pgh-pm] Trying to use DBI:CSV In-Reply-To: References: Message-ID: On Feb 16, 2009, at 3:00 PM, pgh-pm-request at pm.org wrote: > Message: 1 > Date: Mon, 16 Feb 2009 13:40:50 -0500 > From: Greg Akins > Subject: [pgh-pm] Trying to use DBI:CSV > > First, I'm a perl newbie.. so I'm sorry if I'm asking really stupid > questions. > This is not a stupid question. Figuring out how to use DBI is not necessarily self-evident. > I'm trying to use DBI:CSV > Unfortunately, I'm not a DBI expert, so I can't answer this off the top of my head. :( > 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) > But what I can say is that you are running the perl executable that came with your Mac. The vendor-installed executables are in /usr/ bin/. The libraries that come with "Perl core" are in /usr/lib. The libraries that Apple packages with its perl above and beyond the perl core modules are found in /System/Library/Perl/lib/. Or, at least, so it would appear from my Mac OS 10.4.11; I doubt they changed that for 10.5 HTH Jim Keenan