From 8a1b5d8b23f0d80f91ad093324c14333c2fc9b9d Mon Sep 17 00:00:00 2001 From: Ox Cart Date: Thu, 28 Sep 2023 13:13:48 -0500 Subject: [PATCH] Upgraded to latest pathdb to run in WAL mode, solving issue with crash on reopening database --- DBModule/Sources/DBModule/Database.swift | 27 ++++++++++++------------ go.mod | 4 ++-- go.sum | 4 ++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/DBModule/Sources/DBModule/Database.swift b/DBModule/Sources/DBModule/Database.swift index 17be72a48..2bccf7dd4 100644 --- a/DBModule/Sources/DBModule/Database.swift +++ b/DBModule/Sources/DBModule/Database.swift @@ -64,7 +64,7 @@ class DatabaseManager: NSObject, MinisqlDBProtocol, MinisqlTxProtocol { } savepointName = nil } - + public func close() throws { // Automatically manages the database connections } @@ -90,18 +90,7 @@ class DatabaseManager: NSObject, MinisqlDBProtocol, MinisqlTxProtocol { try beginTransaction() } - do { - try statement.run(bindings) - } catch let error { - // Check if the error is a UNIQUE constraint error - //Showhow if we return same error go is not abel to catch it - let errorMessage = String(describing: error) - if errorMessage.contains("UNIQUE constraint failed") { - throw NSError(domain: "UNIQUE constraint failed", code: 19, userInfo: nil) - } else { - throw error - } - } + try runStatement(statement, bindings) return QueryResult(changes: database.changes) } @@ -121,12 +110,22 @@ class DatabaseManager: NSObject, MinisqlDBProtocol, MinisqlTxProtocol { var rows: [Statement.Element] = [] - for row in try statement.run(bindings) { + for row in try runStatement(statement, bindings) { rows.append(row) } return RowData(rows: rows) } + + func runStatement(_ statement: Statement, _ bindings: [Binding?]) throws -> Statement { + do { + return try statement.run(bindings) + } catch let SQLite.Result.error(message, code, _) { + throw NSError(domain: message, code: Int(code), userInfo: nil) + } catch let error { + throw NSError(domain: String(describing: error), code: 0, userInfo: nil) + } + } } class QueryResult: NSObject, MinisqlResultProtocol { diff --git a/go.mod b/go.mod index cecbe744f..8b018b951 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/getlantern/android-lantern go 1.19 // replace github.com/getlantern/flashlight/v7 => ../flashlight -// replace github.com/getlantern/pathdb => ../pathDb/pathDb +// replace github.com/getlantern/pathdb => ../pathdb // replace github.com/getlantern/fronted => ../fronted @@ -41,7 +41,7 @@ require ( github.com/getlantern/idletiming v0.0.0-20201229174729-33d04d220c4e github.com/getlantern/ipproxy v0.0.0-20230511223023-ee52513fd782 github.com/getlantern/mtime v0.0.0-20200417132445-23682092d1f7 - github.com/getlantern/pathdb v0.0.0-20230927035327-d2d7aea21efa + github.com/getlantern/pathdb v0.0.0-20230928181307-bc862721de69 github.com/getlantern/replica v0.14.2 github.com/gorilla/mux v1.8.0 github.com/stretchr/testify v1.8.3 diff --git a/go.sum b/go.sum index c07f5587f..72bddd572 100644 --- a/go.sum +++ b/go.sum @@ -484,8 +484,8 @@ github.com/getlantern/osversion v0.0.0-20230401075644-c2a30e73c451 h1:3Nn0AqIlIm github.com/getlantern/osversion v0.0.0-20230401075644-c2a30e73c451/go.mod h1:kaUdXyKE1Y8bwPnlN7ChFXWnkADpL0zZrk8F0XbpKcc= github.com/getlantern/packetforward v0.0.0-20201001150407-c68a447b0360 h1:pijUoofaQcAM/8zbDzZM2LQ90kGVbKfnSAkFnQwLZZU= github.com/getlantern/packetforward v0.0.0-20201001150407-c68a447b0360/go.mod h1:nsJPNYUSY96xB+p7uiDW8O4uiKea+KjeUdS5d6tf9IU= -github.com/getlantern/pathdb v0.0.0-20230927035327-d2d7aea21efa h1:NF1KTNcLBAyOp2zPG59eB6oNj60SW8cFkzltk2FmzvE= -github.com/getlantern/pathdb v0.0.0-20230927035327-d2d7aea21efa/go.mod h1:SFQy+f58IbLpnbq2nVqlq7ccwaUiO7ablKv631WVIuc= +github.com/getlantern/pathdb v0.0.0-20230928181307-bc862721de69 h1:AhBcKSQvU60dgznK3rWZyelTwx00B0By+Ekf8YG52to= +github.com/getlantern/pathdb v0.0.0-20230928181307-bc862721de69/go.mod h1:SFQy+f58IbLpnbq2nVqlq7ccwaUiO7ablKv631WVIuc= github.com/getlantern/preconn v0.0.0-20180328114929-0b5766010efe/go.mod h1:FvIxQD61iYA42UjaJyzGl9DNne8jbowbgicdeNk/7kE= github.com/getlantern/preconn v1.0.0 h1:DsY3l/y/BJUj86WyaxXylbJnCC9QbKcc3D6js6rFL60= github.com/getlantern/preconn v1.0.0/go.mod h1:i/AnXvx715Fq7HgZLlmQlw3sGfEkku8BQT5hLHMK4+k=