Skip to content

Crash when lastInsertRowId is negative #438

@zmeyc

Description

@zmeyc

Consider, for example, the following statement:

Insert(template: "INSERT INTO \"sessions\" (\"owner_id\", \"started\", \"victim_name\", \"topic\", \"line\", \"chat_id\") VALUES (?, ?, ?, ?, ?, ?)", bindings: [Optional(230594948), Optional(1), Optional(""), Optional(""), Optional(0), Optional(-147636081)])

chat_id is INTEGER PRIMARY KEY and negative value is inserted.

sqlite3_last_insert_rowid() returns -147636081 (as expected)

Lib's lastInsertRowId turns it into nil:

    public var lastInsertRowid: Int64? {
        let rowid = sqlite3_last_insert_rowid(handle)
        return rowid > 0 ? rowid : nil
    }

The app crashes because Connection.run() dereferences nil.

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