querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

WhereDatePart error for SQLite

Open kztneda opened this issue 2 years ago • 1 comments

I tried to use WhereDatePart and I saw I had no results even when I have data on the DB, so I get the sqlkata generated SQL and I see for this function you use "cast(? as text)" instead of the integer itself.

I solve it using WhereRaw but I guess this is an issue.

This is What I had before: (this returns no information)

_com.DB.Query(table)
        .Where("field", ID)
        .WhereNot("Status", "DROPPED")
        .WhereDatePart("month", "date", ">=", DateTime.Now.Month)
        .OrderBy("date")
        .Get<Date>().ToList();

and the sql sqlKata did for this is this (this returns no information)

SELECT * FROM \"table\" WHERE \"field\" = ? AND NOT (\"Status\" = ?) AND strftime('%m', \"date\") >= cast(? as text) ORDER BY \"date\"

This is what I have now (this works!!)

_com.DB.Query(table)
         .Where("field", ID)
         .WhereNot("Status", "DROPPED")
         .WhereRaw("strftime('%m', date) >= " + DateTime.Now.Month)
         .OrderBy("date")
         .Get<Date>().ToList();

and the sql sqlKata did for this is this (this works!!)

SELECT * FROM \"table\" WHERE \"field\" = ? AND NOT (\"Status\" = ?) AND strftime('%m', \"date\") >= ?  ORDER BY \"date\"

kztneda avatar Jul 14 '21 00:07 kztneda

Could you share a project that reproduce this issue?

ahmad-moussawi avatar Jul 14 '21 08:07 ahmad-moussawi

Closing since no enough information to reproduce

ahmad-moussawi avatar Oct 01 '22 04:10 ahmad-moussawi