Java Code Examples for net.sqlcipher.database.SQLiteQueryBuilder

The following examples show how to use net.sqlcipher.database.SQLiteQueryBuilder. These examples are extracted from open source projects. 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
private long getContactId(final SQLiteDatabase db, final String accountId, final String contact) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(TABLE_CONTACTS);
    qb.setProjectionMap(sContactsProjectionMap);

    mQueryContactIdSelectionArgs2[0] = accountId;
    mQueryContactIdSelectionArgs2[1] = contact;

    Cursor c = qb.query(db, CONTACT_ID_PROJECTION, CONTACT_ID_QUERY_SELECTION,
            mQueryContactIdSelectionArgs2, null, null, null, null);

    long contactId = 0;

    try {
        if (c.moveToFirst()) {
            contactId = c.getLong(CONTACT_ID_COLUMN);
        }
    } finally {
        c.close();
    }

    return contactId;
}
 
Example 2
private void buildQueryContactsByProvider(SQLiteQueryBuilder qb, StringBuilder whereClause,
        Uri url) {
    qb.setTables(CONTACT_JOIN_PRESENCE_CHAT_AVATAR_TABLE);
    qb.setProjectionMap(sContactsProjectionMap);
    // we don't really need the provider id in query. account id is enough.
    appendWhere(whereClause, Imps.Contacts.ACCOUNT, "=", url.getLastPathSegment());
}
 
Example 3
Source Project: commcare-android   Source File: SqlStorage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Vector<Integer> getIDsForValues(String[] fieldNames, Object[] values, LinkedHashSet returnSet) {
    SQLiteDatabase db = helper.getHandle();

    Pair<String, String[]> whereClause = helper.createWhereAndroid(fieldNames, values, em, null);

    if (STORAGE_OUTPUT_DEBUG) {
        String sql = SQLiteQueryBuilder.buildQueryString(false, table, new String[]{DatabaseHelper.ID_COL}, whereClause.first, null, null, null, null);
        DbUtil.explainSql(db, sql, whereClause.second);
    }

    Cursor c = db.query(table, new String[]{DatabaseHelper.ID_COL}, whereClause.first, whereClause.second, null, null, null);
    return fillIdWindow(c, DatabaseHelper.ID_COL, returnSet);
}
 
Example 4
@Override
 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) 
 {
 	// Using SQLiteQueryBuilder instead of query() method
  SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
  
  int uriType = sURIMatcher.match(uri);

  // Check if the caller has requested a column which does not exists
  checkColumns(projection, uriType);
 
  switch (uriType)
  {
      case ADDRESS_ID:
          // Adding the ID to the original query
          queryBuilder.appendWhere(AddressesTable.COLUMN_ID + "=" + uri.getLastPathSegment());
      case ADDRESSES:
          queryBuilder.setTables(AddressesTable.TABLE_ADDRESSES);
          break;

      case ADDRESS_BOOK_RECORD_ID:
          // Adding the ID to the original query
          queryBuilder.appendWhere(AddressBookRecordsTable.COLUMN_ID + "=" + uri.getLastPathSegment());
      case ADDRESS_BOOK_RECORDS:
          queryBuilder.setTables(AddressBookRecordsTable.TABLE_ADDRESS_BOOK_RECORDS);
          break;
          
      case MESSAGE_ID:
          // Adding the ID to the original query
          queryBuilder.appendWhere(MessagesTable.COLUMN_ID + "=" + uri.getLastPathSegment());
      case MESSAGES:
          queryBuilder.setTables(MessagesTable.TABLE_MESSAGES);
          break;
          
      case QUEUE_RECORD_ID:
          // Adding the ID to the original query
          queryBuilder.appendWhere(QueueRecordsTable.COLUMN_ID + "=" + uri.getLastPathSegment());
      case QUEUE_RECORDS:
          queryBuilder.setTables(QueueRecordsTable.TABLE_QUEUE_RECORDS);
          break;
          
      case PAYLOAD_ID:
          // Adding the ID to the original query
          queryBuilder.appendWhere(PayloadsTable.COLUMN_ID + "=" + uri.getLastPathSegment());
      case PAYLOADS:
          queryBuilder.setTables(PayloadsTable.TABLE_PAYLOADS);
          break;
          
      case PUBKEY_ID:
          // Adding the ID to the original query
          queryBuilder.appendWhere(PubkeysTable.COLUMN_ID + "=" + uri.getLastPathSegment());
      case PUBKEYS:
          queryBuilder.setTables(PubkeysTable.TABLE_PUBKEYS);
          break;
          
      case SERVER_RECORD_ID:
          // Adding the ID to the original query
          queryBuilder.appendWhere(ServerRecordsTable.COLUMN_ID + "=" + uri.getLastPathSegment());
      case SERVER_RECORDS:
          queryBuilder.setTables(ServerRecordsTable.TABLE_SERVER_RECORDS);
          break;
    
   default:
   	throw new IllegalArgumentException("Unknown URI: " + uri + " Exception occurred in DatabaseContentProvider.query()");
  }
  
  Cursor cursor = queryBuilder.query(sDatabase, projection, selection, selectionArgs, null, null, sortOrder);
  // make sure that potential listeners are getting notified
  cursor.setNotificationUri(sContext.getContentResolver(), uri);
  return cursor;
}