[Dbix-class] IF conditional
Chris Lock
CLock at EU.Advertising.com
Fri Jul 7 17:33:52 CEST 2006
Im doing something screwy here... I need the DB to return me a true or
false depending on if the date is bigger than than the end date
my $dates = $c->model('Foo::Bar')->search(
{ bar_id => $c->session->{bar_id} },
{
select => [
{ IF => [
'DATE_ADD ("'.$date.'", INTERVAL 1 DAY ) > bar_end',
1,
0
] },
{ DATE_FORMAT => [
{ DATE_SUB => [
'"'.$date.'"',
'INTERVAL 1 DAY'
] },
'"%d-%m-%Y"'
] }
],
as => [ qw/ next_date prev_date /]
} );
Which produces the following...
SELECT IF( DATE_ADD ("2006-06-05", INTERVAL 1 DAY ) < bar_end, 1, 0 ),
DATE_FORMAT( DATE_SUB( "2006-06-05", INTERVAL 1 DAY ), "%d-%m-%Y" ) FROM
bar me WHERE ( bar_id = ? )
Which looks fine to me and if I run it in mysql works, but code tells
me...
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'("2006-06-05", INTERVAL 1 DAY ) < bar_end, 1, 0 ), DATE_FORMAT(
DATE_SUB( "' at line 1 at
/home/clock/cvs/branding/script/../lib/Foo/Controller/Bar.pm line 211
Any ideas?
More information about the Dbix-class
mailing list