Devart's handling of Date params causing error in query
Posted: Fri 17 Feb 2012 19:42
Consider the following TMyQuery with SQL
select * from (select date('2012-02-17') as DateFld) tbl1 left join (select date('2012-02-17') as DateFld, 'X' as StrFld) tbl2
using (DateFld)
where DateFld=:DateParam;
Suppose I make the MasterSource for this query point to a MySQL table where DateParam is of type Date and currently has the value '2012-02-17'. The TMyQuery component ends up sending the following SQL to the server
select * from (select date('2012-02-17') as DateFld) tbl1 left join (select date('2012-02-17') as DateFld, 'X' as StrFld) tbl2
using (DateFld)
where DateFld='2012-02-17 00:00:00';
This returns values ('2012-02-17', NULL) which is clearly wrong.
It's as if Devart adding the Time to the Date value means the join isn't made YET the following join does work
select * from (select date('2012-02-17') as DateFld) tbl1 inner join (select date('2012-02-17') as DateFld, 'X' as StrFld) tbl2
using (DateFld)
where DateFld='2012-02-17 00:00:00';
and returns the values ('2012-02-17', 'X');
MySQL itself is being inconsistent here but Devart adding ' 00:00:00' to pure Date fields isn't helping matters. Both queries return the same values ('2012-02-17', 'X') for
where DateFld='2012-02-17';
select * from (select date('2012-02-17') as DateFld) tbl1 left join (select date('2012-02-17') as DateFld, 'X' as StrFld) tbl2
using (DateFld)
where DateFld=:DateParam;
Suppose I make the MasterSource for this query point to a MySQL table where DateParam is of type Date and currently has the value '2012-02-17'. The TMyQuery component ends up sending the following SQL to the server
select * from (select date('2012-02-17') as DateFld) tbl1 left join (select date('2012-02-17') as DateFld, 'X' as StrFld) tbl2
using (DateFld)
where DateFld='2012-02-17 00:00:00';
This returns values ('2012-02-17', NULL) which is clearly wrong.
It's as if Devart adding the Time to the Date value means the join isn't made YET the following join does work
select * from (select date('2012-02-17') as DateFld) tbl1 inner join (select date('2012-02-17') as DateFld, 'X' as StrFld) tbl2
using (DateFld)
where DateFld='2012-02-17 00:00:00';
and returns the values ('2012-02-17', 'X');
MySQL itself is being inconsistent here but Devart adding ' 00:00:00' to pure Date fields isn't helping matters. Both queries return the same values ('2012-02-17', 'X') for
where DateFld='2012-02-17';