Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GRDB/Core/Database+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ extension Database {
}
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Returns information about a table or a view
func table(_ tableName: String) throws -> TableInfo? {
for schemaID in try fetchSchemaIdentifiers() {
Expand Down Expand Up @@ -575,7 +575,7 @@ extension Database {
/// - precondition: table exists.
private func fetchTableHasRowID(_ table: DatabaseObjectID) throws -> Bool {
// Prefer PRAGMA table_list if available
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
// Maybe SQLCipher is too old: check actual version
if sqlite3_libversion_number() >= 3037000 {
return try self.table(for: table)!.isWithoutRowIDTable == false
Expand Down
4 changes: 2 additions & 2 deletions GRDB/Core/DatabaseWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ extension DatabaseWriter {
// This method is declared on DatabaseWriter instead of DatabaseReader,
// so that it is not available on DatabaseSnaphot. VACUUM INTO is not
// available inside the transaction that is kept open by DatabaseSnaphot.
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Creates a new database file at the specified path with a minimum
/// amount of disk space.
///
Expand Down Expand Up @@ -665,7 +665,7 @@ extension DatabaseWriter {
try await writeWithoutTransaction { try $0.execute(sql: "VACUUM") }
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Creates a new database file at the specified path with a minimum
/// amount of disk space.
///
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Dump/Database+Dump.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ extension Database {
}

private func isShadowTable(_ tableName: String) throws -> Bool {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
// Maybe SQLCipher is too old: check actual version
if Database.sqliteLibVersionNumber >= 3037000 {
guard let table = try table(tableName) else {
Expand Down
4 changes: 2 additions & 2 deletions GRDB/FTS/FTS3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public struct FTS3 {
/// the `remove_diacritics=1` tokenizer argument.
case removeLegacy

#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Remove diacritics from Latin script characters. This option matches
/// the `remove_diacritics=2` tokenizer argument.
case remove
#elseif !GRDBCIPHER
#else
/// Remove diacritics from Latin script characters. This option matches
/// the `remove_diacritics=2` tokenizer argument.
@available(iOS 14, macOS 10.16, tvOS 14, *) // SQLite 3.27+
Expand Down
4 changes: 2 additions & 2 deletions GRDB/FTS/FTS3TokenizerDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ public struct FTS3TokenizerDescriptor: Sendable {
break
case .keep:
arguments.append("remove_diacritics=0")
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
case .remove:
arguments.append("remove_diacritics=2")
#elseif !GRDBCIPHER
#else
case .remove:
arguments.append("remove_diacritics=2")
#endif
Expand Down
4 changes: 2 additions & 2 deletions GRDB/FTS/FTS5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public struct FTS5 {
/// Remove diacritics from Latin script characters. This
/// option matches the raw "remove_diacritics=1" tokenizer argument.
case removeLegacy
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Remove diacritics from Latin script characters. This
/// option matches the raw "remove_diacritics=2" tokenizer argument,
/// available from SQLite 3.27.0
case remove
#elseif !GRDBCIPHER
#else
/// Remove diacritics from Latin script characters. This
/// option matches the raw "remove_diacritics=2" tokenizer argument,
/// available from SQLite 3.27.0
Expand Down
4 changes: 2 additions & 2 deletions GRDB/FTS/FTS5TokenizerDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ public struct FTS5TokenizerDescriptor: Sendable {
break
case .keep:
components.append(contentsOf: ["remove_diacritics", "0"])
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
case .remove:
components.append(contentsOf: ["remove_diacritics", "2"])
#elseif !GRDBCIPHER
#else
case .remove:
components.append(contentsOf: ["remove_diacritics", "2"])
#endif
Expand Down
2 changes: 1 addition & 1 deletion GRDB/JSON/SQLJSONExpressible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ extension SQLSpecificExpressible {
}
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
extension SQLJSONExpressible {
/// The `->>` SQL operator.
///
Expand Down
2 changes: 1 addition & 1 deletion GRDB/JSON/SQLJSONFunctions.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
// MARK: - JSON

extension Database {
Expand Down
4 changes: 2 additions & 2 deletions GRDB/QueryInterface/Request/QueryInterfaceRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ extension QueryInterfaceRequest {
// MARK: - Batch Delete and Fetch

extension QueryInterfaceRequest {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Returns a `DELETE RETURNING` prepared statement.
///
/// For example:
Expand Down Expand Up @@ -1176,7 +1176,7 @@ extension QueryInterfaceRequest {
// MARK: - Batch Update and Fetch

extension QueryInterfaceRequest {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Returns an `UPDATE RETURNING` prepared statement.
///
/// For example:
Expand Down
8 changes: 4 additions & 4 deletions GRDB/QueryInterface/SQL/SQLExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public struct SQLExpression: Sendable {
/// The `>>` bitwise right shift operator
static let rightShift = BinaryOperator(">>")

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `->` SQL operator
static let jsonExtractJSON = BinaryOperator("->", isJSONValue: true)

Expand Down Expand Up @@ -2121,7 +2121,7 @@ extension SQLExpression {
}
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Returns an expression suitable in JSON building contexts.
var jsonBuilderExpression: SQLExpression {
switch preferredJSONInterpretation {
Expand Down Expand Up @@ -2373,7 +2373,7 @@ extension SQLSpecificExpressible {
.desc(sqlExpression)
}

#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// An ordering term for ascending order (nulls last).
public var ascNullsLast: SQLOrdering {
.ascNullsLast(sqlExpression)
Expand All @@ -2383,7 +2383,7 @@ extension SQLSpecificExpressible {
public var descNullsFirst: SQLOrdering {
.descNullsFirst(sqlExpression)
}
#elseif !GRDBCIPHER
#else
/// An ordering term for ascending order (nulls last).
@available(iOS 14, macOS 10.16, tvOS 14, *) // SQLite 3.30+
public var ascNullsLast: SQLOrdering {
Expand Down
10 changes: 5 additions & 5 deletions GRDB/QueryInterface/SQL/SQLFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public func abs(_ value: some SQLSpecificExpressible) -> SQLExpression {
.function("ABS", [value.sqlExpression])
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `AVG` SQL aggregate function.
///
/// For example:
Expand Down Expand Up @@ -163,7 +163,7 @@ public func max(
.simpleFunction("MAX", [value1.sqlExpression, value2.sqlExpression] + values.map(\.sqlExpression))
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `MAX` SQL aggregate function.
///
/// For example:
Expand Down Expand Up @@ -224,7 +224,7 @@ public func min(
.simpleFunction("MIN", [value1.sqlExpression, value2.sqlExpression] + values.map(\.sqlExpression))
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `MIN` SQL aggregate function.
///
/// For example:
Expand Down Expand Up @@ -269,7 +269,7 @@ public func min(_ value: some SQLSpecificExpressible) -> SQLExpression {
}
#endif

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `SUM` SQL aggregate function.
///
/// For example:
Expand Down Expand Up @@ -333,7 +333,7 @@ public func sum(_ value: some SQLSpecificExpressible) -> SQLExpression {
}
#endif

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// The `TOTAL` SQL aggregate function.
///
/// For example:
Expand Down
2 changes: 1 addition & 1 deletion GRDB/QueryInterface/SQLGeneration/SQLTableGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct SQLTableGenerator {

var tableOptions: [String] = []

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
if options.contains(.strict) {
tableOptions.append("STRICT")
}
Expand Down
2 changes: 1 addition & 1 deletion GRDB/QueryInterface/Schema/ColumnDefinition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public final class ColumnDefinition {
return self
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Defines the column as a generated column.
///
/// For example:
Expand Down
2 changes: 1 addition & 1 deletion GRDB/QueryInterface/Schema/TableAlteration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public final class TableAlteration {
alterations.append(.addColumnLiteral(literal))
}

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Renames a column.
///
/// For example:
Expand Down
2 changes: 1 addition & 1 deletion GRDB/QueryInterface/Schema/TableDefinition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct TableOptions: OptionSet, Sendable {
/// Such tables can not be tracked with <doc:DatabaseObservation> tools.
public static let withoutRowID = TableOptions(rawValue: 1 << 2)

#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Creates a [STRICT](https://www.sqlite.org/stricttables.html) table.
public static let strict = TableOptions(rawValue: 1 << 3)
#else
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Record/MutablePersistableRecord+Insert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension MutablePersistableRecord {
// MARK: - Insert and Fetch

extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT RETURNING` statement, and returns a new record built
/// from the inserted row.
///
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Record/MutablePersistableRecord+Save.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension MutablePersistableRecord {
// MARK: - Save and Fetch

extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT RETURNING` or `UPDATE RETURNING` statement, and
/// returns a new record built from the saved row.
///
Expand Down
4 changes: 2 additions & 2 deletions GRDB/Record/MutablePersistableRecord+Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ extension MutablePersistableRecord {
// MARK: - Update and Fetch

extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `UPDATE RETURNING` statement on all columns, and returns a
/// new record built from the updated row.
///
Expand Down Expand Up @@ -839,7 +839,7 @@ extension MutablePersistableRecord {
// MARK: - Internals

extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
@inlinable // allow specialization so that empty callbacks are removed
func updateChangesAndFetch<T>(
_ db: Database,
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Record/MutablePersistableRecord+Upsert.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// MARK: - Upsert

extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT ON CONFLICT DO UPDATE` statement.
///
/// The upsert behavior is triggered by a violation of any uniqueness
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Record/PersistableRecord+Insert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension PersistableRecord {
// MARK: - Insert and Fetch

extension PersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT RETURNING` statement, and returns a new record built
/// from the inserted row.
///
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Record/PersistableRecord+Save.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension PersistableRecord {
// MARK: - Save and Fetch

extension PersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT RETURNING` or `UPDATE RETURNING` statement, and
/// returns a new record built from the saved row.
///
Expand Down
2 changes: 1 addition & 1 deletion GRDB/Record/PersistableRecord+Upsert.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// MARK: - Upsert

extension PersistableRecord {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
/// Executes an `INSERT ON CONFLICT DO UPDATE` statement.
///
/// The upsert behavior is triggered by a violation of any uniqueness
Expand Down
9 changes: 6 additions & 3 deletions Tests/GRDBTests/FTS3TableBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ class FTS3TableBuilderTests: GRDBTestCase {
}
}

#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
func testUnicode61TokenizerDiacriticsRemove() throws {
guard Database.sqliteLibVersionNumber >= 3027000 else {
throw XCTSkip("remove_diacritics=2 is not available")
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
Expand All @@ -96,10 +99,10 @@ class FTS3TableBuilderTests: GRDBTestCase {
assertDidExecute(sql: "CREATE VIRTUAL TABLE \"documents\" USING fts3(tokenize=unicode61 \"remove_diacritics=2\")")
}
}
#elseif !GRDBCIPHER
#else
func testUnicode61TokenizerDiacriticsRemove() throws {
guard #available(iOS 14, macOS 10.16, tvOS 14, *) else {
throw XCTSkip()
throw XCTSkip("remove_diacritics=2 is not available")
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
Expand Down
29 changes: 28 additions & 1 deletion Tests/GRDBTests/FTS3TokenizerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,35 @@ class FTS3TokenizerTests: GRDBTestCase {
}
}

#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || SQLITE_HAS_CODEC
func testUnicode61TokenizerDiacriticsRemove() throws {
guard Database.sqliteLibVersionNumber >= 3027000 else {
throw XCTSkip("remove_diacritics=2 is not available")
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
t.tokenizer = .unicode61(diacritics: .remove)
}

// simple match
XCTAssertTrue(match(db, "abcDÉF", "abcDÉF"))

// English stemming
XCTAssertFalse(match(db, "database", "databases"))

// diacritics in latin characters
XCTAssertTrue(match(db, "eéÉ", "Èèe"))

// unicode case
XCTAssertTrue(match(db, "jérôme", "JÉRÔME"))
}
}
#else
func testUnicode61TokenizerDiacriticsRemove() throws {
guard #available(iOS 14, macOS 10.16, tvOS 14, *) else {
throw XCTSkip("remove_diacritics=2 is not available")
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(virtualTable: "documents", using: FTS3()) { t in
Expand Down
Loading