Search code examples
androidsqliteandroid-contentprovider

Querying Android db for specific piece of data


I'm creating a method that will see if a column in a database row is populated; and if so, it returns the varchar in that row, else it calls a web service to return that data.

My question is: What is the standard way of simply selecting a column with Android? (select mycolumn from mytable where _id = x;)

I've created a ContentProvider around my database. Should I just call 'query' directly? Note: This method is in a Service


Solution

  • you just need to mess with the selection argument in the query

    String selection = MyDatabaseConstants.ID " = " + String.valueOf(x);
    Cursor c = getContentResolver().query(MyDatabaseConstants.Content_URI,MyDatabaseConstants.Proj, selection,null,null,null);