Skip to content

sqlite3_prepare errors are fatal #187

@zmeyc

Description

@zmeyc

In Statement's constructor try! statement makes impossible handling schema mismatch errors gracefully:

public final class Statement {
    init(_ connection: Connection, _ SQL: String) {
        self.connection = connection
        try! check(sqlite3_prepare_v2(connection.handle, SQL, -1, &handle, nil))
    }

This leads to crashes in some unexpected places such as:

do {
        let sql = table
            .filter(keyColumn == value)
            .update(setters)
        let rowsUpdated = try db.run(sql) // crash
} catch {
}

I propose considering making Statement's constructor throwable and replacing try! with try. This will lead to API changes in other places (pluck and some other functions will become throw-able), but will allow recovering from errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions