Skip to content

Commit b276402

Browse files
committed
Fix readTransaction throwing for connection pools
1 parent 0b150e0 commit b276402

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.14.2
4+
5+
* Fix `readTransaction` throwing. This issue was introduced in version 1.14.0.
6+
37
## 1.14.1
48

59
* [Internal] The GRDB integration uses high-level GRDB APIs to run statements.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// The current version of the PowerSync Swift SDK. This should be updated to the latest version in `CHANGELOG.md` when a new version is released.
2-
let libraryVersion = "1.14.1"
2+
let libraryVersion = "1.14.2"

Sources/PowerSync/Implementation/AsyncConnectionPool.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ final class AsyncConnectionPool: SQLiteConnectionPoolProtocol {
9090

9191
if isWriter {
9292
let _ = try context.execute(sql: "pragma journal_mode = WAL", parameters: [])
93-
} else {
94-
// This is mainly an additional safety element, we also open read connections SQLITE_READONLY.
95-
let _ = try context.execute(sql: "pragma query_only = TRUE", parameters: [])
9693
}
9794

9895
let _ = try context.execute(sql: "pragma journal_size_limit = \(6 * 1024 * 1024)", parameters: [])
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Foundation
2+
@testable import PowerSync
3+
import Testing
4+
5+
struct DatabaseImplementationTests {
6+
@Test func readTransaction() async throws {
7+
// Regression test for https://github.com/powersync-ja/powersync-swift/issues/142.
8+
let db = PowerSyncDatabase(
9+
schema: Schema(),
10+
dbFilename: "read-tx-regression-test",
11+
logger: DefaultLogger()
12+
)
13+
14+
let error = try await db.readTransaction { tx in
15+
try tx.get(sql: "SELECT 1", parameters: [], mapper: { cursor in })
16+
17+
// Writing to the database in a read-only connection must fail.
18+
let error = #expect(throws: PowerSyncError.self) {
19+
try tx.execute(sql: "DELETE FROM ps_kv", parameters: [])
20+
}
21+
return try #require(error?.errorDescription)
22+
}
23+
try await db.close(deleteDatabase: true)
24+
#expect(error.contains("attempt to write a readonly database") == true)
25+
}
26+
}

0 commit comments

Comments
 (0)