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:com.dm.wallpaper.board.databases.Database.java

public void selectCategory(int id, boolean isSelected) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_SELECTED, isSelected ? 1 : 0);
    db.update(TABLE_CATEGORIES, values, KEY_ID + " = ?", new String[] { String.valueOf(id) });
    db.close();//  ww w . jav a 2  s .c o m
}

From source file:com.dm.wallpaper.board.databases.Database.java

public void favoriteWallpaper(int id, boolean isFavorite) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_FAVORITE, isFavorite ? 1 : 0);
    db.update(TABLE_WALLPAPERS, values, KEY_ID + " = ?", new String[] { String.valueOf(id) });
    db.close();//  w w  w .  ja v a  2  s .co  m
}

From source file:com.dm.wallpaper.board.databases.Database.java

public void selectCategoryForMuzei(int id, boolean isSelected) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_MUZEI_SELECTED, isSelected ? 1 : 0);
    db.update(TABLE_CATEGORIES, values, KEY_ID + " = ?", new String[] { String.valueOf(id) });
    db.close();/*from w w  w . ja va 2  s. c o m*/
}

From source file:org.mozilla.labs.Soup.provider.AppsProvider.java

@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count;//w w w .j  a  v  a2  s .c  om

    Log.d(TAG, "Update " + values.toString());

    switch (sUriMatcher.match(uri)) {
    case APPS:
        count = db.update(APPS_TABLE_NAME, values, where, whereArgs);
        break;

    case APP_ID:
        String appId = uri.getPathSegments().get(1);

        // values.put(AppsContract.Apps.MODIFIED_DATE,
        // Long.valueOf(System.currentTimeMillis()));

        count = db.update(APPS_TABLE_NAME, values,
                Apps._ID + "=" + appId + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
        break;

    default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}

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

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selArgs) {
    int uriType = sURIMatcher.match(uri);
    SQLiteDatabase sqlDB = database.getWritableDatabase();
    int rowsUpdated = 0;
    String id;//from   ww  w .  j a v a 2 s .com

    switch (uriType) {
    case SRS:
        rowsUpdated = sqlDB.update(SRTable.TABLE_NAME, values, selection, selArgs);
        break;
    case SR_ID:
        rowsUpdated = updateIdTypeUri(uri, values, selection, selArgs, sqlDB, SRTable.TABLE_NAME);
        break;
    case DAILIES:
        rowsUpdated = sqlDB.update(DailyTable.TABLE_NAME, values, selection, selArgs);
        break;
    case DAILY_ID:
        rowsUpdated = updateIdTypeUri(uri, values, selection, selArgs, sqlDB, DailyTable.TABLE_NAME);
        break;
    case PARTS:
        rowsUpdated = sqlDB.update(PartTable.TABLE_NAME, values, selection, selArgs);
        break;
    case PART_ID:
        rowsUpdated = updateIdTypeUri(uri, values, selection, selArgs, sqlDB, PartTable.TABLE_NAME);
        break;
    default:
        throw new IllegalArgumentException("Unknown URI: " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return rowsUpdated;
}

From source file:com.itime.team.itime.fragments.SettingsFragment.java

private void updateUserTable() {
    UserTableHelper dbHelper = new UserTableHelper(getContext(), "userbase1");
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    ContentValues values = new ContentValues();
    values.put("remember", false);
    db.update("itime_user", values, "id=?", new String[] { "1" });
    dbHelper.close();//from   w  w w. j a  v a  2s .c o  m
    db.close();
}

From source file:uk.org.rivernile.edinburghbustracker.android.SettingsDatabase.java

/**
 * Modify the stopName string of an item in the database.
 *
 * @param stopCode The stop code of the item to modify.
 * @param stopName The new stop name./* ww w  .j  av a  2 s .c om*/
 */
public void modifyFavouriteStop(final String stopCode, final String stopName) {
    if (stopCode == null || stopName == null || stopCode.length() == 0 || stopName.length() == 0)
        return;
    if (!getFavouriteStopExists(stopCode))
        return;
    final ContentValues cv = new ContentValues();
    cv.put(FAVOURITE_STOPS_STOPNAME, stopName);

    final SQLiteDatabase db = getWritableDatabase();
    db.update(FAVOURITE_STOPS_TABLE, cv, FAVOURITE_STOPS_STOPCODE + " = ?", new String[] { stopCode });

    BackupManager.dataChanged(context.getPackageName());
}

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

/**
 * Helper method to update an item represented by an ID type Uri 
 * @param uri Uri to update/*  ww w .ja  va  2  s .c  o  m*/
 * @param values Values to update items represented by Uri with
 * @param selection Selection to select items to update with
 * @param selArgs arguments for selection
 * @param sqlDB db to perform update on
 * @param table table to perform update on
 * @return number of rows updated
 */
private int updateIdTypeUri(Uri uri, ContentValues values, String selection, String[] selArgs,
        SQLiteDatabase sqlDB, String table) {
    String id = uri.getLastPathSegment();
    if (StringUtils.isBlank(selection)) {
        selection = "_id = " + id;
    } else {
        selection = "_id = " + id + selection;
    }
    return sqlDB.update(table, values, selection, selArgs);
}

From source file:org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryDataExtender.java

/**
 * Store visit data.//from w  w w. java 2 s . c  o m
 *
 * If a row with GUID `guid` does not exist, insert a new row.
 * If a row with GUID `guid` does exist, replace the visits column.
 *
 * @param guid The GUID to store to.
 * @param visits New visits data.
 */
public void store(String guid, JSONArray visits) {
    SQLiteDatabase db = this.getCachedWritableDatabase();

    ContentValues cv = new ContentValues();
    cv.put(COL_GUID, guid);
    if (visits == null) {
        cv.put(COL_VISITS, "[]");
    } else {
        cv.put(COL_VISITS, visits.toJSONString());
    }

    String where = COL_GUID + " = ?";
    String[] args = new String[] { guid };
    int rowsUpdated = db.update(TBL_HISTORY_EXT, cv, where, args);
    if (rowsUpdated >= 1) {
        Logger.debug(LOG_TAG, "Replaced history extension record for row with GUID " + guid);
    } else {
        long rowId = db.insert(TBL_HISTORY_EXT, null, cv);
        Logger.debug(LOG_TAG, "Inserted history extension record into row: " + rowId);
    }
}

From source file:redgun.bakingapp.data.RecipesProvider.java

@Override
public int update(Uri uri, ContentValues contentValues, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    int rowsUpdated;
    // this makes delete all rows return the number of rows deleted
    if (null == selection)
        selection = "1";
    switch (match) {
    case RECIPES:
        rowsUpdated = db.update(RecipesContract.RecipeEntry.TABLE_NAME, contentValues, selection,
                selectionArgs);/*from   w  ww.j  ava  2s.c o m*/
        break;

    default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    // Because a null deletes all rows
    if (rowsUpdated != 0) {
        getContext().getContentResolver().notifyChange(uri, null);
    }
    return rowsUpdated;
}