Java Code Examples for android.database.sqlite.SQLiteQueryBuilder#buildUnionSubQuery()

The following examples show how to use android.database.sqlite.SQLiteQueryBuilder#buildUnionSubQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MmsSmsDatabase.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private Cursor queryTables(String[] projection, String selection, String order, String limit, String groupBy, String having) {
        String[] mmsProjection = getMmsProjection();

        String[] smsProjection = getSmsProjection();

        SQLiteQueryBuilder mmsQueryBuilder = new SQLiteQueryBuilder();
        SQLiteQueryBuilder smsQueryBuilder = new SQLiteQueryBuilder();

        mmsQueryBuilder.setDistinct(true);
        smsQueryBuilder.setDistinct(true);

        smsQueryBuilder.setTables(SmsDatabase.TABLE_NAME);
        mmsQueryBuilder.setTables(MmsDatabase.TABLE_NAME + " LEFT OUTER JOIN " +
                AttachmentDatabase.TABLE_NAME +
                " ON " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.ROW_ID + " = " +
                " (SELECT " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.ROW_ID +
                " FROM " + AttachmentDatabase.TABLE_NAME + " WHERE " +
                AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.MMS_ID + " = " +
                MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID + " LIMIT 1)");


        Set<String> mmsColumnsPresent = getMmsColumnsPresent();

        Set<String> smsColumnsPresent = getSmsColumnsPresent();

//        @SuppressWarnings("deprecation")
        String mmsSubQuery = mmsQueryBuilder.buildUnionSubQuery(TRANSPORT, mmsProjection, mmsColumnsPresent, 4, MMS_TRANSPORT, selection, null, null);
        ALog.d(TAG, "mmsSubQuery: " + mmsSubQuery + "\n");

//        @SuppressWarnings("deprecation")
        String smsSubQuery = smsQueryBuilder.buildUnionSubQuery(TRANSPORT, smsProjection, smsColumnsPresent, 4, SMS_TRANSPORT, selection, null, null);
        ALog.d(TAG, "smsSubQuery: " + smsSubQuery + "\n");

        SQLiteQueryBuilder unionQueryBuilder = new SQLiteQueryBuilder();
        String unionQuery = unionQueryBuilder.buildUnionQuery(new String[]{smsSubQuery, mmsSubQuery}, order, limit);
        ALog.d(TAG, "unionQuery: " + unionQuery + "\n");

        SQLiteQueryBuilder outerQueryBuilder = new SQLiteQueryBuilder();
        outerQueryBuilder.setTables("(" + unionQuery + ")");
//        @SuppressWarnings("deprecation")
        String query = outerQueryBuilder.buildQuery(projection, null, groupBy, having, null, null);
        ALog.d(TAG, "target query: " + query + "\n");

        SQLiteDatabase db = databaseHelper.getReadableDatabase();
        return db.rawQuery(query, null);
    }
 
Example 2
Source File: AndroidSql.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void sampleSQLiteQueryBuilder(SQLiteQueryBuilder builder, String input) {
    builder.appendWhere(input);
    //buildQueryString
    builder.buildQueryString(false, null, null, input, null, null, null, null);
    builder.buildQueryString(false, null, null, null, input, null, null, null);
    builder.buildQueryString(false, null, null, null, null, input, null, null);
    builder.buildQueryString(false, null, null, null, null, null, input,null);
    builder.buildQueryString(false, null, null, null, null, null,null, input);
    //query no limit
    builder.query(null, null, input, null, null, null,null);
    builder.query(null, null, null, null, input, null,null);
    builder.query(null, null, null, null,null,input,null);
    builder.query(null, null, null, null,null,null,input);
    //query with limit
    builder.query(null, null, input, null, null, null,null, null);
    builder.query(null, null, null, null, input, null,null, null);
    builder.query(null, null, null, null,null,input,null, null);
    builder.query(null, null, null, null,null,null,input, null);
    builder.query(null, null, null, null,null,null,null, input);
    //query with limit with cancellation system
    builder.query(null, null, input, null, null, null,null, null, new CancellationSignal());
    builder.query(null, null, null, null, input, null,null, null, new CancellationSignal());
    builder.query(null, null, null, null,null,input,null, null, new CancellationSignal());
    builder.query(null, null, null, null,null,null,input, null, new CancellationSignal());
    builder.query(null, null, null, null,null,null,null, input, new CancellationSignal());
    //buildQuery
    builder.buildQuery(null, input, null, null, null, null);
    builder.buildQuery(null, null, input,null, null, null);
    builder.buildQuery(null, null, null, input, null, null);
    builder.buildQuery(null, null, null, null, input, null);
    builder.buildQuery(null, null, null, null, null, input);
    //buildQuery with selectionArgs
    builder.buildQuery(null, input, new String[0], null, null, null, null);
    builder.buildQuery(null, null, new String[0], input, null, null, null);
    builder.buildQuery(null, null, new String[0],null, input,null, null);
    builder.buildQuery(null, null, new String[0],null, null, input,null);
    builder.buildQuery(null, null, new String[0],null, null, null, input);
    //buildUnionQuery
    builder.buildUnionQuery(new String[] {input}, null, null);
    builder.buildUnionQuery(null, input, null);
    builder.buildUnionQuery(null, null, input);
    //buildUnionSubQuery
    builder.buildUnionSubQuery(null, null, null,0, null, input, null, null);
    builder.buildUnionSubQuery(null, null, null,0, null, null, input, null);
    builder.buildUnionSubQuery(null, null, null,0, null, null, null, input);
    //buildUnionSubQuery with selectionArgs
    builder.buildUnionSubQuery(null, null, null,0, null, input, new String[0],null, null);
    builder.buildUnionSubQuery(null, null, null,0, null, null, new String[0], input, null);
    builder.buildUnionSubQuery(null, null, null,0, null, null, new String[0], null, input);
}