Thank you for  your comments.

I swapped the order of setting f_dir & csv_tables and it seems to be working 
fine now.  Looks to be more going on than just setting a value in a hash.

I'll review the docs on f_file in DBD::CSV and make the recommended changes 
there as well.  But it appears the "file" alias is still in place.  But I'll 
still fix it so that I won't have an issue the next time I do an upgrade.

Thanks again!

Curtis

-----Original Message-----
From: Jens Rehsack [mailto:rehs...@gmail.com] 
Sent: Wednesday, September 11, 2013 3:59 AM
To: Curtis Leach
Cc: dbi-users@perl.org
Subject: Re: A question about DBI

Am 10.09.2013 um 21:45 schrieb Curtis Leach <cle...@caesars.com>:

> Hello,

Aloah /o\

>  
> I'm having issues trying to query flat files using DBI & DBD::CSV.  I'm 
> currently upgrading from v5.8.8 to v5.16.3 and with the latest Perl platform 
> my code no longer works.  I'm running on various Windows platforms.
>  
> I'm going to Strawberry Perl v5.16.3  (32-bit)
> DBI 1.628    (upgraded core module)
> DBD-CSV 0.41
> SQL-Statement 1.405
> Text-CSV_XS 1.01
>  
> From:  Active State Perl v 5.8.8
> DBI  1.49
> DBD-CSV 0.22
> SQL-Statement 1.14
> Text-CSV_XS 0.23
>  
> Here is a code sample that reproduces my issue:
>  
> my %attr = (PrintError => 0, RaiseError => 1, AutoCommit => 1); my 
> $dbh = DBI->connect ("DBI:CSV:csv_sep_char=|;csv_eol=\n", "", "", 
> \%attr); $dbh->{csv_tables}->{logs} = { 'file' => basename ($src_file) 
> };

Please use f_file instead of file (see Changes).
For a long time, "file" was handled as a depreciated flag and was mapped to 
f_file.
It might be removed sooner or later (or maybe is, see alias def in 
DBD::File::Table).

> $dbh->{f_dir} = dirname ($src_file);

It might help to do move this line before the csv_tables meta initialization 
(do global init before local init).

> my $sql = "SELECT File, Extension, Directory, Message from logs where Status 
> = " .
>                 $dbh->quote ("ERROR") . " ORDER BY Time"; my $sth = 
> $dbh->prepare ( $sql ); $sth->execute ();
>  
> I turned on tracing (level 2) and according to the error message the file I'm 
> trying to find isn't being found.
>  
> It looks like the query is ignoring the setting of "f_dir".  It's 
> instead looking for the file in the current directory, which isn't 
> what "f_dir" points to!  (The trace acknowledges f_dir is pointing to 
> the correct location)
>  
> So if I manually run the code from the location where the log file is 
> located, everything works.
>  
> So I see one of two things being true:
> 1)      "f_dir" is being ignored.

Only for table "logs", because logs's f_dir is initialized before you set it.

> 2)      There is a problem with how I initialized things.

Indeed. You should really carefully study the Changes since DBI 1.49, also for 
SQL::Statement since 1.405.

> Can anyone comment about which is the real issue?  With the files I'm 
> querying all over the place, putting chdir's all over my code isn't really a 
> good option.
>  
> Curtis Leach
> Lead Engineer
> RMS  IT & ERM IT
> Phone: (702) 494-4562
> <image001.jpg>
>  
>  
> <dbitrace.log>

Cheers
--
Jens Rehsack
pkgsrc, Perl5
rehs...@cpan.org





Reply via email to