Java Code Examples for android.database.sqlite.SQLiteDatabase#delete()

The following examples show how to use android.database.sqlite.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: HistoryManager.java    From ZXing-Standalone-library with Apache License 2.0 6 votes vote down vote up
public void deleteHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getWritableDatabase();      
    cursor = db.query(DBHelper.TABLE_NAME,
                      ID_COL_PROJECTION,
                      null, null, null, null,
                      DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(number + 1);
    db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
  } finally {
    close(cursor, db);
  }
}
 
Example 2
Source File: MessagesStorage.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
public void deleteMessages(ArrayList<Integer> messages) {
    //db.execute('DELETE FROM producten WHERE id NOT IN (' + ids.join(",") + ')');
    DaoMaster.DevOpenHelper databaseHelper = new DaoMaster.DevOpenHelper(ApplicationLoader.applicationContext,
            "ycache.sqlite", null);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    DaoMaster daoMaster = new DaoMaster(database);
    DaoSession daoSession = daoMaster.newSession();
    MessagesDao messagesDao = daoSession.getMessagesDao();
    ChatsDao chatsDao = daoSession.getChatsDao();

    //FileLog.e("Test deleteMessage", String.format(Locale.US, "id IN (%s)",join(messages,',')) + "");
    database.delete(messagesDao.getTablename(), String.format(Locale.US, "mid IN (%s)", join(messages, ',')), null);


    Utilities.RunOnUIThread(new Runnable() {
        @Override
        public void run() {
            NotificationCenter.getInstance().postNotificationName(XMPPManager.updateInterfaces);
        }
    });
    daoSession.clear();
    database.close();
    databaseHelper.close();
}
 
Example 3
Source File: DatabaseBackend.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
public void wipeAxolotlDb(Account account) {
    String accountName = account.getUuid();
    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + ">>> WIPING AXOLOTL DATABASE FOR ACCOUNT " + accountName + " <<<");
    SQLiteDatabase db = this.getWritableDatabase();
    String[] deleteArgs = {
            accountName
    };
    db.delete(SQLiteAxolotlStore.SESSION_TABLENAME,
            SQLiteAxolotlStore.ACCOUNT + " = ?",
            deleteArgs);
    db.delete(SQLiteAxolotlStore.PREKEY_TABLENAME,
            SQLiteAxolotlStore.ACCOUNT + " = ?",
            deleteArgs);
    db.delete(SQLiteAxolotlStore.SIGNED_PREKEY_TABLENAME,
            SQLiteAxolotlStore.ACCOUNT + " = ?",
            deleteArgs);
    db.delete(SQLiteAxolotlStore.IDENTITIES_TABLENAME,
            SQLiteAxolotlStore.ACCOUNT + " = ?",
            deleteArgs);
}
 
Example 4
Source File: InstanceProvider.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * This method removes the entry from the content provider, and also removes any associated files.
 * files:  form.xml, [formmd5].formdef, formname-media {directory}
 */
@Override
public int delete(@NonNull Uri uri, String where, String[] whereArgs) {

    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    int count;
    switch (sUriMatcher.match(uri)) {
        case INSTANCE_ID:
            init(uri.getLastPathSegment());
            count = db.delete(INSTANCES_TABLE_NAME, InstanceProviderAPI.InstanceColumns._ID + "=?", new String[]{uri.getPathSegments().get(1)});
            break;
        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }

    db.close();
    notifyChangeSafe(getContext(), uri);
    return count;

}
 
Example 5
Source File: DaoMetadata.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Delete a metadata item.
 *
 * @param key the key to use.
 * @throws IOException
 */
public static void deleteItem(String key) throws IOException {
    SQLiteDatabase sqliteDatabase = GeopaparazziApplication.getInstance().getDatabase();
    sqliteDatabase.beginTransaction();
    try {
        String where = MetadataTableFields.COLUMN_KEY.getFieldName() + "='" + key + "'";
        sqliteDatabase.delete(TABLE_METADATA, where, null);

        sqliteDatabase.setTransactionSuccessful();
    } catch (Exception e) {
        GPLog.error("DaoMetadata", e.getLocalizedMessage(), e);
        throw new IOException(e.getLocalizedMessage());
    } finally {
        sqliteDatabase.endTransaction();
    }
}
 
Example 6
Source File: DBHelper.java    From Liapp with Apache License 2.0 6 votes vote down vote up
public void deleteAllData() {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        db.delete(TABLE_HISTORY, null, null);
        db.delete(TABLE_LASTSCAN, null, null);
        db.delete(TABLE_SENSOR, null, null);
        db.delete(TABLE_SCANS, null, null);

        db.setTransactionSuccessful();
    } catch (Exception e) {

    } finally {
        db.endTransaction();
    }
}
 
Example 7
Source File: MainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void listing9_20(String hoardId) {
  HoardDBOpenHelper hoardDBOpenHelper = new HoardDBOpenHelper(this,
    HoardDBOpenHelper.DATABASE_NAME, null,
    HoardDBOpenHelper.DATABASE_VERSION);

  // Listing 9-20: Deleting a database row
  // Specify a where clause that determines which row(s) to delete.
  // Specify where arguments as necessary.
  String where = HoardContract.KEY_ID + "=?";
  String whereArgs[] = {hoardId};

  // Delete the rows that match the where clause.
  SQLiteDatabase db = hoardDBOpenHelper.getWritableDatabase();
  db.delete(HoardDBOpenHelper.DATABASE_TABLE, where, whereArgs);
}
 
Example 8
Source File: KcaQuestTracker.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
public boolean check_quest_completed(KcaDBHelper helper) {
    SQLiteDatabase db = this.getReadableDatabase();
    int count = 0;
    boolean result = false;
    Cursor c = db.rawQuery("SELECT * from "
            .concat(qt_table_name)
            .concat(" WHERE ACTIVE=1"), null);
    while (c.moveToNext()) {
        String key = c.getString(c.getColumnIndex("KEY"));
        String cond0 = c.getString(c.getColumnIndex("CND0"));
        String cond1 = c.getString(c.getColumnIndex("CND1"));
        String cond2 = c.getString(c.getColumnIndex("CND2"));
        String cond3 = c.getString(c.getColumnIndex("CND3"));
        String cond4 = c.getString(c.getColumnIndex("CND4"));
        String cond5 = c.getString(c.getColumnIndex("CND5"));
        String time = c.getString(c.getColumnIndex("TIME"));
        String[] cond_value = {cond0, cond1, cond2, cond3, cond4, cond5};
        JsonObject questTrackInfo = KcaApiData.getQuestTrackInfo(key);
        if (questTrackInfo != null) {
            int counter = 0;
            JsonArray cond = questTrackInfo.getAsJsonArray("cond");
            int type = questTrackInfo.get("type").getAsInt();
            for (int i = 0; i < cond.size(); i++) {
                if (cond_value[i] == null || cond_value[i].equals("")) continue;
                if(Integer.parseInt(cond_value[i]) >= Integer.parseInt(cond.get(i).getAsString())) {
                    if (!checkQuestValid(type, Integer.parseInt(key), time)) {
                        db.delete(qt_table_name, "KEY=?", new String[]{String.valueOf(key)});
                    } else {
                        counter += 1;
                    }
                }
            }
            if (counter == cond.size()) {
                result = true;
            }
        }
    }
    c.close();
    return result;
}
 
Example 9
Source File: WidgetPreviewLoader.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private void clearDb() {
    SQLiteDatabase db = mDb.getWritableDatabase();
    // Delete everything
    try {
        db.delete(CacheDb.TABLE_NAME, null, null);
    } catch (SQLiteDiskIOException e) {
    }
}
 
Example 10
Source File: DatabaseHandler.java    From repay-android with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a singular debt from the database
 * @throws android.database.SQLException
 * @throws IndexOutOfBoundsException
 * @throws NullPointerException
 */
public void removeDebt(int debtID) throws SQLException, IndexOutOfBoundsException,
		NullPointerException{
	SQLiteDatabase db = this.getWritableDatabase();
	db.delete(Names.D_TABLENAME, Names.D_DEBTID+"=?",
			new String[]{Integer.toString(debtID)});
	db.close();
}
 
Example 11
Source File: HueDBHelper.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 指定されたIPアドレスと同じアクセスポイントを削除します.
 * @param ipAddress 削除するアクセスポイントのIPアドレス
 * @return 削除した個数
 */
synchronized int removeAccessPointByIpAddress(final String ipAddress) {
    String whereClause = COL_IP_ADDRESS + "=?";
    String[] whereArgs = {
            ipAddress
    };

    SQLiteDatabase db = mDBHelper.getWritableDatabase();
    try {
        return db.delete(TBL_NAME, whereClause, whereArgs);
    } finally {
        db.close();
    }
}
 
Example 12
Source File: KcaDBHelper.java    From kcanotify_h5-master with GNU General Public License v3.0 4 votes vote down vote up
public void removeQuest(int key) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(questlist_table_name, "KEY=?", new String[]{String.valueOf(key)});
    qt.removeQuestTrack(key, false);
}
 
