Statement
public final class Statement
extension Statement: _RowLayout
extension Statement: CustomStringConvertible
A statement represents an SQL query.
-
The raw SQLite statement, suitable for the SQLite C API.
Declaration
Swift
public let sqliteStatement: SQLiteStatement
-
The SQL query
Declaration
Swift
public var sql: String { get }
-
The column names, ordered from left to right.
Declaration
Swift
public lazy var columnNames: [String] { get set }
-
The database region that the statement looks into.
Declaration
Swift
public internal(set) var databaseRegion: DatabaseRegion { get }
-
Returns true if and only if the prepared statement makes no direct changes to the content of the database file.
Declaration
Swift
public var isReadonly: Bool { get }
-
The statement arguments.
Declaration
Swift
public var arguments: StatementArguments { get set }
-
Throws a DatabaseError of code SQLITE_ERROR if arguments don’t fill all statement arguments.
For example:
let statement = try db.makeUpdateArgument(sql: """ INSERT INTO player (id, name) VALUES (?, ?) """) // OK statement.validateArguments([1, "Arthur"]) // Throws statement.validateArguments([1])
See also setArguments(_:)
Declaration
Swift
public func validateArguments(_ arguments: StatementArguments) throws
-
Set arguments without any validation. Trades safety for performance.
Only call this method if you are sure input arguments match all expected arguments of the statement.
For example:
let statement = try db.makeUpdateArgument(sql: """ INSERT INTO player (id, name) VALUES (?, ?) """) // OK statement.setUncheckedArguments([1, "Arthur"]) // OK let arguments: StatementArguments = ... // some untrusted arguments try statement.validateArguments(arguments) statement.setUncheckedArguments(arguments) // NOT OK statement.setUncheckedArguments([1])
Declaration
Swift
public func setUncheckedArguments(_ arguments: StatementArguments)
-
Set the statement arguments, or throws a DatabaseError of code SQLITE_ERROR if arguments don’t fill all statement arguments.
For example:
let statement = try db.makeUpdateArgument(sql: """ INSERT INTO player (id, name) VALUES (?, ?) """) // OK try statement.setArguments([1, "Arthur"]) // Throws an error try statement.setArguments([1])
Declaration
Swift
public func setArguments(_ arguments: StatementArguments) throws
-
Declaration
Swift
public var description: String { get }
-
The number of columns in the resulting rows.
Declaration
Swift
public var columnCount: Int { get }
-
Returns the index of the leftmost column named
name
, in a case-insensitive way.Declaration
Swift
public func index(ofColumn name: String) -> Int?
-
Executes the prepared statement.
Throws
A DatabaseError whenever an SQLite error occurs.Declaration
Swift
public func execute(arguments: StatementArguments? = nil) throws
Parameters
arguments
Optional statement arguments.