Java Code Examples for net.sqlcipher.database.SQLiteDatabase#delete()

The following examples show how to use net.sqlcipher.database.SQLiteDatabase#delete() . 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
/**
 * Trims data related to expired messages. Only intended to be run after a backup restore.
 */
void trimEntriesForExpiredMessages() {
  SQLiteDatabase database         = databaseHelper.getWritableDatabase();
  String         trimmedCondition = " NOT IN (SELECT " + MmsDatabase.ID + " FROM " + MmsDatabase.TABLE_NAME + ")";

  database.delete(GroupReceiptDatabase.TABLE_NAME, GroupReceiptDatabase.MMS_ID + trimmedCondition, null);

  String[] columns = new String[] { AttachmentDatabase.ROW_ID, AttachmentDatabase.UNIQUE_ID };
  String   where   = AttachmentDatabase.MMS_ID + trimmedCondition;

  try (Cursor cursor = database.query(AttachmentDatabase.TABLE_NAME, columns, where, null, null, null, null)) {
    while (cursor != null && cursor.moveToNext()) {
      DatabaseFactory.getAttachmentDatabase(context).deleteAttachment(new AttachmentId(cursor.getLong(0), cursor.getLong(1)));
    }
  }

  try (Cursor cursor = database.query(ThreadDatabase.TABLE_NAME, new String[] { ThreadDatabase.ID }, ThreadDatabase.EXPIRES_IN + " > 0", null, null, null, null)) {
    while (cursor != null && cursor.moveToNext()) {
      DatabaseFactory.getThreadDatabase(context).update(cursor.getLong(0), false);
    }
  }
}
 
Example 2
Source Project: commcare-android   File: SqlStorage.java    License: Apache License 2.0 6 votes vote down vote up
public void remove(List<Integer> ids) {
    if (ids.size() == 0) {
        return;
    }
    SQLiteDatabase db = helper.getHandle();
    db.beginTransaction();
    try {
        List<Pair<String, String[]>> whereParamList = TableBuilder.sqlList(ids);
        for (Pair<String, String[]> whereParams : whereParamList) {
            db.delete(table, DatabaseHelper.ID_COL + " IN " + whereParams.first, whereParams.second);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
 
Example 3
@Override
public void remove(int id) {
    SQLiteDatabase db = getDbOrThrow();

    String filename = HybridFileBackedSqlHelpers.getEntryFilename(helper, table, id);
    db.beginTransaction();
    try {
        db.delete(table, DatabaseHelper.ID_COL + "=?", new String[]{String.valueOf(id)});
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }

    if (filename != null) {
        File dataFile = new File(filename);
        dataFile.delete();
    }
}
 
Example 4
private void deleteWithSelection(SQLiteDatabase db, String tableName, String selection,
        String[] selectionArgs) {
    
        log("deleteWithSelection: table " + tableName + ", selection => " + selection);
    int count = db.delete(tableName, selection, selectionArgs);
    
        log("deleteWithSelection: deleted " + count + " rows");
}
 
Example 5
protected static void unsetFileAsOrphan(SQLiteDatabase db, String filename) {
    int deleteCount = db.delete(DbUtil.orphanFileTableName, DatabaseHelper.FILE_COL + "=?", new String[]{filename});
    if (deleteCount != 1) {
        Logger.log(LogTypes.SOFT_ASSERT,
                "Unable to unset orphaned file: " + deleteCount + " entries effected.b");
    }
}
 
Example 6
@SuppressWarnings("ResultOfMethodCallIgnored")
void deleteAllAttachments() {
  SQLiteDatabase database = databaseHelper.getWritableDatabase();
  database.delete(TABLE_NAME, null, null);

  FileUtils.deleteDirectoryContents(context.getDir(DIRECTORY, Context.MODE_PRIVATE));

  notifyAttachmentListeners();
}
 
Example 7
private void deleteThreads(Set<Long> threadIds) {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  String where      = "";

  for (long threadId : threadIds) {
    where += ID + " = '" + threadId + "' OR ";
  }

  where = where.substring(0, where.length() - 4);

  db.delete(TABLE_NAME, where, null);
  notifyConversationListListeners();
}
 
Example 8
Source Project: commcare-android   File: SqlStorage.java    License: Apache License 2.0 5 votes vote down vote up
public static void wipeTable(SQLiteDatabase db, String table) {
    db.beginTransaction();
    try {
        if (isTableExist(db, table)) {
            db.delete(table, null, null);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
 
Example 9
void deleteMessagesInThreadBeforeDate(long threadId, long date) {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  String where      = THREAD_ID + " = ? AND (CASE " + TYPE;

  for (long outgoingType : Types.OUTGOING_MESSAGE_TYPES) {
    where += " WHEN " + outgoingType + " THEN " + DATE_SENT + " < " + date;
  }

  where += (" ELSE " + DATE_RECEIVED + " < " + date + " END)");

  db.delete(TABLE_NAME, where, new String[] {threadId + ""});
}
 
Example 10
private void deletePack(@NonNull SQLiteDatabase db, @NonNull String packId) {
  String   selection = PACK_ID + " = ?";
  String[] args      = new String[] { packId };

  db.delete(TABLE_NAME, selection, args);

  deleteStickersInPack(db, packId);
}
 
Example 11
void deleteThread(long threadId) {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, THREAD_ID + " = ?", new String[] {threadId+""});
}
 
Example 12
void deleteAllThreads() {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, null, null);
}
 
Example 13
public void removePreKey(int keyId) {
  SQLiteDatabase database = databaseHelper.getWritableDatabase();
  database.delete(TABLE_NAME, KEY_ID + " = ?", new String[] {String.valueOf(keyId)});
}
 
Example 14
void deleteAllRows() {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, null, null);
}
 
Example 15
Source Project: commcare-android   File: SqlStorage.java    License: Apache License 2.0 4 votes vote down vote up
public static void wipeTableWithoutCommit(SQLiteDatabase db, String table) {
    db.delete(table, null, null);
}
 
Example 16
public void removeSignedPreKey(int keyId) {
  SQLiteDatabase database = databaseHelper.getWritableDatabase();
  database.delete(TABLE_NAME, KEY_ID + " = ? AND " + SIGNATURE + " IS NOT NULL", new String[] {String.valueOf(keyId)});
}
 
Example 17
public void delete(@NonNull RecipientId recipientId, int deviceId) {
  SQLiteDatabase database = databaseHelper.getWritableDatabase();

  database.delete(TABLE_NAME, RECIPIENT_ID + " = ? AND " + DEVICE + " = ?",
                  new String[] {recipientId.serialize(), String.valueOf(deviceId)});
}
 
Example 18
private void deleteThread(long threadId) {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, ID_WHERE, new String[] {threadId + ""});
  notifyConversationListListeners();
}
 
Example 19
private void deleteAll(SQLiteDatabase database) {
    database.delete(DbHelper.Tables.SIMPLE_ENTITY, null, emptyWhereArgs);
}
 
Example 20
private void deleteAllThreads() {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, null, null);
  notifyConversationListListeners();
}