Parameter substitution for MySQL TIME value bug
-
NoComprende
- Posts: 135
- Joined: Tue 09 Jan 2007 13:44
Parameter substitution for MySQL TIME value bug
If I put the following code in a TMyQuery
select * from MySQLTable where TimeValue > :ParamTimeValue;
and ParamTimeValue is taken from a MasterSource table where the value is 14:10:00 then the final text that is sent to the MySQL server is
select * from MySQLTable where TimeValue > '14:10:0';
The missing '0' in the substitution means the result contains records where the value of TimeValue was 14:10:00 because
'14:10:00' > '14:10:0'
select * from MySQLTable where TimeValue > :ParamTimeValue;
and ParamTimeValue is taken from a MasterSource table where the value is 14:10:00 then the final text that is sent to the MySQL server is
select * from MySQLTable where TimeValue > '14:10:0';
The missing '0' in the substitution means the result contains records where the value of TimeValue was 14:10:00 because
'14:10:00' > '14:10:0'
-
NoComprende
- Posts: 135
- Joined: Tue 09 Jan 2007 13:44
-
NoComprende
- Posts: 135
- Joined: Tue 09 Jan 2007 13:44
Dimon, I simplified the code in the above example. It may be because I am using the following codeDimon wrote:I could not reproduce the problem.
The point is that MySQL compares Time fields as time, but not as string. Therefore '14:10:00' = '14:10:0'.
where (MyDate,MyTime,MyString)>(:MyDate,:MyTime,:MyString)
in my query rather than writing out the long winded version of that comparison. Try to reproduce it using
select * from MySQLTable where (TimeValue,StringValue) > (:TimeValue,:StringValue);
-
NoComprende
- Posts: 135
- Joined: Tue 09 Jan 2007 13:44