diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index ae30f0f4f..bcce91c53 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -6,6 +6,7 @@ import SQLite3 #elseif GRDBCUSTOMSQLITE // GRDBCustom Framework #elseif SQLCipher import SQLCipher +import GRDBSQLCipher #else // Default SPM trait must be the default. It impossible to detect from Xcode. import GRDBSQLite #endif diff --git a/Package.swift b/Package.swift index 26c61734a..606b665ef 100644 --- a/Package.swift +++ b/Package.swift @@ -36,6 +36,12 @@ if ProcessInfo.processInfo.environment["SPI_BUILDER"] == "1" { dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")) } +// GRDB+SQLCipher: Uncomment those lines +//dependencies.append(.package(url: "https://github.com/sqlcipher/SQLCipher.swift.git", from: "4.11.0")) +//cSettings.append(.define("SQLITE_HAS_CODEC")) +//swiftSettings.append(.define("SQLITE_HAS_CODEC")) +//swiftSettings.append(.define("SQLCipher")) + let package = Package( name: "GRDB", defaultLocalization: "en", // for tests @@ -46,19 +52,30 @@ let package = Package( .watchOS(.v7), ], products: [ + // GRDB+SQLCipher: Delete the GRDBSQLite library .library(name: "GRDBSQLite", targets: ["GRDBSQLite"]), .library(name: "GRDB", targets: ["GRDB"]), .library(name: "GRDB-dynamic", type: .dynamic, targets: ["GRDB"]), ], dependencies: dependencies, targets: [ + // GRDB+SQLCipher: Delete the GRDBSQLite target .systemLibrary( name: "GRDBSQLite", providers: [.apt(["libsqlite3-dev"])]), + // GRDB+SQLCipher: Uncomment the GRDBSQLCipher target + //.target( + // name: "GRDBSQLCipher", + // dependencies: [.product(name: "SQLCipher", package: "SQLCipher.swift")] + //), .target( name: "GRDB", dependencies: [ + // GRDB+SQLCipher: Delete the GRDBSQLite dependency .target(name: "GRDBSQLite"), + // GRDB+SQLCipher: Uncomment the SQLCipher and GRDBSQLCipher dependencies + //.product(name: "SQLCipher", package: "SQLCipher.swift"), + //.target(name: "GRDBSQLCipher"), ], path: "GRDB", resources: [.copy("PrivacyInfo.xcprivacy")], @@ -85,6 +102,7 @@ let package = Package( .copy("GRDBTests/Betty.jpeg"), .copy("GRDBTests/InflectionsTests.json"), .copy("GRDBTests/Issue1383.sqlite"), + .copy("GRDBTests/db.SQLCipher3"), ], cSettings: cSettings, swiftSettings: swiftSettings + [ diff --git a/Sources/GRDBSQLCipher/SQLCipher_config.c b/Sources/GRDBSQLCipher/SQLCipher_config.c new file mode 100644 index 000000000..26b22bdb9 --- /dev/null +++ b/Sources/GRDBSQLCipher/SQLCipher_config.c @@ -0,0 +1 @@ +// empty c-file diff --git a/Sources/GRDBSQLCipher/include/SQLCipher_config.h b/Sources/GRDBSQLCipher/include/SQLCipher_config.h new file mode 100644 index 000000000..a405306f6 --- /dev/null +++ b/Sources/GRDBSQLCipher/include/SQLCipher_config.h @@ -0,0 +1,32 @@ +#ifndef grdb_config_h +#define grdb_config_h + +#include + +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. +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 +#endif /* grdb_config_h */ diff --git a/Sources/GRDBSQLCipher/include/module.modulemap b/Sources/GRDBSQLCipher/include/module.modulemap new file mode 100644 index 000000000..b5e64c362 --- /dev/null +++ b/Sources/GRDBSQLCipher/include/module.modulemap @@ -0,0 +1,4 @@ +module GRDBSQLCipher { + header "SQLCipher_config.h" + export * + }