Using @Upsert annotation of room2/room3 and SQLCipherDriver leads to UNIQUE constraint failed exception
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 32/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- databases, mobile, mobile-dev
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 277
- Fork
- 39
- Merge medio
- 1g 11h
- PR unite (30g)
- 1
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sqlcipher/sqlcipher-android
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
sqlcipher/sqlcipher-android#97 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 32/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
sqlcipher/sqlcipher-android#23 · 2 commenti ·
Tutte le issue di sqlcipher/sqlcipher-android
Issue simili
-
enhancement good first issue
Difficoltà 2/5 Mezza giornata Idoneità per principianti 66/100
apache/fineract-consumer-facing#175 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] 订单:会员凭订单号即可取消其他会员的待付款订单(取消接口不校验订单归属)Forse già presa @dadiyang l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
macrozheng/mall#1016 ·
-
[Bug] The producer summary counts an unreported client version as a second version and warns about a version mixForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
apache/rocketmq-dashboard#6110 ·
I maintainer di solito rispondono entro 4 giorni
-
Feature:Resolution
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
intellij-elixir/intellij-elixir#4396 ·
I maintainer di solito rispondono entro 1 giorno
-
Python 3.15 supportForse già presa @amnesiaof l’ha presa oggi. ApertaL: python L: python:uv
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
dependabot/dependabot-core#16524 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno