Example usage for android.database.sqlite SQLiteQueryBuilder buildQuery

List of usage examples for android.database.sqlite SQLiteQueryBuilder buildQuery

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteQueryBuilder buildQuery.

Prototype

@Deprecated
public String buildQuery(String[] projectionIn, String selection, String[] selectionArgs, String groupBy,
        String having, String sortOrder, String limit) 

Source Link

Usage

From source file:pl.selvin.android.syncframework.content.BaseContentProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    final int code = contentHelper.matchUri(uri);
    if (code != UriMatcher.NO_MATCH) {
        if (code == ContentHelper.uriSyncCode) {
            return null;
        }/*from  w  w  w  .  ja va  2s .c o m*/
        SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
        final TableInfo tab = contentHelper.getTableFromCode(code & ContentHelper.uriCode);
        builder.setTables(tab.name);
        if (isItemCode(code)) {
            if (isItemRowIDCode(code)) {
                selection = "isDeleted=0 AND ROWID=" + uri.getPathSegments().get(2)
                        + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
            } else {
                selection = "isDeleted=0" + tab.getSelection()
                        + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ")" : "");
                int i = 0;
                final String[] old = selectionArgs;
                final int len = (old == null) ? 0 : old.length;
                selectionArgs = new String[len + tab.primaryKey.length];
                for (; i < tab.primaryKey.length; i++) {
                    selectionArgs[i] = uri.getPathSegments().get(i + 1);
                }
                if (len > 0) {
                    for (; i < old.length; i++) {
                        selectionArgs[i] = old[i - tab.primaryKey.length];
                    }
                }
            }
        } else {
            selection = "isDeleted=0" + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
        }
        builder.setProjectionMap(tab.map);

        Cursor cursor = builder.query(getReadableDatabase(), projection, selection, selectionArgs, null, null,
                sortOrder);
        if (DEBUG) {
            Log.d("Query",
                    builder.buildQuery(projection, selection, selectionArgs, null, null, sortOrder, null));
        }
        cursor.setNotificationUri(getContext().getContentResolver(), uri);
        return cursor;
    }
    throw new IllegalArgumentException("Unknown Uri " + uri);
}