<commit_before>/// SQL statements can have arguments:
///
///     INSERT INTO persons (name, age) VALUES (?, ?)
///     INSERT INTO persons (name, age) VALUES (:name, :age)
///
/// To fill question mark arguments, feed StatementArguments with an array:
///
///     db.execute("INSERT ... (?, ?)", arguments: StatementArguments(["Arthur", 41]))
///
/// Array literals are automatically converted to StatementArguments:
///
///     db.execute("INSERT ... (?, ?)", arguments: ["Arthur", 41])
///
/// To fill named arguments, feed StatementArguments with a dictionary:
///
///     db.execute("INSERT ... (:name, :age)", arguments: StatementArguments(["name": "Arthur", "age": 41]))
///
/// Dictionary literals are automatically converted to StatementArguments:
///
///     db.execute("INSERT ... (:name, :age)", arguments: ["name": "Arthur", "age": 41])
///
/// GRDB.swift only supports colon-prefixed named arguments, even though SQLite
/// supports other syntaxes. See https://www.sqlite.org/lang_expr.html#varparam
/// for more information.
public struct StatementArguments {
    
    // MARK: - Positional Arguments
    
    /// Initializes arguments from a sequence of optional values.
    ///
    ///     let values: [String?] = ["foo", "bar", nil]
    ///     db.execute("INSERT ... (?,?,?)", arguments: StatementArguments(values))
    ///
    /// - parameter sequence: A sequence of optional values that adopt the
    ///   DatabaseValueConvertible protocol.
    /// - returns: A StatementArguments.
    public init<Sequence: SequenceType where Sequence.Generator.Element == Optional<DatabaseValueConvertible>>(_ sequence: Sequence) {
        impl = StatementArgumentsArrayImpl(values: Array(sequence))
    }
    
    
    // MARK: - Named Arguments
    
    /// Initializes arguments from a dictionary of optional values.
    ///
    ///     let values: [String: String?] = ["firstName": nil, "lastName": "Miller"]
    ///     db.execute("INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values))
    ///
    /// GRDB.swift only supports colon-prefixed named arguments, even though
    /// SQLite supports other syntaxes. See https://www.sqlite.org/lang_expr.html#varparam
    /// for more information.
    ///
    /// - parameter dictionary: A dictionary of optional values that adopt the
    ///   DatabaseValueConvertible protocol.
    /// - returns: A StatementArguments.
    public init(_ dictionary: [String: DatabaseValueConvertible?]) {
        impl = StatementArgumentsDictionaryImpl(dictionary: dictionary)
    }
    
    
    // MARK: - Default Arguments
    
    /// Whenever you need to write a method with optional statement arguments,
    /// do not use nil as a sentinel. This is because StatementArguments has
    /// failable initializers, and you do not want such a failed initializer
    /// have your method behave as if no arguments was given.
    ///
    /// Instead, use a non-optional StatementArguments parameter type, and use
    /// StatementArguments.Default as its default value.
    ///
    /// Compare:
    ///
    ///     func bad(arguments: StatementArguments? = nil)
    ///     func good(arguments: StatementArguments = StatementArguments.Default)
    ///
    ///     let badDict: NSDictionary = ["foo": NSObject()] // can't be used as arguments
    ///     let arguments = StatementArguments(badDict)     // nil, actually
    ///
    ///     // Bad function swallows nil. Bad, bad function!
    ///     bad(arguments: arguments)
    ///
    ///     // Good function forces the user to handle the invalid input case:
    ///     good(arguments: arguments)  // won't compile
    ///     if let arguments = arguments {
    ///         good(arguments: arguments)
    ///     } else {
    ///         // handle wrong dictionary
    ///     }
    public static var Default = StatementArguments(impl: DefaultStatementArgumentsImpl())
    
    /// True if and only if the receiver is StatementArguments.Default.
    public var isDefault: Bool { return impl.isDefault }
    
    
    // MARK: - Not Public
    
    let impl: StatementArgumentsImpl
    
    init(impl: StatementArgumentsImpl) {
        self.impl = impl
    }
    
    // Supported usage: Statement.arguments property
    //
    //     let statement = db.UpdateStatement("INSERT INTO persons (name, age) VALUES (?,?)"
    //     statement.execute(arguments: ["Arthur", 41])
    func bindInStatement(statement: Statement) {
        impl.bindInStatement(statement)
    }
    
    
    // Mark: - StatementArguments.DefaultImpl
    
    private struct DefaultStatementArgumentsImpl : StatementArgumentsImpl {
        var isDefault: Bool { return true }
        
        func bindInStatement(statement: Statement) {
        }
        
        var description: String {
            return "StatementArguments.DefaultImpl"
        }
    }
    
    
    // MARK: - StatementArgumentsArrayImpl
    
    /// Support for positional arguments
    private struct StatementArgumentsArrayImpl : StatementArgumentsImpl {
        let values: [DatabaseValueConvertible?]
        var isDefault: Bool { return false }
        
        init(values: [DatabaseValueConvertible?]) {
            self.values = values
        }
        
