@@ -90,6 +90,7 @@ type mvccFile struct {
9090 data * wbt.Tree [int64 , string ]
9191 lock vfs.LockLevel
9292 readOnly bool
93+ wrflag bool
9394}
9495
9596var (
@@ -212,6 +213,14 @@ func (m *mvccFile) Truncate(size int64) error {
212213 return nil
213214}
214215
216+ func (m * mvccFile ) Pragma (name , value string ) (string , error ) {
217+ // notest // https://sqlite.org/forum/forumpost/c4ca8e7f4a887aa4
218+ if name == "experimental_pragma_20251114" {
219+ m .wrflag = true
220+ }
221+ return "" , sqlite3 .NOTFOUND
222+ }
223+
215224func (m * mvccFile ) Lock (lock vfs.LockLevel ) error {
216225 if m .lock >= lock {
217226 return nil
@@ -225,7 +234,7 @@ func (m *mvccFile) Lock(lock vfs.LockLevel) error {
225234 defer m .mtx .Unlock ()
226235
227236 // Take a snapshot of the database.
228- if lock == vfs .LOCK_SHARED {
237+ if lock == vfs .LOCK_SHARED && ! m . wrflag {
229238 m .data = m .mvccDB .data
230239 m .lock = lock
231240 return nil
@@ -244,7 +253,7 @@ func (m *mvccFile) Lock(lock vfs.LockLevel) error {
244253 defer time .AfterFunc (time .Millisecond , m .waiter .Broadcast ).Stop ()
245254 for m .owner != nil {
246255 // Our snapshot is invalid.
247- if m .data != m .mvccDB .data {
256+ if m .data != nil && m . data != m .mvccDB .data {
248257 return sqlite3 .BUSY_SNAPSHOT
249258 }
250259 if time .Since (before ) > time .Millisecond {
@@ -253,11 +262,15 @@ func (m *mvccFile) Lock(lock vfs.LockLevel) error {
253262 m .waiter .Wait ()
254263 }
255264 }
256- // Our snapshot is invalid.
257- if m .data != m .mvccDB .data {
265+ switch {
266+ case m .data == nil :
267+ m .data = m .mvccDB .data
268+ case m .data != m .mvccDB .data :
269+ // Our snapshot is invalid.
258270 return sqlite3 .BUSY_SNAPSHOT
259271 }
260272 // Take ownership.
273+ m .wrflag = false
261274 m .lock = lock
262275 m .owner = m
263276 return nil
0 commit comments