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:net.smart_json_database.JSONDatabase.java

public boolean deleteAll() {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    boolean returnValue = false;
    try {//from ww w .java2  s . c om
        db.beginTransaction();
        db.delete(TABLE_REL_JSON_DATA_JSON_DATA, "", null);
        db.delete(TABLE_REL_JSON_DATA_JSON_DATA, "", null);
        db.delete(TABLE_REL_TAG_JSON_DATA, "", null);
        db.delete(TABLE_JSON_DATA, "", null);
        db.setTransactionSuccessful();
        returnValue = true;
    } catch (Exception e) {
        returnValue = false;
    } finally {
        db.endTransaction();
        db.close();
    }
    return returnValue;
}

From source file:eu.operando.operandoapp.database.DatabaseHelper.java

public boolean removeBlockedDomain(String domain, String exfiltrated) {
    SQLiteDatabase db = this.getWritableDatabase();
    try {//  w w  w . j  a va2 s.  c o  m
        int id = (int) db.delete(TABLE_BLOCKED_DOMAINS,
                KEY_APP_INFO + " LIKE '%" + domain + "%' AND " + KEY_PERMISSIONS + "='" + exfiltrated + "'",
                null);
        return id > 0;
    } catch (Exception e) {
        return false;
    }
}

From source file:eu.operando.operandoapp.database.DatabaseHelper.java

public boolean removeAllowedDomain(String domain, String exfiltrated) {
    SQLiteDatabase db = this.getWritableDatabase();
    try {/*from   w  w  w.  j a va  2 s.co m*/
        int id = (int) db.delete(TABLE_ALLOWED_DOMAINS,
                KEY_APP_INFO + " LIKE '%" + domain + "%' AND " + KEY_PERMISSIONS + "='" + exfiltrated + "'",
                null);
        return true;
    } catch (Exception e) {
        e.getMessage();
        return false;
    }
}

From source file:net.smart_json_database.JSONDatabase.java

private boolean deleteTag(String name, SQLiteDatabase db) {

    int id = -1;//from  ww w  . j a  v a 2s  .  c  o m
    if (!tags.containsKey(name)) {
        return false;
    } else {
        id = tags.get(name);
    }
    db.delete(TABLE_REL_TAG_JSON_DATA, "from_id = ?", new String[] { "" + id });
    db.delete(TABLE_TAG, "tag_uid = ?", new String[] { "" + id });
    tags.remove(name);
    invertedTags.remove(new Integer(id));
    return true;
}

From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java

@VisibleForTesting
void refreshShortcut(Source source, final String shortcutId, SuggestionCursor refreshed) {
    if (source == null)
        throw new NullPointerException("source");
    if (shortcutId == null)
        throw new NullPointerException("shortcutId");

    final String[] whereArgs = { shortcutId, source.getName() };
    final ContentValues shortcut;
    if (refreshed == null || refreshed.getCount() == 0) {
        shortcut = null;//from   w  w w .j  a v a  2  s  .  c  o  m
    } else {
        refreshed.moveTo(0);
        shortcut = makeShortcutRow(refreshed);
    }

    runTransactionAsync(new SQLiteTransaction() {
        @Override
        protected boolean performTransaction(SQLiteDatabase db) {
            if (shortcut == null) {
                if (DBG)
                    Log.d(TAG, "Deleting shortcut: " + shortcutId);
                db.delete(Shortcuts.TABLE_NAME, SHORTCUT_BY_ID_WHERE, whereArgs);
            } else {
                if (DBG)
                    Log.d(TAG, "Updating shortcut: " + shortcut);
                db.updateWithOnConflict(Shortcuts.TABLE_NAME, shortcut, SHORTCUT_BY_ID_WHERE, whereArgs,
                        SQLiteDatabase.CONFLICT_REPLACE);
            }
            return true;
        }
    });
}

From source file:com.fututel.db.DBProvider.java

@Override
public int delete(Uri uri, String where, String[] whereArgs) {

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    String finalWhere;//from   ww  w  .j  a v a  2 s .c o m
    int count = 0;
    int matched = URI_MATCHER.match(uri);
    Uri regUri = uri;

    ArrayList<Long> oldRegistrationsAccounts = null;

    switch (matched) {
    case ACCOUNTS:
        count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, where, whereArgs);
        break;
    case ACCOUNTS_ID:
        finalWhere = DatabaseUtilsCompat
                .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case CALLLOGS:
        count = db.delete(SipManager.CALLLOGS_TABLE_NAME, where, whereArgs);
        break;
    case CALLLOGS_ID:
        finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri),
                where);
        count = db.delete(SipManager.CALLLOGS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case FILTERS:
        count = db.delete(SipManager.FILTERS_TABLE_NAME, where, whereArgs);
        break;
    case FILTERS_ID:
        finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipManager.FILTERS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case MESSAGES:
        count = db.delete(SipMessage.MESSAGES_TABLE_NAME, where, whereArgs);
        break;
    case MESSAGES_ID:
        finalWhere = DatabaseUtilsCompat
                .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipMessage.MESSAGES_TABLE_NAME, finalWhere, whereArgs);
        break;
    case THREADS_ID:
        String from = uri.getLastPathSegment();
        if (!TextUtils.isEmpty(from)) {
            count = db.delete(SipMessage.MESSAGES_TABLE_NAME, MESSAGES_THREAD_SELECTION,
                    new String[] { from, from });
        } else {
            count = 0;
        }
        regUri = SipMessage.MESSAGE_URI;
        break;
    case ACCOUNTS_STATUS:
        oldRegistrationsAccounts = new ArrayList<Long>();
        synchronized (profilesStatus) {
            for (Long accId : profilesStatus.keySet()) {
                oldRegistrationsAccounts.add(accId);
            }
            profilesStatus.clear();
        }
        break;
    case ACCOUNTS_STATUS_ID:
        long id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            profilesStatus.remove(id);
        }
        break;
    default:
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    getContext().getContentResolver().notifyChange(regUri, null);

    if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) {
        long rowId = ContentUris.parseId(uri);
        if (rowId >= 0) {
            if (matched == ACCOUNTS_ID) {
                broadcastAccountChange(rowId);
            } else if (matched == ACCOUNTS_STATUS_ID) {
                broadcastRegistrationChange(rowId);
            }
        }
    }
    if (matched == FILTERS || matched == FILTERS_ID) {
        Filter.resetCache();
    }
    if (matched == ACCOUNTS_STATUS && oldRegistrationsAccounts != null) {
        for (Long accId : oldRegistrationsAccounts) {
            if (accId != null) {
                broadcastRegistrationChange(accId);
            }
        }
    }

    return count;
}

From source file:net.smart_json_database.JSONDatabase.java

public boolean delete(JSONEntity entity) {
    boolean returnValue = false;
    if (entity.getUid() == -1) {
        return returnValue;
    }//  ww  w. j ava2  s.c  o m
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    try {
        db.beginTransaction();
        String[] params = new String[] { "" + entity.getUid() };
        db.delete(TABLE_REL_JSON_DATA_JSON_DATA, "from_id = ?", params);
        db.delete(TABLE_REL_JSON_DATA_JSON_DATA, "to_id = ?", params);
        db.delete(TABLE_REL_TAG_JSON_DATA, "to_id = ?", params);
        db.delete(TABLE_JSON_DATA, "json_uid = ?", params);
        db.setTransactionSuccessful();
        notifyListenersOnEntityChange(entity.getUid(), IDatabaseChangeListener.CHANGETYPE_DELETE);
        returnValue = true;
    } catch (Exception e) {
        returnValue = false;
    } finally {
        db.endTransaction();
        db.close();
    }

    return returnValue;
}

From source file:net.potterpcs.recipebook.RecipeData.java

public void clearCache() {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.delete(CACHE_TABLE, null, null);
    }/* w w w. jav  a 2  s.  co m*/
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

public static void deleteAlarm(Context context, Lecture lecture) {
    AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context);
    SQLiteDatabase db = alarmDB.getWritableDatabase();
    Cursor cursor;/*w w w. j a  v  a 2  s.co  m*/

    try {
        cursor = db.query(AlarmsTable.NAME, AlarmsDBOpenHelper.allcolumns, AlarmsTable.Columns.EVENT_ID + "=?",
                new String[] { lecture.lecture_id }, null, null, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        MyApp.LogDebug("delete alarm", "failure on alarm query");
        db.close();
        return;
    }

    if (cursor.getCount() == 0) {
        db.close();
        cursor.close();
        MyApp.LogDebug("delete_alarm", "alarm for " + lecture.lecture_id + " not found");
        return;
    }

    cursor.moveToFirst();

    Intent intent = new Intent(context, AlarmReceiver.class);

    String lecture_id = cursor.getString(cursor.getColumnIndex(AlarmsTable.Columns.EVENT_ID));
    intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture_id);
    int day = cursor.getInt(cursor.getColumnIndex(AlarmsTable.Columns.DAY));
    intent.putExtra(BundleKeys.ALARM_DAY, day);
    String title = cursor.getString(cursor.getColumnIndex(AlarmsTable.Columns.EVENT_TITLE));
    intent.putExtra(BundleKeys.ALARM_TITLE, title);
    long startTime = cursor.getLong(cursor.getColumnIndex(AlarmsTable.Columns.TIME));
    intent.putExtra(BundleKeys.ALARM_START_TIME, startTime);

    // delete any previous alarms of this lecture
    db.delete(AlarmsTable.NAME, AlarmsTable.Columns.EVENT_ID + "=?", new String[] { lecture.lecture_id });
    db.close();

    intent.setAction("de.machtnix.fahrplan.ALARM");
    intent.setData(Uri.parse("alarm://" + lecture.lecture_id));

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingintent = PendingIntent.getBroadcast(context, Integer.parseInt(lecture.lecture_id),
            intent, 0);

    // Cancel any existing alarms for this lecture
    alarmManager.cancel(pendingintent);

    lecture.has_alarm = false;
}

From source file:net.potterpcs.recipebook.RecipeData.java

public void deleteRecipe(long rid) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try {//  w  w  w.  java2  s .c o m
            db.delete(INGREDIENTS_TABLE, IT_RECIPE_ID + " = ?", new String[] { Long.toString(rid) });
            db.delete(DIRECTIONS_TABLE, DT_RECIPE_ID + " = ?", new String[] { Long.toString(rid) });
            db.delete(TAGS_TABLE, TT_RECIPE_ID + " = ?", new String[] { Long.toString(rid) });
            db.delete(RECIPES_TABLE, RT_ID + " = ?", new String[] { Long.toString(rid) });
        } finally {
            db.close();
        }
    }
}