irobotxx
irobotxx

Reputation: 6063

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 the database. Thank you.

Upvotes: 0

Views: 75

Answers (1)

smith324
smith324

Reputation: 13060

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

Upvotes: 1

Related Questions