ParameterBindable

public protocol ParameterBindable

A type that can bind its value directly to a parameter in an SQLite statement.

The implementation should use one of the sqlite_bind_X() functions documented at Binding Values To Prepared Statements.

For example, the implementation for Int64 is:

extension Int64: ParameterBindable {
    public func bind(to stmt: SQLitePreparedStatement, parameter idx: Int32) throws {
        guard sqlite3_bind_int64(stmt, idx, self) == SQLITE_OK else {
            throw SQLiteError("Error binding Int64 \(self) to parameter \(idx)", takingDescriptionFromStatement: stmt)
        }
    }
}
  • Binds the value of self to the SQL parameter at idx in stmt.

    Note

    Parameter indexes are 1-based. The leftmost parameter in a statement has index 1.

    Requires

    index > 0

    Requires

    index < parameterCount

    Throws

    An error if idx is out of bounds or self couldn’t be bound

    Declaration

    Swift

    func bind(to stmt: SQLitePreparedStatement, parameter idx: Int32) throws

    Parameters

    stmt

    An sqlite3_stmt * object

    idx

    The index of the SQL parameter to bind