Example 13
Source File: ActionBatch.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(final Context context) {
    if (null == mWordList) { // This should never happen
        Log.e(TAG, "TryRemoveAction with a null word list!");
        return;
    }
    DebugLogUtils.l("Trying to remove word list : " + mWordList);
    final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
    final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
            mWordList.mId, mWordList.mVersion);
    if (null == values) {
        Log.e(TAG, "Trying to update the metadata of a non-existing wordlist. Cancelling.");
        return;
    }
    final int status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN);
    if (mHasNewerVersion && MetadataDbHelper.STATUS_AVAILABLE != status) {
        // If we have a newer version of this word list, we should be here ONLY if it was
        // not installed - else we should be upgrading it.
        Log.e(TAG, "Unexpected status for forgetting a word list info : " + status
                + ", removing URL to prevent re-download");
    }
    if (MetadataDbHelper.STATUS_INSTALLED == status
            || MetadataDbHelper.STATUS_DISABLED == status
            || MetadataDbHelper.STATUS_DELETING == status) {
        // If it is installed or disabled, we need to mark it as deleted so that LatinIME
        // will remove it next time it enquires for dictionaries.
        // If it is deleting and we don't have a new version, then we have to wait until
        // LatinIME actually has deleted it before we can remove its metadata.
        // In both cases, remove the URI from the database since it is not supposed to
        // be accessible any more.
        values.put(MetadataDbHelper.REMOTE_FILENAME_COLUMN, "");
        values.put(MetadataDbHelper.STATUS_COLUMN, MetadataDbHelper.STATUS_DELETING);
        db.update(MetadataDbHelper.METADATA_TABLE_NAME, values,
                MetadataDbHelper.WORDLISTID_COLUMN + " = ? AND "
                        + MetadataDbHelper.VERSION_COLUMN + " = ?",
                new String[] { mWordList.mId, Integer.toString(mWordList.mVersion) });
    } else {
        // If it's AVAILABLE or DOWNLOADING or even UNKNOWN, delete the entry.
        db.delete(MetadataDbHelper.METADATA_TABLE_NAME,
                MetadataDbHelper.WORDLISTID_COLUMN + " = ? AND "
                        + MetadataDbHelper.VERSION_COLUMN + " = ?",
                new String[] { mWordList.mId, Integer.toString(mWordList.mVersion) });
    }
}
 
Example 14
Source File: DbCamera.java    From evercam-android with GNU Affero General Public License v3.0 4 votes vote down vote up
public void deleteCameraByOwner(String ownerUsername) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_CAMERA, " upper(" + KEY_OWNER + ") = upper(?)",
            new String[]{String.valueOf(ownerUsername)});
    db.close();
}
 
Example 15
Source File: TasksManagerDBOpenHelper.java    From YCAudioPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if (oldVersion == 1 && newVersion == 2) {
        db.delete(TasksManagerDBController.TABLE_NAME, null, null);
    }
}
 
Example 16
Source File: DAOProfileWeight.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void deleteMeasure(long id) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_NAME, KEY + " = ?",
        new String[]{String.valueOf(id)});
}
 
Example 17
Source File: EasyDB.java    From AndroidEasySQL-Library with MIT License 4 votes vote down vote up
public boolean deleteRow(int id) {
    SQLiteDatabase db = this.getWritableDatabase();
    return db.delete(TABLE_NAME, "id = ?", new String[]{String.valueOf(id)}) == 1;
}
 
Example 18
Source File: DraftDatabase.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
public void clearDrafts(long threadId) {
  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.delete(TABLE_NAME, THREAD_ID + " = ?", new String[] {threadId+""});
}
 
Example 19
Source File: AccountsDb.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
boolean deleteAccountVisibilityForPackage(String packageName) {
    SQLiteDatabase db = mDeDatabase.getWritableDatabase();
    return db.delete(TABLE_VISIBILITY, VISIBILITY_PACKAGE + "=? ",
            new String[] {packageName}) > 0;
}
 
Example 20
Source File: SQLiteTokenManager.java    From DeviceConnect-Android with MIT License 2 votes vote down vote up
/**
 * 指定条件でtokenデータをDBから削除する.
 * 
 * @param db DBオブジェクト
 * @param whereClause where条件(key = value)。複数あるときはAnd条件になる。
 * @param whereArgs ?の値
 */
private void dbDeleteTokens(final SQLiteDatabase db, final String whereClause, final String[] whereArgs) {
    String table = LocalOAuthOpenHelper.TOKENS_TABLE;
    db.delete(table, whereClause, whereArgs);
}