        func bindInStatement(statement: Statement) {
            statement.validateArgumentCount(values.count)<commit_msg>minor<commit_after>/// SQL statements can have arguments:
///
///     INSERT INTO persons (name, age) VALUES (?, ?)
///     INSERT INTO persons (name, age) VALUES (:name, :age)
///
/// To fill question mark arguments, feed StatementArguments with an array:
///
///     db.execute("INSERT ... (?, ?)", arguments: StatementArguments(["Arthur", 41]))
///
/// Array literals are automatically converted to StatementArguments:
///
///     db.execute("INSERT ... (?, ?)", arguments: ["Arthur", 41])
///
/// To fill named arguments, feed StatementArguments with a dictionary:
///
///     db.execute("INSERT ... (:name, :age)", arguments: StatementArguments(["name": "Arthur", "age": 41]))
///
/// Dictionary literals are automatically converted to StatementArguments:
///
///     db.execute("INSERT ... (:name, :age)", arguments: ["name": "Arthur", "age": 41])
///
/// GRDB.swift only supports colon-prefixed named arguments, even though SQLite
/// supports other syntaxes. See https://www.sqlite.org/lang_expr.html#varparam
/// for more information.
public struct StatementArguments {
    
    // MARK: - Positional Arguments
    
    /// Initializes arguments from a sequence of optional values.
    ///
    ///     let values: [String?] = ["foo", "bar", nil]
    ///     db.execute("INSERT ... (?,?,?)", arguments: StatementArguments(values))
    ///
    /// - parameter sequence: A sequence of optional values that adopt the
    ///   DatabaseValueConvertible protocol.
    /// - returns: A StatementArguments.
    public init<Sequence: SequenceType where Sequence.Generator.Element == Optional<DatabaseValueConvertible>>(_ sequence: Sequence) {
        impl = StatementArgumentsArrayImpl(values: Array(sequence))
    }
    
    
    // MARK: - Named Arguments
    
    /// Initializes arguments from a dictionary of optional values.
    ///
    ///     let values: [String: String?] = ["firstName": nil, "lastName": "Miller"]
    ///     db.execute("INSERT ... (:firstName, :lastName)", arguments: StatementArguments(values))
    ///
    /// GRDB.swift only supports colon-prefixed named arguments, even though
    /// SQLite supports other syntaxes. See https://www.sqlite.org/lang_expr.html#varparam
    /// for more information.
    ///
    /// - parameter dictionary: A dictionary of optional values that adopt the
    ///   DatabaseValueConvertible protocol.
    /// - returns: A StatementArguments.
    public init(_ dictionary: [String: DatabaseValueConvertible?]) {
        impl = StatementArgumentsDictionaryImpl(dictionary: dictionary)
    }
    
    
    // MARK: - Default Arguments
    
    /// Whenever you need to write a method with optional statement arguments,
    /// do not use nil as a sentinel. This is because StatementArguments has
    /// failable initializers, and you do not want such a failed initializer
    /// have your method behave as if no arguments was given.
    ///
    /// Instead, use a non-optional StatementArguments parameter type, and use
    /// StatementArguments.Default as its default value.
    ///
    /// Compare:
    ///
    ///     func bad(arguments: StatementArguments? = nil)
    ///     func good(arguments: StatementArguments = StatementArguments.Default)
    ///
    ///     let badDict: NSDictionary = ["foo": NSObject()] // can't be used as arguments
    ///     let arguments = StatementArguments(badDict)     // nil, actually
    ///
    ///     // Bad function swallows nil. Bad, bad function!
    ///     bad(arguments: arguments)
    ///
    ///     // Good function forces the user to handle the invalid input case:
    ///     good(arguments: arguments)  // won't compile
    ///     if let arguments = arguments {
    ///         good(arguments: arguments)
    ///     } else {
    ///         // handle wrong dictionary
    ///     }
    public static var Default = StatementArguments(impl: DefaultStatementArgumentsImpl())
    
    /// True if and only if the receiver is StatementArguments.Default.
    public var isDefault: Bool { return impl.isDefault }
    
    
    // MARK: - Not Public
    
    let impl: StatementArgumentsImpl
    
    init(impl: StatementArgumentsImpl) {
        self.impl = impl
    }
    
    // Supported usage: Statement.arguments property
    //
    //     let statement = db.UpdateStatement("INSERT INTO persons (name, age) VALUES (?,?)"
    //     statement.execute(arguments: ["Arthur", 41])
    func bindInStatement(statement: Statement) {
        impl.bindInStatement(statement)
    }
    
    
    // Mark: - StatementArguments.DefaultImpl
    
    private struct DefaultStatementArgumentsImpl : StatementArgumentsImpl {
        var isDefault: Bool { return true }
        
        func bindInStatement(statement: Statement) {
            fatalError("DefaultStatementArgumentsImpl is a sentinel value and must not be used.")
        }
        
        var description: String {
            return "StatementArguments.DefaultImpl"
        }
    }
    
    
    // MARK: - StatementArgumentsArrayImpl
    
    /// Support for positional arguments
    private struct StatementArgumentsArrayImpl : StatementArgumentsImpl {
        let values: [DatabaseValueConvertible?]
        var isDefault: Bool { return false }
        
        init(values: [DatabaseValueConvertible?]) {
            self.values = values
        }
        
        func bindInStatement(statement: Statement) {
            statement.validateArgumentCount(values.count)
{'fraction_non_alphanumeric': 0.12502316960148285, 'fraction_numerical': 0.0018535681186283596, 'mean_word_length': 2.3574984443061604, 'pattern_counts': {'":': 14, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2867330', 'n_tokens_mistral': 2771, 'n_tokens_neox': 2667, 'n_words': 851}