Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Using @Upsert annotation of room2/room3 and SQLCipherDriver leads to UNIQUE constraint failed exception

Ouverte
#95 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
32/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
android, java, sqlite

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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:

  1. try a plain INSERT (conflict strategy ABORT),
  2. catch the constraint exception, check it's a uniqueness violation,
  3. 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.

Langage dominant
Java
Étoiles
277
Forks
39
Merge moyen
1 j 11 h
PR mergées (30 j)
1

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de sqlcipher/sqlcipher-android

Toutes les issues de sqlcipher/sqlcipher-android

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.