Missing input validation on participant registration causes SQLite constraint crash #2

Open
opened 2026-10-20 19:33:44 +00:00 by gemini · 0 comments
Collaborator

Description

In NewParticipantScreen.kt, the "Register Participant" button invokes onRegister without validating that mandatory fields have been completed:

onRegister = { form ->
    val id = participantRepo.insert(
        dob                = form.dob,
        gender             = form.gender,
        recordId           = recordId.toInt(),
        denominationId     = form.denominationId,
        educationalLevelId = form.educationalLevelId,
        cityName           = form.city,
        dialectName        = form.accent
    )
    if (id == -1L) { ... }
}

Issues Found:

  1. Gender Check Constraint Crash: The database schema defines:
    gender TEXT NOT NULL CHECK(gender IN ('Male','Female','Other'))
    
    If the user has not selected a gender yet, form.gender is "". SQLite throws SQLiteConstraintException: CHECK constraint failed, which is unhandled and crashes the application.
  2. Missing Selections: If religion/denomination or educational level are not selected, -1 is passed into foreign key columns.
  3. UI Inconsistency: The gender dropdown in NewParticipantScreen.kt only provides listOf("Male", "Female"), omitting "Other" which is allowed by the database constraint.
  4. Unchecked Empty Strings: city and accent can be submitted as blank strings.

Suggested Fix

  • Add validation in NewParticipantScreen to ensure dob, gender, denominationId, educationalLevelId, city, and accent are non-empty before enabling the button or submitting.
  • Include "Other" in the gender dropdown options.
  • Catch SQLiteException in ParticipantRepository to display a user-friendly error message rather than crashing.
### Description In `NewParticipantScreen.kt`, the "Register Participant" button invokes `onRegister` without validating that mandatory fields have been completed: ```kotlin onRegister = { form -> val id = participantRepo.insert( dob = form.dob, gender = form.gender, recordId = recordId.toInt(), denominationId = form.denominationId, educationalLevelId = form.educationalLevelId, cityName = form.city, dialectName = form.accent ) if (id == -1L) { ... } } ``` ### Issues Found: 1. **Gender Check Constraint Crash**: The database schema defines: ```sql gender TEXT NOT NULL CHECK(gender IN ('Male','Female','Other')) ``` If the user has not selected a gender yet, `form.gender` is `""`. SQLite throws `SQLiteConstraintException: CHECK constraint failed`, which is unhandled and crashes the application. 2. **Missing Selections**: If religion/denomination or educational level are not selected, `-1` is passed into foreign key columns. 3. **UI Inconsistency**: The gender dropdown in `NewParticipantScreen.kt` only provides `listOf("Male", "Female")`, omitting `"Other"` which is allowed by the database constraint. 4. **Unchecked Empty Strings**: `city` and `accent` can be submitted as blank strings. ### Suggested Fix - Add validation in `NewParticipantScreen` to ensure `dob`, `gender`, `denominationId`, `educationalLevelId`, `city`, and `accent` are non-empty before enabling the button or submitting. - Include `"Other"` in the gender dropdown options. - Catch `SQLiteException` in `ParticipantRepository` to display a user-friendly error message rather than crashing.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
charlie/Tanit#2
No description provided.