Java Code Examples for android.database.sqlite.SQLiteDatabase#replace()

The following examples show how to use android.database.sqlite.SQLiteDatabase#replace() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: YiBo   File: UserGroupDao.java    License: Apache License 2.0 6 votes vote down vote up
void save(SQLiteDatabase sqLiteDatabase, UserGroup userGroup) {
	if (isNull(userGroup)) {
		return;
	}
	if(Logger.isDebug()){
		Log.d("Save UserGroup:", userGroup.toString());
	}

	ContentValues values = new ContentValues();
	values.put("Service_Provider", userGroup.getServiceProvider().getSpNo());
	values.put("User_ID", userGroup.getUserId());
	values.put("Group_ID", userGroup.getGroupId());
	values.put("State", userGroup.getState());

	sqLiteDatabase.replace(TABLE, null, values);
}
 
Example 2
Source Project: school_shop   File: UserDao.java    License: MIT License 6 votes vote down vote up
/**
 * 保存好友list
 * 
 * @param contactList
 */
public void saveContactList(List<User> contactList) {
	SQLiteDatabase db = dbHelper.getWritableDatabase();
	if (db.isOpen()) {
		db.delete(TABLE_NAME, null, null);
		for (User user : contactList) {
			ContentValues values = new ContentValues();
			values.put(COLUMN_NAME_ID, user.getUsername());
			if(user.getNick() != null)
				values.put(COLUMN_NAME_NICK, user.getNick());
			if(user.getAvatar() != null)
			    values.put(COLUMN_NAME_AVATAR, user.getAvatar());
			db.replace(TABLE_NAME, null, values);
		}
	}
}
 
Example 3
/**
 * 保存好友list
 * 
 * @param contactList
 */
synchronized public void saveContactList(List<EaseUser> contactList) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    if (db.isOpen()) {
        db.delete(UserDao.TABLE_NAME, null, null);
        for (EaseUser user : contactList) {
            ContentValues values = new ContentValues();
            values.put(UserDao.COLUMN_NAME_ID, user.getUsername());
            if(user.getNick() != null)
                values.put(UserDao.COLUMN_NAME_NICK, user.getNick());
            if(user.getAvatar() != null)
                values.put(UserDao.COLUMN_NAME_AVATAR, user.getAvatar());
            db.replace(UserDao.TABLE_NAME, null, values);
        }
    }
}
 
Example 4
public void addNotification(Reminder reminder) {
    SQLiteDatabase database = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COL_ID, reminder.getId());
    values.put(COL_TITLE, reminder.getTitle());
    values.put(COL_CONTENT, reminder.getContent());
    values.put(COL_DATE_AND_TIME, reminder.getDateAndTime());
    values.put(COL_REPEAT_TYPE, reminder.getRepeatType());
    values.put(COL_FOREVER, reminder.getForeverState());
    values.put(COL_NUMBER_TO_SHOW, reminder.getNumberToShow());
    values.put(COL_NUMBER_SHOWN, reminder.getNumberShown());
    values.put(COL_ICON, reminder.getIcon());
    values.put(COL_COLOUR, reminder.getColour());
    values.put(COL_INTERVAL, reminder.getInterval());
    database.replace(NOTIFICATION_TABLE, null, values);
}
 
Example 5
Source Project: PluginLoader   File: PluginSQLiteHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 改
 * 
 * @param db db
 * @param values values
 * @param selectionArgs args
 * @return result
 */
public static long update(SQLiteDatabase db, ContentValues values, String[] selectionArgs) {
       try {
           return db.replace(TABLE_NAME, null,values);
       } catch (Exception e) {
           e.printStackTrace();
       }
       return -1;
}
 
Example 6
/**
 * 保存一个联系人
 * @param user
 */
public void saveContact(User user){
	SQLiteDatabase db = dbHelper.getWritableDatabase();
	ContentValues values = new ContentValues();
	values.put(COLUMN_NAME_ID, user.getUsername());
	if (user.getNick() != null) {
           values.put(COLUMN_NAME_NICK, user.getNick());
       }
       if (user.getBeizhu() != null) {
           values.put(COLUMN_NAME_BEIZHU, user.getBeizhu());
       }
       if (user.getTel() != null) {
           values.put(COLUMN_NAME_TEL, user.getTel());
       }
       if (user.getSex() != null) {
           values.put(COLUMN_NAME_SEX, user.getSex());
       }
       if (user.getAvatar() != null) {
           values.put(COLUMN_NAME_AVATAR, user.getAvatar());
       }
       if (user.getSign() != null) {
           values.put(COLUMN_NAME_SIGN, user.getSign());
       }
       if (user.getFxid() != null) {
           values.put(COLUMN_NAME_FXID, user.getFxid());
       }
       if (user.getRegion()!= null) {
           values.put(COLUMN_NAME_REGION, user.getRegion());
       }
	if(db.isOpen()){
		db.replace(TABLE_NAME, null, values);
	}
}
 
