From aa6f55d72f03a2a59aa5e010ca4f0a6bdebc167a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 13 Feb 2019 08:49:04 +0100 Subject: [PATCH] Statement arguments are generally non optional --- GRDB.xcodeproj/project.pbxproj | 4 +-- GRDB/Core/Database+Statements.swift | 7 ++-- GRDB/Core/DatabaseValueConvertible.swift | 35 ++++++++----------- GRDB/Core/Row.swift | 21 +++++------ GRDB/Core/SQLInterpolation.swift | 12 +++---- GRDB/Core/SQLLiteral.swift | 6 ++-- GRDB/Core/SQLRequest.swift | 7 ++-- GRDB/Core/Statement.swift | 2 +- GRDB/Core/StatementColumnConvertible.swift | 35 ++++++++----------- .../QueryInterfaceRequest.swift | 22 +++++------- GRDB/QueryInterface/RequestProtocols.swift | 25 ++++++------- .../SQLExpression+QueryInterface.swift | 5 ++- GRDB/Record/FetchableRecord.swift | 21 +++++------ GRDB/Record/FetchedRecordsController.swift | 6 ++-- GRDBCipher.xcodeproj/project.pbxproj | 4 +-- GRDBCustom.xcodeproj/project.pbxproj | 4 +-- .../Contents.swift | 9 ++--- 17 files changed, 95 insertions(+), 130 deletions(-) diff --git a/GRDB.xcodeproj/project.pbxproj b/GRDB.xcodeproj/project.pbxproj index 3bf6ea54d..8b2df9fcb 100755 --- a/GRDB.xcodeproj/project.pbxproj +++ b/GRDB.xcodeproj/project.pbxproj @@ -3610,7 +3610,7 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -3657,7 +3657,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MTL_ENABLE_DEBUG_INFO = NO; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 4.2; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/GRDB/Core/Database+Statements.swift b/GRDB/Core/Database+Statements.swift index f5d95daee..fde653fee 100644 --- a/GRDB/Core/Database+Statements.swift +++ b/GRDB/Core/Database+Statements.swift @@ -123,12 +123,11 @@ extension Database { /// /// - parameters: /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - throws: A DatabaseError whenever an SQLite error occurs. - public func execute(_ sql: String, arguments: StatementArguments? = nil) throws { + public func execute(_ sql: String, arguments: StatementArguments = StatementArguments()) throws { // TODO: force sql parameter name: execute(sql:...) - // TODO: make arguments non optional - try execute(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + try execute(SQLLiteral(sql: sql, arguments: arguments)) } /// Executes one or several SQL statements, separated by semi-colons. diff --git a/GRDB/Core/DatabaseValueConvertible.swift b/GRDB/Core/DatabaseValueConvertible.swift index 8ffd33d30..e4157ebc1 100644 --- a/GRDB/Core/DatabaseValueConvertible.swift +++ b/GRDB/Core/DatabaseValueConvertible.swift @@ -253,14 +253,13 @@ extension DatabaseValueConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor { - // TODO: make arguments non optional + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns an array of values fetched from an SQL query. @@ -270,14 +269,13 @@ extension DatabaseValueConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { - // TODO: make arguments non optional + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns a single value fetched from an SQL query. @@ -290,14 +288,13 @@ extension DatabaseValueConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { - // TODO: make arguments non optional + public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } } @@ -581,14 +578,13 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor { - // TODO: make arguments non optional + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns an array of optional values fetched from an SQL query. @@ -598,14 +594,13 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - parameter arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] { - // TODO: make arguments non optional + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } } diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 6a20f71e7..46bbae98f 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -744,14 +744,13 @@ extension Row { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor { - // TODO: make arguments non optional + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns an array of rows fetched from an SQL query. @@ -765,14 +764,13 @@ extension Row { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row] { - // TODO: make arguments non optional + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row] { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns a single row fetched from an SQL query. @@ -786,14 +784,13 @@ extension Row { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row? { - // TODO: make arguments non optional + public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row? { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } } diff --git a/GRDB/Core/SQLInterpolation.swift b/GRDB/Core/SQLInterpolation.swift index f763ddc4a..c603a8483 100644 --- a/GRDB/Core/SQLInterpolation.swift +++ b/GRDB/Core/SQLInterpolation.swift @@ -14,16 +14,14 @@ public struct SQLInterpolation: StringInterpolationProtocol { } /// "SELECT * FROM player" - public mutating func appendLiteral(_ literal: String) { - sql += literal + public mutating func appendLiteral(_ sql: String) { + self.sql += sql } /// "SELECT * FROM \(raw: "player")" - public mutating func appendInterpolation(sql literal: String, arguments: StatementArguments? = nil) { - sql += literal - if let arguments = arguments { - self.arguments += arguments - } + public mutating func appendInterpolation(sql: String, arguments: StatementArguments = StatementArguments()) { + self.sql += sql + self.arguments += arguments } /// "SELECT * FROM player WHERE \(condition)" diff --git a/GRDB/Core/SQLLiteral.swift b/GRDB/Core/SQLLiteral.swift index 42515c9f0..47aa10058 100644 --- a/GRDB/Core/SQLLiteral.swift +++ b/GRDB/Core/SQLLiteral.swift @@ -29,11 +29,9 @@ extension SQLLiteral { self += other } - public mutating func append(sql: String, arguments: StatementArguments? = nil) { + public mutating func append(sql: String, arguments: StatementArguments = StatementArguments()) { self.sql += sql - if let arguments = arguments { - self.arguments += arguments - } + self.arguments += arguments } } diff --git a/GRDB/Core/SQLRequest.swift b/GRDB/Core/SQLRequest.swift index 97c91a4aa..dee436cfb 100644 --- a/GRDB/Core/SQLRequest.swift +++ b/GRDB/Core/SQLRequest.swift @@ -21,15 +21,14 @@ public struct SQLRequest : FetchRequest { /// /// - parameters: /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter. /// - cached: Defaults to false. If true, the request reuses a cached /// prepared statement. /// - returns: A SQLRequest - public init(_ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil, cached: Bool = false) { - // TODO: make arguments non optional + public init(_ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, cached: Bool = false) { // TODO: force sql parameter name: init(sql:...) - self.init(SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter, fromCache: cached ? .public : nil) + self.init(SQLLiteral(sql: sql, arguments: arguments), adapter: adapter, fromCache: cached ? .public : nil) } /// Creates a request from an SQLLiteral, and optional row adapter. diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index 303b233ac..2bfea2799 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -465,7 +465,7 @@ public final class UpdateStatement : Statement { /// Executes the SQL query. /// - /// - parameter arguments: Statement arguments. + /// - parameter arguments: Optional statement arguments. /// - throws: A DatabaseError whenever an SQLite error occurs. public func execute(arguments: StatementArguments? = nil) throws { SchedulingWatchdog.preconditionValidQueue(database) diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index a97c5b016..581bcccdd 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -241,14 +241,13 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor { - // TODO: make arguments non optional + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns an array of values fetched from an SQL query. @@ -258,14 +257,13 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { - // TODO: make arguments non optional + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns a single value fetched from an SQL query. @@ -275,14 +273,13 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { - // TODO: make arguments non optional + public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } } @@ -562,14 +559,13 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor { - // TODO: make arguments non optional + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns an array of optional values fetched from an SQL query. @@ -579,14 +575,13 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - parameter arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] { - // TODO: make arguments non optional + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } } diff --git a/GRDB/QueryInterface/QueryInterfaceRequest.swift b/GRDB/QueryInterface/QueryInterfaceRequest.swift index 3533b2978..7e2a44f6b 100644 --- a/GRDB/QueryInterface/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/QueryInterfaceRequest.swift @@ -106,9 +106,8 @@ extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest { /// let request = Player.all().select(sql: "max(score)", as: Int.self) /// let maxScore: Int? = try request.fetchOne(db) /// } - public func select(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest { - // TODO: make arguments non optional - return select(SQLLiteral(sql: sql, arguments: arguments ?? .init()), as: type) + public func select(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest { + return select(SQLLiteral(sql: sql, arguments: arguments), as: type) } /// Creates a request which selects *sql*, and fetches values of @@ -372,9 +371,8 @@ extension TableRecord { /// /// // SELECT id, email FROM player /// let request = Player.select(sql: "id, email") - public static func select(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest { - // TODO: make arguments non optional - return select(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + public static func select(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest { + return select(SQLLiteral(sql: sql, arguments: arguments)) } /// Creates a request which selects *sql*. @@ -417,9 +415,8 @@ extension TableRecord { /// let request = Player.select(sql: "max(score)", as: Int.self) /// let maxScore: Int? = try request.fetchOne(db) /// } - public static func select(sql: String, arguments: StatementArguments? = nil, as type: RowDecoder.Type) -> QueryInterfaceRequest { - // TODO: make arguments non optional - return all().select(SQLLiteral(sql: sql, arguments: arguments ?? .init()), as: type) + public static func select(sql: String, arguments: StatementArguments = StatementArguments(), as type: RowDecoder.Type) -> QueryInterfaceRequest { + return all().select(SQLLiteral(sql: sql, arguments: arguments), as: type) } /// Creates a request which selects *sql*, and fetches values of @@ -508,9 +505,8 @@ extension TableRecord { /// The selection defaults to all columns. This default can be changed for /// all requests by the `TableRecord.databaseSelection` property, or /// for individual requests with the `TableRecord.select` method. - public static func filter(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest { - // TODO: make arguments non optional - return filter(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + public static func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest { + return filter(SQLLiteral(sql: sql, arguments: arguments)) } /// Creates a request with the provided *predicate*. @@ -580,7 +576,7 @@ extension TableRecord { /// The selection defaults to all columns. This default can be changed for /// all requests by the `TableRecord.databaseSelection` property, or /// for individual requests with the `TableRecord.select` method. - public static func order(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest { + public static func order(sql: String, arguments: StatementArguments = StatementArguments()) -> QueryInterfaceRequest { return all().order(sql: sql, arguments: arguments) } diff --git a/GRDB/QueryInterface/RequestProtocols.swift b/GRDB/QueryInterface/RequestProtocols.swift index f7e03c2be..5516f49e8 100644 --- a/GRDB/QueryInterface/RequestProtocols.swift +++ b/GRDB/QueryInterface/RequestProtocols.swift @@ -51,9 +51,8 @@ extension SelectionRequest { /// request /// .select(sql: "id") /// .select(sql: "email") - public func select(sql: String, arguments: StatementArguments? = nil) -> Self { - // TODO: make arguments non optional - return select(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + public func select(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return select(SQLLiteral(sql: sql, arguments: arguments)) } /// Creates a request which selects *sql*. @@ -122,9 +121,8 @@ extension FilteredRequest { /// // SELECT * FROM player WHERE email = 'arthur@example.com' /// var request = Player.all() /// request = request.filter(sql: "email = ?", arguments: ["arthur@example.com"]) - public func filter(sql: String, arguments: StatementArguments? = nil) -> Self { - // TODO: make arguments non optional - return filter(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + public func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return filter(SQLLiteral(sql: sql, arguments: arguments)) } /// Creates a request with the provided *predicate* added to the @@ -322,9 +320,8 @@ extension AggregatingRequest { } /// Creates a request with a new grouping. - public func group(sql: String, arguments: StatementArguments? = nil) -> Self { - // TODO: make arguments non optional - return group(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + public func group(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return group(SQLLiteral(sql: sql, arguments: arguments)) } /// Creates a request with a new grouping. @@ -345,9 +342,8 @@ extension AggregatingRequest { /// Creates a request with the provided *sql* added to the /// eventual set of already applied predicates. - public func having(sql: String, arguments: StatementArguments? = nil) -> Self { - // TODO: make arguments non optional - return having(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + public func having(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return having(SQLLiteral(sql: sql, arguments: arguments)) } /// Creates a request with the provided *sql* added to the @@ -443,9 +439,8 @@ extension OrderedRequest { /// request /// .order(sql: "email") /// .order(sql: "name") - public func order(sql: String, arguments: StatementArguments? = nil) -> Self { - // TODO: make arguments non optional - return order(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + public func order(sql: String, arguments: StatementArguments = StatementArguments()) -> Self { + return order(SQLLiteral(sql: sql, arguments: arguments)) } /// Creates a request with the provided *sql* used for sorting. diff --git a/GRDB/QueryInterface/SQLExpression+QueryInterface.swift b/GRDB/QueryInterface/SQLExpression+QueryInterface.swift index 8dbd68bdb..c860e7f8c 100644 --- a/GRDB/QueryInterface/SQLExpression+QueryInterface.swift +++ b/GRDB/QueryInterface/SQLExpression+QueryInterface.swift @@ -49,10 +49,9 @@ public struct SQLExpressionLiteral : SQLExpression { /// SQLExpressionLiteral("1 + 2") /// SQLExpressionLiteral("? + ?", arguments: [1, 2]) /// SQLExpressionLiteral(":one + :two", arguments: ["one": 1, "two": 2]) - public init(_ sql: String, arguments: StatementArguments? = nil) { - // TODO: make arguments non optional + public init(_ sql: String, arguments: StatementArguments = StatementArguments()) { // TODO: force sql parameter name: fetchCursor(db, sql:...) - self.init(SQLLiteral(sql: sql, arguments: arguments ?? .init())) + self.init(SQLLiteral(sql: sql, arguments: arguments)) } /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) diff --git a/GRDB/Record/FetchableRecord.swift b/GRDB/Record/FetchableRecord.swift index 07fe9c195..7e24715c6 100644 --- a/GRDB/Record/FetchableRecord.swift +++ b/GRDB/Record/FetchableRecord.swift @@ -212,14 +212,13 @@ extension FetchableRecord { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor { - // TODO: make arguments non optional + public static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns an array of records fetched from an SQL query. @@ -229,14 +228,13 @@ extension FetchableRecord { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { - // TODO: make arguments non optional + public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } /// Returns a single record fetched from an SQL query. @@ -246,14 +244,13 @@ extension FetchableRecord { /// - parameters: /// - db: A database connection. /// - sql: An SQL query. - /// - arguments: Optional statement arguments. + /// - arguments: Statement arguments. /// - adapter: Optional RowAdapter /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { - // TODO: make arguments non optional + public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { // TODO: force sql parameter name: fetchCursor(db, sql:...) - return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments ?? .init()), adapter: adapter) + return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } } diff --git a/GRDB/Record/FetchedRecordsController.swift b/GRDB/Record/FetchedRecordsController.swift index 99f56e00e..329a6ccf2 100644 --- a/GRDB/Record/FetchedRecordsController.swift +++ b/GRDB/Record/FetchedRecordsController.swift @@ -40,7 +40,7 @@ public final class FetchedRecordsController { public convenience init( _ databaseWriter: DatabaseWriter, sql: String, - arguments: StatementArguments? = nil, + arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, queue: DispatchQueue = .main, isSameRecord: ((Record, Record) -> Bool)? = nil) throws @@ -196,7 +196,7 @@ public final class FetchedRecordsController { /// /// This method must be used from the controller's dispatch queue (the /// main queue unless stated otherwise in the controller's initializer). - public func setRequest(sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { + public func setRequest(sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws { try setRequest(SQLRequest(sql, arguments: arguments, adapter: adapter)) } @@ -429,7 +429,7 @@ extension FetchedRecordsController where Record: TableRecord { public convenience init( _ databaseWriter: DatabaseWriter, sql: String, - arguments: StatementArguments? = nil, + arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil, queue: DispatchQueue = .main) throws { diff --git a/GRDBCipher.xcodeproj/project.pbxproj b/GRDBCipher.xcodeproj/project.pbxproj index 59127dcc4..0dfd97a90 100755 --- a/GRDBCipher.xcodeproj/project.pbxproj +++ b/GRDBCipher.xcodeproj/project.pbxproj @@ -3615,7 +3615,7 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -3662,7 +3662,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MTL_ENABLE_DEBUG_INFO = NO; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 4.2; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/GRDBCustom.xcodeproj/project.pbxproj b/GRDBCustom.xcodeproj/project.pbxproj index c99ca4cca..464a623c9 100755 --- a/GRDBCustom.xcodeproj/project.pbxproj +++ b/GRDBCustom.xcodeproj/project.pbxproj @@ -2637,7 +2637,7 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -2684,7 +2684,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MTL_ENABLE_DEBUG_INFO = NO; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 4.2; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift b/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift index b2d7d6962..63c391dad 100644 --- a/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift +++ b/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift @@ -386,20 +386,17 @@ extension MyDatabaseDecoder { // MARK: - Fetch from SQL - static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> MapCursor { - // TODO: make arguments non optional + static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> MapCursor { // TODO: force sql parameter name: fetchCursor(db, sql:...) return try fetchCursor(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } - static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [DecodedType] { - // TODO: make arguments non optional + static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [DecodedType] { // TODO: force sql parameter name: fetchCursor(db, sql:...) return try fetchAll(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) } - static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DecodedType? { - // TODO: make arguments non optional + static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DecodedType? { // TODO: force sql parameter name: fetchCursor(db, sql:...) return try fetchOne(db, SQLLiteral(sql: sql, arguments: arguments), adapter: adapter) }