I wrote a quick file dumper which seems to work on windows for short file names. However I have some files with special characters such as '-' in the file name. DBI/DBD::XBASE does not seem to like this one bit. Any help or suggestions would be appreciated. Attached is the code and the error:

ERROR:

C:\Perl\Perlscripts>dumplog.pl "Controller - 20030721"
DBD::XBase::db prepare failed: Extra characters in SQL command near `- 20030721'
at C:\Perl\Perlscripts\dumplog.pl line 44.
Can't call method "execute" on an undefined value at C:\Perl\Perlscripts\dumplog
.pl line 45.


#Libraries # DBI is the Data base Interface it uses a module DBD::XBase # to access Foxpro database files. # # use DBI; my $basedir = "G:/"; my $logdir = "LOGS"; read_log ( shift ); sub read_log (@){ my $log = join '',@_; my $href = get_columns ($log); my $logref = get_log_dump($log); print " Confirm ". @$logref. " records \n"; print "Dumping Log ".$basedir.$logdir."/$log\n"; foreach $field ( @$href ) { print "$field\t"; } print "\n###################################################\n"; foreach my $log_row ( @$logref){ foreach my $log_entry (@$log_row) { print "$log_entry\t"; } print "\n"; } } sub get_columns ($) { my $log = shift; my @Cols = (); my $dbobject = DBI->connect("DBI:XBase:".$basedir.$logdir) or die $DBI::errstr; # sth is used for the variable it means statement handle my $sql = "SELECT * FROM $log"; $sth = $dbobject->prepare($sql); $sth->execute(); for ( $i = 1; $i <= $sth->{NUM_OF_FIELDS}; $i++){ push @Cols, $sth->{NAME}->[$i-1]; } $dbobject->disconnect(); return \@Cols } sub get_log_dump ($) { my $log = shift; my $dbobject = DBI->connect("DBI:XBase:".$basedir.$logdir) or die $DBI::errstr; $sth = $dbobject->prepare("SELECT * FROM $log"); $sth->execute(); my $resultref = $sth->fetchall_arrayref(); print "Retrieved ". @$resultref ." records\n"; return $resultref; }

In reply to DBI Long File names? by talwyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.