我想知道如何在Android中的SQLite表中插入一个空值.
这是表:
"create table my table (_id integer primary key autoincrement, " +
"deviceAddress text not null unique, " +
"lookUpKey text , " +
"deviceName text , " +
"contactName text , " +
"playerName text , " +
"playerPhoto blob " +
");";
Run Code Online (Sandbox Code Playgroud)
我想使用一个简单的插入命令,execSQL但因为其中一个值是blob我不能这样做(我认为).
所以,我正在使用标准db.Insert命令.如何使其中一个值为null?
如果我只是在ContentValues对象中跳过它会自动在列中放置一个空值吗?
小智 30
是的,您可以跳过ContentValues中的字段,db.insert会将其设置为NULL.你也可以用另一种方式:
ContentValues cv = new ContentValues();
cv.putNull("column1");
db.insert("table1", null, cv);
Run Code Online (Sandbox Code Playgroud)
这个directrly将"column1"设置为NULL.您也可以在update语句中使用这种方式.
| 归档时间: |
|
| 查看次数: |
47205 次 |
| 最近记录: |