SQLiteDatabase delete - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SQLiteDatabase delete method.

This code example shows how to use the following methods:delete, execSQL, rawQuery
 
    @Test(expected = Exception.class) 
    public void testExecSQLInsertNullShouldBeException() throws Exception { 
        //this inserts null in android, but it when it happens it is likely an error.  H2 throws an exception.  So we'll make Robolectric expect an Exception so that the error can be found. 
 
        database.delete("exectable", null, null);
 
        Cursor cursor = database.rawQuery("select * from exectable", null);
        cursor.moveToFirst();
        assertThat(cursor.getCount()).isEqualTo(0);
 
        database.execSQL("insert into exectable (first_column) values (?);", new String[]{});
        Cursor cursor2 = database.rawQuery("select * from exectable", new String[]{null});
        cursor.moveToFirst();
        assertThat(cursor2.getCount()).isEqualTo(1);
 
    } 
 
    @Test 
    public void testExecSQLAutoIncrementSQLite() throws Exception { 
9
CodeRank
This code example shows how to use the following methods:close, delete, insert, query
		if(fileName != null)
			mActivity.deleteFile(fileName);
		//mActivity.openFileOutput(fileName, Context.MODE_PRIVATE).getFD(). 
 
		String[] whereArgs = {playlistName};
		db.delete(TABLE_PLAYLIST, "PlaylistName = ?", whereArgs);
 
		db.close();
	} 
 
	@Override 
	public ArrayList<String> getAvailablePlaylists() {
		ArrayList<String> playlists = new ArrayList<String>(); 
		SQLiteDatabase db = mActivity.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
 
		String[] columns = {"PlaylistName"};
		Cursor query = db.query(TABLE_PLAYLIST, columns, null, null, null, null, "PlaylistName ASC");
 
		if(query != null){
			query.moveToFirst();

6
CodeRank
This code example shows how to use the following methods:beginTransaction, delete, endTransaction, setTransactionSuccessful
            file = new File(getLockPatternFilename(userId));
            if (file.exists()) {
                file.delete();
            } 
 
            db.beginTransaction();
            db.delete(TABLE, COLUMN_USERID + "='" + userId + "'", null);
            db.setTransactionSuccessful();
        } finally { 
            db.endTransaction();
        } 
    } 
 
    private void writeFile(String name, byte[] hash) {
        try { 
            // Write the hash to file 
            RandomAccessFile raf = new RandomAccessFile(name, "rw");
            // Truncate the file if pattern is null, to clear the lock 
            if (hash == null || hash.length == 0) {
                raf.setLength(0);
7
CodeRank
This code example shows how to use the following methods:delete, isOpen
    private SQLiteDatabase mDatabase;
 
    @SuppressWarnings("deprecation") 
    public synchronized SQLiteDatabase getDatabase(Context context) {
        // Always return the cached database, if we've got one 
        if (mDatabase == null || !mDatabase.isOpen()) {
            DatabaseHelper helper = new DatabaseHelper(context, DATABASE_NAME);
            mDatabase = helper.getWritableDatabase();
            if (mDatabase != null) {
                mDatabase.setLockingEnabled(true);
            } 
		} 
 
        return mDatabase;
    } 
 
    private class DatabaseHelper extends SQLiteOpenHelper {
 
        DatabaseHelper(Context context, String name) {
            super(context, name, null, DATABASE_VERSION);

6
CodeRank
This code example shows how to use the following methods:delete
     * @param productId the product to update 
     * @param quantity the number of times the product has been purchased 
     */ 
    private void updatePurchasedItem(String productId, int quantity) {
        if (quantity == 0) {
            mDb.delete(PURCHASED_ITEMS_TABLE_NAME, PURCHASED_PRODUCT_ID_COL + "=?",
                    new String[] { productId });
            return; 
        } 
        ContentValues values = new ContentValues();
        values.put(PURCHASED_PRODUCT_ID_COL, productId);
        values.put(PURCHASED_QUANTITY_COL, quantity);
        mDb.replace(PURCHASED_ITEMS_TABLE_NAME, null /* nullColumnHack */, values);
    } 
 
    /** 
     * Adds the given purchase information to the database and returns the total 
     * number of times that the given product has been purchased. 
     * @param orderId a string identifying the order 
     * @param productId the product ID (sku) 
6
CodeRank
This code example shows how to use the following methods:delete
            case CODE_SINGLE:
                String rowId = uri.getPathSegments().get(1);
                if (TextUtils.isEmpty(selection)) {
                    count = db.delete(mTableName, BaseColumns._ID + "=?", new String[] { rowId });
                } else { 
                    count = db.delete(mTableName,
                        selection + " AND " + BaseColumns._ID + "=" + rowId,
                        selectionArgs);
                } 
                break; 
            case CODE_COLLECTION:
                count = db.delete(mTableName, selection, selectionArgs);
                break; 
        } 
        getContext().getContentResolver().notifyChange(uri, null);
        return count;
    } 
 
    @Override 
    public int update (Uri uri, ContentValues values, String selection, String[] selectionArgs) {
6
CodeRank
This code example shows how to use the following methods:beginTransaction, delete, endTransaction, setTransactionSuccessful
     * @see de.dan_nrw.android.boobleftboobright.dao.IFavouriteDAO#remove(java.lang.String) 
     */ 
    @Override 
    public void remove(String id) {
    	SQLiteDatabase database = this.getDatabaseInstance();
    	database.beginTransaction();
    	 
    	try { 
    		database.delete(TABLE_NAME, String.format("%s = ?", WALLPAPER_ID), new String[] { id });
    		database.setTransactionSuccessful();
    	} 
    	finally { 
    		database.endTransaction();
    	} 
    } 
 
	/* (non-Javadoc) 
     * @see de.dan_nrw.android.boobleftboobright.dao.IFavouriteDAO#isFavourite(java.lang.String) 
     */ 
    @Override 
6
CodeRank
This code example shows how to use the following methods:beginTransaction, delete, endTransaction, setTransactionSuccessful
            mDb.insertOrThrow(DATABASE_TABLE_RELATION, null, relationValues);
        } 
    } 
 
    public void deleteNote(long id) {
        mDb.beginTransaction();
        try { 
            mDb.delete(DATABASE_TABLE_RELATION, KEY_NOTEID + "=" + id, null);
            mDb.delete(DATABASE_TABLE_NOTE, KEY_ROWID + "=" + id, null);
            mDb.setTransactionSuccessful();
        } finally { 
            mDb.endTransaction();
        } 
    } 
 
    public void deleteAllNotes() { 
        mDb.beginTransaction();
        try { 
            mDb.delete(DATABASE_TABLE_TAG, null, null);
            mDb.delete(DATABASE_TABLE_NOTE, null, null);
6
CodeRank
This code example shows how to use the following methods:delete
			clearDB(db);
		} 
	} 
 
	private void clearDB(SQLiteDatabase db) {
		db.delete("subscriptions", null, null);
		db.delete("pending_add", null, null);
		db.delete("pending_remove", null, null);
 
		SharedPreferences prefs = _context.getSharedPreferences("gpodder", Context.MODE_PRIVATE);
		prefs.edit().clear().commit();
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:delete, query
		String path = getString(cursor, RecordingColumn.RECORDING_PATH);
		cursor.close();
		if (new File(path).exists()) {
			Runtime.getRuntime().exec("rm " + path);
		} 
		db.delete(TABLE_RECORDINGS, recordingIdClause(id), null);
	} 
 
	public Cursor getAllScenes() {
		return db.query(TABLE_SCENES, null, null, null, null, null, SceneColumn.SCENE_TITLE.label);
	} 
	 
	public Cursor getAllRecordings() {
		return db.query(TABLE_RECORDINGS, null, null, null, null, null, RecordingColumn.RECORDING_TIMESTAMP.label);
	} 
	 
	public Cursor getScene(long id) {
		Cursor cursor = db.query(TABLE_SCENES, null, sceneIdClause(id), null, null, null, null);
		cursor.moveToFirst();
		return cursor;

6
CodeRank

Related SQLiteDatabase delete Questions & Answers:

Other SQLiteDatabase delete Examples

159:		public void deleteSite(WebSite site) {
160:			SQLiteDatabase db = this.getWritableDatabase();
161:			db.delete(TABLE_RSS, KEY_ID + " = ?",
162:					new String[] { String.valueOf(site.getId())});
163:			db.close();

Read More

123:		public void deleteContact(Contact contact) {
124:			SQLiteDatabase db = this.getWritableDatabase();
125:			db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
126:					new String[] { String.valueOf(contact.getID()) });
127:			db.close();

Read More

1:		public void deleteContact(Contact contact) {
2:			SQLiteDatabase db = this.getWritableDatabase();
3:			db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
4:					new String[] { String.valueOf(contact.getID()) });
5:			db.close();

Read More

delete Method Overview
Convenience method for deleting rows in the database.
See Code Examples for other Android SQLiteDatabase Methods: