Reputation: 1
I've researched a bit and found that using mysql_use_result=1
is supposed to alleviate the memory issue. However, since I am new to this DBI module
I don't understand what is happening here:
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI>connect('DBI:mysql:blah;host=blah.blah.blah.blah;mysql_use_result=1','blah','blah',{RaiseError => 1});
my $sth = $dbh->prepare('select * from TaqMinute where tradeDate<=\'2014-04-22\' and symbol<=\'AAPL\' ;') ;
if (defined($sth)) {
$sth->execute();
my @row;
while (@row = $sth-> fetchrow_array()) {
print "@row\n" ;
}
}
$sth->finish();
$dbh->disconnect
Before I added mysql_use_result=1
, the script would fail after about 1.5 minutes complaining that it ran out of memory. After adding this my query arguments are ignored and I simply get all the data in the database.
Any ideas how to help me or how to use this switch
properly? Btw, the database that I am querying is very large.
Thanks in advance!
Craig
Upvotes: 0
Views: 901
Reputation: 5069
Try to use parametized queries, maybe something wrong with your qoutes.
my $dbh = DBI>connect('DBI:mysql:blah;host=blah.blah.blah.blah','blah','blah',{RaiseError => 1});
my $sth = $dbh->prepare_cached('select * from TaqMinute where tradeDate<=? and symbol<=?') ;
die "sth undef!" if ! defined $sth;
$sth->execute('2014-04-22','AAPL');
while (my $rowref = $sth->fetchrow_arrayref()) {
print Dumper($rowref) ;
}
$sth->finish;
Upvotes: 1