0

How can I query CalendcarContract.Instances with a LIMIT clause?

I would like to query starting with a particular start date for a LIMIT of "n" rows.

What I've tried is:

final Uri uri = Uri.parse(CalendarContract.Instances.CONTENT_URI + "/" + 
                          Long.toString(startDate) + "/" + 
                          Long.MAX_VALUE);

final String sortOrder = Instances.BEGIN;

String selection = " limit " + rows;

Cursor cursor = context.getContentResolver().query (
  uri,
  projection, 
  selection,
  null,
  sortOrder);

This generates an error, reported in the log file:

...while compiling: SELECT Instances._id...WHERE (begin<=? AND end>=? AND (limit 1)...

I believe the error is the "AND" before (limit 1). The service is adding that, not me. So, is there another URI I can use or another technique?

NB: I specifically want the Instances versions, which joins single events with recurring events.

Thanks.

Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
  • 1
    The `ContentProvider` API does not support this. Any hacking-in-the-SQL solution like you are doing will be fragile, dependent as it is upon the specific implementation of the provider, which will vary by OS level and manufacturer. – CommonsWare Dec 10 '14 at 23:00
  • Agreed. Unfortunately I'll have to live with that risk or forego the functionality I need. – Peri Hartman Dec 16 '14 at 18:43

1 Answers1

0

Ok, never mind unless you have a better answer.

I realized this is a more general URI problem, not specifically related to CalendarContract. In searching for other results, I found one suggestion to append LIMIT n to the sort clause, e.g.

final String sortOrder = Instances.BEGIN + " limit " + 10;

Credit to How to add limit clause using content provider

Community
  • 1
  • 1
Peri Hartman
  • 19,314
  • 18
  • 55
  • 101