Merge pull request #592 from groue/dev/issue-591

Fix Data interpolation
This commit is contained in:
Gwendal Roué authored and GitHub committed 2019-08-12 12:34:24 +02:00
commit a6112a5ca2
4 files changed
+33 -4

No files matched your search

+5 -4
View File
@@ -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.
<!--
[Next Release](#next-release)
-->
#### 4.x Releases
@@ -55,9 +53,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one expection:
- [0.110.0](#01100), ...
<!--
## Next Release
-->
**Fixed**
- [#592](https://github.com/groue/GRDB.swift/pull/592): Fix Data interpolation
## 4.2.0
@@ -75,6 +75,15 @@ extension SQLInterpolation {
appendInterpolation(Column(codingKey.stringValue))
}
// 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<T>(_ 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 (?,?,?)
@@ -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)
+9
View File
@@ -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"))