mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Database.assertExclusiveLockPrevention mirrors assertNotInsideAbortedTransactionBlock
This commit is contained in:
1 parent
d1db8406f4
commit
d85a7883bb
2 files changed
+19
-17
No files matched your search
@@ -222,13 +222,8 @@ extension Database {
|
||||
extension Database {
|
||||
|
||||
func executeUpdateStatement(_ statement: UpdateStatement) throws {
|
||||
if preventsExclusiveLock.value && statement.createsExclusiveLock {
|
||||
try? rollback()
|
||||
throw DatabaseError(
|
||||
resultCode: .SQLITE_ABORT,
|
||||
message: "Can't acquire exclusive lock",
|
||||
sql: statement.sql,
|
||||
arguments: statement.arguments)
|
||||
if statement.createsExclusiveLock {
|
||||
try assertExclusiveLockPrevention(from: statement)
|
||||
}
|
||||
|
||||
// In aborted transaction, forbid all statements but statements that
|
||||
@@ -305,13 +300,8 @@ extension Database {
|
||||
|
||||
@inline(__always)
|
||||
func selectStatementWillExecute(_ statement: SelectStatement) throws {
|
||||
if preventsExclusiveLock.value && !statement.isReadonly {
|
||||
try? rollback()
|
||||
throw DatabaseError(
|
||||
resultCode: .SQLITE_ABORT,
|
||||
message: "Can't acquire exclusive lock",
|
||||
sql: statement.sql,
|
||||
arguments: statement.arguments)
|
||||
if !statement.isReadonly {
|
||||
try assertExclusiveLockPrevention(from: statement)
|
||||
}
|
||||
|
||||
try assertNotInsideAbortedTransactionBlock(sql: statement.sql, arguments: statement.arguments)
|
||||
|
||||
@@ -707,15 +707,27 @@ extension Database {
|
||||
// - the rollback may fail, and a lock could remain.
|
||||
//
|
||||
// We work around this situation by issuing a rollback on next
|
||||
// database access which requires an exclusive lock.
|
||||
// See Database.executeUpdateStatement(_:) and
|
||||
// Database.selectStatementWillExecute(_:).
|
||||
// database access which requires an exclusive lock,
|
||||
// in preventExclusiveLock(from:).
|
||||
}
|
||||
}
|
||||
|
||||
func stopPreventingExclusiveLock() {
|
||||
preventsExclusiveLock.value = false
|
||||
}
|
||||
|
||||
func assertExclusiveLockPrevention(from statement: Statement) throws {
|
||||
if preventsExclusiveLock.value {
|
||||
// Attempt at releasing eventual exclusive lock.
|
||||
// See Database.startPreventingExclusiveLock()
|
||||
try? rollback()
|
||||
throw DatabaseError(
|
||||
resultCode: .SQLITE_ABORT,
|
||||
message: "Can't acquire exclusive lock",
|
||||
sql: statement.sql,
|
||||
arguments: statement.arguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Database {
|
||||
|
||||
Reference in new issue
Block a user