September 16, 2019, 11:29am
I have a generic method to return a list of a certain type of data on my CBL database. I have implemented pagination, as that makes sense for
some of the queries. But for others I just want all.
So I have this code:
using (var query = QueryBuilder.Select(
var result = query?.Execute()?.AllResults();
limit is an integer. Question: is there a way where I can set the Limit expression to “All”?
Obviously, I see two “clumpsy” solutions. One is to override the
limit by setting it to e.g. 10000. The other is to create an almost identical query - just without the limit expression…
September 16, 2019, 4:33pm
As in SQL, a negative
LIMIT means “all”.
September 16, 2019, 7:24pm
Well, I had already tested that. But whether I set limit to 0 or -1 it returns zero docs…
I also set the offset to -1.
Should I do more?
I’m on CBL 2.5.3 in Xamarin (C#). I know there is a later version that I can try - is this feature new?
You are right. It doesn’t seem that limit of “ALL” is supported with -1 - even on v2.6. You could do what you suggested (int max) as a workaround but If you are not interested in pagination, then you can remove the limit clause altogether and it should just get everything from offset 0.
September 17, 2019, 6:39am
Well, yes - I cannot remove the condition without affecting the other doc. types
- without having two query statements. So I’ll just bump it up very high…
… but it would make sense to make it work as unlimited with either “0” or “-1”
September 17, 2019, 10:15pm
Sorry I led you astray — I thought -1 would work since AFAIK we just pass the value into a SQLite LIMIT clause. Sounds like somewhere in the code we’re trying to be “smart” and pinning it to zero…