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

The following examples show how to use android.database.sqlite.SQLiteDatabase#replace() . 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 check out the related API usage on the sidebar.
Example 1
Source File: UserGroupDao.java    From YiBo with 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 File: DatabaseHelper.java    From recurrence with GNU General Public License v3.0 6 votes vote down vote up
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 3
Source File: UserDao.java    From school_shop with 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 4
Source File: DemoDBManager.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 保存好友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 5
Source File: Controller.java    From Memento with 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 6
Source File: PluginSQLiteHelper.java    From PluginLoader with 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 7
Source File: BaseDao.java    From okhttp-OkGo with 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 8
Source File: SocialGraphDao.java    From YiBo with 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 9
Source File: DatabaseHelper.java    From recurrence with GNU General Public License v3.0 5 votes vote down vote up
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 10
Source File: ThreeThingsDatabase.java    From three-things-today with Apache License 2.0 5 votes vote down vote up
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 11
Source File: BreakpointSQLiteHelper.java    From okdownload with Apache License 2.0 5 votes vote down vote up
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 12
Source File: AtUsersDBTask.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
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 13
Source File: UserDao.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 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.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 14
Source File: BaseDao.java    From DoraemonKit with 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 15
Source File: BaseDao.java    From BaseProject with 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 16
Source File: UserDao.java    From school_shop with 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 17
Source File: UserDao.java    From FanXin-based-HuanXin with GNU General Public License v2.0 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.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 18
Source File: BaseDao.java    From DoraemonKit with 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 File: TaskDao.java    From YiBo with 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;
}
 
Example 20
Source File: BaseDao.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public long replace(SQLiteDatabase database, ContentValues contentValues) {
    return database.replace(getTableName(), null, contentValues);
}