diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index 143c29d78..23d1eeff0 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -225,14 +225,14 @@ extension DatabaseValue { /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// :nodoc: public func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) throws -> String { - // fast path for NULL if isNull { + // fast path for NULL return "NULL" - } - - if context.append(arguments: [self]) { + } else if context.append(arguments: [self]) { + // Use statement arguments if possible return "?" } else { + // Quoting needed: just use SQLite, which knows better. return try String.fetchOne(context.db, sql: "SELECT QUOTE(?)", arguments: [self])! } } diff --git a/GRDB/Core/SQLRequest.swift b/GRDB/Core/SQLRequest.swift index 1b8161deb..2b4a486ea 100644 --- a/GRDB/Core/SQLRequest.swift +++ b/GRDB/Core/SQLRequest.swift @@ -165,13 +165,9 @@ public struct SQLRequest: FetchRequest { } extension SQLRequest: SQLCollection { + /// :nodoc public func collectionSQL(_ context: inout SQLGenerationContext) throws -> String { - if context.append(arguments: arguments) == false { - // GRDB limitation: we don't know how to look for `?` in sql and - // replace them with literals. - fatalError("Not implemented") - } - return sql + try sqlLiteral.sql(&context) } } diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift index 407bee4b0..fa4356d9d 100644 --- a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift @@ -409,6 +409,7 @@ extension QueryInterfaceRequest: Refinable { } extension QueryInterfaceRequest: SQLCollection { + /// :nodoc public func collectionSQL(_ context: inout SQLGenerationContext) throws -> String { try SQLQueryGenerator(query).sql(&context) } diff --git a/GRDB/QueryInterface/SQL/Column.swift b/GRDB/QueryInterface/SQL/Column.swift index d88088933..a0e1f36b1 100644 --- a/GRDB/QueryInterface/SQL/Column.swift +++ b/GRDB/QueryInterface/SQL/Column.swift @@ -27,7 +27,7 @@ public protocol ColumnExpression: SQLExpression { extension ColumnExpression { /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// :nodoc: - public func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) throws -> String { + public func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) -> String { name.quotedDatabaseIdentifier } @@ -73,7 +73,7 @@ struct QualifiedColumn: ColumnExpression { self.alias = alias } - func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) throws -> String { + func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) -> String { if let qualifier = context.qualifier(for: alias) { return qualifier.quotedDatabaseIdentifier + "." + name.quotedDatabaseIdentifier } diff --git a/GRDB/QueryInterface/SQL/SQLExpression+QueryInterface.swift b/GRDB/QueryInterface/SQL/SQLExpression+QueryInterface.swift index 253a80319..14d395537 100644 --- a/GRDB/QueryInterface/SQL/SQLExpression+QueryInterface.swift +++ b/GRDB/QueryInterface/SQL/SQLExpression+QueryInterface.swift @@ -469,7 +469,8 @@ struct SQLExpressionContains: SQLExpression { } func qualifiedExpression(with alias: TableAlias) -> SQLExpression { - SQLExpressionContains(expression.qualifiedExpression(with: alias), collection, negated: isNegated) + #warning("TODO: why isn't collection qualified as well?") + return SQLExpressionContains(expression.qualifiedExpression(with: alias), collection, negated: isNegated) } func matchedRowIds(rowIdName: String?) -> Set? { diff --git a/GRDB/QueryInterface/SQL/SQLSelectable+QueryInterface.swift b/GRDB/QueryInterface/SQL/SQLSelectable+QueryInterface.swift index e66e8e8fc..036469aac 100644 --- a/GRDB/QueryInterface/SQL/SQLSelectable+QueryInterface.swift +++ b/GRDB/QueryInterface/SQL/SQLSelectable+QueryInterface.swift @@ -21,13 +21,13 @@ public struct AllColumns { extension AllColumns: SQLSelectable { /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// :nodoc: - public func resultColumnSQL(_ context: inout SQLGenerationContext) throws -> String { + public func resultColumnSQL(_ context: inout SQLGenerationContext) -> String { "*" } /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// :nodoc: - public func countedSQL(_ context: inout SQLGenerationContext) throws -> String { + public func countedSQL(_ context: inout SQLGenerationContext) -> String { "*" } @@ -70,14 +70,14 @@ struct QualifiedAllColumns { } extension QualifiedAllColumns: SQLSelectable { - func resultColumnSQL(_ context: inout SQLGenerationContext) throws -> String { + func resultColumnSQL(_ context: inout SQLGenerationContext) -> String { if let qualifier = context.qualifier(for: alias) { return qualifier.quotedDatabaseIdentifier + ".*" } return "*" } - func countedSQL(_ context: inout SQLGenerationContext) throws -> String { + func countedSQL(_ context: inout SQLGenerationContext) -> String { // TODO: restore the check below. // // It is currently disabled because of AssociationAggregateTests.testHasManyIsEmpty: