Android:replaceOrThrow()可以用于在SQLite数据库中插入新行吗
是否可以使用Android:replaceOrThrow()可以用于在SQLite数据库中插入新行吗,android,Android,是否可以使用replacetorthrow()将新行插入Android SQLite数据库?否,但有一种insertOrThrow方法- 它使用以下参数: public long insertOrThrow (String table, String nullColumnHack, ContentValues values) 下面的代码对我来说很好,skd26。在大多数数据库中,replace的功能应该与insert类似 if (comicBook == null) { retur
replacetorthrow()
将新行插入Android SQLite数据库?否,但有一种insertOrThrow
方法-
它使用以下参数:
public long insertOrThrow (String table, String nullColumnHack, ContentValues values)
下面的代码对我来说很好,skd26。在大多数数据库中,replace的功能应该与insert类似
if (comicBook == null) {
return false;
}
long id = -1;
try {
id = mDatabase.replaceOrThrow(TABLE_NAME, null, generateContentValuesFromObject(comicBook));
} catch (SQLException e) {
Log.e("ComicBookFav", e.getMessage());
}
return id != -1;
是的,它会插入一个新行,但前提是该行不存在 见: 如果行不存在,则插入新行 实际上,它首先尝试插入提供的值,如果发生冲突,它会进行替换。正如您在其调用中所看到的那样,
insertWithOnConflict