Commit phase-two API.

This commit is contained in:
Nuno Cruces
2023-06-02 13:40:08 +01:00
parent 00ba681bb5
commit f7d987fdf1
2 changed files with 17 additions and 3 deletions

View File

@@ -81,6 +81,15 @@ type FilePowersafeOverwrite interface {
SetPowersafeOverwrite(bool)
}
// FilePowersafeOverwrite extends File to implement the
// SQLITE_FCNTL_COMMIT_PHASETWO file control opcode.
//
// https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
type FileCommitPhaseTwo interface {
File
CommitPhaseTwo() error
}
// FileBatchAtomicWrite extends File to implement the
// SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE
// and SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE file control opcodes.

View File

@@ -336,6 +336,12 @@ func vfsFileControl(ctx context.Context, mod api.Module, pFile uint32, op _Fcntl
return vfsErrorCode(err, _IOERR_FSTAT)
}
case _FCNTL_COMMIT_PHASETWO:
if file, ok := file.(FileCommitPhaseTwo); ok {
err := file.CommitPhaseTwo()
return vfsErrorCode(err, _IOERR)
}
case _FCNTL_BEGIN_ATOMIC_WRITE:
if file, ok := file.(FileBatchAtomicWrite); ok {
err := file.BeginAtomicWrite()
@@ -356,9 +362,8 @@ func vfsFileControl(ctx context.Context, mod api.Module, pFile uint32, op _Fcntl
// Consider also implementing these opcodes (in use by SQLite):
// _FCNTL_PDB
// _FCNTL_BUSYHANDLER
// _FCNTL_CHUNK_SIZE
// _FCNTL_COMMIT_PHASETWO
// _FCNTL_OVERWRITE
// _FCNTL_CHUNK_SIZE
// _FCNTL_OVERWRITE
// _FCNTL_PRAGMA
// _FCNTL_SYNC
return _NOTFOUND