Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:replaceOrThrow()可以用于在SQLite数据库中插入新行吗_Android - Fatal编程技术网

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