StatementColumnConvertible

The StatementColumnConvertible protocol grants access to the low-level C interface that extracts values from query results: https://www.sqlite.org/c3ref/column_blob.html. It can bring performance improvements.

To use it, have a value type adopt both StatementColumnConvertible and DatabaseValueConvertible. GRDB will then automatically apply the optimization whenever direct access to SQLite is possible:

let rows = Row.fetchCursor(db, sql: "SELECT ...")
while let row = try rows.next() {
    let int: Int = row[0]                 // there
}
let ints = Int.fetchAll(db, sql: "SELECT ...") // there
struct Player {
    init(row: Row) {
        name = row["name"]                // there
        score = row["score"]              // there
    }
}
  • fromStatement(_:atUncheckedIndex:) Default implementation

    Creates a value from a raw SQLite statement pointer, if possible.

    This method can be called with a NULL database value.

    Warning

    Do not customize the default implementation.

    Default Implementation

    Default implementation fails on decoding NULL.

  • init(sqliteStatement:index:) Default implementation

    Creates a value from a raw SQLite statement pointer, if possible.

    For example, here is the how Int64 adopts StatementColumnConvertible:

    extension Int64: StatementColumnConvertible {
        init?(sqliteStatement: SQLiteStatement, index: CInt) {
            self = sqlite3_column_int64(sqliteStatement, index)
        }
    }
    

    See https://www.sqlite.org/c3ref/column_blob.html for more information.

    Precondition

    This initializer must not be called with NULL database values.

    Default Implementation