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

The following are Jave code examples for showing how to use delete() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: boohee_v5.6   File: f.java   View Source Code Vote up 6 votes
public synchronized void b(String str) {
    if (!TextUtils.isEmpty(str)) {
        SQLiteDatabase writableDatabase = getWritableDatabase();
        if (writableDatabase != null) {
            try {
                writableDatabase.delete("via_cgi_report", "type = ?", new String[]{str});
                if (writableDatabase != null) {
                    writableDatabase.close();
                }
            } catch (Exception e) {
                com.tencent.open.a.f.e(a, "clearReportItem has exception.");
                if (writableDatabase != null) {
                    writableDatabase.close();
                }
            } catch (Throwable th) {
                if (writableDatabase != null) {
                    writableDatabase.close();
                }
            }
        }
    }
}
 
Example 2
Project: Cable-Android   File: MmsDatabase.java   View Source Code Vote up 5 votes
public boolean delete(long messageId) {
  long               threadId           = getThreadIdForMessage(messageId);
  MmsAddressDatabase addrDatabase       = DatabaseFactory.getMmsAddressDatabase(context);
  AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
  attachmentDatabase.deleteAttachmentsForMessage(messageId);
  addrDatabase.deleteAddressesForId(messageId);

  SQLiteDatabase database = databaseHelper.getWritableDatabase();
  database.delete(TABLE_NAME, ID_WHERE, new String[] {messageId+""});
  boolean threadDeleted = DatabaseFactory.getThreadDatabase(context).update(threadId, false);
  notifyConversationListeners(threadId);
  return threadDeleted;
}
 
Example 3
Project: RoadLab-Pro   File: IssuesDAO.java   View Source Code Vote up 5 votes
public void deleteIssues(final IssuesModel issuesModel) {
    long issuesId = issuesModel.getId();
    SQLiteDatabase db = getDatabase();
    try {
        db.beginTransaction();
        db.delete(DataBaseHelper.TABLE_ISSUES, COLUMN_ISSUE_ID + " = " + issuesId, null);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
    } finally {
        db.endTransaction();
    }
}
 
Example 4
Project: SimpleUILauncher   File: LauncherProvider.java   View Source Code Vote up 5 votes
/**
 * Deletes any empty folder from the DB.
 * @return Ids of deleted folders.
 */
private ArrayList<Long> deleteEmptyFolders() {
    ArrayList<Long> folderIds = new ArrayList<>();
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        // Select folders whose id do not match any container value.
        String selection = LauncherSettings.Favorites.ITEM_TYPE + " = "
                + LauncherSettings.Favorites.ITEM_TYPE_FOLDER + " AND "
                + LauncherSettings.Favorites._ID +  " NOT IN (SELECT " +
                        LauncherSettings.Favorites.CONTAINER + " FROM "
                            + Favorites.TABLE_NAME + ")";
        Cursor c = db.query(Favorites.TABLE_NAME,
                new String[] {LauncherSettings.Favorites._ID},
                selection, null, null, null, null);
        while (c.moveToNext()) {
            folderIds.add(c.getLong(0));
        }
        c.close();
        if (!folderIds.isEmpty()) {
            db.delete(Favorites.TABLE_NAME, Utilities.createDbSelectionQuery(
                    LauncherSettings.Favorites._ID, folderIds), null);
        }
        db.setTransactionSuccessful();
    } catch (SQLException ex) {
        Log.e(TAG, ex.getMessage(), ex);
        folderIds.clear();
    } finally {
        db.endTransaction();
    }
    return folderIds;
}
 
Example 5
Project: RoadLab-Pro   File: GeoTagDAO.java   View Source Code Vote up 5 votes
public void deleteItemsWithMeasurementId(final long measurementId) {
    SQLiteDatabase db = getDatabase();
    try {
        db.beginTransaction();
        db.delete(DataBaseHelper.TABLE_GEO_TAGS, COLUMN_GEO_TAG_MEASUREMENT_ID + " = " + measurementId, null);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
    } finally {
        db.endTransaction();
    }
}
 
Example 6
Project: RoadLab-Pro   File: TagDAO.java   View Source Code Vote up 5 votes
public int delete(final TagModel data) {
    long id = data.getId();
    int count = 0;
    SQLiteDatabase db = getDatabase();
    try {
        db.beginTransaction();
        count = db.delete(DataBaseHelper.TABLE_TAGS, COLUMN_TAG_ID + " = " + id, null);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
    } finally {
        db.endTransaction();
    }
    return count;
}
 
