Example usage for android.database.sqlite SQLiteQueryBuilder SQLiteQueryBuilder

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

Introduction

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

Prototype

public SQLiteQueryBuilder() 

Source Link

Usage

From source file:com.money.manager.ex.home.DashboardFragment.java

@SuppressWarnings("deprecation")
private String prepareQueryTopPayees() {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    ViewMobileData mobileData = new ViewMobileData(getContext());
    // data to compose builder
    String[] projectionIn = new String[] { "ROWID AS _id", ViewMobileData.PAYEEID, ViewMobileData.PAYEE,
            "ABS(SUM(" + ViewMobileData.AmountBaseConvRate + ")) AS TOTAL", "COUNT(*) AS NUM" };

    String selection = ViewMobileData.Status + "<>'V' AND " + ViewMobileData.TransactionType
            + " IN ('Withdrawal', 'Deposit') AND (julianday(date('now')) - julianday(" + ViewMobileData.Date
            + ") <= 30)";

    String groupBy = ViewMobileData.PAYEEID + ", " + ViewMobileData.PAYEE;
    String having = null;//  w w  w .jav  a2  s . c  om
    String sortOrder = "ABS(SUM(" + ViewMobileData.AmountBaseConvRate + ")) DESC";
    String limit = "10";
    // compose builder
    builder.setTables(mobileData.getSource());
    // return query
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, limit);
    } else {
        return builder.buildQuery(projectionIn, selection, null, groupBy, having, sortOrder, limit);
    }
}

From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String originalSelection,
        final String[] originalSelectionArgs, final String sortOrder) {
    final SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(DATABASE_TABLE);/* w ww .java 2 s. co  m*/

    final List<String> pathSegments = uri.getPathSegments();
    if (pathSegments.size() > 1)
        throw new IllegalArgumentException(uri.toString());

    String selection = null;
    String[] selectionArgs = null;

    if (pathSegments.size() == 1) {
        final String address = uri.getLastPathSegment();

        qb.appendWhere(KEY_ADDRESS + "=");
        qb.appendWhereEscapeString(address);
    } else if (SELECTION_IN.equals(originalSelection)) {
        final String[] addresses = originalSelectionArgs[0].trim().split(",");

        qb.appendWhere(KEY_ADDRESS + " IN (");
        appendAddresses(qb, addresses);
        qb.appendWhere(")");
    } else if (SELECTION_NOTIN.equals(originalSelection)) {
        final String[] addresses = originalSelectionArgs[0].trim().split(",");

        qb.appendWhere(KEY_ADDRESS + " NOT IN (");
        appendAddresses(qb, addresses);
        qb.appendWhere(")");
    } else if (SELECTION_QUERY.equals(originalSelection)) {
        final String query = '%' + originalSelectionArgs[0].trim() + '%';
        selection = KEY_ADDRESS + " LIKE ? OR " + KEY_LABEL + " LIKE ?";
        selectionArgs = new String[] { query, query };
    }

    final Cursor cursor = qb.query(helper.getReadableDatabase(), projection, selection, selectionArgs, null,
            null, sortOrder);

    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
}

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  ww w  .j  a  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);
}

From source file:org.kontalk.provider.UsersProvider.java

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {/* www . j a va 2  s  .c o  m*/
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    boolean offline = Boolean.parseBoolean(uri.getQueryParameter(Users.OFFLINE));

    int match = sUriMatcher.match(uri);
    if (match == USERS || match == USERS_JID) {
        // use the same table name as an alias
        String table = offline ? (TABLE_USERS_OFFLINE + " " + TABLE_USERS) : TABLE_USERS;
        qb.setTables(table);
        qb.setProjectionMap(usersProjectionMap);
    } else if (match == KEYS || match == KEYS_JID || match == KEYS_JID_FINGERPRINT) {
        qb.setTables(TABLE_KEYS);
        qb.setProjectionMap(keysProjectionMap);
    }

    switch (match) {
    case USERS:
        // nothing to do
        break;

    case USERS_JID: {
        // TODO append to selection
        String userId = uri.getPathSegments().get(1);
        selection = TABLE_USERS + "." + Users.JID + " = ?";
        selectionArgs = new String[] { userId };
        break;
    }

    case KEYS:
        // nothing to do
        break;

    case KEYS_JID:
    case KEYS_JID_FINGERPRINT:
        String userId = uri.getPathSegments().get(1);
        selection = DatabaseUtilsCompat.concatenateWhere(selection, Keys.JID + "=?");
        selectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { userId });
        // TODO support for fingerprint in Uri
        break;

    default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    SQLiteDatabase db = dbHelper.getReadableDatabase();
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
    if ((match == USERS || match == USERS_JID) && c.getCount() == 0
            && (match != USERS_JID || !XMPPUtils.isDomainJID(uri.getPathSegments().get(1)))) {
        // empty result set and sync requested
        SyncAdapter.requestSync(getContext(), false);
    }
    if (Boolean.parseBoolean(uri.getQueryParameter(Users.EXTRA_INDEX)) && c.getCount() > 0) {
        UsersCursor uc = new UsersCursor(c);
        bundleFastScrollingIndexExtras(uc, uri, db, qb, selection, selectionArgs, sortOrder, null);
        c = uc;
    }

    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}

From source file:com.money.manager.ex.MmxContentProvider.java

private Cursor query_internal(Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {//from  ww  w .j a v a 2s.c o m
    Timber.d("Querying URI: %s", uri);

    // find object from uri
    Object sourceObject = getObjectFromUri(uri);

    initializeDependencies();

    SQLiteDatabase database = openHelper.get().getReadableDatabase();
    if (database == null) {
        Timber.e("Database could not be opened");
        return null;
    }

    Cursor cursor;

    // check type of instance data set
    if (Dataset.class.isInstance(sourceObject)) {
        Dataset dataset = ((Dataset) sourceObject);

        //            logQuery(dataset, projection, selection, selectionArgs, sortOrder);

        switch (dataset.getType()) {
        case QUERY:
            String query = prepareQuery(dataset.getSource(), projection, selection, sortOrder);
            cursor = database.rawQuery(query, selectionArgs);
            break;
        case SQL:
            cursor = database.rawQuery(selection, selectionArgs);
            break;
        case TABLE:
        case VIEW:
            SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
            queryBuilder.setTables(dataset.getSource());
            cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder);
            break;
        default:
            throw new IllegalArgumentException("Type of dataset not defined");
        }
    } else {
        throw new IllegalArgumentException("Object sourceObject of mapContent is not instance of dataset");
    }

    // notify listeners waiting for the data is ready
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    if (!cursor.isClosed()) {
        Timber.d("Rows returned: %d", cursor.getCount());
    }

    return cursor;
}

From source file:de.nware.app.hsDroid.provider.onlineService2Provider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    Cursor cursor = null;//from w ww . j  a  v  a 2s  .c om
    switch (mUriMatcher.match(uri)) {
    case EXAMS:
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        qb.setTables(mOpenHelper.getTableName());
        qb.setProjectionMap(examsProjectionMap);
        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        try {
            cursor = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
        } catch (SQLException e) {
            e.printStackTrace();
            Log.d(TAG, "SqlError: " + e.getMessage());
        }
        cursor.setNotificationUri(getContext().getContentResolver(), uri);
        break;
    case EXAMS_UPDATE:
        MatrixCursor cur = new MatrixCursor(EXAMS_UPDATE_COLUMNS);
        Integer[] columnValues = updateGrades();
        cur.addRow(new Object[] { 0, columnValues[0], columnValues[1] });
        return cur;
    case EXAMINFOS:
        cursor = getExamInfos(selectionArgs[0], selectionArgs[1], false);
        break;
    case CERTIFICATIONS:
        cursor = getCertifications();
        break;
    default:
        throw new IllegalArgumentException("Unbekannte URI " + uri);
    }

    return cursor;
}

From source file:org.mitre.svmp.common.DatabaseHandler.java

private Cursor _getConnectionInfoCursor(String selection, String... selectionArgs) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder//from   w w w .  j  av  a 2 s.  c  o m
            .setTables(String.format("%s NATURAL LEFT JOIN %s", Tables[TABLE_CONNECTIONS], Tables[TABLE_APPS]));

    // prepared statement for speed and security
    return queryBuilder.query(getDb(),
            new String[] { "ConnectionID", "Description", "Username", "Host", "Port", "EncryptionType",
                    "AuthType", "CertificateAlias", "COUNT(PackageName)", "Status" }, // columns (null == "*")
            selection, // selection ('where' clause)
            selectionArgs, // selection args
            "ConnectionID", // group by
            null, // having
            "Description" // order by
    );
}

From source file:com.appsimobile.appsii.module.home.provider.HomeContentProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    selection = fixWhereProjection(uri, selection);
    SqlArguments args = new SqlArguments(uri, selection, selectionArgs);

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    String tables = createTablesFromTableQuery(args.table);

    qb.setTables(tables);//from  www .  j a  va2  s. c o  m

    Map<String, String> projectionMap = getProjectionMapForTable(args.table);

    if (projectionMap != null) {
        qb.setProjectionMap(projectionMap);
        qb.setStrict(true);
    }

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    if (HomeContract.CELLS_TABLE_NAME.equals(args.table)) {
        sortOrder = fixSortOrder(sortOrder);
    }
    String where = args.where;
    if (HomeContract.HOTSPOT_PAGES_DETAILS_TABLE_NAME.equals(args.table)) {
        where = "_ht." + BaseColumns._ID + "=" + ContentUris.parseId(uri);
    }

    Cursor result = qb.query(db, projection, where, args.args, null, null, sortOrder);

    result.setNotificationUri(getContext().getContentResolver(), uri);

    return result;
}

