我想知道如何在Android中的SQLite表中插入一個空值。在Sqlite表中插入null
這是表:
"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我不能這樣做(我認爲)。
因此,我使用的是標準的db.Insert
命令。 如何使其中一個值爲空?
如果我只是在ContentValues
對象中跳過它,它會自動在列中放置一個空值嗎?
你不能發送null來放置方法,而是你必須使用putNull方法 – mSafdel 2012-12-26 13:28:51
其實答案是沒有錯的。當您檢查位於android.content包中的ContentValues.java的源代碼時,可以看到;該方法只是使用提供的null參數調用put方法。 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/content/ContentValues.java#ContentValues.putNull%28java.lang.String %29 – Fatih 2013-11-11 14:18:26
** public void putNull(String key){mValues.put(key,null); } ** ...我想putNull的實現可能會改變,所以它可能更好地使用它,而不是直接放置。儘管如此,這仍然是一個正確的答案。 – samosaris 2013-12-19 13:44:40