Statement

public final class Statement
extension Statement: _RowLayout
extension Statement: CustomStringConvertible

A statement represents an SQL query.

Arguments

  • 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 }

Select Statements

  • 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?

Update Statements

  • 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.