Example 7
Source Project: school_shop   File: UserDao.java    License: MIT License 5 votes vote down vote up
/**
 * 保存一个联系人
 * @param user
 */
public void saveContact(User user){
	SQLiteDatabase db = dbHelper.getWritableDatabase();
	ContentValues values = new ContentValues();
	values.put(COLUMN_NAME_ID, user.getUsername());
	if(user.getNick() != null)
		values.put(COLUMN_NAME_NICK, user.getNick());
	if(user.getAvatar() != null)
	    values.put(COLUMN_NAME_AVATAR, user.getAvatar());
	if(db.isOpen()){
		db.replace(TABLE_NAME, null, values);
	}
}
 
Example 8
Source Project: BaseProject   File: BaseDao.java    License: Apache License 2.0 5 votes vote down vote up
public boolean replace(SQLiteDatabase database, List<T> ts) {
    try {
        for (T t : ts) {
            database.replace(getTableName(), null, getContentValues(t));
        }
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
        return false;
    }
}
 
Example 9
Source Project: DoraemonKit   File: BaseDao.java    License: Apache License 2.0 5 votes vote down vote up
public boolean replace(SQLiteDatabase database, List<T> ts) {
    try {
        for (T t : ts) {
            database.replace(getTableName(), null, getContentValues(t));
        }
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
        return false;
    }
}
 
Example 10
/**
 * 保存好友list
 * 
 * @param contactList
 */
public void saveContactList(List<User> contactList) {
	SQLiteDatabase db = dbHelper.getWritableDatabase();
	if (db.isOpen()) {
		db.delete(TABLE_NAME, null, null);
		for (User user : contactList) {
			ContentValues values = new ContentValues();
			values.put(COLUMN_NAME_ID, user.getUsername());
			if (user.getNick() != null) {
                   values.put(COLUMN_NAME_NICK, user.getNick());
               }
               if (user.getBeizhu() != null) {
                   values.put(COLUMN_NAME_BEIZHU, user.getBeizhu());
               }
               if (user.getTel() != null) {
                   values.put(COLUMN_NAME_TEL, user.getTel());
               }
               if (user.getSex() != null) {
                   values.put(COLUMN_NAME_SEX, user.getSex());
               }
               if (user.getAvatar() != null) {
                   values.put(COLUMN_NAME_AVATAR, user.getAvatar());
               }
               if (user.getSign() != null) {
                   values.put(COLUMN_NAME_SIGN, user.getSign());
               }
               if (user.getFxid() != null) {
                   values.put(COLUMN_NAME_FXID, user.getFxid());
               }
               if (user.getRegion()!= null) {
                   values.put(COLUMN_NAME_REGION, user.getRegion());
               }
			db.replace(TABLE_NAME, null, values);
		}
	}
}
 
Example 11
public static void add(SQLiteDatabase db, AtUserBean atUserBean, String accountId) {
    Gson gson = new Gson();
    ContentValues cv = new ContentValues();
    cv.put(AtUsersTable.USERID, atUserBean.getUid());
    cv.put(AtUsersTable.ACCOUNTID, accountId);
    String json = gson.toJson(atUserBean);
    cv.put(AtUsersTable.JSONDATA, json);
    db.replace(AtUsersTable.TABLE_NAME, AtUsersTable.ID, cv);

    reduce(accountId);
}
 
Example 12
public void updateFilename(@NonNull String url, @NonNull String filename) {
    final SQLiteDatabase db = getWritableDatabase();
    ContentValues values = new ContentValues(2);
    values.put(URL, url);
    values.put(FILENAME, filename);

    Cursor c = null;
    synchronized (url.intern()) {
        try {
            final String query = "SELECT " + FILENAME + " FROM " + RESPONSE_FILENAME_TABLE_NAME
                    + " WHERE " + URL + " = ?";
            c = db.rawQuery(query, new String[]{url});
            if (c.moveToFirst()) {
                // exist
                if (!filename.equals(c.getString(c.getColumnIndex(FILENAME)))) {
                    // replace if not equal
                    db.replace(RESPONSE_FILENAME_TABLE_NAME, null, values);
                }
            } else {
                // insert
                db.insert(RESPONSE_FILENAME_TABLE_NAME, null, values);
            }
        } finally {
            if (c != null) c.close();
        }
    }
}
 
Example 13
public synchronized boolean writeContentValues(ContentValues values) {
    if (values == null) {
        return false;
    }

    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    Log.d("ThreeThingsDatabase", "writeContentValues: writing: " + values.toString());
    return db.replace(ThreeThingsEntry.TABLE_NAME, null, values) != -1;
}
 
Example 14
public void addColour(Colour colour) {
    SQLiteDatabase database = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COL_PICKER_COLOUR, colour.getColour());
    values.put(COL_PICKER_DATE_AND_TIME, colour.getDateAndTime());
    database.replace(PICKER_COLOUR_TABLE, null, values);
}
 
