我试图了解 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/