Example usage for android.database.sqlite SQLiteDatabase delete

List of usage examples for android.database.sqlite SQLiteDatabase delete

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase delete.

Prototype

public int delete(String table, String whereClause, String[] whereArgs) 

Source Link

Document

Convenience method for deleting rows in the database.

Usage

From source file:com.google.zxing.client.android.history.HistoryManager.java

public void deletePrevious(String text) {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    try {//  www .  java2 s .  com
        db = helper.getWritableDatabase();
        db.delete(DBHelper.TABLE_NAME, DBHelper.TEXT_COL + "= ?", new String[] { text });
    } finally {
        close(null, db);
    }
}

From source file:com.google.zxing.client.android.history.HistoryManager.java

public void clearHistory() {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    try {//w  ww.  j av  a  2 s.  com
        db = helper.getWritableDatabase();
        db.delete(DBHelper.TABLE_NAME, null, null);
    } finally {
        close(null, db);
    }
}

From source file:com.rs.TCOfflineStatementCollection.java

/**
 * delete a statement from the db after it has been posted
 * @param statementPosted/*w w w .  j  a  v a  2  s.c o m*/
 */
public void markStatementPosted(Statement statementPosted) {
    String statementId = statementPosted.getId().toString();
    SQLiteDatabase database;
    TCLocalStorageDatabaseOpenHelper dbHelper;
    dbHelper = new TCLocalStorageDatabaseOpenHelper(appContext);
    database = dbHelper.getWritableDatabase();

    String select = LocalStatements.STATEMENT_ID + "=" + "\'" + statementId + "\'";

    int count = database.delete(TCOfflineDataManager.LOCAL_STATEMENT_TABLE_NAME, select, null);

    database.close();
    dbHelper.close();
}

From source file:org.emergent.android.weave.syncadapter.SyncCache.java

public void clear() {
    SQLiteDatabase db = null;
    try {/* ww  w .  ja  v a  2s . co m*/
        db = m_helper.getWritableDatabase();
        int count = db.delete(KEY_HASH_TABLE_NAME, null, null);
        Log.d(TAG, "SyncCacheKeyManager.clear() : count = " + count);
    } finally {
        if (db != null)
            try {
                db.close();
            } catch (Exception ignored) {
            }
    }
}

From source file:com.boardgamegeek.util.SelectionBuilder.java

/**
 * Execute delete using the current internal state as {@code WHERE} clause.
 *//*from  w  w  w.  j av  a2 s . c om*/
public int delete(SQLiteDatabase db) {
    assertTable();
    Timber.v("DELETE: " + this);
    String selection = getSelection();
    if (TextUtils.isEmpty(selection)) {
        // this forces delete to return the count
        selection = "1";
    }
    int count = db.delete(mTable, selection, getSelectionArgs());
    Timber.v("deleted " + count + " rows");
    return count;
}

From source file:org.emergent.android.weave.syncadapter.SyncCache.java

public void reset() {
    SQLiteDatabase db = null;
    try {//from  ww w  . j  ava 2 s  . c o m
        db = m_helper.getWritableDatabase();
        int count = db.delete(KEY_HASH_TABLE_NAME, null, null);
        count += db.delete(META_GLOBAL_TABLE_NAME, null, null);
        Log.d(TAG, "SyncCacheKeyManager.resetCaches() : count = " + count);
    } finally {
        if (db != null)
            try {
                db.close();
            } catch (Exception ignored) {
            }
    }
}

From source file:net.olejon.mdapp.NotesEditActivity.java

private void deleteNote(boolean delete) {
    if (delete) {
        SQLiteDatabase sqLiteDatabase = new NotesSQLiteHelper(mContext).getWritableDatabase();
        sqLiteDatabase.delete(NotesSQLiteHelper.TABLE, NotesSQLiteHelper.COLUMN_ID + " = " + noteId, null);
        sqLiteDatabase.close();// w w w  .j ava  2s.c om

        mTools.showToast(getString(R.string.notes_edit_deleted), 1);

        finish();
    } else {
        new MaterialDialog.Builder(mContext).title(getString(R.string.notes_edit_delete_dialog_title))
                .content(getString(R.string.notes_edit_delete_dialog_message))
                .positiveText(getString(R.string.notes_edit_delete_dialog_positive_button))
                .neutralText(getString(R.string.notes_edit_delete_dialog_neutral_button))
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        deleteNote(true);
                    }
                }).contentColorRes(R.color.black).positiveColorRes(R.color.red)
                .neutralColorRes(R.color.dark_blue).show();
    }
}

From source file:com.raspi.chatapp.util.storage.MessageHistory.java

public void removeMessages(String buddyId, long... _ID) {
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    for (long id : _ID) {
        db.delete(buddyId, MessageHistoryContract.MessageEntry._ID + "=?", new String[] { String.valueOf(id) });
    }//  w w  w. j a  v a  2s  . c  o m
    db.close();
}

From source file:uk.org.rivernile.edinburghbustracker.android.SettingsDatabase.java

/**
 * Delete a favourite stop from the database.
 *
 * @param stopCode The stop code to delete from the database.
 *//*w w w  .j a v a2 s .c om*/
public void deleteFavouriteStop(final String stopCode) {
    if (stopCode == null || stopCode.length() == 0)
        return;
    if (!getFavouriteStopExists(stopCode))
        return;

    final SQLiteDatabase db = getWritableDatabase();
    db.delete(FAVOURITE_STOPS_TABLE, FAVOURITE_STOPS_STOPCODE + " = ?", new String[] { stopCode });

    BackupManager.dataChanged(context.getPackageName());
}

From source file:uk.org.rivernile.edinburghbustracker.android.SettingsDatabase.java

/**
 * Restore a previous backup from JSON input and insert it in to the
 * database.//from   w  w w  .jav  a2 s .c  o m
 * 
 * @param jsonString The JSON to be restored.
 * @throws JSONException When an error occurs whilst parsing the JSON text.
 */
public void restoreDatabaseFromJSON(final String jsonString) throws JSONException {
    final SQLiteDatabase db = getWritableDatabase();
    db.delete(FAVOURITE_STOPS_TABLE, null, null);

    final JSONObject root = new JSONObject(jsonString);
    final JSONArray favStops = root.getJSONArray(BACKUP_FAVOURITE_STOPS);
    JSONObject stop;

    final int len = favStops.length();
    for (int i = 0; i < len; i++) {
        stop = favStops.getJSONObject(i);
        insertFavouriteStop(stop.getString(BACKUP_STOPCODE), stop.getString(BACKUP_STOPNAME));
    }
}