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 atidx
instmt
.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 orself
couldn’t be boundDeclaration
Swift
func bind(to stmt: SQLitePreparedStatement, parameter idx: Int32) throws
Parameters
stmt
An
sqlite3_stmt *
objectidx
The index of the SQL parameter to bind