diff --git a/Apollo.xcodeproj/project.pbxproj b/Apollo.xcodeproj/project.pbxproj index 1f898c1667..fd0bb919ff 100644 --- a/Apollo.xcodeproj/project.pbxproj +++ b/Apollo.xcodeproj/project.pbxproj @@ -247,6 +247,7 @@ DED46042261CEA8A0086EF63 /* TestServerURLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED45C172615308E0086EF63 /* TestServerURLs.swift */; }; DED46051261CEAD20086EF63 /* StarWarsAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FCE2CFA1E6C213D00E34457 /* StarWarsAPI.framework */; }; E616B6D126C3335600DB049E /* ExecutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E616B6D026C3335600DB049E /* ExecutionTests.swift */; }; + E61DD76526D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */; }; E86D8E05214B32FD0028EFE1 /* JSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E86D8E03214B32DA0028EFE1 /* JSONTests.swift */; }; F16D083C21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */; }; F82E62E122BCD223000C311B /* AutomaticPersistedQueriesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */; }; @@ -808,6 +809,7 @@ DED45FB2261CDE980086EF63 /* Apollo-CITestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-CITestPlan.xctestplan"; sourceTree = ""; }; DED45FB3261CDEC60086EF63 /* Apollo-CodegenTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-CodegenTestPlan.xctestplan"; sourceTree = ""; }; E616B6D026C3335600DB049E /* ExecutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExecutionTests.swift; sourceTree = ""; }; + E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLiteDotSwiftDatabaseBehaviorTests.swift; sourceTree = ""; }; E86D8E03214B32DA0028EFE1 /* JSONTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONTests.swift; sourceTree = ""; }; F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryFromJSONBuildingTests.swift; sourceTree = ""; }; F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutomaticPersistedQueriesTests.swift; sourceTree = ""; }; @@ -1494,6 +1496,7 @@ 9FF90A6B1DDDEB420034C3B6 /* ReadFieldValueTests.swift */, C338DF1622DD9DE9006AF33E /* RequestBodyCreatorTests.swift */, 9B96500824BE6201003C29C0 /* RequestChainTests.swift */, + E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */, 9B9BBB1A24DB75E60021C30F /* UploadRequestTests.swift */, 5BB2C0222380836100774170 /* VersionNumberTests.swift */, ); @@ -2625,6 +2628,7 @@ 9F91CF8F1F6C0DB2008DD0BE /* MutatingResultsTests.swift in Sources */, E616B6D126C3335600DB049E /* ExecutionTests.swift in Sources */, 9B9BBB1C24DB760B0021C30F /* UploadRequestTests.swift in Sources */, + E61DD76526D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift in Sources */, 9BC139A424EDCA6C00876D29 /* InterceptorTests.swift in Sources */, F82E62E122BCD223000C311B /* AutomaticPersistedQueriesTests.swift in Sources */, 9BC139A824EDCE4F00876D29 /* RetryToCountThenSucceedInterceptor.swift in Sources */, diff --git a/Sources/ApolloSQLite/SQLiteDotSwiftDatabase.swift b/Sources/ApolloSQLite/SQLiteDotSwiftDatabase.swift index 4076f12eaa..6e4028289f 100644 --- a/Sources/ApolloSQLite/SQLiteDotSwiftDatabase.swift +++ b/Sources/ApolloSQLite/SQLiteDotSwiftDatabase.swift @@ -36,7 +36,7 @@ public final class SQLiteDotSwiftDatabase: SQLiteDatabase { public func selectRawRows(forKeys keys: Set) throws -> [DatabaseRow] { let query = self.records.filter(keys.contains(keyColumn)) - return try self.db.prepare(query).map { row in + return try self.db.prepareRowIterator(query).map { row in let record = row[self.recordColumn] let key = row[self.keyColumn] diff --git a/Tests/ApolloTests/SQLiteDotSwiftDatabaseBehaviorTests.swift b/Tests/ApolloTests/SQLiteDotSwiftDatabaseBehaviorTests.swift new file mode 100644 index 0000000000..96c8a834e6 --- /dev/null +++ b/Tests/ApolloTests/SQLiteDotSwiftDatabaseBehaviorTests.swift @@ -0,0 +1,26 @@ +import XCTest +@testable import ApolloSQLite +import ApolloTestSupport +import SQLite + +class SQLiteDotSwiftDatabaseBehaviorTests: XCTestCase { + + func testSelection_withForcedError_shouldThrow() throws { + let sqliteFileURL = SQLiteTestCacheProvider.temporarySQLiteFileURL() + let db = try! SQLiteDotSwiftDatabase(fileURL: sqliteFileURL) + + try! db.createRecordsTableIfNeeded() + try! db.addOrUpdateRecordString("record", for: "key") + + var rows = [DatabaseRow]() + XCTAssertNoThrow(rows = try db.selectRawRows(forKeys: ["key"])) + XCTAssertEqual(rows.count, 1) + + // Use SQLite directly to manipulate the database (cannot be done with SQLiteDotSwiftDatabase) + let connection = try Connection(.uri(sqliteFileURL.absoluteString), readonly: false) + let table = Table(SQLiteDotSwiftDatabase.tableName) + try! connection.run(table.drop(ifExists: false)) + + XCTAssertThrowsError(try db.selectRawRows(forKeys: ["key"])) + } +}