Example 15
Source Project: YiBo   File: SocialGraphDao.java    License: Apache License 2.0 5 votes vote down vote up
void save(SQLiteDatabase sqLiteDatabase, User userA, User userB, Relation relation, ServiceProvider sp) {
	ContentValues values = new ContentValues();
	values.put("User_A_ID", userA.getUserId());
	values.put("User_B_ID", userB.getUserId());
	values.put("Service_Provider", sp.getSpNo());
	values.put("Relationship", relation.getType());
	sqLiteDatabase.replace(TABLE, null, values);
}
 
Example 16
Source Project: okhttp-OkGo   File: BaseDao.java    License: Apache License 2.0 5 votes vote down vote up
public boolean replace(SQLiteDatabase database, List<T> ts) {
    try {
        for (T t : ts) {
            database.replace(getTableName(), null, getContentValues(t));
        }
        return true;
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
        return false;
    }
}
 
Example 17
Source Project: Memento   File: Controller.java    License: MIT License 5 votes vote down vote up
/**
 * Reads data from json array
 * @param json an array of json objects
 * @throws Exception
 */
public void readBackup(JSONArray json) throws Exception {
	SQLiteDatabase db = helper.getReadableDatabase();

	try {
		int length = json.length();
		for (int i = 0; i < length; i++) {
			JSONObject item = json.getJSONObject(i);

			ContentValues values = new ContentValues();
			values.put(OpenHelper.COLUMN_ID, item.getLong(OpenHelper.COLUMN_ID));
			values.put(OpenHelper.COLUMN_TITLE, item.getString(OpenHelper.COLUMN_TITLE));
			values.put(OpenHelper.COLUMN_BODY, item.getString(OpenHelper.COLUMN_BODY));
			values.put(OpenHelper.COLUMN_TYPE, item.getInt(OpenHelper.COLUMN_TYPE));
			values.put(OpenHelper.COLUMN_DATE, item.getString(OpenHelper.COLUMN_DATE));
			values.put(OpenHelper.COLUMN_ARCHIVED, item.getInt(OpenHelper.COLUMN_ARCHIVED));
			values.put(OpenHelper.COLUMN_THEME, item.getInt(OpenHelper.COLUMN_THEME));
			values.put(OpenHelper.COLUMN_COUNTER, item.getInt(OpenHelper.COLUMN_COUNTER));
			values.put(OpenHelper.COLUMN_PARENT_ID, item.getLong(OpenHelper.COLUMN_PARENT_ID));
			values.put(OpenHelper.COLUMN_EXTRA, item.getString(OpenHelper.COLUMN_EXTRA));

			db.replace(
				OpenHelper.TABLE_NOTES,
				null,
				values
			);
		}
	} finally {
		db.close();
	}
}
 
Example 18
Source Project: DoraemonKit   File: BaseDao.java    License: Apache License 2.0 4 votes vote down vote up
public long replace(SQLiteDatabase database, ContentValues contentValues) {
    return database.replace(getTableName(), null, contentValues);
}
 
Example 19
Source Project: DoraemonKit   File: BaseDao.java    License: Apache License 2.0 4 votes vote down vote up
public long replace(SQLiteDatabase database, ContentValues contentValues) {
    return database.replace(getTableName(), null, contentValues);
}
 
Example 20
Source Project: YiBo   File: TaskDao.java    License: Apache License 2.0 4 votes vote down vote up
public Task saveRecentContact(Task task) {
	if (task == null) {
		return null;
	}
	
	SQLiteDatabase sqLiteDatabase = dbHelper.getWritableDatabase();
	sqLiteDatabase.beginTransaction();
	try {
		ContentValues values = new ContentValues();
		//values.put("Task_ID", task.getTaskId());
		values.put("Type", task.getType());
		values.put("Content", task.getContent());
		values.put("Result_ID", task.getResultId());
		if (task.getCreatedAt() == null) {
			task.setCreatedAt(new Date());
		}
		values.put("Created_At", task.getCreatedAt().getTime());
		if (task.getFinishedAt() != null) {
		    values.put("Finished_At", task.getFinishedAt().getTime());
		}
		values.put("State", task.getState());
		values.put("Service_Provider", task.getServiceProvider().getSpNo());
		values.put("Account_ID", task.getAccountId());
		
		int rowsAffected = sqLiteDatabase.update(
			TABLE, values, 
			"Type = " + task.getType() + " and Account_ID = " + task.getAccountId() 
			+ " and Result_ID = '" + task.getResultId() + "'", 
			null);
		if (rowsAffected <= 0) {
			values.put("Task_ID", task.getTaskId());
			long rowId = sqLiteDatabase.replace(TABLE, null, values);
			task.setTaskId(rowId);
		}
		
		sqLiteDatabase.setTransactionSuccessful();
	} finally {
		sqLiteDatabase.endTransaction();
	}
	
	return task;
}