Skip to content

Fix query not working on old versions of sqlite

Nick Orlowsky requested to merge sqlite-fix into main

Window versions were introduced in SQLite v 3.25.0. This means that the query within rangesForSystem() in queries.dart won't work on iOS versions < "13.1.3" (https://stackoverflow.com/questions/14288128/what-version-of-sqlite-does-ios-provide) and android versions < "11.0" (https://stackoverflow.com/questions/2421189/version-of-sqlite-used-in-android)

This PR updates this function to use an alternate query on SQLite versions that don't support window functions.

If you go to https://sqliteonline.com , you can run this to get the idea behind how the new query works:

SELECT *, ROW_NUMBER() OVER(ORDER BY Name, id) as rn FROM demo;

SELECT *, 
       (SELECT COUNT(*) 
        FROM demo as d2 
        WHERE demo.Name > d2.Name OR (demo.Name = d2.Name AND demo.id >= d2.id)
       ) as rn 
FROM demo ORDER BY rn;

I tested this on an Android 9 device and it worked

Merge request reports

Loading