Using @Upsert annotation of room2/room3 and SQLCipherDriver leads to UNIQUE constraint failed exception
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 32/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 领域
- databases, mobile, mobile-dev
调研方向
Start from how SQLCipherDriver surfaces constraint failures versus SupportOpenHelperFactory/SupportSQLiteDriver. Room @Upsert expects androidx.sqlite.SQLiteException (and a uniqueness message) so it can fall back from INSERT to UPDATE; SQLCipher currently throws net.zetetic.database.sqlcipher.SQLiteConstraintException. Align exception type/message with Room’s catch (same class of issue as sqlcipher-android#23 and #84). Done when @Upsert succeeds with SQLCipherDriver on Room 2.x and 3 without UNIQUE constraint failed.
由索引模型根据 Issue 内容生成。
描述
Library version used: 4.19.1
Room version used: 2.8.5 & 3.0.3
I'm currently upgrading to room3 and during the Prepare and modernize in Room 2.x part of the Android documentation I'm running into an runtime error.
At the stage Set the SQLite driver I'm doing it like your documentation says and pass a SQLCipherDriver to the databaseBuilder.
Using the @Upsert annotation (both in room2 and room3) now leads to an UNIQUE constraint failed exception at runtime. This also happens after a complete upgrade to room3.
This does not happen when using the room2 way with SupportOpenHelperFactory.
This is what Claude analyzed:
Room implements @Upsert as:
- try a plain INSERT (conflict strategy ABORT),
- catch the constraint exception, check it's a uniqueness violation,
- fall back to UPDATE.
Step 2 is the fragile part: it is a catch on a specific exception type plus a string match on the message. Room's driver-based adapter catches androidx.sqlite.SQLiteException.
SupportOpenHelperFactory went through Room's SupportSQLiteDriver wrapper, where the error surfaced in a form Room's fallback recognised, so step 3 ran and you never saw the error. SQLCipherDriver hands Room SQLCipher's own
net.zetetic.database.sqlcipher.SQLiteConstraintException instead (the (code 1555); query: … message format is zetetic's native formatter). That type is not androidx.sqlite.SQLiteException, so the catch never fires, the UPDATE
fallback is skipped, and the raw insert failure propagates to you.This is the same class of bug as sqlcipher-android#23 (https://github.com/sqlcipher/sqlcipher-android/issues/23) (@Upsert + SQLCipher) and robolectric#8469 (https://github.com/robolectric/robolectric/issues/8469) — any driver
that wraps SQLite errors in its own exception hierarchy breaks Room's upsert fallback. sqlcipher-android#84 (https://github.com/sqlcipher/sqlcipher-android/issues/84) tracks the broader Room 3 / SQLiteDriver migration gap.
- 主要语言
- Java
- 星标
- 277
- 派生
- 39
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sqlcipher/sqlcipher-android 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
sqlcipher/sqlcipher-android#97 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 32/100
-
难度 4/5 3-5 天 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 30/100
sqlcipher/sqlcipher-android#23 · 2 条评论 ·
查看 sqlcipher/sqlcipher-android 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
utopia-rise/godot-jvm#1004 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
spring-projects/spring-grpc#442 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
resilience4j/resilience4j#2547 ·
维护者通常 9 天内回复
-
Clock.MakeDate continues execution and returns a rolled-over instant after dispatching error on invalid date可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1 小时以内 新手友好度 82/100
mit-cml/appinventor-sources#4155 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 62/100
Hira-shi/PW1-DAI-Carrel-Egal-Eyer#28 ·
维护者通常 1 天内回复