插入SQLite表空 [英] Insert null in Sqlite table
问题描述
我试图找出如何插入一个空值到Android中的SQLite表。
I am trying to figure how to insert a null value into an SQLite table in Android.
这是该表:
"create table my table (_id integer primary key autoincrement, " +
"deviceAddress text not null unique, " +
"lookUpKey text , " +
"deviceName text , " +
"contactName text , " +
"playerName text , " +
"playerPhoto blob " +
");";
我想通过execSQL使用一个简单的插入命令,但由于价值观之一是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).
所以,我使用的是标准的db.Insert命令。 如何让我的价值之一空?
So, I am using a standard db.Insert command. How do I make one of the values null?
如果我只是跳过它在ContentValues对象将自动把一个空值在列?
If I just skip it in the ContentValues object will it automatically put a null value in the column?
推荐答案
是的,你可以跳过场ContentValues和db.insert将其设置为NULL。 你也可以用其他的方式:
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.put("column1", null);
db.insert("table1", null, cv);
这directrly集列1NULL。你也可以用这样的方式在update语句。
this directrly sets "column1" NULL. Also you can use this way in update statement.
这篇关于插入SQLite表空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!