The idea for limit with offset is done by modifying the sql on the fly
with numerous assumptions on the structure of the sql string.
The modification is done with reference to the notes from
http://troels.arvin.dk/db/rdbms/#select-limit-offset
SELECT * FROM (
SELECT TOP n * FROM (
SELECT TOP z columns -- (z=n+skip)
FROM tablename
ORDER BY key ASC
) AS FOO ORDER BY key DESC -- ('FOO' may be anything)
) AS BAR ORDER BY key ASC -- ('BAR' may be anything)
Regular expressions are used to alter the SQL query. The resulting SQL query
may be malformed for complex queries. The following restrictions apply
-
In particular, commas should NOT
be used as part of the ordering expression or identifier. Commas must only be
used for separating the ordering clauses.
-
In the ORDER BY clause, the column name should NOT be be qualified
with a table name or view name. Alias the column names or use column index.
-
No clauses should follow the ORDER BY clause, e.g. no COMPUTE or FOR clauses.