Using parameters for .Limit

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:

            Expression.Int(limit);
            using (var query = QueryBuilder.Select(
                    SelectResult.All())
                   .From(dbSource)
                   .Where(_condition)
                   .OrderBy(_orderBy)
                   .Limit(Expression.Int(limit), Expression.Int(offset)))
            {
                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…

As in SQL, a negative LIMIT means “all”.

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.

Well, yes - I cannot remove the condition without affecting the other doc. types :frowning: - 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” :slight_smile:

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… :confused:

1 Like