android - sqlite insertWithOnConflict 的返回值?

标签 android sqlite

我试图了解 SQLiteDatabase.insertWithOnConflict 的返回值。

我的代码是这样的:

long result = db.insertWithOnConflict(
                MyTable.TABLE_NAME,
                null,
                initialValues,
                SQLiteDatabase.CONFLICT_IGNORE);

insertWithOnConflict 的文档说:

Returns: the row ID of the newly inserted row OR the primary key of the existing row if the input param 'conflictAlgorithm' = CONFLICT_IGNORE OR -1 if any error

如果MyTable的主键是TEXT类型怎么办?当插入冲突发生时,如何将现有行的主键,即一个TEXT值,返回给一个long变量?

谢谢。

最佳答案

What if the primary key of MyTable is a TEXT type? When insert conflict happens, how can it return the primary key of the existing row, which is a TEXT value, to a long variable?

他们所说的主键是指 rowid .

如果您的主键是整数主键,那么它将作为 rowid 的别名。

关于android - sqlite insertWithOnConflict 的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34033004/

相关文章:

android - 如何在服务中使用 Universal-Image-Loader?

android - 无法从 admob 加载奖励视频

ios - 从扩展程序写入存储在 App Group 容器中的数据库

c++ - 另一个包含 sqlite header 的 DLL 文件?

android - 如何绘制具有低位图内存影响的平铺游戏板

android - 将工作 Web 应用程序塑造为 Android 原生 Ionic 应用程序时出现 CORS 问题

android - 使用 Espresso 进行测试

Android - Spinner 的数据消失了

Android:随着时间的推移将数据库加载到内存与查询

java - 在 Android 中查询数据库时出现错误