在sqlite上使用更新

时间:2017-02-06 14:17:00

标签: android sqlite android-sqlite

M数据库结构如下所示 我的表名为others,而列为sleep,water and smoke

顺便说一句,这是我在mainactivity中添加的睡眠功能

final Integer newSleep = sleep; // this is the number picker
repo repo = new repo(MainActivity.this);
others sleep = new others();

sleep.sleep = others_id;
sleep.sleep=newSleep;

repo.updateSleep(sleep);

这是我的回购

public int updateSleep(others sleep) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_sleep, sleep.sleep);
    values.put(KEY_water, sleep.water);
    values.put(KEY_smoke, sleep.smoke);

    return db.update(others.TABLE, values, KEY_ID + " = ?",
        new String[]{String.valueOf(sleep.others_id)});
}

PS:我只包含添加睡眠功能,以便我能够轻松理解它。

0 个答案:

没有答案