I am inserting a ContentProvider layer in between the ORM of SugarORM and the underlying SQLite database in order to be able to use a SyncAdapter with it.
The ORM has a method like this:
public static <T extends SugarRecord<?>> List<T> find(Class<T> type,String whereClause,String[] whereArgs,String groupBy, String orderBy, String limit)
which matches nicely a query method of the SQLiteDatabase:
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
the problem is that the ContentProvider only has one query method which doesn't match the necessary parameters:
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
So I was thinking of turning the parameters from the ORM into a SQL query, and then just passing that to my method, which can then run the raw query and return a cursor, like this:
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
{
switch (uriMatcher.match(uri))
{
case RAW_QUERY:
cursor = db.rawQuery(selection, selectionArgs);//query, arguments
...
the first issue is that this method of SQLiteQueryBuilder is deprecated:
buildQuery (String[] projectionIn, String selection, String[] selectionArgs, String groupBy, String having, String sortOrder, String limit)
so then I tried this:
Object args[] = whereArgs;
String where_query = String.format(whereClause, args);
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables(getTableName(type));
String query = builder.buildQuery(null, whereClause, whereArgs, groupBy, null, orderBy, limit);
but the resulting query string is null.
Any suggestions?