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.zionsoft.obadiah.model.translations.TranslationHelper.java

public static void removeTranslation(SQLiteDatabase db, String translationShortName) {
    db.execSQL(String.format("DROP TABLE IF EXISTS %s", translationShortName));

    db.delete(DatabaseHelper.TABLE_BOOK_NAMES,
            String.format("%s = ?", DatabaseHelper.COLUMN_TRANSLATION_SHORT_NAME),
            new String[] { translationShortName });
}

From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java

/**
 * Resets the contents of Topeka's database to it's initial state.
 *
 * @param context The context this is running in.
 *//*from   w  w w .  j a v a2 s. c om*/
public static void reset(Context context) {
    SQLiteDatabase writableDatabase = getWritableDatabase(context);
    writableDatabase.delete(CategoryTable.NAME, null, null);
    writableDatabase.delete(QuizTable.NAME, null, null);
    getInstance(context).preFillDatabase(writableDatabase);
}

From source file:com.gmail.emerssso.srbase.database.SRContentProvider.java

/**
 * Deletes an item indecated by an ID Uri
 * @param uri Uri of item to delete//w ww .  j ava  2 s.c  om
 * @param selection selection for items to delete
 * @param selArgs arguments for selection
 * @param wDB DB to act on
 * @param tableName Table to delete from
 * @return number of rows deleted
 */
private static int deleteIdTypeUri(Uri uri, String selection, String[] selArgs, SQLiteDatabase wDB,
        String tableName) {
    String id = uri.getLastPathSegment();
    if (StringUtils.isBlank(selection)) {
        selection = "_id =" + id;
    } else {
        selection = "_id =" + id + " and " + selection;
    }
    return wDB.delete(tableName, selection, selArgs);
}

From source file:com.jefftharris.passwdsafe.NotificationMgr.java

/** Remove the URI from the database */
private static void removeUri(Long id, SQLiteDatabase db) throws SQLException {
    String[] idarg = new String[] { id.toString() };
    db.delete(DB_TABLE_EXPIRYS, DB_MATCH_EXPIRYS_URI, idarg);
    db.delete(DB_TABLE_URIS, DB_MATCH_URIS_ID, idarg);
}

From source file:com.android.leanlauncher.WidgetPreviewLoader.java

private static void removeItemFromDb(final CacheDb cacheDb, final String objectName) {
    new AsyncTask<Void, Void, Void>() {
        public Void doInBackground(Void... args) {
            SQLiteDatabase db = cacheDb.getWritableDatabase();
            try {
                db.delete(CacheDb.TABLE_NAME, CacheDb.COLUMN_NAME + " = ? ", // SELECT query
                        new String[] { objectName }); // args to SELECT query
            } catch (SQLiteDiskIOException ignored) {
            }//w  w w . ja va  2  s.c om
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}

From source file:com.android.leanlauncher.WidgetPreviewLoader.java

public static void removePackageFromDb(final CacheDb cacheDb, final String packageName) {
    synchronized (sInvalidPackages) {
        sInvalidPackages.add(packageName);
    }//from w  w  w  .  ja va  2 s  .c o  m
    new AsyncTask<Void, Void, Void>() {
        public Void doInBackground(Void... args) {
            SQLiteDatabase db = cacheDb.getWritableDatabase();
            try {
                db.delete(CacheDb.TABLE_NAME,
                        CacheDb.COLUMN_NAME + " LIKE ? OR " + CacheDb.COLUMN_NAME + " LIKE ?", // SELECT query
                        new String[] { WIDGET_PREFIX + packageName + "/%" } // args to SELECT query
                );
            } catch (SQLiteDiskIOException ignored) {
            }
            synchronized (sInvalidPackages) {
                sInvalidPackages.remove(packageName);
            }
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}

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

public static void writeHighlight(Context context, Lecture lecture) {
    HighlightDBOpenHelper highlightDB = new HighlightDBOpenHelper(context);

    SQLiteDatabase db = highlightDB.getWritableDatabase();

    try {//from   w  w w  . j a  v a  2 s. c o m
        db.beginTransaction();
        db.delete(HighlightsTable.NAME, HighlightsTable.Columns.EVENT_ID + "=?",
                new String[] { lecture.lecture_id });

        ContentValues values = new ContentValues();

        values.put(HighlightsTable.Columns.EVENT_ID, Integer.parseInt(lecture.lecture_id));
        int highlightState = lecture.highlight ? HighlightsTable.Values.HIGHLIGHT_STATE_ON
                : HighlightsTable.Values.HIGHLIGHT_STATE_OFF;
        values.put(HighlightsTable.Columns.HIGHLIGHT, highlightState);

        db.insert(HighlightsTable.NAME, null, values);
        db.setTransactionSuccessful();
    } catch (SQLException e) {
    } finally {
        db.endTransaction();
        db.close();
    }
}

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

public static void addAlarm(Context context, Lecture lecture, int alarmTimesIndex) {
    int[] alarm_times = { 0, 5, 10, 15, 30, 45, 60 };
    long when;/*  w w w . j a v  a 2s .c  o m*/
    Time time;
    long startTime;
    long startTimeInSeconds = lecture.dateUTC;

    if (startTimeInSeconds > 0) {
        when = startTimeInSeconds;
        startTime = startTimeInSeconds;
        time = new Time();
    } else {
        time = lecture.getTime();
        startTime = time.normalize(true);
        when = time.normalize(true);
    }
    long alarmTimeDiffInSeconds = alarm_times[alarmTimesIndex] * 60 * 1000;
    when -= alarmTimeDiffInSeconds;

    // DEBUG
    // when = System.currentTimeMillis() + (30 * 1000);

    time.set(when);
    MyApp.LogDebug("addAlarm", "Alarm time: " + time.format("%Y-%m-%dT%H:%M:%S%z") + ", in seconds: " + when);

    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture.lecture_id);
    intent.putExtra(BundleKeys.ALARM_DAY, lecture.day);
    intent.putExtra(BundleKeys.ALARM_TITLE, lecture.title);
    intent.putExtra(BundleKeys.ALARM_START_TIME, startTime);
    intent.setAction(AlarmReceiver.ALARM_LECTURE);

    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);

    // Set new alarm
    alarmManager.set(AlarmManager.RTC_WAKEUP, when, pendingintent);

    int alarmTimeInMin = alarm_times[alarmTimesIndex];

    // write to DB

    AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context);

    SQLiteDatabase db = alarmDB.getWritableDatabase();

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

        ContentValues values = new ContentValues();

        values.put(AlarmsTable.Columns.EVENT_ID, Integer.parseInt(lecture.lecture_id));
        values.put(AlarmsTable.Columns.EVENT_TITLE, lecture.title);
        values.put(AlarmsTable.Columns.ALARM_TIME_IN_MIN, alarmTimeInMin);
        values.put(AlarmsTable.Columns.TIME, when);
        DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
        values.put(AlarmsTable.Columns.TIME_TEXT, df.format(new Date(when)));
        values.put(AlarmsTable.Columns.DISPLAY_TIME, startTime);
        values.put(AlarmsTable.Columns.DAY, lecture.day);

        db.insert(AlarmsTable.NAME, null, values);
        db.setTransactionSuccessful();
    } catch (SQLException e) {
    } finally {
        db.endTransaction();
        db.close();
    }

    lecture.has_alarm = true;
}

From source file:org.opendatakit.common.android.database.DataModelDatabaseHelper.java

public static void deleteTableAndData(SQLiteDatabase db, String formId) {
    try {/*from  www  . j a va  2s .com*/
        IdInstanceNameStruct ids = getIds(db, formId);

        String whereClause = TableDefinitionsColumns.TABLE_ID + " = ?";
        String[] whereArgs = { ids.tableId };

        db.beginTransaction();

        // Drop the table used for the formId
        db.execSQL("DROP TABLE IF EXISTS " + ids.tableId + ";");

        // Delete the table definition for the tableId
        int count = db.delete(TABLE_DEFS_TABLE_NAME, whereClause, whereArgs);

        // Delete the column definitions for this tableId
        db.delete(COLUMN_DEFINITIONS_TABLE_NAME, whereClause, whereArgs);

        // Delete the uploads for the tableId
        String uploadWhereClause = InstanceColumns.DATA_TABLE_TABLE_ID + " = ?";
        db.delete(UPLOADS_TABLE_NAME, uploadWhereClause, whereArgs);

        // Delete the values from the 4 key value stores
        db.delete(KEY_VALUE_STORE_DEFAULT_TABLE_NAME, whereClause, whereArgs);
        db.delete(KEY_VALUE_STORE_ACTIVE_TABLE_NAME, whereClause, whereArgs);
        db.delete(KEY_VALUE_STORE_SERVER_TABLE_NAME, whereClause, whereArgs);
        db.delete(KEY_VALULE_STORE_SYNC_TABLE_NAME, whereClause, whereArgs);

        db.setTransactionSuccessful();

    } catch (Exception ex) {
        Log.e(t, "Exception during deletion of data for formId:" + formId + " exception: " + ex.toString());
    } finally {
        db.endTransaction();
    }
}

From source file:DictionaryDatabase.java

public int deleteRecord(long id) {
    SQLiteDatabase db = getWritableDatabase();
    return db.delete(TABLE_DICTIONARY, "_id = ?", new String[] { String.valueOf(id) });
}