Reputation: 1322
I have a DB in SQLite that saves the current date and time every time that the user inserts a new register. The date is stored in the db using the time string format: YYYY-MM-DD HH:MM:SS.
So the problem is that I need select the registers that are in a range between two dates and sort the result from lower to higher. I'm using my own content provider so, How can I achive this?
This is my Query code:
final String[] projection = {Contrato.Columnas._ID,Contrato.Columnas.SISTOLICA,Contrato.Columnas.DIASTOLICA,Contrato.Columnas.PULSO};
final String orderBy = Contrato.Columnas.SISTOLICA + " DESC";
Cursor c = resolver.query(Contrato.URI_CONTENIDO_BASE,projection,null,null,orderBy);
Upvotes: 0
Views: 233
Reputation: 1006674
A ContentProvider
is a façade. The meaning of any of the ContentProvider
/ContentResolver
API is up to you. So long as the client and the provider are in agreement over what parameters to things like query()
mean, you can do whatever you want.
So, replace:
resolver.query(Contrato.URI_CONTENIDO_BASE,projection,null,null,orderBy)
with something like:
resolver.query(Contrato.URI_CONTENIDO_BASE,projection,Contrato.Columnas.SISTOLICA+">=? AND "+Contrato.Columnas.SISTOLICA+"<=?",args,orderBy)
where args
are the two dates, in YYYY-MM-DD HH:MM:SS
format. Probably, you can pass that stuff along to SQLite without modification. Even if you do need to modify it... again, it's your code, so you can make it do whatever you want.
Upvotes: 1