Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBI:FILE Questions

Status
Not open for further replies.

letsGo123

Programmer
Jun 8, 2004
10
0
0
US
having problem selecting data from from a .csv or a .txt file using dbi:file in the following:

Code:
$dbh = DBI->connect("DBI:File:f_dir=../directoryLocation") or die "Cannot connect: " . $DBI::errstr;

foreach $addedProduct (@productArray)
{
 chop($addedProduct);
 
 $item_number = $addedProduct;
 
 my $query = "Select column1, column2, column3 from file.csv where item='$item_number'";
 
 $sth = $dbh->prepare($query);
 
 if (!$sth) { die "Illegal query: $query" };
 
 $sth ->execute;
 
  while (@row = $sth->fetchrow_array) {
   foreach (@row) {
    $rowResults[$counter].="$_\t" ;
   }
   $counter=$counter+1;
  }
  $sth->finish;  
}

the above code works fine when connecting to mySql, but with file @rowResults is empty.

for the sake of comparisons we want to compare speed to a flat file. any suggestions would be helpful.

thanks.
 
I assume you use .csv files. Then:

- use DBI::CSV, not DBD::File

- make sure your file is correct, ie first line contains columns names not values and use the correct delimitator (default seems to be comma)

 
letsGo123

I think you'll find that DBI::File will not generally be as fast as just reading a text file directly. It offers you great flexibility in reading and writing CSV files but won't help if what you want most of all is blinding speed.

I did some work with DBI on CSV files a while ago - so if you'd like to post the first few lines of your data file I'll have a look.

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top