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

The following are Jave code examples for showing how to use replace() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: KTalk   File: ContactTableDao.java   View Source Code Vote up 7 votes
public void saveContact(UserInfo user, boolean isMyContact) {

        if (user == null) {
            return;
        }

        // 获取数据库链接
        SQLiteDatabase db = mHelper.getReadableDatabase();

        // 执行保存语句
        ContentValues values = new ContentValues();
        values.put(ContactTable.COL_HXID, user.getHxid());
        values.put(ContactTable.COL_NAME, user.getName());
        values.put(ContactTable.COL_NICK, user.getNick());
        values.put(ContactTable.COL_PHOTO, user.getPhoto());
        values.put(ContactTable.COL_IS_CONTACT, isMyContact ? 1 : 0);

        db.replace(ContactTable.TAB_NAME, null, values);
    }
 
Example 2
Project: okdownload   File: BreakpointSQLiteHelper.java   View Source Code Vote up 6 votes
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;
    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 3
Project: SOS-The-Healthcare-Companion   File: DatabaseHelper.java   View Source Code Vote up 6 votes
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_DOSAGE, reminder.getDosage());
    values.put(COL_QUANTITY, reminder.getQuantity());
    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 4
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 6 votes
/**
 * Save Robot list
 */
synchronized public void saveRobotList(List<RobotUser> robotList) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    if (db.isOpen()) {
        db.delete(UserDao.ROBOT_TABLE_NAME, null, null);
        for (RobotUser item : robotList) {
            ContentValues values = new ContentValues();
            values.put(UserDao.ROBOT_COLUMN_NAME_ID, item.getUsername());
            if (item.getNick() != null)
                values.put(UserDao.ROBOT_COLUMN_NAME_NICK, item.getNick());
            if (item.getAvatar() != null)
                values.put(UserDao.ROBOT_COLUMN_NAME_AVATAR, item.getAvatar());
            db.replace(UserDao.ROBOT_TABLE_NAME, null, values);
        }
    }
}
 
Example 5
Project: KTalk   File: InviteTableDao.java   View Source Code Vote up 6 votes
public void addInvitation(InvationInfo invationInfo){
    //获取数据库连接
    SQLiteDatabase db = mHelper.getReadableDatabase();

    //执行添加语句
    ContentValues values = new ContentValues();
    values.put(InviteTable.COL_REASON, invationInfo.getReason());//原因
    values.put(InviteTable.COL_STATUS, invationInfo.getStatus().ordinal());//状态

    UserInfo user = invationInfo.getUser();

    if (user != null){//联系人
        values.put(InviteTable.COL_USER_HXID, invationInfo.getUser().getHxid());
        values.put(InviteTable.COL_USER_NAME, invationInfo.getUser().getName());
    }else{
        values.put(InviteTable.COL_GROUP_HXID,invationInfo.getGroup().getGroupId());
        values.put(InviteTable.COL_GROUP_NAME,invationInfo.getGroup().getGroupName());
        values.put(InviteTable.COL_USER_HXID,invationInfo.getGroup().getInvatePerson());
    }

    db.replace(InviteTable.TAB_NAME,null,values);
}
 
Example 6
Project: simple-upnp   File: BookmarksWriteTask.java   View Source Code Vote up 6 votes
@Override
protected Boolean doInBackground(String... params) {
    if (params.length < 4) {
        return false;
    }

    String udn = params[0];
    String containerName = params[1];
    mContainerId = params[2];
    String deviceName = params[3];

    ContentValues values = new ContentValues();
    values.put(BookmarksEntry.COLUMN_NAME_UDN, udn);
    values.put(BookmarksEntry.COLUMN_NAME_CONTAINER_NAME, containerName);
    values.put(BookmarksEntry.COLUMN_NAME_CONTAINER_ID, mContainerId);
    values.put(BookmarksEntry.COLUMN_NAME_DEVICE_NAME, deviceName);

    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    Log.d(TAG, "doInBackground: writing values " + values.toString() + " to " + BookmarksEntry.TABLE_NAME);
    return db.replace(BookmarksEntry.TABLE_NAME, null, values) != -1;
}
 
