dominion-solutions / laravel-mysqlite

A Laravel Service Provider that injects select MySQL functions into SQLite
MIT License
7 stars 6 forks source link

Possible Bug in mod() function #75

Closed dan24678 closed 3 years ago

dan24678 commented 4 years ago

I noticed an issue with SQLite which I assume is a bug in one of the adapter functions.

The bug is somewhere in this SQL fragment:

            CONCAT(
                DATE_FORMAT(CONVERT_TZ(calculation_dt, 'GMT', int_tz), '%Y-%m-%d %H:'),
                COALESCE(
                    LPAD(
                       MINUTE(calculation_dt)-MOD(MINUTE(calculation_dt), 15),
                       2,0
                    ),
                    '00'
                )
            )

That sql fragment when used as a select against a dataset where "calculation_dt" is a datetime, should return data that looks like this:

2020-02-08 20:00 2020-02-08 20:15 2020-02-08 20:30 2020-02-08 20:45 2020-02-08 21:00

But instead of returning 15 minute chunks, it is returning only hourly ones:

2020-02-08 20:00 2020-02-08 21:00

My best guess as to the cause is a bug in the mod() implementation which causes it to return 0 regardless of what arguments are passed in. But I didn't really get deep into debugging it to pinpoint the specifics.