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.example.pc.mylauncher.SettingsFragment.java

@Override
public boolean onPreferenceClick(Preference preference) {
    if (preference.getKey().equals(getString(R.string.pref_uri_clear_key))) {
        AppsListDbHelper dbHelper = new AppsListDbHelper(SettingsFragment.this.getContext());
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.delete(AppsListContract.URLEntry.TABLE_NAME, null, null);
        return true;
    } else if (preference.getKey().equals(getString(R.string.pref_favourite_clear_key))) {
        AppsManager.removeAllFavourites(getContext());
        Intent intent = new Intent();
        intent.setAction(AppsManager.FAVOURITE_STATE_CHANGED);
        getActivity().sendBroadcast(intent);
        return true;
    } else {//from w  w  w.ja  va2 s.co  m
        return false;
    }
}

From source file:com.andreadec.musicplayer.IndexFolderService.java

private void clearSongsDatabase() {
    SQLiteDatabase db = new SongsDatabase().getWritableDatabase();
    db.delete("Songs", "", null);
    db.close();/*from  www  . ja  v a 2s . com*/
}

From source file:com.github.gw2app.events.Gw2StaticData.java

/**
 * Downloads all static data and stores it in the database.
 *//*w ww  .  j  a v  a  2s  .  c o m*/

private void _delete_all_data() {
    SQLiteDatabase db = mDBHelper.getWritableDatabase();
    db.delete(Gw2DB.EVENT_NAMES_TABLE, null, null);
    db.delete(Gw2DB.MAP_NAMES_TABLE, null, null);
    db.delete(Gw2DB.WORLD_NAMES_TABLE, null, null);

}

From source file:pl.reticular.ttw.HighScoresActivity.java

private void clearHighScores() {
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    db.delete(ResultsTableHelper.TABLE_NAME, null, null);
}

From source file:org.thomnichols.android.gmarks.WebViewCookiesDB.java

public void deleteCookie(String key) {
    SQLiteDatabase db = openDatabase(SQLiteDatabase.OPEN_READWRITE);
    if (db == null)
        return;/*w ww .  j  av a 2s .c  om*/
    try {
        db.delete(TABLE_NAME, COLUMNS[COL_NAME] + "=?", new String[] { key });
    } catch (SQLiteException ex) {
        Log.w(TAG, "Error deleting cookie: " + key, ex);
    } finally {
        db.close();
    }
}

From source file:org.thomnichols.android.gmarks.WebViewCookiesDB.java

public void deleteAllCookies() {
    SQLiteDatabase db = openDatabase(SQLiteDatabase.OPEN_READWRITE);
    if (db == null)
        return;//from  ww w . ja  v a 2  s .c o m
    try {
        db.delete(TABLE_NAME, null, null);
    } catch (SQLiteException ex) {
        Log.w(TAG, "Error deleting cookies", ex);
    } finally {
        db.close();
    }
}

From source file:org.egov.android.data.SQLiteHelper.java

/**
 * Truncate table/* w w w . j  a  va 2  s  .  c  o  m*/
 * 
 * @param tableName
 */

public void truncate(String tableName) {
    SQLiteDatabase db = getWritableDatabase();
    db.delete(tableName, null, null);
    db.close();
}

From source file:org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryDataExtender.java

/**
 * Delete a row.//from  w  w  w  .  j a v a  2  s  . c  o  m
 *
 * @param guid The GUID of the row to delete.
 * @return The number of rows deleted, either 0 (if a row with this GUID does not exist) or 1.
 */
public int delete(String guid) {
    String where = COL_GUID + " = ?";
    String[] args = new String[] { guid };

    SQLiteDatabase db = this.getCachedWritableDatabase();
    return db.delete(TBL_HISTORY_EXT, where, args);
}

From source file:com.onesignal.NotificationBundleProcessor.java

private static void saveNotification(Context context, Bundle bundle, boolean opened, int notificationId) {
    try {//from www.  j  a  va2 s  . c o m
        JSONObject customJSON = new JSONObject(bundle.getString("custom"));

        OneSignalDbHelper dbHelper = new OneSignalDbHelper(context);
        SQLiteDatabase writableDb = dbHelper.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(NotificationTable.COLUMN_NAME_NOTIFICATION_ID, customJSON.getString("i"));
        if (bundle.containsKey("grp"))
            values.put(NotificationTable.COLUMN_NAME_GROUP_ID, bundle.getString("grp"));

        values.put(NotificationTable.COLUMN_NAME_OPENED, opened ? 1 : 0);
        if (!opened)
            values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, notificationId);

        if (bundle.containsKey("title"))
            values.put(NotificationTable.COLUMN_NAME_TITLE, bundle.getString("title"));
        values.put(NotificationTable.COLUMN_NAME_MESSAGE, bundle.getString("alert"));

        values.put(NotificationTable.COLUMN_NAME_FULL_DATA, bundleAsJSONObject(bundle).toString());

        writableDb.insert(NotificationTable.TABLE_NAME, null, values);

        // Clean up old records that have been dismissed or opened already after 1 week.
        writableDb.delete(NotificationTable.TABLE_NAME,
                NotificationTable.COLUMN_NAME_CREATED_TIME + " < "
                        + ((System.currentTimeMillis() / 1000) - 604800) + " AND " + "("
                        + NotificationTable.COLUMN_NAME_DISMISSED + " = 1 OR "
                        + NotificationTable.COLUMN_NAME_OPENED + " = 1" + ")",
                null);

        writableDb.close();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:org.egov.android.data.SQLiteHelper.java

/**
 * Delete data from table//from   w ww .j  a v  a2s .  c o m
 * 
 * @param tableName
 * @param whereClause
 * @param whereArgs
 */

public int delete(String tableName, String whereClause, String[] whereArgs) {
    SQLiteDatabase db = getWritableDatabase();
    int result = db.delete(tableName, whereClause, whereArgs);
    db.close();
    return result;
}