From 48ef6918979311f0d9362b16c4331636c8cc44b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 11:03:18 +0200 Subject: [PATCH] Disallow FTS5 column matching against NULL SQLite just throws a syntax error --- GRDB/QueryInterface/FTS5+QueryInterface.swift | 7 ++----- Tests/GRDBTests/FTS5RecordTests.swift | 3 --- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/GRDB/QueryInterface/FTS5+QueryInterface.swift b/GRDB/QueryInterface/FTS5+QueryInterface.swift index e6c2c72b2..dcf0272ee 100644 --- a/GRDB/QueryInterface/FTS5+QueryInterface.swift +++ b/GRDB/QueryInterface/FTS5+QueryInterface.swift @@ -48,11 +48,8 @@ extension ColumnExpression { /// /// // content MATCH '...' /// Column("content").match(pattern) - /// - /// If the search pattern is nil, SQLite will evaluate the expression - /// to false. - public func match(_ pattern: FTS5Pattern?) -> SQLExpression { - .binary(.match, sqlExpression, pattern?.sqlExpression ?? .null) + public func match(_ pattern: FTS5Pattern) -> SQLExpression { + .binary(.match, sqlExpression, pattern.sqlExpression) } } #endif diff --git a/Tests/GRDBTests/FTS5RecordTests.swift b/Tests/GRDBTests/FTS5RecordTests.swift index f854c9fdf..fd1fcd26c 100644 --- a/Tests/GRDBTests/FTS5RecordTests.swift +++ b/Tests/GRDBTests/FTS5RecordTests.swift @@ -89,9 +89,6 @@ class FTS5RecordTests: GRDBTestCase { let pattern = FTS5Pattern(matchingAllTokensIn: "") XCTAssertTrue(pattern == nil) XCTAssertEqual(try Book.matching(pattern).fetchCount(db), 0) - XCTAssertEqual(try Book.filter(Column("books").match(pattern)).fetchCount(db), 0) - XCTAssertEqual(try Book.filter(Column("author").match(pattern)).fetchCount(db), 0) - XCTAssertEqual(try Book.filter(Column("title").match(pattern)).fetchCount(db), 0) } }