Example 7
Project: HiBangClient   File: HelpMeMsgDB.java   View Source Code Vote up 5 votes
public void deleteHelpMeMsgById(int id) {
	SQLiteDatabase db = this.getWritableDatabase();
	db.delete(TABLE_NAME, "id=?",
			new String[] { Integer.toString(id) });
	db.close();

}
 
Example 8
Project: stynico   File: SQLManager.java   View Source Code Vote up 5 votes
@Override
public boolean deleteAll(SQLiteDatabase sqLiteDatabase, String tableName)
{
	//Log.d(DEG_TAG, "deleteAll");
	int number = sqLiteDatabase.delete(tableName, null, null);
	//Log.d(DEG_TAG, "deleteAll_result:" + number);
	if (number != 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
 
Example 9
Project: PeSanKita-android   File: DraftDatabase.java   View Source Code Vote up 5 votes
public void clearDrafts(Set<Long> threadIds) {
  SQLiteDatabase db        = databaseHelper.getWritableDatabase();
  StringBuilder  where     = new StringBuilder();
  List<String>   arguments = new LinkedList<>();

  for (long threadId : threadIds) {
    where.append(" OR ")
         .append(THREAD_ID)
         .append(" = ?");

    arguments.add(String.valueOf(threadId));
  }

  db.delete(TABLE_NAME, where.toString().substring(4), arguments.toArray(new String[0]));
}
 
Example 10
Project: APIJSON-Android-RxJava   File: SQLHelper.java   View Source Code Vote up 5 votes
/**删除数据
 * @param column
 * @param value
 * @return
 */
public int delete(String column, String value) {
	SQLiteDatabase db = this.getWritableDatabase();
	try {
		return db.delete(TABLE_NAME, getSelection(column), getSelectionArgs(column, value));
	} catch (Exception e) {
		Log.e(TAG, "update   try { return db.delete(.... } catch (Exception e) {\n " + e.getMessage());
	}
	return 0;
}
 
Example 11
Project: MovieGuide   File: TestProvider.java   View Source Code Vote up 5 votes
public void deleteAllRecordsFromDB() {
    Context appContext = InstrumentationRegistry.getTargetContext();
    FavoritesDbHelper dbHelper = new FavoritesDbHelper(appContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    db.delete(FavoritesContract.FavoriteColumns.FAVORITE_MOVIES_TBL, null, null);
    db.delete(FavoritesContract.FavoriteColumns.FAVORITE_TV_SHOWS_TBL, null, null);
    db.delete(FavoritesContract.FavoriteColumns.FAVORITE_PERSON_TBL, null, null);
    db.close();
}
 
Example 12
Project: open-journal-android   File: DBHelper.java   View Source Code Vote up 4 votes
public Integer deleteNote(Integer id) {
    SQLiteDatabase db = this.getWritableDatabase();
    return db.delete(NOTES_TABLE_NAME,
            ""+NOTES_COLUMN_ID+" = ? ",
            new String[] { Integer.toString(id) });
}
 
Example 13
Project: keepass2android   File: HistoryProvider.java   View Source Code Vote up 4 votes
@Override
public synchronized int delete(Uri uri, String selection,
        String[] selectionArgs) {
    // Opens the database object in "write" mode.
    SQLiteDatabase db = mHistoryHelper.getWritableDatabase();
    String finalWhere;

    int count;

    // Does the delete based on the incoming URI pattern.
    switch (URI_MATCHER.match(uri)) {
    /*
     * If the incoming pattern matches the general pattern for history
     * items, does a delete based on the incoming "where" columns and
     * arguments.
     */
    case URI_HISTORY:
        count = db.delete(HistoryContract.TABLE_NAME, selection,
                selectionArgs);
        break;// URI_HISTORY

    /*
     * If the incoming URI matches a single note ID, does the delete based
     * on the incoming data, but modifies the where clause to restrict it to
     * the particular history item ID.
     */
    case URI_HISTORY_ID:
        /*
         * Starts a final WHERE clause by restricting it to the desired
         * history item ID.
         */
        finalWhere = DbUtils.SQLITE_FTS_COLUMN_ROW_ID + " = "
                + uri.getLastPathSegment();

        /*
         * If there were additional selection criteria, append them to the
         * final WHERE clause
         */
        if (selection != null)
            finalWhere = finalWhere + " AND " + selection;

        // Performs the delete.
        count = db.delete(HistoryContract.TABLE_NAME, finalWhere,
                selectionArgs);
        break;// URI_HISTORY_ID

    // If the incoming pattern is invalid, throws an exception.
    default:
        throw new IllegalArgumentException("UNKNOWN URI " + uri);
    }

    /*
     * Gets a handle to the content resolver object for the current context,
     * and notifies it that the incoming URI changed. The object passes this
     * along to the resolver framework, and observers that have registered
     * themselves for the provider are notified.
     */
    getContext().getContentResolver().notifyChange(uri, null);

    // Returns the number of rows deleted.
    return count;
}
 
Example 14
Project: FaceRecognition   File: DBHelper.java   View Source Code Vote up 4 votes
public void delete(int id){
    SQLiteDatabase db = getWritableDatabase();
    db.delete(TABLE_NAME, "_id=?", new String[]{String.valueOf(id)});
}
 
Example 15
Project: sekai   File: UserRepo.java   View Source Code Vote up 4 votes
public void delete(long user_Id)
{
    SQLiteDatabase db = dbHandler.getWritableDatabase();
    db.delete(User.TABLE, User.KEY_ID + "= ?", new String[] { String.valueOf(user_Id) });
    db.close(); // Closing database connection
}
 
Example 16
Project: Orin   File: HistoryStore.java   View Source Code Vote up 4 votes
public void clear() {
    final SQLiteDatabase database = getWritableDatabase();
    database.delete(RecentStoreColumns.NAME, null, null);
}
 
Example 17
Project: ObjectBoxDebugBrowser   File: CarDBHelper.java   View Source Code Vote up 4 votes
public Integer deleteCar(Integer id) {
    SQLiteDatabase db = this.getWritableDatabase();
    return db.delete("cars",
            "id = ? ",
            new String[]{Integer.toString(id)});
}
 
Example 18
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 3 votes
/**
 * This method will clear all rows from the weather table in our database.
 * <p>
 * Please note:
 * <p>
 * - This does NOT delete the table itself. We call this method from our @Before annotated
 * method to clear all records from the database before each test on the ContentProvider.
 * <p>
 * - We don't use the ContentProvider's delete functionality to perform this row deletion
 * because in this class, we are attempting to test the ContentProvider. We can't assume
 * that our ContentProvider's delete method works in our ContentProvider's test class.
 */
private void deleteAllRecordsFromWeatherTable() {
    /* Access writable database through WeatherDbHelper */
    WeatherDbHelper helper = new WeatherDbHelper(InstrumentationRegistry.getTargetContext());
    SQLiteDatabase database = helper.getWritableDatabase();

    /* The delete method deletes all of the desired rows from the table, not the table itself */
    database.delete(WeatherContract.WeatherEntry.TABLE_NAME, null, null);

    /* Always close the database when you're through with it */
    database.close();
}
 
Example 19
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 3 votes
/**
 * This method will clear all rows from the weather table in our database.
 * <p>
 * Please note:
 * <p>
 * - This does NOT delete the table itself. We call this method from our @Before annotated
 * method to clear all records from the database before each test on the ContentProvider.
 * <p>
 * - We don't use the ContentProvider's delete functionality to perform this row deletion
 * because in this class, we are attempting to test the ContentProvider. We can't assume
 * that our ContentProvider's delete method works in our ContentProvider's test class.
 */
private void deleteAllRecordsFromWeatherTable() {
    /* Access writable database through WeatherDbHelper */
    WeatherDbHelper helper = new WeatherDbHelper(InstrumentationRegistry.getTargetContext());
    SQLiteDatabase database = helper.getWritableDatabase();

    /* The delete method deletes all of the desired rows from the table, not the table itself */
    database.delete(WeatherContract.WeatherEntry.TABLE_NAME, null, null);

    /* Always close the database when you're through with it */
    database.close();
}
 
Example 20
Project: KomaMusic   File: SongPlayCount.java   View Source Code Vote up 2 votes
/**
 * Deletes the entry
 *
 * @param database database to use
 * @param stringId id to delete
 */
private void deleteEntry(final SQLiteDatabase database, final String stringId) {
    database.delete(SongPlayCountColumns.NAME, WHERE_ID_EQUALS, new String[]{stringId});
}