earl_the_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I've been attempting to get a mod_perl program to utilize the DBD:CSV module. Here is the handler code
use strict; use Apache::Constants qw(:common); use Apache::Request; use DBI; use CGI::Carp; sub handler { my $r=Apache::Request->new(shift); carp("calling DBI:CSV connect"); DBI->trace( 2, 'dbitrace.log' ); my $dbh1 = DBI->connect("DBI:CSV:f_dir=/local/tmp") or die carp("$D +BI::errstr $!") carp("after DBI:CSV connect"); ....some other stuff.... return OK; }
My error log prints the debug statement "calling DBI:CSV connect" and then that's it. I never see the second debug message. Firefox just shows a blank screen. The DBI tracelog shows these two messages:
-> DBI->connect(DBI:CSV:f_dir=/local/tmp, , ****) -> DBI->install_driver(CSV) for dynixptx perl=5.006001 pid=15252 ruid= +50195 euid=50195
and that's it. I can successfully connect to an Oracle db with the same code with the oracle specific changes to the connect line.
Any ideas?
ETP

Replies are listed 'Best First'.
Re: DBD::CSV not connecting
by shenme (Priest) on Sep 24, 2004 at 22:02 UTC
    Since the _form_ of the connect() looks good to me (but not a DBD::CSV user) could there be a problem with the referenced directory? Does it exist? Do you have write/create privileges therein, while running from mod_perl? Something to look for until the Coder Super Valiant's arrive.
      The same thought hit me about halfway through troubleshooting this. Yep the user apache runs as does have read and write permissions on the directory. The directory exists as well.
Re: DBD::CSV not connecting
by jZed (Prior) on Sep 25, 2004 at 17:37 UTC
    DBD::CSV works fine for me with mod_perl. Here's an example script which will print "MAKING NEW CONNECTION..." on the first run and then "RE-USING EXISTING CONNECTION" on all the following runs:

    #!/usr/bin/perl -wT use strict; print "Content-type: text/html\n\n"; my $dbh = My::DB->connect(); print "ok!" if $dbh->{RaiseError} == 1 and $dbh->{f_dir} eq '/foo/bar'; package My::DB; use strict; use DBI; sub connect { if (defined $My::DB::conn) { eval {$My::DB::conn->ping}; print "RE-USING EXISTING CONNECTION ...<p>" if !$@; return $My::DB::conn if !$@; } print "MAKING NEW CONNECTION ...<p>"; $My::DB::conn = DBI->connect( 'DBI:CSV(RaiseError=1):f_dir=/foo/bar' ); return $My::DB::conn; } 1;

    Note, that it doesn't make any difference if the f_dir directory "/foo/bar" exists - no checking for existence of the f_dir is done at connection time, only when you attempt to access or create a table.

    If the script above doesn't work for you, make sure that you are using the latest versions of DBD::CSV and DBD::File (which is found in the latest distribution of DBI).

      Thank you jZed. I took your connect statement directly and still encountered the same error. The dbitrace was still hanging on the statement

      -> DBI->install_driver(CSV) for dynixptx perl=5.006001 pid=25729 ruid=50195 euid=50195

      I then did a find for the CSV.pm file itself inside the DBD folder and it wasn't there. The module management is not very good here and they are challenged managing modules built for a variety flavors of Solaris, Sequent and Windows. Modules that exist in some environments are missing in others. That's were the fun begins!!

      I would expect DBD to error out when it cannot find the CSV.pm file though, wouldn't you?
      Thanks ETP
        If I rename ...site/lib/DBD/CSV.pm, the script above does error out with "install_driver(CSV) failed: Can't locate DBD/CSV.pm in @INC..." as it should. If you're not getting that error message, then perhaps you have a CSV.pm somewhere else in your @INC, or else you haven't turned RaiseError on for the connect, or have some other bug in your error reporting strategy.
Re: DBD::CSV not connecting
by jdalbec (Deacon) on Sep 25, 2004 at 04:00 UTC
    I think you may want croak() rather than die carp(). Also that line appears to be missing a semicolon at the end.