Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to figure how to insert a null value into an SQLite table in Android.

This is the table:

"create table my table (_id integer primary key autoincrement, " +
                                               "deviceAddress   text not null unique, " +
                                               "lookUpKey text , " + 
                                               "deviceName text , " +
                                               "contactName text , " +
                                               "playerName text , " +
                                               "playerPhoto blob " +
                                               ");";    

I wanted to use a simple Insert command via execSQL but since one of the values is a blob I can't do it (I think).

So, I am using a standard db.Insert command. How do I make one of the values null?

If I just skip it in the ContentValues object will it automatically put a null value in the column?

question from:https://stackoverflow.com/questions/9823514/insert-null-in-sqlite-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
97 views
Welcome To Ask or Share your Answers For Others

1 Answer

Yes, you can skip the field in ContentValues and db.insert will set it NULL. Also you can use the other way:

ContentValues cv = new ContentValues();
cv.putNull("column1");
db.insert("table1", null, cv);

this directrly sets "column1" NULL. Also you can use this way in update statement.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...