Skip to content

Commit

Permalink
Refine attach and detach database
Browse files Browse the repository at this point in the history
  • Loading branch information
guanlisheng committed Dec 17, 2024
1 parent 571e552 commit 182c2d2
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions MMEX/App/MMEXDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ extension ViewModel {
defer { url.stopAccessingSecurityScopedResource() }
do {
// Attach the external database
let attachSQL = "ATTACH DATABASE ? AS ?"
try db.run(attachSQL, url.path, resolvedAlias)
try db.attach(.uri(url.path, parameters: [.mode(.readOnly)]), as: resolvedAlias)
log.info("Successfully attached database at \(url.path) as \(resolvedAlias)")
} catch {
log.error("Failed to attach database: \(error)")
Expand All @@ -88,10 +87,9 @@ extension ViewModel {
return
}
// Determine the alias to detach
let resolvedAlias = alias ?? "attachedDB" // Default alias if none is provided
let resolvedAlias = alias ?? "attach" // Default alias if none is provided
do {
let detachSQL = "DETACH DATABASE ?"
try db.run(detachSQL, alias)
try db.detach(resolvedAlias)
log.info("Successfully detached database with alias \(resolvedAlias)")
} catch {
log.error("Failed to detach database: \(error)")
Expand Down

0 comments on commit 182c2d2

Please sign in to comment.