From d28847bf3d9cdf32df2699fc47778e032b904d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 11 Aug 2019 12:56:29 +0200 Subject: [PATCH 1/4] Failing test for https://github.com/groue/GRDB.swift/issues/591 --- Tests/GRDBTests/SQLInterpolationTests.swift | 10 ++++++++++ Tests/GRDBTests/SQLLiteralTests.swift | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/Tests/GRDBTests/SQLInterpolationTests.swift b/Tests/GRDBTests/SQLInterpolationTests.swift index bce0ba8e2..100a1f555 100644 --- a/Tests/GRDBTests/SQLInterpolationTests.swift +++ b/Tests/GRDBTests/SQLInterpolationTests.swift @@ -104,6 +104,16 @@ class SQLInterpolationTests: GRDBTestCase { test(value: V(), isInterpolatedAs: "V".databaseValue) } + func testDataInterpolation() { + // This test makes sure the Sequence conformance of Data does not + // kick in. + let data = "SQLite".data(using: .utf8)! + var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 1) + sql.appendInterpolation(data) + XCTAssertEqual(sql.sql, "?") + XCTAssertEqual(sql.arguments, [data]) + } + func testQualifiedExpressionInterpolation() { var sql = SQLInterpolation(literalCapacity: 0, interpolationCount: 1) diff --git a/Tests/GRDBTests/SQLLiteralTests.swift b/Tests/GRDBTests/SQLLiteralTests.swift index a649545c4..bae20c007 100644 --- a/Tests/GRDBTests/SQLLiteralTests.swift +++ b/Tests/GRDBTests/SQLLiteralTests.swift @@ -234,6 +234,15 @@ extension SQLLiteralTests { test(value: V(), isInterpolatedAs: "V".databaseValue) } + func testDataInterpolation() { + // This test makes sure the Sequence conformance of Data does not + // kick in. + let data = "SQLite".data(using: .utf8)! + let query: SQLLiteral = "SELECT \(data)" + XCTAssertEqual(query.sql, "SELECT ?") + XCTAssertEqual(query.arguments, [data]) + } + func testQualifiedExpressionInterpolation() { let query: SQLLiteral = """ SELECT \(Column("name").aliased("foo")) From 8e38af9aaeb7391527a08bf4169f57957800d353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 11 Aug 2019 13:03:43 +0200 Subject: [PATCH 2/4] Fix #591 --- .../QueryInterface/SQLInterpolation+QueryInterface.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift b/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift index 6d7d71382..892118e9f 100644 --- a/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift +++ b/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift @@ -75,6 +75,15 @@ extension SQLInterpolation { appendInterpolation(Column(codingKey.stringValue)) } + // When a value is both an expression and a sequence of expression, + // favor the expression side. Use case: Foundation.Data interpolation. + /// :nodoc: + public mutating func appendInterpolation(_ expressible: T) + where T: Sequence, T.Element: SQLExpressible, T: SQLExpressible + { + sql += expressible.sqlExpression.expressionSQL(&context, wrappedInParenthesis: false) + } + /// Appends a sequence of expressions, wrapped in parentheses. /// /// // SELECT * FROM player WHERE id IN (?,?,?) From 01a1a7c962f4fc30b5c06efb25bb194d2bb94267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 11 Aug 2019 13:04:24 +0200 Subject: [PATCH 3/4] Fix typo --- GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift b/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift index 892118e9f..0ec52db3c 100644 --- a/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift +++ b/GRDB/QueryInterface/SQLInterpolation+QueryInterface.swift @@ -75,7 +75,7 @@ extension SQLInterpolation { appendInterpolation(Column(codingKey.stringValue)) } - // When a value is both an expression and a sequence of expression, + // When a value is both an expression and a sequence of expressions, // favor the expression side. Use case: Foundation.Data interpolation. /// :nodoc: public mutating func appendInterpolation(_ expressible: T) From d219f5589eec16e289f093eb86929ff130bf07ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 11 Aug 2019 13:14:44 +0200 Subject: [PATCH 4/4] CHANGELOG --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ab0c698d..1a424b00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,7 @@ All notable changes to this project will be documented in this file. GRDB adheres to [Semantic Versioning](https://semver.org/), with one expection: APIs flagged [**:fire: EXPERIMENTAL**](README.md#what-are-experimental-features). Those are unstable, and may break between any two minor releases of the library. - #### 4.x Releases @@ -55,9 +53,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one expection: - [0.110.0](#01100), ... - + +**Fixed** + +- [#592](https://github.com/groue/GRDB.swift/pull/592): Fix Data interpolation + ## 4.2.0