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
Source File: MmsDatabase.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 File: SqlStorage.java    From commcare-android with 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
Source File: HybridFileBackedSqlStorage.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@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
Source File: SqlStorage.java    From commcare-android with 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 5
Source File: StickerDatabase.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: SmsDatabase.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: ImpsProvider.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
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 8
Source File: ThreadDatabase.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: AttachmentDatabase.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("ResultOfMethodCallIgnored")
void deleteAllAttachments() {
  SQLiteDatabase database = databaseHelper.getWritableDatabase();
  database.delete(TABLE_NAME, null, null);

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

  notifyAttachmentListeners();
}
 
Example 10
Source File: HybridFileBackedSqlHelpers.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
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 11
Source File: OneTimePreKeyDatabase.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public void removePreKey(int keyId) {
  SQLiteDatabase database = databaseHelper.getWritableDatabase();
  database.delete(TABLE_NAME, KEY_ID + " = ?", new String[] {String.valueOf(keyId)});
}
 
Example 12
Source File: GroupReceiptDatabase.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
void deleteAllRows() {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, null, null);
}
 
Example 13
Source File: SmsDatabase.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
void deleteAllThreads() {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, null, null);
}
 
Example 14
Source File: SmsDatabase.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
void deleteThread(long threadId) {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, THREAD_ID + " = ?", new String[] {threadId+""});
}
 
Example 15
Source File: SqlStorage.java    From commcare-android with 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
Source File: SignedPreKeyDatabase.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
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
Source File: SessionDatabase.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
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
Source File: ThreadDatabase.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private void deleteThread(long threadId) {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, ID_WHERE, new String[] {threadId + ""});
  notifyConversationListListeners();
}
 
Example 19
Source File: PerfTestSqlite.java    From android-database-performance with Apache License 2.0 4 votes vote down vote up
private void deleteAll(SQLiteDatabase database) {
    database.delete(DbHelper.Tables.SIMPLE_ENTITY, null, emptyWhereArgs);
}
 
Example 20
Source File: ThreadDatabase.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private void deleteAllThreads() {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, null, null);
  notifyConversationListListeners();
}