Uh oh!
There was an error while loading. Please reload this page.
Cast datetime columns in sqlite before comparing - #26540
Conversation
nickvergessen
commented
Apr 13, 2021
Looking at https://github.com/nextcloud/server/blob/master/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php thats a lot of duplication. Xan we abstract the prepareColumn calls to another level? |
cfc381e to
f2d744bComparejuliusknorr
commented
Oct 14, 2022
@nickvergessen I moved the prepareColum to the regular ExpressionBuilder so that sqlite and OCI now just extend that. |
f2d744b to
43608b8Comparenickvergessen
commented
Oct 17, 2022
Can we add a test? :) |
juliusknorr
commented
Nov 11, 2022
Definitely. I'd probably add a case for this in https://github.com/nextcloud/server/blob/6312c0df6949955d1cd59c3dd444268e0773293c/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php but we'd need a new table in the testing app to properly test this against real databases. Or would you have any other idea to cover that? |
43608b8 to
ab3cdccComparejuliusknorr
commented
Jul 10, 2023
Rebased and pushed a test case for this. I added a new table to the testing app to have a datetime column around during tests. |
197d052 to
c829472Comparec829472 to
4d1edf2Compare4d1edf2 to
58c4c1eCompareMove the logic to prepare a column to the parent ExpressionBuilder so that it can be reused for OCI and sqlite Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
58c4c1e to
e50cb0aCompare
When debugging failing integration tests in nextcloud/deck#2934 i noticed that sqlite does strange things when trying to compare a datetime field with a DateTime value through the expression builder. It turns out sqlite doesn't store them as real dates and therefore operates a string comparison through our database abstraction:
https://www.sqlite.org/datatype3.html
In order to resolve this issue globally this PR wraps the required parameters when they are passed to the query builder with using the
DATETIME()function so both values are compared as real datetimes.Might make sense to also look into covering this with some tests, but I didn't have time to look into yet. I can have a look if the general approach to this is fine.