@@ -220,8 +220,7 @@ class DatabaseObservationBroker {
220
220
221
221
/// Prepares observation of changes that are about to be performed by the statement.
222
222
func statementWillExecute( _ statement: Statement ) {
223
- // If any observer observes row deletions, we'll have to disable
224
- if transactionObservations. isEmpty == false {
223
+ if !database. isReadOnly && !transactionObservations. isEmpty {
225
224
// As statement executes, it may trigger database changes that will
226
225
// be notified to transaction observers. As a consequence, observers
227
226
// may disable themselves with stopObservingDatabaseChangesUntilNextTransaction()
@@ -310,7 +309,7 @@ class DatabaseObservationBroker {
310
309
// SQLITE_CONSTRAINT error)
311
310
databaseDidRollback ( notifyTransactionObservers: false )
312
311
case . cancelledCommit( let error) :
313
- databaseDidRollback ( notifyTransactionObservers: true )
312
+ databaseDidRollback ( notifyTransactionObservers: !database . isReadOnly )
314
313
throw error
315
314
default :
316
315
break
@@ -382,7 +381,7 @@ class DatabaseObservationBroker {
382
381
case . commit:
383
382
databaseDidCommit ( )
384
383
case . rollback:
385
- databaseDidRollback ( notifyTransactionObservers: true )
384
+ databaseDidRollback ( notifyTransactionObservers: !database . isReadOnly )
386
385
default :
387
386
break
388
387
}
@@ -391,6 +390,8 @@ class DatabaseObservationBroker {
391
390
#if SQLITE_ENABLE_PREUPDATE_HOOK
392
391
// Called from sqlite3_preupdate_hook
393
392
private func databaseWillChange( with event: DatabasePreUpdateEvent ) {
393
+ assert ( !database. isReadOnly, " Read-only transactions are not notified " )
394
+
394
395
if savepointStack. isEmpty {
395
396
// Notify now
396
397
for (observation, predicate) in statementObservations where predicate. evaluate ( event) {
@@ -405,6 +406,8 @@ class DatabaseObservationBroker {
405
406
406
407
// Called from sqlite3_update_hook
407
408
private func databaseDidChange( with event: DatabaseEvent ) {
409
+ assert ( !database. isReadOnly, " Read-only transactions are not notified " )
410
+
408
411
// We're about to call the databaseDidChange(with:) method of
409
412
// transaction observers. In this method, observers may disable
410
413
// themselves with stopObservingDatabaseChangesUntilNextTransaction()
@@ -430,18 +433,23 @@ class DatabaseObservationBroker {
430
433
// Called from sqlite3_commit_hook and databaseDidCommitEmptyDeferredTransaction()
431
434
private func databaseWillCommit( ) throws {
432
435
notifyBufferedEvents ( )
433
- for observation in transactionObservations {
434
- try observation. databaseWillCommit ( )
436
+ if !database. isReadOnly {
437
+ for observation in transactionObservations {
438
+ try observation. databaseWillCommit ( )
439
+ }
435
440
}
436
441
}
437
442
438
443
// Called from statementDidExecute
439
444
private func databaseDidCommit( ) {
440
445
savepointStack. clear ( )
441
446
442
- for observation in transactionObservations {
443
- observation. databaseDidCommit ( database)
447
+ if !database. isReadOnly {
448
+ for observation in transactionObservations {
449
+ observation. databaseDidCommit ( database)
450
+ }
444
451
}
452
+
445
453
databaseDidEndTransaction ( )
446
454
}
447
455
@@ -485,7 +493,7 @@ class DatabaseObservationBroker {
485
493
try databaseWillCommit ( )
486
494
databaseDidCommit ( )
487
495
} catch {
488
- databaseDidRollback ( notifyTransactionObservers: true )
496
+ databaseDidRollback ( notifyTransactionObservers: !database . isReadOnly )
489
497
throw error
490
498
}
491
499
}
@@ -495,6 +503,7 @@ class DatabaseObservationBroker {
495
503
savepointStack. clear ( )
496
504
497
505
if notifyTransactionObservers {
506
+ assert ( !database. isReadOnly, " Read-only transactions are not notified " )
498
507
for observation in transactionObservations {
499
508
observation. databaseDidRollback ( database)
500
509
}
@@ -566,6 +575,7 @@ class DatabaseObservationBroker {
566
575
savepointStack. clear ( )
567
576
568
577
for (event, statementObservations) in eventsBuffer {
578
+ assert ( statementObservations. isEmpty || !database. isReadOnly, " Read-only transactions are not notified " )
569
579
for (observation, predicate) in statementObservations where predicate. evaluate ( event) {
570
580
event. send ( to: observation)
571
581
}
0 commit comments