开发者

slight misunderstanding with sqlite database in android

i created a database with 6 columns and i have a create and update method in my class that takes 6 parameters/arguments which represent these columns. my problem is that, anytime i try to update or create the database without using all 6 arguments (setting some to null), i get an error "constraint failed". this is most particular with the update method.

any ideas how i can get around this? because sometimes i don't want to fill all columns. I have removed the "text not null" constraint when creating 开发者_JS百科the database. Thank you.


You're going to want to use the ContentValues to achieve this. Heres a quick demo.

My function

public boolean updateStuff(int id,ContentValues args) {
        return mDb.update(TableName, args, _id_col + "=" + id, null) > 0;
    }

And to call it. Note you can put as many ContentValues as you need

ContentValues initValues = new ContentValues();
initValues.put(col_key,col_value);

Edit: mDB is a SQLiteDatabase

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