Example usage for android.database.sqlite SQLiteDatabase updateWithOnConflict

List of usage examples for android.database.sqlite SQLiteDatabase updateWithOnConflict

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase updateWithOnConflict.

Prototype

public int updateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs,
        int conflictAlgorithm) 

Source Link

Document

Convenience method for updating rows in the database.

Usage

From source file:ru.gkpromtech.exhibition.db.Table.java

public void update(T item, int conflictAlgorithm) {
    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {//from ww w .j a  va 2  s . co m
        db.beginTransaction();
        db.updateWithOnConflict(mTableName, itemToRow(item), "id = ?", new String[] { String.valueOf(item.id) },
                conflictAlgorithm);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void update(List<T> items, int conflictAlgorithm) {
    SQLiteDatabase db = mSqlHelper.getWritableDatabase();
    try {/*from   w  w  w.  ja  v  a  2 s.c om*/
        db.beginTransaction();
        for (T item : items)
            db.updateWithOnConflict(mTableName, itemToRow(item), "id = ?",
                    new String[] { String.valueOf(item.id) }, conflictAlgorithm);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
        db.close();
    }
}

From source file:ru.gkpromtech.exhibition.db.Table.java

public void partialUpdate(SQLiteDatabase db, int id, ObjectNode item, int conflictAlgorithm)
        throws IllegalAccessException, ParseException {
    ContentValues values = jsonToRow(item);
    db.updateWithOnConflict(mTableName, values, "id = ?", new String[] { String.valueOf(id) },
            conflictAlgorithm);//  w w w.  j a  v a  2s.c o m
}

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

public void updateIngredients(long rid, ContentValues values) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try {/*from  ww  w  .  j  a v  a2  s.  c  o m*/
            db.updateWithOnConflict(INGREDIENTS_TABLE, values, IT_RECIPE_ID + " = ?",
                    new String[] { Long.toString(rid) }, SQLiteDatabase.CONFLICT_IGNORE);
        } finally {
            db.close();
        }
    }
}

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

public void updateDirections(long rid, ContentValues values) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try {/*from   w w  w .java  2  s .  c o m*/
            db.updateWithOnConflict(DIRECTIONS_TABLE, values, DT_RECIPE_ID + " = ?",
                    new String[] { Long.toString(rid) }, SQLiteDatabase.CONFLICT_IGNORE);
        } finally {
            db.close();
        }
    }
}

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

public void updateTags(long rid, ContentValues values) {
    synchronized (DB_LOCK) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try {/*from   www.  j av a  2s  . c  o m*/
            db.updateWithOnConflict(TAGS_TABLE, values, TT_RECIPE_ID + " = ?",
                    new String[] { Long.toString(rid) }, SQLiteDatabase.CONFLICT_IGNORE);
        } finally {
            db.close();
        }
    }
}

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;// w ww . j  a  v  a2 s  . c om
    } 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;
        }
    });
}