List of usage examples for android.database.sqlite SQLiteDatabase delete
public int delete(String table, String whereClause, String[] whereArgs)
From source file:cl.gisred.android.RepartoActivity.java
public void deleteData(int id) { SQLiteDatabase db = sqlReparto.getWritableDatabase(); db.delete("repartos", "id=" + id, null); db.close();// www . j a v a2 s . co m if (iContRep > 0) { iContRep--; updDashboard(); } }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public void deleteFavorites() { SQLiteDatabase db = this.getWritableDatabase(); if (db == null) return;//from w w w .j a v a2 s. co m db.delete(TABLE_FAVORITES, null, null); db.close(); IbikeApplication.setFavoritesFetched(false); }
From source file:com.google.zxing.client.android.history.HistoryManager.java
public void trimHistory() { SQLiteOpenHelper helper = new DBHelper(activity); SQLiteDatabase db = null; Cursor cursor = null;// w ww . j ava2 s . c o m try { db = helper.getWritableDatabase(); cursor = db.query(DBHelper.TABLE_NAME, ID_COL_PROJECTION, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC"); cursor.move(MAX_ITEMS); while (cursor.moveToNext()) { String id = cursor.getString(0); Log.i(TAG, "Deleting scan history ID " + id); db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + id, null); } } catch (SQLiteException sqle) { // We're seeing an error here when called in // CaptureActivity.onCreate() in rare cases // and don't understand it. First theory is that it's transient so // can be safely ignored. Log.w(TAG, sqle); // continue } finally { close(cursor, db); } }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public void deleteFavorite(FavoritesData fd, Context context) { SQLiteDatabase db = this.getWritableDatabase(); if (db == null) return;/*from w w w. ja v a 2 s. c o m*/ db.delete(TABLE_FAVORITES, KEY_ID + " = ?", new String[] { "" + fd.getId() }); db.close(); if (context != null) deleteFavoriteFromServer(fd, context); }
From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java
public void removeFromHistory(SuggestionCursor suggestions, int position) { suggestions.moveTo(position);//w w w .ja va 2 s . c o m final String intentKey = makeIntentKey(suggestions); runTransactionAsync(new SQLiteTransaction() { @Override public boolean performTransaction(SQLiteDatabase db) { db.delete(Shortcuts.TABLE_NAME, Shortcuts.intent_key.fullName + " = ?", new String[] { intentKey }); return true; } }); }
From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java
public void clearHistory() { runTransactionAsync(new SQLiteTransaction() { @Override// w ww . j a v a2 s . com public boolean performTransaction(SQLiteDatabase db) { db.delete(ClickLog.TABLE_NAME, null, null); db.delete(Shortcuts.TABLE_NAME, null, null); db.delete(SourceStats.TABLE_NAME, null, null); return true; } }); }
From source file:net.smart_json_database.JSONDatabase.java
private int deleteRelation(String relName, int from_id, int to_id, SQLiteDatabase db) { return db.delete(TABLE_REL_JSON_DATA_JSON_DATA, "from_id = ? AND to_id = ? AND rel_name = ?", new String[] { "" + from_id, "" + to_id, relName }); }
From source file:de.nware.app.hsDroid.provider.onlineService2Provider.java
@Override public int delete(Uri uri, String whereClause, String[] whereArgs) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); int count;// w w w .j a v a 2s .c o m switch (mUriMatcher.match(uri)) { case EXAMS: count = db.delete(mOpenHelper.getTableName(), whereClause, whereArgs); break; default: throw new IllegalArgumentException("Unbekannte URI " + uri); } return count; }
From source file:net.olejon.mdapp.MedicationActivity.java
private void favorite() { SQLiteDatabase sqLiteDatabase = new MedicationsFavoritesSQLiteHelper(mContext).getWritableDatabase(); String snackbarString;//www. j a v a 2 s. co m if (isFavorite()) { sqLiteDatabase.delete(MedicationsFavoritesSQLiteHelper.TABLE, MedicationsFavoritesSQLiteHelper.COLUMN_NAME + " = " + mTools.sqe(medicationName) + " AND " + MedicationsFavoritesSQLiteHelper.COLUMN_MANUFACTURER + " = " + mTools.sqe(medicationManufacturer), null); mFavoriteMenuItem.setIcon(R.drawable.ic_star_outline_white_24dp) .setTitle(getString(R.string.medication_menu_add_favorite)); snackbarString = getString(R.string.medication_favorite_removed); } else { ContentValues contentValues = new ContentValues(); contentValues.put(MedicationsFavoritesSQLiteHelper.COLUMN_PRESCRIPTION_GROUP, medicationPrescriptionGroup); contentValues.put(MedicationsFavoritesSQLiteHelper.COLUMN_NAME, medicationName); contentValues.put(MedicationsFavoritesSQLiteHelper.COLUMN_SUBSTANCE, medicationSubstance); contentValues.put(MedicationsFavoritesSQLiteHelper.COLUMN_MANUFACTURER, medicationManufacturer); sqLiteDatabase.insert(MedicationsFavoritesSQLiteHelper.TABLE, null, contentValues); Intent intent = new Intent(); intent.setAction("update"); mContext.sendBroadcast(intent); mFavoriteMenuItem.setIcon(R.drawable.ic_star_white_24dp) .setTitle(getString(R.string.medication_menu_remove_favorite)); snackbarString = getString(R.string.medication_favorite_saved); } Snackbar snackbar = Snackbar.make(mRelativeLayout, snackbarString, Snackbar.LENGTH_LONG) .setAction(R.string.snackbar_undo, new View.OnClickListener() { @Override public void onClick(View view) { favorite(); } }).setActionTextColor(ContextCompat.getColor(mContext, R.color.orange)); View snackbarView = snackbar.getView(); TextView snackbarTextView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text); snackbarTextView.setTextColor(ContextCompat.getColor(mContext, R.color.white)); snackbar.show(); mTools.updateWidget(); sqLiteDatabase.close(); }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<FavoritesData> getFavoritesFromServer(Context context, ArrayList<FavoritesData> ret) { if (ret == null) { ret = new ArrayList<FavoritesData>(); } else {//from w w w . jav a2 s . c o m ret.clear(); } if (IbikeApplication.isUserLogedIn()) { String authToken = IbikeApplication.getAuthToken(); try { JsonNode getObject = HttpUtils .getFromServer(Config.serverUrl + "/favourites?auth_token=" + authToken); if (getObject != null && getObject.has("data")) { SQLiteDatabase db = this.getWritableDatabase(); if (db != null) { db.delete(TABLE_FAVORITES, null, null); } IbikeApplication.setFavoritesFetched(true); JsonNode favoritesList = getObject.get("data"); for (int i = 0; i < favoritesList.size(); i++) { JsonNode data = favoritesList.get(i); FavoritesData fd = new FavoritesData(data.get("name").asText(), data.get("address").asText(), data.get("sub_source").asText(), data.get("lattitude").asDouble(), data.get("longitude").asDouble(), data.get("id").asInt()); saveFavorite(fd, null, false); // ret.add(fd); } LOG.d("favorites fetched = " + ret); } } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) { LOG.e(e.getLocalizedMessage()); } } } getFavorites(ret); return ret; }