Example usage for android.database.sqlite SQLiteDatabase update

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

Introduction

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

Prototype

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

Source Link

Document

Convenience method for updating rows in the database.

Usage

From source file:Main.java

public static int updateItemsFromStateToState(SQLiteDatabase database, Integer original_state,
        Integer new_state) {
    String where_clause = COLUMN_STATE + " = " + original_state;
    ContentValues values = new ContentValues();
    values.put(COLUMN_STATE, new_state);

    int affected = database.update(TABLE_NAME, values, where_clause, null);

    return affected;
}

From source file:uk.ac.horizon.ubihelper.service.PeersOpenHelper.java

public static boolean updatePeerInfo(SQLiteDatabase database, PeerInfo pi) {
    int rval = database.update(PEER_TABLE_NAME, getContentValues(pi), KEY_ROW_ID + " = ?",
            new String[] { Long.toString(pi._id) });
    if (rval == 0) {
        Log.e(TAG, "Error updating PeerInfo " + pi._id);
        return false;
    } else/*from www  .  j  a v  a 2s.c  o m*/
        Log.d(TAG, "Updated PeerInfo " + pi._id);
    return true;
}

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

/**
 * Updates values for a category.//w ww.  j  a  v  a  2 s.  co m
 *
 * @param context The context this is running in.
 * @param category The category to update.
 */
public static void updateCategory(Context context, Category category) {
    if (mCategories != null && mCategories.contains(category)) {
        final int location = mCategories.indexOf(category);
        mCategories.remove(location);
        mCategories.add(location, category);
    }
    SQLiteDatabase writableDatabase = getWritableDatabase(context);
    ContentValues categoryValues = createContentValuesFor(category);
    writableDatabase.update(CategoryTable.NAME, categoryValues, CategoryTable.COLUMN_ID + "=?",
            new String[] { category.getId() });
    final List<Quiz> quizzes = category.getQuizzes();
    updateQuizzes(writableDatabase, quizzes);
}

From source file:com.onesignal.NotificationOpenedProcessor.java

private static void markNotificationsConsumed(SQLiteDatabase writableDb) {
    String group = intent.getStringExtra("summary");
    String whereStr;//from  w w w .  ja  v a2  s  .co m
    String[] whereArgs = null;

    if (group != null) {
        whereStr = NotificationTable.COLUMN_NAME_GROUP_ID + " = ?";
        whereArgs = new String[] { group };
    } else
        whereStr = NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID + " = "
                + intent.getIntExtra("notificationId", 0);

    writableDb.update(NotificationTable.TABLE_NAME, newContentValuesWithConsumed(), whereStr, whereArgs);
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

protected static void saveFetch(Context context, PublicScript script, String trollId, String uuid,
        String status) {// w w  w.j a  v a 2  s  . c  o  m

    String format = "Saving fetch for category %s (script=%s) and troll=%s";
    String message = String.format(format, script.category, script, trollId);
    Log.d(TAG, message);

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getWritableDatabase();

    ContentValues values = new ContentValues(2);
    long now = System.currentTimeMillis();
    values.put(MhDlaSQLHelper.SCRIPTS_END_DATE_COLUMN, now);
    values.put(MhDlaSQLHelper.SCRIPTS_STATUS_COLUMN, status);

    String whereClause = String.format("%s = ?", MhDlaSQLHelper.SCRIPTS_ID_COLUMN);
    database.update(MhDlaSQLHelper.SCRIPTS_TABLE, values, whereClause, new String[] { uuid });

    database.close();
}

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

/**
 * Updates a list of given quizzes.//from  ww  w .  j av  a2 s.  com
 *
 * @param writableDatabase The database to write the quizzes to.
 * @param quizzes The quizzes to write.
 */
private static void updateQuizzes(SQLiteDatabase writableDatabase, List<Quiz> quizzes) {
    Quiz quiz;
    ContentValues quizValues = new ContentValues();
    String[] quizArgs = new String[1];
    for (int i = 0; i < quizzes.size(); i++) {
        quiz = quizzes.get(i);
        quizValues.clear();
        quizValues.put(QuizTable.COLUMN_SOLVED, quiz.isSolved());

        quizArgs[0] = quiz.getQuestion();
        writableDatabase.update(QuizTable.NAME, quizValues, QuizTable.COLUMN_QUESTION + "=?", quizArgs);
    }
}

From source file:com.onesignal.NotificationOpenedProcessor.java

private static void updateSummaryNotification(SQLiteDatabase writableDb) {
    String grpId = intent.getStringExtra("grp");

    Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME,
            new String[] { NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID }, // retColumn
            NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String
                    NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED
                    + " = 0 AND " + NotificationTable.COLUMN_NAME_IS_SUMMARY + " = 0",
            new String[] { grpId }, // whereArgs
            null, null, null);//www  .  j  av a  2s  .  c  om

    // All individual notifications consumed, make summary notification as consumed as well.
    if (cursor.getCount() == 0)
        writableDb.update(NotificationTable.TABLE_NAME, newContentValuesWithConsumed(),
                NotificationTable.COLUMN_NAME_GROUP_ID + " = ?", new String[] { grpId });
    else {
        try {
            GenerateNotification.createSummaryNotification(context, true,
                    new JSONObject("{\"grp\": \"" + grpId + "\"}"));
        } catch (JSONException e) {
        }
    }

    cursor.close();
}

From source file:net.survivalpad.android.entity.AbsData.java

public long update(SQLiteDatabase db) {
    ContentValues values = new ContentValues();
    write(values);//  ww w  .  j  a va 2s.  c o m
    return db.update(getTableName(), values, "_id = ?", new String[] { String.valueOf(id) });
}

From source file:net.survivalpad.android.entity.AbsData.java

public long update(SQLiteDatabase db, String whereClause, String[] whereArgs) {
    ContentValues values = new ContentValues();
    write(values);//from w ww.j  a  v  a 2s . c  om
    return db.update(getTableName(), values, whereClause, whereArgs);
}

From source file:org.egov.android.data.SQLiteHelper.java

/**
 * Update data in table/*w  ww .  j ava2 s  . c o m*/
 * 
 * @param tableName
 * @param ContentValues
 * @param whereClause
 * @param whereArgs
 */

public int update(String tableName, ContentValues cv, String whereClause, String[] whereArgs) {
    SQLiteDatabase db = getWritableDatabase();
    int result = db.update(tableName, cv, whereClause, whereArgs);
    db.close();
    return result;
}