StatementColumnConvertible

public protocol 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
    }
}

StatementColumnConvertible is already adopted by all Swift integer types, Float, Double, String, and Bool.

  • Initializes a value from a raw SQLite statement pointer.

    For example, here is the how Int64 adopts StatementColumnConvertible:

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

    This initializer is never called for NULL database values: don’t perform any extra check.

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

    Declaration

    Swift

    init(sqliteStatement: SQLiteStatement, index: Int32)

    Parameters

    sqliteStatement

    A pointer to an SQLite statement.

    index

    The column index.