From source file:com.fututel.db.DBProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    // Constructs a new query builder and sets its table name
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    String finalSortOrder = sortOrder;
    String[] finalSelectionArgs = selectionArgs;
    String finalGrouping = null;//from w  ww  . j a  va2 s . c om
    String finalHaving = null;
    int type = URI_MATCHER.match(uri);

    Uri regUri = uri;

    int remoteUid = Binder.getCallingUid();
    int selfUid = android.os.Process.myUid();
    if (remoteUid != selfUid) {
        if (type == ACCOUNTS || type == ACCOUNTS_ID) {
            for (String proj : projection) {
                if (proj.toLowerCase().contains(SipProfile.FIELD_DATA) || proj.toLowerCase().contains("*")) {
                    throw new SecurityException("Password not readable from external apps");
                }
            }
        }
    }

    Cursor c;
    long id;
    switch (type) {
    case ACCOUNTS:
        qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipProfile.FIELD_PRIORITY + " ASC";
        }
        break;
    case ACCOUNTS_ID:
        qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME);
        qb.appendWhere(SipProfile.FIELD_ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case CALLLOGS:
        qb.setTables(SipManager.CALLLOGS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = CallLog.Calls.DATE + " DESC";
        }
        break;
    case CALLLOGS_ID:
        qb.setTables(SipManager.CALLLOGS_TABLE_NAME);
        qb.appendWhere(CallLog.Calls._ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case FILTERS:
        qb.setTables(SipManager.FILTERS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = Filter.DEFAULT_ORDER;
        }
        break;
    case FILTERS_ID:
        qb.setTables(SipManager.FILTERS_TABLE_NAME);
        qb.appendWhere(Filter._ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case MESSAGES:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        break;
    case MESSAGES_ID:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        qb.appendWhere(SipMessage.FIELD_ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case THREADS:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_FROM_FULL,
                SipMessage.FIELD_TO,
                "CASE " + "WHEN " + SipMessage.FIELD_FROM + "='SELF' THEN " + SipMessage.FIELD_TO + " WHEN "
                        + SipMessage.FIELD_FROM + "!='SELF' THEN " + SipMessage.FIELD_FROM
                        + " END AS message_ordering",
                SipMessage.FIELD_BODY, "MAX(" + SipMessage.FIELD_DATE + ") AS " + SipMessage.FIELD_DATE,
                "MIN(" + SipMessage.FIELD_READ + ") AS " + SipMessage.FIELD_READ,
                //SipMessage.FIELD_READ,
                "COUNT(" + SipMessage.FIELD_DATE + ") AS counter" };
        //qb.appendWhere(SipMessage.FIELD_TYPE + " in (" + SipMessage.MESSAGE_TYPE_INBOX
        //        + "," + SipMessage.MESSAGE_TYPE_SENT + ")");
        finalGrouping = "message_ordering";
        regUri = SipMessage.MESSAGE_URI;
        break;
    case THREADS_ID:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_TO,
                SipMessage.FIELD_BODY, SipMessage.FIELD_DATE, SipMessage.FIELD_MIME_TYPE, SipMessage.FIELD_TYPE,
                SipMessage.FIELD_STATUS, SipMessage.FIELD_FROM_FULL };
        qb.appendWhere(MESSAGES_THREAD_SELECTION);
        String from = uri.getLastPathSegment();
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { from, from });
        regUri = SipMessage.MESSAGE_URI;
        break;
    case ACCOUNTS_STATUS:
        synchronized (profilesStatus) {
            ContentValues[] cvs = new ContentValues[profilesStatus.size()];
            int i = 0;
            for (ContentValues ps : profilesStatus.values()) {
                cvs[i] = ps;
                i++;
            }
            c = getCursor(cvs);
        }
        if (c != null) {
            c.setNotificationUri(getContext().getContentResolver(), uri);
        }
        return c;
    case ACCOUNTS_STATUS_ID:
        id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            ContentValues cv = profilesStatus.get(id);
            if (cv == null) {
                return null;
            }
            c = getCursor(new ContentValues[] { cv });
        }
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;
    default:
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();

    c = qb.query(db, projection, selection, finalSelectionArgs, finalGrouping, finalHaving, finalSortOrder);

    c.setNotificationUri(getContext().getContentResolver(), regUri);
    return c;
}

