danieleteti / delphimvcframework

DMVCFramework (for short) is a popular and powerful framework for WEB API in Delphi. Supports RESTful and JSON-RPC WEB APIs development.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MSSQLServer and RQL with Offset/Fetch throws exceptions

Voscha opened this issue · comments

The following RQL from the sample "activerecord_showcases" throws an exception with MS SQLServer:

cRQL2 = 'and(eq(City,"Rome"),or(contains(CompanyName,"GAS"),contains(CompanyName,"Motors")))';
...
lCustList := TMVCActiveRecord.SelectRQL<TCustomer>(cRQL2, 20);

because the resulting SQL has no ORDER BY clause:

'SELECT id, code,description,city,rating,note FROM customers WHERE ((city = ''Rome'') and ((LOWER(description) LIKE ''%gas%'') or (LOWER(description) LIKE ''%motors%''))) /*limit*/ OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY'

Offset/Fetch have to be used with the order by clause, I think this must be done in the SQL generator of MS SQLServer.

This is the approach with the less level of "surprise". The only thing we could do is to raise a specific exception before returning the (wrong) statement. What's you POV about the "solution" for this issue? In other words, what should happend using an RQL exception like gt("id", 1);limit(10)?

Perhaps add a default sort on the primary key in the sql generator if there is no specific sort in the RQL? so we could avoid to raise an exception.

I decided to switch this issue in the 3.2.2-nitrogen. Please, check if it works on your side.