mxhdev / SQLChecker

GNU General Public License v3.0
1 stars 1 forks source link

[SolutionGenerator] Date/Time arguments in functions #24

Closed mxhdev closed 8 years ago

mxhdev commented 8 years ago

Introduction

In Version 3.2 of DBFit, there seems to be a bug in which time functions don't work

Bug Description

In order to run a date/time function like time_to_sec if mysql, the time has to be in single quotes, however DBFit throws a parse exception if the date is given in single quotes. Furthermore, DBFit expects Date/Time values to be without quotes. Because MySQL requires quotes, this causes problems.

Code Sample

The following (dbfit code) will pass, however the function call should not return 0 if the call works properly. In the following code it will.

|Execute|!-CREATE DEFINER=`root`@`localhost` FUNCTION dttest(dauer time) RETURNS decimal(20,2)
BEGIN
declare anzahl int;
set anzahl = ((time_to_sec(dauer)/3600)/24);
RETURN anzahl;
END
-!|

|Execute Procedure|dttest|
|dauer|?|
|48:00:00|0.00|

However, mysql expects the call to have single quotes around the date/time

call dttest('48:00:00');

This can be solves by using a different function call syntax inside the dbfit script

|Query|SELECT dttest('48:00:00') as result|
|result|
|2.00|

Relevant Classes

dbfit.util.SqlTimeParseDelegate

Task

Change the SolutionGenerator in such a way, that function calls will always be written in the (safer) workaround syntax (see above)

mxhdev commented 8 years ago

DBFit also contains a bug which is related to parsing time values. The dbfit class dbfit.util.SqlTimeParseDelegate parses time values with the following patterns:

static final SimpleDateFormat FMT_S = new SimpleDateFormat("HH:mm:ss");
static final SimpleDateFormat FMT_MS = new SimpleDateFormat("HH:mm:ss.S");

However, the MySQL 5.7 Reference Manual / ... / 11.3.2 The TIME Type allows the time format to have 3 hour digints.

This is inconsistent and should be changed on the side of dbfit.

mxhdev commented 8 years ago

Implemented by commit 20eb16f