github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/const.go (about)

     1  package vfs
     2  
     3  import "github.com/ncruces/go-sqlite3/internal/util"
     4  
     5  const (
     6  	_MAX_NAME            = 1e6 // Self-imposed limit for most NUL terminated strings.
     7  	_MAX_SQL_LENGTH      = 1e9
     8  	_MAX_PATHNAME        = 1024
     9  	_DEFAULT_SECTOR_SIZE = 4096
    10  
    11  	ptrlen = 4
    12  )
    13  
    14  // https://sqlite.org/rescode.html
    15  type _ErrorCode uint32
    16  
    17  func (e _ErrorCode) Error() string {
    18  	return util.ErrorCodeString(uint32(e))
    19  }
    20  
    21  const (
    22  	_OK                      _ErrorCode = util.OK
    23  	_ERROR                   _ErrorCode = util.ERROR
    24  	_PERM                    _ErrorCode = util.PERM
    25  	_BUSY                    _ErrorCode = util.BUSY
    26  	_READONLY                _ErrorCode = util.READONLY
    27  	_IOERR                   _ErrorCode = util.IOERR
    28  	_NOTFOUND                _ErrorCode = util.NOTFOUND
    29  	_CANTOPEN                _ErrorCode = util.CANTOPEN
    30  	_IOERR_READ              _ErrorCode = util.IOERR_READ
    31  	_IOERR_SHORT_READ        _ErrorCode = util.IOERR_SHORT_READ
    32  	_IOERR_WRITE             _ErrorCode = util.IOERR_WRITE
    33  	_IOERR_FSYNC             _ErrorCode = util.IOERR_FSYNC
    34  	_IOERR_DIR_FSYNC         _ErrorCode = util.IOERR_DIR_FSYNC
    35  	_IOERR_TRUNCATE          _ErrorCode = util.IOERR_TRUNCATE
    36  	_IOERR_FSTAT             _ErrorCode = util.IOERR_FSTAT
    37  	_IOERR_UNLOCK            _ErrorCode = util.IOERR_UNLOCK
    38  	_IOERR_RDLOCK            _ErrorCode = util.IOERR_RDLOCK
    39  	_IOERR_DELETE            _ErrorCode = util.IOERR_DELETE
    40  	_IOERR_ACCESS            _ErrorCode = util.IOERR_ACCESS
    41  	_IOERR_CHECKRESERVEDLOCK _ErrorCode = util.IOERR_CHECKRESERVEDLOCK
    42  	_IOERR_LOCK              _ErrorCode = util.IOERR_LOCK
    43  	_IOERR_CLOSE             _ErrorCode = util.IOERR_CLOSE
    44  	_IOERR_SHMOPEN           _ErrorCode = util.IOERR_SHMOPEN
    45  	_IOERR_SHMSIZE           _ErrorCode = util.IOERR_SHMSIZE
    46  	_IOERR_SHMLOCK           _ErrorCode = util.IOERR_SHMLOCK
    47  	_IOERR_SHMMAP            _ErrorCode = util.IOERR_SHMMAP
    48  	_IOERR_SEEK              _ErrorCode = util.IOERR_SEEK
    49  	_IOERR_DELETE_NOENT      _ErrorCode = util.IOERR_DELETE_NOENT
    50  	_IOERR_BEGIN_ATOMIC      _ErrorCode = util.IOERR_BEGIN_ATOMIC
    51  	_IOERR_COMMIT_ATOMIC     _ErrorCode = util.IOERR_COMMIT_ATOMIC
    52  	_IOERR_ROLLBACK_ATOMIC   _ErrorCode = util.IOERR_ROLLBACK_ATOMIC
    53  	_CANTOPEN_FULLPATH       _ErrorCode = util.CANTOPEN_FULLPATH
    54  	_CANTOPEN_ISDIR          _ErrorCode = util.CANTOPEN_ISDIR
    55  	_READONLY_CANTINIT       _ErrorCode = util.READONLY_CANTINIT
    56  	_OK_SYMLINK              _ErrorCode = util.OK_SYMLINK
    57  )
    58  
    59  // OpenFlag is a flag for the [VFS] Open method.
    60  //
    61  // https://sqlite.org/c3ref/c_open_autoproxy.html
    62  type OpenFlag uint32
    63  
    64  const (
    65  	OPEN_READONLY      OpenFlag = 0x00000001 /* Ok for sqlite3_open_v2() */
    66  	OPEN_READWRITE     OpenFlag = 0x00000002 /* Ok for sqlite3_open_v2() */
    67  	OPEN_CREATE        OpenFlag = 0x00000004 /* Ok for sqlite3_open_v2() */
    68  	OPEN_DELETEONCLOSE OpenFlag = 0x00000008 /* VFS only */
    69  	OPEN_EXCLUSIVE     OpenFlag = 0x00000010 /* VFS only */
    70  	OPEN_AUTOPROXY     OpenFlag = 0x00000020 /* VFS only */
    71  	OPEN_URI           OpenFlag = 0x00000040 /* Ok for sqlite3_open_v2() */
    72  	OPEN_MEMORY        OpenFlag = 0x00000080 /* Ok for sqlite3_open_v2() */
    73  	OPEN_MAIN_DB       OpenFlag = 0x00000100 /* VFS only */
    74  	OPEN_TEMP_DB       OpenFlag = 0x00000200 /* VFS only */
    75  	OPEN_TRANSIENT_DB  OpenFlag = 0x00000400 /* VFS only */
    76  	OPEN_MAIN_JOURNAL  OpenFlag = 0x00000800 /* VFS only */
    77  	OPEN_TEMP_JOURNAL  OpenFlag = 0x00001000 /* VFS only */
    78  	OPEN_SUBJOURNAL    OpenFlag = 0x00002000 /* VFS only */
    79  	OPEN_SUPER_JOURNAL OpenFlag = 0x00004000 /* VFS only */
    80  	OPEN_NOMUTEX       OpenFlag = 0x00008000 /* Ok for sqlite3_open_v2() */
    81  	OPEN_FULLMUTEX     OpenFlag = 0x00010000 /* Ok for sqlite3_open_v2() */
    82  	OPEN_SHAREDCACHE   OpenFlag = 0x00020000 /* Ok for sqlite3_open_v2() */
    83  	OPEN_PRIVATECACHE  OpenFlag = 0x00040000 /* Ok for sqlite3_open_v2() */
    84  	OPEN_WAL           OpenFlag = 0x00080000 /* VFS only */
    85  	OPEN_NOFOLLOW      OpenFlag = 0x01000000 /* Ok for sqlite3_open_v2() */
    86  )
    87  
    88  // AccessFlag is a flag for the [VFS] Access method.
    89  //
    90  // https://sqlite.org/c3ref/c_access_exists.html
    91  type AccessFlag uint32
    92  
    93  const (
    94  	ACCESS_EXISTS    AccessFlag = 0
    95  	ACCESS_READWRITE AccessFlag = 1 /* Used by PRAGMA temp_store_directory */
    96  	ACCESS_READ      AccessFlag = 2 /* Unused */
    97  )
    98  
    99  // SyncFlag is a flag for the [File] Sync method.
   100  //
   101  // https://sqlite.org/c3ref/c_sync_dataonly.html
   102  type SyncFlag uint32
   103  
   104  const (
   105  	SYNC_NORMAL   SyncFlag = 0x00002
   106  	SYNC_FULL     SyncFlag = 0x00003
   107  	SYNC_DATAONLY SyncFlag = 0x00010
   108  )
   109  
   110  // LockLevel is a value used with [File] Lock and Unlock methods.
   111  //
   112  // https://sqlite.org/c3ref/c_lock_exclusive.html
   113  type LockLevel uint32
   114  
   115  const (
   116  	// No locks are held on the database.
   117  	// The database may be neither read nor written.
   118  	// Any internally cached data is considered suspect and subject to
   119  	// verification against the database file before being used.
   120  	// Other processes can read or write the database as their own locking
   121  	// states permit.
   122  	// This is the default state.
   123  	LOCK_NONE LockLevel = 0 /* xUnlock() only */
   124  
   125  	// The database may be read but not written.
   126  	// Any number of processes can hold SHARED locks at the same time,
   127  	// hence there can be many simultaneous readers.
   128  	// But no other thread or process is allowed to write to the database file
   129  	// while one or more SHARED locks are active.
   130  	LOCK_SHARED LockLevel = 1 /* xLock() or xUnlock() */
   131  
   132  	// A RESERVED lock means that the process is planning on writing to the
   133  	// database file at some point in the future but that it is currently just
   134  	// reading from the file.
   135  	// Only a single RESERVED lock may be active at one time,
   136  	// though multiple SHARED locks can coexist with a single RESERVED lock.
   137  	// RESERVED differs from PENDING in that new SHARED locks can be acquired
   138  	// while there is a RESERVED lock.
   139  	LOCK_RESERVED LockLevel = 2 /* xLock() only */
   140  
   141  	// A PENDING lock means that the process holding the lock wants to write to
   142  	// the database as soon as possible and is just waiting on all current
   143  	// SHARED locks to clear so that it can get an EXCLUSIVE lock.
   144  	// No new SHARED locks are permitted against the database if a PENDING lock
   145  	// is active, though existing SHARED locks are allowed to continue.
   146  	LOCK_PENDING LockLevel = 3 /* internal use only */
   147  
   148  	// An EXCLUSIVE lock is needed in order to write to the database file.
   149  	// Only one EXCLUSIVE lock is allowed on the file and no other locks of any
   150  	// kind are allowed to coexist with an EXCLUSIVE lock.
   151  	// In order to maximize concurrency, SQLite works to minimize the amount of
   152  	// time that EXCLUSIVE locks are held.
   153  	LOCK_EXCLUSIVE LockLevel = 4 /* xLock() only */
   154  )
   155  
   156  // DeviceCharacteristic is a flag retuned by the [File] DeviceCharacteristics method.
   157  //
   158  // https://sqlite.org/c3ref/c_iocap_atomic.html
   159  type DeviceCharacteristic uint32
   160  
   161  const (
   162  	IOCAP_ATOMIC                DeviceCharacteristic = 0x00000001
   163  	IOCAP_ATOMIC512             DeviceCharacteristic = 0x00000002
   164  	IOCAP_ATOMIC1K              DeviceCharacteristic = 0x00000004
   165  	IOCAP_ATOMIC2K              DeviceCharacteristic = 0x00000008
   166  	IOCAP_ATOMIC4K              DeviceCharacteristic = 0x00000010
   167  	IOCAP_ATOMIC8K              DeviceCharacteristic = 0x00000020
   168  	IOCAP_ATOMIC16K             DeviceCharacteristic = 0x00000040
   169  	IOCAP_ATOMIC32K             DeviceCharacteristic = 0x00000080
   170  	IOCAP_ATOMIC64K             DeviceCharacteristic = 0x00000100
   171  	IOCAP_SAFE_APPEND           DeviceCharacteristic = 0x00000200
   172  	IOCAP_SEQUENTIAL            DeviceCharacteristic = 0x00000400
   173  	IOCAP_UNDELETABLE_WHEN_OPEN DeviceCharacteristic = 0x00000800
   174  	IOCAP_POWERSAFE_OVERWRITE   DeviceCharacteristic = 0x00001000
   175  	IOCAP_IMMUTABLE             DeviceCharacteristic = 0x00002000
   176  	IOCAP_BATCH_ATOMIC          DeviceCharacteristic = 0x00004000
   177  )
   178  
   179  // https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html
   180  type _FcntlOpcode uint32
   181  
   182  const (
   183  	_FCNTL_LOCKSTATE             _FcntlOpcode = 1
   184  	_FCNTL_GET_LOCKPROXYFILE     _FcntlOpcode = 2
   185  	_FCNTL_SET_LOCKPROXYFILE     _FcntlOpcode = 3
   186  	_FCNTL_LAST_ERRNO            _FcntlOpcode = 4
   187  	_FCNTL_SIZE_HINT             _FcntlOpcode = 5
   188  	_FCNTL_CHUNK_SIZE            _FcntlOpcode = 6
   189  	_FCNTL_FILE_POINTER          _FcntlOpcode = 7
   190  	_FCNTL_SYNC_OMITTED          _FcntlOpcode = 8
   191  	_FCNTL_WIN32_AV_RETRY        _FcntlOpcode = 9
   192  	_FCNTL_PERSIST_WAL           _FcntlOpcode = 10
   193  	_FCNTL_OVERWRITE             _FcntlOpcode = 11
   194  	_FCNTL_VFSNAME               _FcntlOpcode = 12
   195  	_FCNTL_POWERSAFE_OVERWRITE   _FcntlOpcode = 13
   196  	_FCNTL_PRAGMA                _FcntlOpcode = 14
   197  	_FCNTL_BUSYHANDLER           _FcntlOpcode = 15
   198  	_FCNTL_TEMPFILENAME          _FcntlOpcode = 16
   199  	_FCNTL_MMAP_SIZE             _FcntlOpcode = 18
   200  	_FCNTL_TRACE                 _FcntlOpcode = 19
   201  	_FCNTL_HAS_MOVED             _FcntlOpcode = 20
   202  	_FCNTL_SYNC                  _FcntlOpcode = 21
   203  	_FCNTL_COMMIT_PHASETWO       _FcntlOpcode = 22
   204  	_FCNTL_WIN32_SET_HANDLE      _FcntlOpcode = 23
   205  	_FCNTL_WAL_BLOCK             _FcntlOpcode = 24
   206  	_FCNTL_ZIPVFS                _FcntlOpcode = 25
   207  	_FCNTL_RBU                   _FcntlOpcode = 26
   208  	_FCNTL_VFS_POINTER           _FcntlOpcode = 27
   209  	_FCNTL_JOURNAL_POINTER       _FcntlOpcode = 28
   210  	_FCNTL_WIN32_GET_HANDLE      _FcntlOpcode = 29
   211  	_FCNTL_PDB                   _FcntlOpcode = 30
   212  	_FCNTL_BEGIN_ATOMIC_WRITE    _FcntlOpcode = 31
   213  	_FCNTL_COMMIT_ATOMIC_WRITE   _FcntlOpcode = 32
   214  	_FCNTL_ROLLBACK_ATOMIC_WRITE _FcntlOpcode = 33
   215  	_FCNTL_LOCK_TIMEOUT          _FcntlOpcode = 34
   216  	_FCNTL_DATA_VERSION          _FcntlOpcode = 35
   217  	_FCNTL_SIZE_LIMIT            _FcntlOpcode = 36
   218  	_FCNTL_CKPT_DONE             _FcntlOpcode = 37
   219  	_FCNTL_RESERVE_BYTES         _FcntlOpcode = 38
   220  	_FCNTL_CKPT_START            _FcntlOpcode = 39
   221  	_FCNTL_EXTERNAL_READER       _FcntlOpcode = 40
   222  	_FCNTL_CKSM_FILE             _FcntlOpcode = 41
   223  	_FCNTL_RESET_CACHE           _FcntlOpcode = 42
   224  )
   225  
   226  // https://sqlite.org/c3ref/c_shm_exclusive.html
   227  type _ShmFlag uint32
   228  
   229  const (
   230  	_SHM_UNLOCK    _ShmFlag = 1
   231  	_SHM_LOCK      _ShmFlag = 2
   232  	_SHM_SHARED    _ShmFlag = 4
   233  	_SHM_EXCLUSIVE _ShmFlag = 8
   234  )