Example 7
Project: Cable-Android   File: IdentityDatabase.java   View Source Code Vote up 6 votes
public void saveIdentity(long recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus,
                         boolean firstUse, long timestamp, boolean nonBlockingApproval)
{
  SQLiteDatabase database          = databaseHelper.getWritableDatabase();
  String         identityKeyString = Base64.encodeBytes(identityKey.serialize());

  ContentValues contentValues = new ContentValues();
  contentValues.put(RECIPIENT, recipientId);
  contentValues.put(IDENTITY_KEY, identityKeyString);
  contentValues.put(TIMESTAMP, timestamp);
  contentValues.put(VERIFIED, verifiedStatus.toInt());
  contentValues.put(NONBLOCKING_APPROVAL, nonBlockingApproval ? 1 : 0);
  contentValues.put(FIRST_USE, firstUse ? 1 : 0);

  database.replace(TABLE_NAME, null, contentValues);

  EventBus.getDefault().post(new IdentityRecord(recipientId, identityKey, verifiedStatus,
                                                firstUse, timestamp, nonBlockingApproval));
}
 
Example 8
Project: GitHub   File: BaseDao.java   View Source Code Vote up 5 votes
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
Project: PeSanKita-android   File: TextSecureDirectory.java   View Source Code Vote up 5 votes
public void setNumber(ContactTokenDetails token, boolean active) {
  SQLiteDatabase db     = databaseHelper.getWritableDatabase();
  ContentValues  values = new ContentValues();
  values.put(NUMBER, token.getNumber());
  values.put(REGISTERED, active ? 1 : 0);
  values.put(TIMESTAMP, System.currentTimeMillis());
  values.put(RELAY, token.getRelay());
  values.put(VOICE, token.isVoice());
  values.put(VIDEO, token.isVideo());
  db.replace(TABLE_NAME, null, values);
}
 
Example 10
Project: PeSanKita-android   File: IdentityDatabase.java   View Source Code Vote up 5 votes
public void saveIdentity(long recipientId, IdentityKey identityKey)
{
  SQLiteDatabase database          = databaseHelper.getWritableDatabase();
  String         identityKeyString = Base64.encodeBytes(identityKey.serialize());

  ContentValues contentValues = new ContentValues();
  contentValues.put(RECIPIENT, recipientId);
  contentValues.put(IDENTITY_KEY, identityKeyString);

  database.replace(TABLE_NAME, null, contentValues);

  context.getContentResolver().notifyChange(CHANGE_URI, null);
}
 
Example 11
Project: SOS-The-Healthcare-Companion   File: DatabaseHelper.java   View Source Code Vote up 5 votes
public void addDaysOfWeek(Reminder reminder) {
    SQLiteDatabase database = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COL_ID, reminder.getId());
    values.put(COL_SUNDAY, Boolean.toString(reminder.getDaysOfWeek()[0]));
    values.put(COL_MONDAY, Boolean.toString(reminder.getDaysOfWeek()[1]));
    values.put(COL_TUESDAY, Boolean.toString(reminder.getDaysOfWeek()[2]));
    values.put(COL_WEDNESDAY, Boolean.toString(reminder.getDaysOfWeek()[3]));
    values.put(COL_THURSDAY, Boolean.toString(reminder.getDaysOfWeek()[4]));
    values.put(COL_FRIDAY, Boolean.toString(reminder.getDaysOfWeek()[5]));
    values.put(COL_SATURDAY, Boolean.toString(reminder.getDaysOfWeek()[6]));
    database.replace(DAYS_OF_WEEK_TABLE, null, values);
}
 
Example 12
Project: SOS-The-Healthcare-Companion   File: DatabaseHelper.java   View Source Code Vote up 5 votes
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 13
Project: KTalk   File: UserAccountDao.java   View Source Code Vote up 5 votes
public void addAccount (UserInfo user){
    //获取数据库对象
    SQLiteDatabase db = mHelper.getReadableDatabase();

    //执行添加操作
    ContentValues values = new ContentValues();
    values.put(UserAccountTable.COL_HXID,user.getHxid());
    values.put(UserAccountTable.COL_NAME,user.getName());
    values.put(UserAccountTable.COL_NICK,user.getNick());
    values.put(UserAccountTable.COL_PHOTO,user.getPhoto());

    db.replace(UserAccountTable.TAB_NAME,null,values);
}
 
