diff --git a/CHANGELOG.md b/CHANGELOG.md index 845371d96..9c20d39ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,19 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: - [#656](https://github.com/groue/GRDB.swift/pull/656): Type inference of selected columns - [#659](https://github.com/groue/GRDB.swift/pull/659): Database interruption - [#660](https://github.com/groue/GRDB.swift/pull/660): Database Lock Prevention +- [#662](https://github.com/groue/GRDB.swift/pull/662): Upgrade custom SQLite builds to version 3.30.1 (thanks to [@swiftlyfalling](https://github.com/swiftlyfalling/SQLiteLib)) + +### Breaking Changes + +[Custom SQLite builds](Documentation/CustomSQLiteBuilds.md) now disable by default the support for the [Double-quoted String Literals misfeature](https://sqlite.org/quirks.html#dblquote). You can restore the previous behavior if your application relies on it: + +```swift +// Enable support for the Double-quoted String Literals misfeature +var configuration = Configuration() +configuration.acceptsDoubleQuotedStringLiterals = true +let dbQueue = try DatabaseQueue(path: ..., configuration: configuration) +``` + ### Documentation Diff diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index bd72ee6e8..e9d3c985c 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -75,6 +75,29 @@ public struct Configuration { /// Default: nil public var trace: TraceFunction? + /// If false, SQLite from version 3.29.0 will not interpret a double-quoted + /// string as a string literal if it does not match any valid identifier. + /// + /// For example: + /// + /// // Error: no such column: foo + /// let name = try String.fetchOne(db, sql: """ + /// SELECT "foo" FROM "player" + /// """) + /// + /// When true, or before version 3.29.0, such strings are interpreted as + /// string literals, as in the example below. This is a well known SQLite + /// [misfeature](https://sqlite.org/quirks.html#dblquote). + /// + /// // Success: "foo" + /// let name = try String.fetchOne(db, sql: """ + /// SELECT "foo" FROM "player" + /// """) + /// + /// - Recommended value: false + /// - Default value: false + public var acceptsDoubleQuotedStringLiterals = false + // MARK: - Encryption #if SQLITE_HAS_CODEC diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 54f2aebdb..c8ea618e5 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -209,6 +209,7 @@ public final class Database { func setup() throws { // Setup trace first, so that setup queries are traced. setupTrace() + setupDoubleQuotedStringLiterals() try setupForeignKeys() setupBusyMode() setupDefaultFunctions() @@ -294,6 +295,14 @@ public final class Database { return SQLITE_OK } + private func setupDoubleQuotedStringLiterals() { + if configuration.acceptsDoubleQuotedStringLiterals { + enableDoubleQuotedStringLiterals(sqliteConnection) + } else { + disableDoubleQuotedStringLiterals(sqliteConnection) + } + } + private func setupForeignKeys() throws { // Foreign keys are disabled by default with SQLite3 if configuration.foreignKeysEnabled { diff --git a/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift b/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift index f80d4de53..1cdc5cc2b 100644 --- a/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift +++ b/GRDB/QueryInterface/SQL/SQLCollatedExpression.swift @@ -40,6 +40,32 @@ public struct SQLCollatedExpression { return SQLOrdering.desc(sqlExpression) } + #if GRDBCUSTOMSQLITE + /// Returns an ordering suitable for QueryInterfaceRequest.order() + /// + /// let email: SQLCollatedExpression = Column("email").collating(.nocase) + /// + /// // SELECT * FROM player ORDER BY email COLLATE NOCASE ASC NULLS LAST + /// Player.order(email.ascNullsLast) + /// + /// See https://github.com/groue/GRDB.swift/#the-query-interface + public var ascNullsLast: SQLOrderingTerm { + return SQLOrdering.ascNullsLast(sqlExpression) + } + + /// Returns an ordering suitable for QueryInterfaceRequest.order() + /// + /// let email: SQLCollatedExpression = Column("email").collating(.nocase) + /// + /// // SELECT * FROM player ORDER BY email COLLATE NOCASE DESC NULLS FIRST + /// Player.order(email.descNullsFirst) + /// + /// See https://github.com/groue/GRDB.swift/#the-query-interface + public var descNullsFirst: SQLOrderingTerm { + return SQLOrdering.descNullsFirst(sqlExpression) + } + #endif + init(_ expression: SQLExpression, collationName: Database.CollationName) { self.expression = expression self.collationName = collationName diff --git a/GRDB/QueryInterface/SQL/SQLOrdering.swift b/GRDB/QueryInterface/SQL/SQLOrdering.swift index 25be3e43e..2908cbc8e 100644 --- a/GRDB/QueryInterface/SQL/SQLOrdering.swift +++ b/GRDB/QueryInterface/SQL/SQLOrdering.swift @@ -26,6 +26,10 @@ public protocol SQLOrderingTerm { enum SQLOrdering: SQLOrderingTerm { case asc(SQLExpression) case desc(SQLExpression) + #if GRDBCUSTOMSQLITE + case ascNullsLast(SQLExpression) + case descNullsFirst(SQLExpression) + #endif var reversed: SQLOrderingTerm { switch self { @@ -33,6 +37,12 @@ enum SQLOrdering: SQLOrderingTerm { return SQLOrdering.desc(expression) case .desc(let expression): return SQLOrdering.asc(expression) + #if GRDBCUSTOMSQLITE + case .ascNullsLast(let expression): + return SQLOrdering.descNullsFirst(expression) + case .descNullsFirst(let expression): + return SQLOrdering.ascNullsLast(expression) + #endif } } @@ -42,6 +52,12 @@ enum SQLOrdering: SQLOrderingTerm { return expression.expressionSQL(&context, wrappedInParenthesis: false) + " ASC" case .desc(let expression): return expression.expressionSQL(&context, wrappedInParenthesis: false) + " DESC" + #if GRDBCUSTOMSQLITE + case .ascNullsLast(let expression): + return expression.expressionSQL(&context, wrappedInParenthesis: false) + " ASC NULLS LAST" + case .descNullsFirst(let expression): + return expression.expressionSQL(&context, wrappedInParenthesis: false) + " DESC NULLS FIRST" + #endif } } @@ -51,6 +67,12 @@ enum SQLOrdering: SQLOrderingTerm { return SQLOrdering.asc(expression.qualifiedExpression(with: alias)) case .desc(let expression): return SQLOrdering.desc(expression.qualifiedExpression(with: alias)) + #if GRDBCUSTOMSQLITE + case .ascNullsLast(let expression): + return SQLOrdering.ascNullsLast(expression.qualifiedExpression(with: alias)) + case .descNullsFirst(let expression): + return SQLOrdering.descNullsFirst(expression.qualifiedExpression(with: alias)) + #endif } } } diff --git a/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift b/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift index 25e8bfceb..8d6ce9af8 100644 --- a/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift +++ b/GRDB/QueryInterface/SQL/SQLSpecificExpressible+QueryInterface.swift @@ -16,6 +16,22 @@ extension SQLSpecificExpressible { public var desc: SQLOrderingTerm { return SQLOrdering.desc(sqlExpression) } + + #if GRDBCUSTOMSQLITE + /// Returns a value that can be used as an argument to QueryInterfaceRequest.order() + /// + /// See https://github.com/groue/GRDB.swift/#the-query-interface + public var ascNullsLast: SQLOrderingTerm { + return SQLOrdering.ascNullsLast(sqlExpression) + } + + /// Returns a value that can be used as an argument to QueryInterfaceRequest.order() + /// + /// See https://github.com/groue/GRDB.swift/#the-query-interface + public var descNullsFirst: SQLOrderingTerm { + return SQLOrdering.descNullsFirst(sqlExpression) + } + #endif } diff --git a/README.md b/README.md index e6007c61d..970c71ca8 100644 --- a/README.md +++ b/README.md @@ -4083,6 +4083,13 @@ You can now build requests with the following methods: `all`, `none`, `select`, Player.order(scoreColumn.desc, nameColumn) ``` + SQLite considers NULL values to be smaller than any other values for sorting purposes. Hence, NULLs naturally appear at the beginning of an ascending ordering and at the end of a descending ordering. With a [custom SQLite build], this can be changed using `.ascNullsLast` and `.descNullsFirst`: + + ```swift + // SELECT * FROM player ORDER BY score ASC NULLS LAST + Player.order(nameColumn.ascNullsLast) + ``` + Each `order` call clears any previous ordering: ```swift diff --git a/SQLiteCustom/src b/SQLiteCustom/src index d3829a886..7de55d32c 160000 --- a/SQLiteCustom/src +++ b/SQLiteCustom/src @@ -1 +1 @@ -Subproject commit d3829a886bdd69f9e6a34d3c0a8df4a1117eb4f5 +Subproject commit 7de55d32c9e2c83f454e4d17c02b30ef0904b986 diff --git a/Sources/sqlite3/shim.h b/Sources/sqlite3/shim.h index d018d2fce..be4cd9cf9 100644 --- a/Sources/sqlite3/shim.h +++ b/Sources/sqlite3/shim.h @@ -2,8 +2,27 @@ typedef void(*errorLogCallback)(void *pArg, int iErrCode, const char *zMsg); -// Wrapper around sqlite3_config(SQLITE_CONFIG_LOG, ...) which is a variadic -// function that can't be used from Swift. +/// Wrapper around sqlite3_config(SQLITE_CONFIG_LOG, ...) which is a variadic +/// function that can't be used from Swift. static inline void registerErrorLogCallback(errorLogCallback callback) { sqlite3_config(SQLITE_CONFIG_LOG, callback, 0); } + +#if SQLITE_VERSION_NUMBER >= 3029000 +/// Wrapper around sqlite3_db_config() which is a variadic function that can't +/// be used from Swift. +static inline void disableDoubleQuotedStringLiterals(sqlite3 *db) { + sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, (void *)0); + sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, (void *)0); +} + +/// Wrapper around sqlite3_db_config() which is a variadic function that can't +/// be used from Swift. +static inline void enableDoubleQuotedStringLiterals(sqlite3 *db) { + sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 1, (void *)0); + sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 1, (void *)0); +} +#else +static inline void disableDoubleQuotedStringLiterals(sqlite3 *db) { } +static inline void enableDoubleQuotedStringLiterals(sqlite3 *db) { } +#endif diff --git a/Support/grdb_config.h b/Support/grdb_config.h index 90e83eb5e..5038365c8 100644 --- a/Support/grdb_config.h +++ b/Support/grdb_config.h @@ -15,12 +15,31 @@ typedef void(*errorLogCallback)(void *pArg, int iErrCode, const char *zMsg); -// Wrapper around sqlite3_config(SQLITE_CONFIG_LOG, ...) which is a variadic -// function that can't be used from Swift. +/// Wrapper around sqlite3_config(SQLITE_CONFIG_LOG, ...) which is a variadic +/// function that can't be used from Swift. static inline void registerErrorLogCallback(errorLogCallback callback) { sqlite3_config(SQLITE_CONFIG_LOG, callback, 0); } +#if SQLITE_VERSION_NUMBER >= 3029000 +/// Wrapper around sqlite3_db_config() which is a variadic function that can't +/// be used from Swift. +static inline void disableDoubleQuotedStringLiterals(sqlite3 *db) { + sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, (void *)0); + sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, (void *)0); +} + +/// Wrapper around sqlite3_db_config() which is a variadic function that can't +/// be used from Swift. +static inline void enableDoubleQuotedStringLiterals(sqlite3 *db) { + sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 1, (void *)0); + sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 1, (void *)0); +} +#else +static inline void disableDoubleQuotedStringLiterals(sqlite3 *db) { } +static inline void enableDoubleQuotedStringLiterals(sqlite3 *db) { } +#endif + // Expose APIs that are missing from system #ifdef GRDB_SQLITE_ENABLE_PREUPDATE_HOOK SQLITE_API void *sqlite3_preupdate_hook( diff --git a/TODO.md b/TODO.md index 8c18ba1de..a345e5bd8 100644 --- a/TODO.md +++ b/TODO.md @@ -41,6 +41,7 @@ ## Unsure if necessary +- [ ] https://sqlite.org/pragma.html#pragma_index_xinfo - [ ] Deprecate DatabaseQueue/Pool.addFunction, collation, tokenizer: those should be done in Configuration.prepareDatabase - [ ] filter(rowid:), filter(rowids:) - [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0075-import-test.md diff --git a/Tests/GRDBTests/DatabaseConfigurationTests.swift b/Tests/GRDBTests/DatabaseConfigurationTests.swift index d9ab79d88..3441ac76c 100644 --- a/Tests/GRDBTests/DatabaseConfigurationTests.swift +++ b/Tests/GRDBTests/DatabaseConfigurationTests.swift @@ -2,6 +2,11 @@ import XCTest #if GRDBCUSTOMSQLITE import GRDBCustomSQLite #else + #if SWIFT_PACKAGE + import CSQLite + #else + import SQLite3 + #endif import GRDB #endif @@ -72,4 +77,79 @@ class DatabaseConfigurationTests: GRDBTestCase { } catch is TestError { } } } + + func testAcceptsDoubleQuotedStringLiteralsDefault() throws { + let configuration = Configuration() + XCTAssertFalse(configuration.acceptsDoubleQuotedStringLiterals) + } + + func testAcceptsDoubleQuotedStringLiteralsTrue() throws { + var configuration = Configuration() + configuration.acceptsDoubleQuotedStringLiterals = true + let dbQueue = try makeDatabaseQueue(configuration: configuration) + try dbQueue.inDatabase { db in + try db.execute(sql: """ + CREATE TABLE player(name TEXT); + INSERT INTO player DEFAULT VALUES; + """) + } + + // Test SQLITE_DBCONFIG_DQS_DML + let foo = try dbQueue.inDatabase { db in + try String.fetchOne(db, sql: "SELECT \"foo\" FROM player") + } + XCTAssertEqual(foo, "foo") + + // Test SQLITE_DBCONFIG_DQS_DDL + if sqlite3_libversion_number() > 3008010 { + try dbQueue.inDatabase { db in + try db.execute(sql: "CREATE INDEX i ON player(\"foo\")") + } + } + } + + func testAcceptsDoubleQuotedStringLiteralsFalse() throws { + var configuration = Configuration() + configuration.acceptsDoubleQuotedStringLiterals = false + let dbQueue = try makeDatabaseQueue(configuration: configuration) + try dbQueue.inDatabase { db in + try db.execute(sql: """ + CREATE TABLE player(name TEXT); + INSERT INTO player DEFAULT VALUES; + """) + } + + // Test SQLITE_DBCONFIG_DQS_DML + do { + let foo = try dbQueue.inDatabase { db in + try String.fetchOne(db, sql: "SELECT \"foo\" FROM player") + } + if sqlite3_libversion_number() >= 3029000 { + XCTFail("Expected error") + } else { + XCTAssertEqual(foo, "foo") + } + } catch let error as DatabaseError { + XCTAssertEqual(error.resultCode, .SQLITE_ERROR) + XCTAssertEqual(error.message, "no such column: foo") + XCTAssertEqual(error.sql, "SELECT \"foo\" FROM player") + } + + // Test SQLITE_DBCONFIG_DQS_DDL + do { + try dbQueue.inDatabase { db in + try db.execute(sql: "CREATE INDEX i ON player(\"foo\")") + } + if sqlite3_libversion_number() >= 3029000 { + XCTFail("Expected error") + } + } catch let error as DatabaseError { + XCTAssertEqual(error.resultCode, .SQLITE_ERROR) + XCTAssert([ + "no such column: foo", + "table player has no column named foo"] + .contains(error.message)) + XCTAssertEqual(error.sql, "CREATE INDEX i ON player(\"foo\")") + } + } } diff --git a/Tests/GRDBTests/FTS5PatternTests.swift b/Tests/GRDBTests/FTS5PatternTests.swift index 9d51de329..72105ba93 100644 --- a/Tests/GRDBTests/FTS5PatternTests.swift +++ b/Tests/GRDBTests/FTS5PatternTests.swift @@ -32,7 +32,7 @@ class FTS5PatternTests: GRDBTestCase { ("écarlates", 1), ("fooéı👨👨🏿🇫🇷🇨🇮", 0), // Prefix queries - ("*", 1), // weird + // ("*", 1), // No longer valid on SQLite 3.30.1 ("Robin*", 1), // Phrase queries ("\"foulent muscles\"", 1), diff --git a/Tests/GRDBTests/QueryInterfaceRequestTests.swift b/Tests/GRDBTests/QueryInterfaceRequestTests.swift index 6fcf432ba..a14268f6e 100644 --- a/Tests/GRDBTests/QueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/QueryInterfaceRequestTests.swift @@ -1,8 +1,8 @@ import XCTest #if GRDBCUSTOMSQLITE - import GRDBCustomSQLite +import GRDBCustomSQLite #else - import GRDB +import GRDB #endif private struct Col { @@ -18,7 +18,7 @@ private struct Reader : TableRecord { private let tableRequest = Reader.all() class QueryInterfaceRequestTests: GRDBTestCase { - + var collation: DatabaseCollation! override func setup(_ dbWriter: DatabaseWriter) throws { @@ -88,10 +88,10 @@ class QueryInterfaceRequestTests: GRDBTestCase { } } } - - + + // MARK: - Count - + func testFetchCount() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -135,10 +135,10 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual(lastSQLQuery, "SELECT COUNT(*) FROM (SELECT MAX(\"age\") FROM \"readers\" GROUP BY \"name\")") } } - - + + // MARK: - Select - + func testSelectLiteral() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -155,7 +155,7 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual(rows[1][1] as Int64, 1) } } - + func testSelectLiteralWithPositionalArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -172,7 +172,7 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual(rows[1][1] as Int64, 1) } } - + func testSelectLiteralWithNamedArguments() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -228,7 +228,7 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual(rows[1][1] as Int64, 1) } } - + func testSelectionCustomKey() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in @@ -576,14 +576,14 @@ class QueryInterfaceRequestTests: GRDBTestCase { .filter(sql: "name = :name", arguments: ["name": "arthur"])), "SELECT * FROM \"readers\" WHERE (age > 20) AND (name = 'arthur')") } - + func testFilter() throws { let dbQueue = try makeDatabaseQueue() XCTAssertEqual( sql(dbQueue, tableRequest.filter(true)), "SELECT * FROM \"readers\" WHERE 1") } - + func testMultipleFilter() throws { let dbQueue = try makeDatabaseQueue() XCTAssertEqual( @@ -667,7 +667,7 @@ class QueryInterfaceRequestTests: GRDBTestCase { let dbQueue = try makeDatabaseQueue() XCTAssertEqual( sql(dbQueue, tableRequest.group(Col.name).having(min(Col.age) > 18).having(max(Col.age) < 50)), - "SELECT * FROM \"readers\" GROUP BY \"name\" HAVING (MIN(\"age\") > 18) AND (MAX(\"age\") < 50)") + "SELECT * FROM \"readers\" GROUP BY \"name\" HAVING (MIN(\"age\") > 18) AND (MAX(\"age\") < 50)") } @@ -711,6 +711,14 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, tableRequest.order(abs(Col.age))), "SELECT * FROM \"readers\" ORDER BY ABS(\"age\")") + #if GRDBCUSTOMSQLITE + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.age.ascNullsLast)), + "SELECT * FROM \"readers\" ORDER BY \"age\" ASC NULLS LAST") + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.age.descNullsFirst)), + "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + #endif } func testSortWithCollation() throws { @@ -724,6 +732,14 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, tableRequest.order(Col.name.collating(collation))), "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE localized_case_insensitive") + #if GRDBCUSTOMSQLITE + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).ascNullsLast)), + "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE ASC NULLS LAST") + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).descNullsFirst)), + "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE DESC NULLS FIRST") + #endif } func testMultipleSort() throws { @@ -756,6 +772,14 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, tableRequest.order(abs(Col.age)).reversed()), "SELECT * FROM \"readers\" ORDER BY ABS(\"age\") DESC") + #if GRDBCUSTOMSQLITE + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.age.descNullsFirst).reversed()), + "SELECT * FROM \"readers\" ORDER BY \"age\" ASC NULLS LAST") + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.age.ascNullsLast).reversed()), + "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + #endif } func testReverseWithCollation() throws { @@ -769,6 +793,14 @@ class QueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, tableRequest.order(Col.name.collating(collation)).reversed()), "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE localized_case_insensitive DESC") + #if GRDBCUSTOMSQLITE + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).ascNullsLast).reversed()), + "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE DESC NULLS FIRST") + XCTAssertEqual( + sql(dbQueue, tableRequest.order(Col.name.collating(.nocase).descNullsFirst).reversed()), + "SELECT * FROM \"readers\" ORDER BY \"name\" COLLATE NOCASE ASC NULLS LAST") + #endif } func testMultipleReverse() throws { diff --git a/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift b/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift index b7791daf7..4a211a52a 100644 --- a/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift +++ b/Tests/GRDBTests/TableRecord+QueryInterfaceRequestTests.swift @@ -258,6 +258,14 @@ class TableRecordQueryInterfaceRequestTests: GRDBTestCase { XCTAssertEqual( sql(dbQueue, Reader.order(abs(Col.age))), "SELECT * FROM \"readers\" ORDER BY ABS(\"age\")") + #if GRDBCUSTOMSQLITE + XCTAssertEqual( + sql(dbQueue, Reader.order(Col.age.ascNullsLast)), + "SELECT * FROM \"readers\" ORDER BY \"age\" ASC NULLS LAST") + XCTAssertEqual( + sql(dbQueue, Reader.order(Col.age.descNullsFirst)), + "SELECT * FROM \"readers\" ORDER BY \"age\" DESC NULLS FIRST") + #endif } func testMultipleSort() throws {