SQLiteDatabase update - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SQLiteDatabase update method.

This code example shows how to use the following methods:beginTransaction, endTransaction, setTransactionSuccessful, update
    @Override 
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        SQLiteDatabase db = null;
        try { 
            db = mDatabaseHelper.getWritableDatabase();
            db.beginTransaction();
 
            String newSelection = buildSelection(uri, selection);
            int count = db.update("tests", values, newSelection, selectionArgs);
            db.setTransactionSuccessful();
            return count;
        } finally { 
            if (db != null) {
                db.endTransaction();
            } 
        } 
    } 
 
    private String buildSelection(Uri uri, String selection) {
        long id = 0;
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:beginTransaction, update
		} 
	} 
	 
	public static long updateOrInsert(SQLiteDatabase db, String table, ContentValues values, String selection, String[] selectionArgs) {
		long retval = -1;
		db.beginTransaction();
		try { 
			retval = db.update(table, values, selection, selectionArgs);
			if(retval == 0){
				retval = db.insert(table, null, values);
			} 
			db.setTransactionSuccessful();
		} finally { 
			db.endTransaction();
		} 
		return retval;
	} 
	 
	/* 
	public static long updateOrReplaceRow(SQLiteDatabase db, ContentValues values, String table, String selection, String[] selectionArgs) { 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:execSQL, update
	 
	private void resetDefaultAccount(SQLiteDatabase sqLiteDatabase) {
		StringBuilder sql = new StringBuilder();
		sql.append(" update Account set Is_Default = 0 ");
		sql.append(" where Is_Default = 1");
		sqLiteDatabase.execSQL(sql.toString());
	} 
	 
	private void clearDeletedAccount(SQLiteDatabase sqLiteDatabase, Account account) {
		StringBuilder whereClause = new StringBuilder();
		whereClause.append(" State = ").append(Account.STATE_INVALID);
		whereClause.append(" and Service_Provider = ").append(account.getServiceProviderNo());
		whereClause.append(" and User_Id = '").append(account.getUserId()).append("'");
		sqLiteDatabase.delete(TABLE, whereClause.toString(), null);
	} 
 
	public int update(Account account) {
		if (isNull(account)) {
			return -1; 
		} 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, insert, update
		 
		// put radio data into the table 
		ContentValues values = new RadioDatabaseBuilder().deconstruct(radio);
		 
		String[] whereArgs = {""+radio.getId()};
		int row_count = db.update(TABLE_RECENT_RADIOS, values, "radio_id=?", whereArgs);
		 
		if(row_count == 0){
			db.insert(TABLE_RECENT_RADIOS, null, values);
		} 
		 
		db.close();
	} 
 
	@Override 
	public ArrayList<Radio> getRecentRadios(int limit) {
		ArrayList<Radio> radios = new ArrayList<Radio>(); 
		SQLiteDatabase db = getDb();
		 
		String[] columns = {"radio_id","radio_idstr","radio_name","radio_image"};
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:update
        isValidUri(uri);
 
        SQLiteDatabase db = mBookOpenHelper.getWritableDatabase();
        // URIからテーブル名を取得 
        String tableName = uri.getPathSegments().get(0);
        int updatedCount = db.update(tableName, values, selection, selectionArgs);
        getContext().getContentResolver().notifyChange(uri, null);
        return updatedCount;
    } 
 
    // このContentProviderで使用可能なURIかを判定します。 
    // 使用不可の場合はIllegalArgumentExceptionを投げます。 
    private void isValidUri(Uri uri) {
        if (URI_MATCHER.match(uri) != Book.BOOK) {
            throw new IllegalArgumentException("Unknown URI : " + uri);
        } 
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isOpen, update
    private SQLiteDatabase mDatabase;
 
    @SuppressWarnings("deprecation") 
    public synchronized SQLiteDatabase getDatabase(Context context) {
        // Always return the cached database, if we've got one 
        if (mDatabase == null || !mDatabase.isOpen()) {
            DatabaseHelper helper = new DatabaseHelper(context, DATABASE_NAME);
            mDatabase = helper.getWritableDatabase();
            if (mDatabase != null) {
                mDatabase.setLockingEnabled(true);
            } 
		} 
 
        return mDatabase;
    } 
 
    private class DatabaseHelper extends SQLiteOpenHelper {
 
        DatabaseHelper(Context context, String name) {
            super(context, name, null, DATABASE_VERSION);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:execSQL, update
				//introducing sub accounts 
				Log.i(TAG, "Adding column for parent accounts");
				String addParentAccountSql = "ALTER TABLE " + ACCOUNTS_TABLE_NAME + 
						" ADD COLUMN " + KEY_PARENT_ACCOUNT_UID + " varchar(255)";
	 
				db.execSQL(addColumnSql);
				db.execSQL(addParentAccountSql);
			} 
			 
			//update account types to GnuCash account types 
			//since all were previously CHECKING, now all will be CASH 
			Log.i(TAG, "Converting account types to GnuCash compatible types");
			ContentValues cv = new ContentValues();
			cv.put(KEY_TYPE, AccountType.CASH.toString());
			db.update(ACCOUNTS_TABLE_NAME, cv, null, null);
 
            if (oldVersion == 2 && newVersion == 3){
                Log.i(TAG, "Adding flag for placeholder accounts");
                String addPlaceHolderAccountFlagSql = "ALTER TABLE " + ACCOUNTS_TABLE_NAME +
                        " ADD COLUMN " + KEY_PLACEHOLDER + " tinyint default 0";

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:put, update
		getWritableDatabase().insert("restaurants", "name", cv);
	} 
	 
	public void update(String id, String name, String address,
										 String type, String notes) {
		ContentValues cv=new ContentValues();
		String[] args={id};
		 
		cv.put("name", name);
		cv.put("address", address);
		cv.put("type", type);
		cv.put("notes", notes);
		 
		getWritableDatabase().update("restaurants", cv, "_ID=?",
																 args);
	} 
	 
	public String getName(Cursor c) {
		return(c.getString(1));
	} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, beginTransaction, endTransaction, update
    private final int performUpdate(SQLiteDatabase db, T t, boolean autoClose) {
        return performUpdate(db, t, autoClose, SELECT_ID, wrapId(t));
    } 
 
    private final int performUpdate(SQLiteDatabase db, T t, boolean autoClose, String whereClause, String... whereArgs) {
        db.beginTransaction();
        int updated;
        try { 
            updated = db.update(mName, t.toContentValues(mTable), whereClause, whereArgs);
            db.setTransactionSuccessful();
        } finally { 
            db.endTransaction();
            if (autoClose) {
                db.close();
            } 
        } 
        return updated;
    } 
 
    private final String[] wrapId(T t) {
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:update
 
    /** 
     * Execute update using the current internal state as {@code WHERE} clause. 
     */ 
    public int update(SQLiteDatabase db, String table, ContentValues values) {
        return db.update(table, values, getSelection(), getSelectionArgs());
    } 
 
    /** 
     * Execute delete using the current internal state as {@code WHERE} clause. 
     */ 
    public int delete(SQLiteDatabase db, String table) {
        return db.delete(table, getSelection(), getSelectionArgs());
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related SQLiteDatabase update Questions & Answers:

Other SQLiteDatabase update Examples

122:	
123:			// updating row return
124:			int update = db.update(TABLE_RSS, values, KEY_RSS_LINK + " = ?",
125:					new String[] { String.valueOf(site.getRSSLink()) });
126:			db.close();

Read More

116:	
117:			// updating row
118:			return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
119:					new String[] { String.valueOf(contact.getID()) });
120:		}

Read More

7:	
8:			// updating row
9:			return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
10:					new String[] { String.valueOf(contact.getID()) });
11:		}

Read More

update Method Overview
Convenience method for updating rows in the database.
See Code Examples for other Android SQLiteDatabase Methods: