const.go

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