[Dbix-class] occassional query failure
Maurice Height
mauriceh at bigpond.net.au
Tue Nov 14 14:25:10 GMT 2006
I am getting an error with code using DBIX::Class which is driving me nuts.
I have a schema set up as:
package DB_Schema::History;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('history');
__PACKAGE__->add_columns(qw/code day open high low close volume/);
__PACKAGE__->set_primary_key(qw/code day/);
1;
In my code I want to get the record with the max value of 'close'
within a period defined by $date to $date2.
Getting the max value of close (ie. $max_close) works fine,
but when I try to retrieve the record that contained the max value
I OCCASSIONALLY get nothing back from the DBIC query which looks
like this:
# Find most recent record that had that max value of 'close'
my $max_close = ...
my $rs = $schema->resultset('History')->search(
{ code => $code,
day => { '>=', $date1, '<=', $date2 },
close => $max_close,
},
{ page => 1,
rows => 1,
order_by => 'day DESC',
}
);
while(my $row = $rs->next) {
my %record = $row->get_columns;
print dump(\%record);
}
I have confirmed that the equivalent queries, using the same values
entered into MySQL Query Browser, do work correctly.
For example:
SELECT * FROM history WHERE code = 'TLS' AND close = 3.970
AND day >= '2006-08-16' AND day <= '2006-11-13';
I am using DBIx::Class v0.07002 with MySQL v5.0.27-community-nt on
Windows XP.
Any tips or thoughts would be greatly appreciated.
Thanks
Maurice
More information about the Dbix-class
mailing list