Enable UPSERT and RETURNING with SQLCipher

This commit is contained in:
Gwendal Roué committed 2022-08-21 21:22:34 +02:00
1 parent 8f8b273424
commit 2789444acd
14 files changed
+165 -43

No files matched your search

@@ -426,7 +426,7 @@ extension QueryInterfaceRequest {
// MARK: - Batch Delete and Fetch
extension QueryInterfaceRequest {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Returns a `DELETE ... RETURNING ...` prepared statement.
///
/// For example:
@@ -714,7 +714,7 @@ extension QueryInterfaceRequest {
// MARK: - Batch Update and Fetch
extension QueryInterfaceRequest {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Returns an `UPDATE ... RETURNING ...` prepared statement.
///
/// For example:
@@ -402,7 +402,6 @@ struct SQLQueryGenerator: Refinable {
statement.arguments = arguments
return statement
} else {
assert(sqlite3_libversion_number() >= 3035000)
let context = SQLGenerationContext(db)
var sql = sql
var arguments = arguments
@@ -190,7 +190,6 @@ final class DAO<Record: MutablePersistableRecord> {
statement.setUncheckedArguments(arguments)
return statement
} else {
assert(sqlite3_libversion_number() >= 3035000)
let context = SQLGenerationContext(db)
var sql = sql
var arguments = arguments
@@ -72,7 +72,7 @@ extension MutablePersistableRecord {
// MARK: - Insert and Fetch
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Executes an `INSERT ... RETURNING ...` statement, and returns the
/// inserted record.
///
@@ -77,7 +77,7 @@ extension MutablePersistableRecord {
// MARK: - Save and Fetch
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Executes an `INSERT ... RETURNING ...` or `UPDATE ... RETURNING ...`
/// statement, and returns the saved row.
///
@@ -150,7 +150,7 @@ extension MutablePersistableRecord {
// MARK: - Update and Fetch
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Executes an `UPDATE ... RETURNING ...` statement, and returns the
/// updated record.
///
@@ -700,7 +700,7 @@ extension MutablePersistableRecord {
// MARK: - Internals
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
@inlinable // allow specialization so that empty callbacks are removed
func updateChangesAndFetch<T>(
_ db: Database,
@@ -1,7 +1,7 @@
// MARK: - Upsert
extension MutablePersistableRecord {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Executes an `INSERT ... ON CONFLICT DO UPDATE` statement.
///
/// - parameter db: A database connection.
+1 -1
View File
@@ -36,7 +36,7 @@ extension PersistableRecord {
// MARK: - Insert and Fetch
extension PersistableRecord {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Executes an `INSERT ... RETURNING ...` statement, and returns a new
/// record built from the inserted row.
///
+1 -1
View File
@@ -32,7 +32,7 @@ extension PersistableRecord {
// MARK: - Save and Fetch
extension PersistableRecord {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Executes an `INSERT ... RETURNING ...` or `UPDATE ... RETURNING ...`
/// statement, and returns a new record built from the saved row.
///
+1 -1
View File
@@ -1,7 +1,7 @@
// MARK: - Upsert
extension PersistableRecord {
#if GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Executes an `INSERT ... ON CONFLICT DO UPDATE` statement.
///
/// - parameter db: A database connection.
@@ -1163,7 +1163,11 @@ class MutablePersistableRecordTests: GRDBTestCase {
extension MutablePersistableRecordTests {
func test_insertAndFetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1180,7 +1184,11 @@ extension MutablePersistableRecordTests {
}
func test_insertAndFetch_as() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1226,7 +1234,11 @@ extension MutablePersistableRecordTests {
}
func test_insertAndFetch_selection_fetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1276,7 +1288,11 @@ extension MutablePersistableRecordTests {
extension MutablePersistableRecordTests {
func test_saveAndFetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1293,7 +1309,11 @@ extension MutablePersistableRecordTests {
}
func test_saveAndFetch_as() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1415,7 +1435,11 @@ extension MutablePersistableRecordTests {
}
func test_saveAndFetch_selection_fetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1541,7 +1565,11 @@ extension MutablePersistableRecordTests {
extension MutablePersistableRecordTests {
func test_updateAndFetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1588,7 +1616,11 @@ extension MutablePersistableRecordTests {
}
func test_updateAndFetch_as() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1634,7 +1666,11 @@ extension MutablePersistableRecordTests {
}
func test_updateAndFetch_selection_fetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1684,7 +1720,11 @@ extension MutablePersistableRecordTests {
}
func test_updateAndFetch_columns_selection_fetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1734,7 +1774,11 @@ extension MutablePersistableRecordTests {
}
func test_updateChangesAndFetch_modify() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1791,7 +1835,11 @@ extension MutablePersistableRecordTests {
}
func test_updateChangesAndFetch_as_modify() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1847,7 +1895,11 @@ extension MutablePersistableRecordTests {
}
func test_updateChangesAndFetch_selection_fetch_modify() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1909,7 +1961,11 @@ extension MutablePersistableRecordTests {
extension MutablePersistableRecordTests {
func test_upsert() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("UPSERT is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("UPSERT is not available")
}
@@ -2054,7 +2110,11 @@ extension MutablePersistableRecordTests {
}
func test_upsertAndFetch_as() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("UPSERT is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("UPSERT is not available")
}
+30 -6
View File
@@ -1327,7 +1327,11 @@ extension PersistableRecordTests {
extension PersistableRecordTests {
func test_insertAndFetch_as() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1372,7 +1376,11 @@ extension PersistableRecordTests {
}
func test_insertAndFetch_selection_fetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1421,7 +1429,11 @@ extension PersistableRecordTests {
extension PersistableRecordTests {
func test_saveAndFetch_as() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1540,7 +1552,11 @@ extension PersistableRecordTests {
}
func test_saveAndFetch_selection_fetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -1663,7 +1679,11 @@ extension PersistableRecordTests {
extension PersistableRecordTests {
func test_upsert() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("UPSERT is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("UPSERT is not available")
}
@@ -1796,7 +1816,11 @@ extension PersistableRecordTests {
}
func test_upsertAndFetch_as() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("UPSERT is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("UPSERT is not available")
}
+30 -6
View File
@@ -230,7 +230,11 @@ class TableRecordDeleteTests: GRDBTestCase {
}
func testRequestDeleteAndFetchStatement() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -246,7 +250,11 @@ class TableRecordDeleteTests: GRDBTestCase {
}
func testRequestDeleteAndFetchCursor() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -295,7 +303,11 @@ class TableRecordDeleteTests: GRDBTestCase {
}
func testRequestDeleteAndFetchArray() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -319,7 +331,11 @@ class TableRecordDeleteTests: GRDBTestCase {
}
func testRequestDeleteAndFetchSet() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -401,7 +417,11 @@ class TableRecordDeleteTests: GRDBTestCase {
}
func testJoinedRequestDeleteAndFetch() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -564,7 +584,11 @@ class TableRecordDeleteTests: GRDBTestCase {
}
func testGroupedRequestDeleteAndFetchCursor() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
+20 -4
View File
@@ -118,7 +118,11 @@ class TableRecordUpdateTests: GRDBTestCase {
}
func testRequestUpdateAndFetchStatement() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -137,7 +141,11 @@ class TableRecordUpdateTests: GRDBTestCase {
}
func testRequestUpdateAndFetchCursor() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -160,7 +168,11 @@ class TableRecordUpdateTests: GRDBTestCase {
}
func testRequestUpdateAndFetchAll() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}
@@ -184,7 +196,11 @@ class TableRecordUpdateTests: GRDBTestCase {
}
func testRequestUpdateAndFetchSet() throws {
#if !GRDBCUSTOMSQLITE
#if GRDBCUSTOMSQLITE || GRDBCIPHER
guard sqlite3_libversion_number() >= 3035000 else {
throw XCTSkip("RETURNING clause is not available")
}
#else
guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) else {
throw XCTSkip("RETURNING clause is not available")
}