thevahidal / soul

🕉 A SQLite REST and realtime server
https://thevahidal.github.io/soul/
MIT License
1.45k stars 50 forks source link

Bug in __gte for string filters #135

Closed IanMayo closed 10 months ago

IanMayo commented 11 months ago

Describe the bug When providing a string filter to __gte the query fails if the string contains a - character

To Reproduce Steps to reproduce the behavior:

  1. Run soul-cli, connecting to chinook.db
  2. Enter this URL: http://localhost:8000/api/tables/invoices/rows?_filters=BillingAddress__gte:Theodor
  3. Note that there are 21 matching records, and the first has a BillingAddress of Theodor-Heuss-Straße 34
  4. Now filter for address including the hyphen: Theodor-Heuss. So a URL of: http://localhost:8000/api/tables/invoices/rows?_filters=BillingAddress__gte:Theodor-Heuss
  5. Note that Soul returns an error:

    {"message":"near \"LIMIT\": syntax error","error":{"code":"SQLITE_ERROR"}}

Note: We seem to have a related issue with filters on InvoiceDate that contain a "-".

http://localhost:8000/api/tables/invoices/rows?_filters=InvoiceDate:2009-01-01%2000:00:00

Returns this:

{"message":"near \".01\": syntax error","error":{"code":"SQLITE_ERROR"}}

Note 2:

The invoices are all dated 2009. So this query reports 412 matching records:

http://localhost:8000/api/tables/invoices/rows?_page=1&_limit=20&_filters=InvoiceDate__gt:2009

But, if I change the year to 2030, there are still 412 matching records:

http://localhost:8000/api/tables/invoices/rows?_page=1&_limit=20&_filters=InvoiceDate__gt:2030

In contrast, using a __lt operator, records are never returned:

http://localhost:8000/api/tables/invoices/rows?_page=1&_limit=20&_filters=InvoiceDate__lt:2030

These suggest __lt, __gt, __lte and __gte aren't working properly.

Separately to that, the query parsing is failing if the filter value includes a hyphen, like: 2009-01.

Expected behavior I expected the 21 matching records to still be returned