Example 14
Project: Hubs   File: PreferenceManager.java   View Source Code Vote up 5 votes
@Override
public void updateHubPreferences(@NonNull HubPreference... preferences) {
    final SQLiteDatabase db = mDBHelper.getWritableDatabase();

    for (HubPreference preference : preferences) {
        final ContentValues values = new ContentValues();
        values.put("hub_id", preference.getHubId());
        values.put("is_visible", preference.isVisible() ? 1 : 0);
        values.put("_order", preference.getOrder());
        db.replace(PreferenceDBHelper.TABLE_NAME, "hub_id", values);
    }

    db.close();
}
 
Example 15
Project: boohee_v5.6   File: b.java   View Source Code Vote up 5 votes
public long a(String str, ContentValues contentValues) {
    long j = -1;
    if (this.a == null) {
        c.a("create db fail, lost permission--->android.permission.WRITE_EXTERNAL_STORAGE");
    } else {
        try {
            SQLiteDatabase writableDatabase = this.a.getWritableDatabase();
            c.b("insert database, insert");
            j = writableDatabase.replace(str, null, contentValues);
        } catch (Exception e) {
            c.a("when insert database occur error table:" + str + e.getMessage());
        }
    }
    return j;
}
 
Example 16
Project: GitHub   File: BaseDao.java   View Source Code Vote up 4 votes
public long replace(SQLiteDatabase database, T t) {
    return database.replace(getTableName(), null, getContentValues(t));
}
 
Example 17
Project: GitHub   File: BaseDao.java   View Source Code Vote up 4 votes
public long replace(SQLiteDatabase database, ContentValues contentValues) {
    return database.replace(getTableName(), null, contentValues);
}
 
Example 18
Project: AndroidTvDemo   File: RecentMediaStorage.java   View Source Code Vote up 4 votes
public void save(ContentValues contentValue)
{
    OpenHelper openHelper = new OpenHelper(mAppContext);
    SQLiteDatabase db = openHelper.getWritableDatabase();
    db.replace(Entry.TABLE_NAME, null, contentValue);
}
 
Example 19
Project: minVideo   File: RecentMediaStorage.java   View Source Code Vote up 4 votes
public void save(ContentValues contentValue) {
    OpenHelper openHelper = new OpenHelper(mAppContext);
    SQLiteDatabase db = openHelper.getWritableDatabase();
    db.replace(Entry.TABLE_NAME, null, contentValue);
}
 
Example 20
Project: GCSApp   File: DemoDBManager.java   View Source Code Vote up 4 votes
/**
 * save a contact
 *
 * @param user
 */
synchronized public void saveContact(EaseUser user) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(UserDao.COLUMN_NAME_ID, user.getUsername());
    if (user.getNick() != null) {
        values.put(UserDao.COLUMN_NAME_NICK, user.getNewnickName());

    } else {
        values.put(UserDao.COLUMN_NAME_NICK, "");

    }
    if (user.getNewnickName() != null) {
        values.put(UserDao.ROBOT_COLUMN_NAME_NICKNAME, user.getNewnickName());
    } else {
        values.put(UserDao.ROBOT_COLUMN_NAME_NICKNAME, "");
    }

    if (user.getAvatar() != null) {
        values.put(UserDao.COLUMN_NAME_AVATAR, user.getAvatar());
    } else {
        values.put(UserDao.COLUMN_NAME_AVATAR, "");

    }
    if (user.getPhone() != null) {
        values.put(UserDao.COLUMN_NAME_PHONE, user.getPhone());
    } else {
        values.put(UserDao.COLUMN_NAME_PHONE, "");

    }
    if (user.getPosition() != null) {
        values.put(UserDao.ROBOT_COLUMN_NAME_POSITION, user.getPosition());
    } else {
        values.put(UserDao.ROBOT_COLUMN_NAME_POSITION, "");

    }
    if (user.getCompany() != null) {
        values.put(UserDao.ROBOT_COLUMN_NAME_COMPANY, user.getCompany());
    } else {
        values.put(UserDao.ROBOT_COLUMN_NAME_COMPANY, "");

    }
    values.put(UserDao.COLUMN_NAME_MEMBER_ID, user.getMemberId());
    if (db.isOpen()) {
        db.replace(UserDao.TABLE_NAME, null, values);
    }
}