From source file:com.sonetel.db.DBProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    // Constructs a new query builder and sets its table name
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    String finalSortOrder = sortOrder;
    String[] finalSelectionArgs = selectionArgs;
    String finalGrouping = null;//  w ww. jav a2  s  . c om
    String finalHaving = null;
    int type = URI_MATCHER.match(uri);

    Uri regUri = uri;

    int remoteUid = Binder.getCallingUid();
    int selfUid = android.os.Process.myUid();
    if (remoteUid != selfUid) {
        if (type == ACCOUNTS || type == ACCOUNTS_ID) {
            for (String proj : projection) {
                if (proj.toLowerCase().contains(SipProfile.FIELD_DATA) || proj.toLowerCase().contains("*")) {
                    throw new SecurityException("Password not readable from external apps");
                }
            }
        }
    }

    Cursor c;
    long id;
    switch (type) {
    case ACCOUNTS:
        qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipProfile.FIELD_PRIORITY + " ASC";
        }
        break;
    case ACCOUNTS_ID:
        qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME);
        qb.appendWhere(SipProfile.FIELD_ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case CALLLOGS:
        qb.setTables(SipManager.CALLLOGS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = CallLog.Calls.DATE + " DESC";
        }
        break;
    case CALLLOGS_ID:
        qb.setTables(SipManager.CALLLOGS_TABLE_NAME);
        qb.appendWhere(CallLog.Calls._ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case FILTERS:
        qb.setTables(SipManager.FILTERS_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = Filter.DEFAULT_ORDER;
        }
        break;
    case FILTERS_ID:
        qb.setTables(SipManager.FILTERS_TABLE_NAME);
        qb.appendWhere(Filter._ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case MESSAGES:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        break;
    case MESSAGES_ID:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        qb.appendWhere(SipMessage.FIELD_ID + "=?");
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { uri.getLastPathSegment() });
        break;
    case THREADS:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_FROM_FULL,
                SipMessage.FIELD_TO,
                "CASE " + "WHEN " + SipMessage.FIELD_FROM + "='SELF' THEN " + SipMessage.FIELD_TO + " WHEN "
                        + SipMessage.FIELD_FROM + "!='SELF' THEN " + SipMessage.FIELD_FROM
                        + " END AS message_ordering",
                SipMessage.FIELD_BODY, "MAX(" + SipMessage.FIELD_DATE + ") AS " + SipMessage.FIELD_DATE,
                "MIN(" + SipMessage.FIELD_READ + ") AS " + SipMessage.FIELD_READ,
                //SipMessage.FIELD_READ,
                "COUNT(" + SipMessage.FIELD_DATE + ") AS counter" };
        //qb.appendWhere(SipMessage.FIELD_TYPE + " in (" + SipMessage.MESSAGE_TYPE_INBOX
        //        + "," + SipMessage.MESSAGE_TYPE_SENT + ")");
        finalGrouping = "message_ordering";
        regUri = SipMessage.MESSAGE_URI;
        break;
    case THREADS_ID:
        qb.setTables(SipMessage.MESSAGES_TABLE_NAME);
        if (sortOrder == null) {
            finalSortOrder = SipMessage.FIELD_DATE + " DESC";
        }
        projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_TO,
                SipMessage.FIELD_BODY, SipMessage.FIELD_DATE, SipMessage.FIELD_MIME_TYPE, SipMessage.FIELD_TYPE,
                SipMessage.FIELD_STATUS, SipMessage.FIELD_FROM_FULL };
        qb.appendWhere(MESSAGES_THREAD_SELECTION);
        String from = uri.getLastPathSegment();
        finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
                new String[] { from, from });
        regUri = SipMessage.MESSAGE_URI;
        break;
    case ACCOUNTS_STATUS:
        synchronized (profilesStatus) {
            ContentValues[] cvs = new ContentValues[profilesStatus.size()];
            int i = 0;
            for (ContentValues ps : profilesStatus.values()) {
                cvs[i] = ps;
                i++;
            }
            c = getCursor(cvs);
        }
        if (c != null) {
            c.setNotificationUri(getContext().getContentResolver(), uri);
        }
        return c;
    case ACCOUNTS_STATUS_ID:
        id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            ContentValues cv = profilesStatus.get(id);
            if (cv == null) {
                return null;
            }
            c = getCursor(new ContentValues[] { cv });
        }
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;
    case ACCESSNO:
        qb.setTables(SipProfile.ACCESS_NUMS_TABLE_NAME);

        break;
    default:
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();

    c = qb.query(db, projection, selection, finalSelectionArgs, finalGrouping, finalHaving, finalSortOrder);

    c.setNotificationUri(getContext().getContentResolver(), regUri);
    return c;
}