1.Dd December 19, 2018 2.Dt SQLITE_FCNTL_LOCKSTATE 3 3.Os 4.Sh NAME 5.Nm SQLITE_FCNTL_LOCKSTATE , 6.Nm SQLITE_FCNTL_GET_LOCKPROXYFILE , 7.Nm SQLITE_FCNTL_SET_LOCKPROXYFILE , 8.Nm SQLITE_FCNTL_LAST_ERRNO , 9.Nm SQLITE_FCNTL_SIZE_HINT , 10.Nm SQLITE_FCNTL_CHUNK_SIZE , 11.Nm SQLITE_FCNTL_FILE_POINTER , 12.Nm SQLITE_FCNTL_SYNC_OMITTED , 13.Nm SQLITE_FCNTL_WIN32_AV_RETRY , 14.Nm SQLITE_FCNTL_PERSIST_WAL , 15.Nm SQLITE_FCNTL_OVERWRITE , 16.Nm SQLITE_FCNTL_VFSNAME , 17.Nm SQLITE_FCNTL_POWERSAFE_OVERWRITE , 18.Nm SQLITE_FCNTL_PRAGMA , 19.Nm SQLITE_FCNTL_BUSYHANDLER , 20.Nm SQLITE_FCNTL_TEMPFILENAME , 21.Nm SQLITE_FCNTL_MMAP_SIZE , 22.Nm SQLITE_FCNTL_TRACE , 23.Nm SQLITE_FCNTL_HAS_MOVED , 24.Nm SQLITE_FCNTL_SYNC , 25.Nm SQLITE_FCNTL_COMMIT_PHASETWO , 26.Nm SQLITE_FCNTL_WIN32_SET_HANDLE , 27.Nm SQLITE_FCNTL_WAL_BLOCK , 28.Nm SQLITE_FCNTL_ZIPVFS , 29.Nm SQLITE_FCNTL_RBU , 30.Nm SQLITE_FCNTL_VFS_POINTER , 31.Nm SQLITE_FCNTL_JOURNAL_POINTER , 32.Nm SQLITE_FCNTL_WIN32_GET_HANDLE , 33.Nm SQLITE_FCNTL_PDB , 34.Nm SQLITE_FCNTL_BEGIN_ATOMIC_WRITE , 35.Nm SQLITE_FCNTL_COMMIT_ATOMIC_WRITE , 36.Nm SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE , 37.Nm SQLITE_FCNTL_LOCK_TIMEOUT , 38.Nm SQLITE_FCNTL_DATA_VERSION 39.Nd Standard File Control Opcodes 40.Sh SYNOPSIS 41.Fd #define SQLITE_FCNTL_LOCKSTATE 42.Fd #define SQLITE_FCNTL_GET_LOCKPROXYFILE 43.Fd #define SQLITE_FCNTL_SET_LOCKPROXYFILE 44.Fd #define SQLITE_FCNTL_LAST_ERRNO 45.Fd #define SQLITE_FCNTL_SIZE_HINT 46.Fd #define SQLITE_FCNTL_CHUNK_SIZE 47.Fd #define SQLITE_FCNTL_FILE_POINTER 48.Fd #define SQLITE_FCNTL_SYNC_OMITTED 49.Fd #define SQLITE_FCNTL_WIN32_AV_RETRY 50.Fd #define SQLITE_FCNTL_PERSIST_WAL 51.Fd #define SQLITE_FCNTL_OVERWRITE 52.Fd #define SQLITE_FCNTL_VFSNAME 53.Fd #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 54.Fd #define SQLITE_FCNTL_PRAGMA 55.Fd #define SQLITE_FCNTL_BUSYHANDLER 56.Fd #define SQLITE_FCNTL_TEMPFILENAME 57.Fd #define SQLITE_FCNTL_MMAP_SIZE 58.Fd #define SQLITE_FCNTL_TRACE 59.Fd #define SQLITE_FCNTL_HAS_MOVED 60.Fd #define SQLITE_FCNTL_SYNC 61.Fd #define SQLITE_FCNTL_COMMIT_PHASETWO 62.Fd #define SQLITE_FCNTL_WIN32_SET_HANDLE 63.Fd #define SQLITE_FCNTL_WAL_BLOCK 64.Fd #define SQLITE_FCNTL_ZIPVFS 65.Fd #define SQLITE_FCNTL_RBU 66.Fd #define SQLITE_FCNTL_VFS_POINTER 67.Fd #define SQLITE_FCNTL_JOURNAL_POINTER 68.Fd #define SQLITE_FCNTL_WIN32_GET_HANDLE 69.Fd #define SQLITE_FCNTL_PDB 70.Fd #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 71.Fd #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 72.Fd #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 73.Fd #define SQLITE_FCNTL_LOCK_TIMEOUT 74.Fd #define SQLITE_FCNTL_DATA_VERSION 75.Sh DESCRIPTION 76These integer constants are opcodes for the xFileControl method of 77the sqlite3_io_methods object and for the sqlite3_file_control() 78interface. 79.Bl -bullet 80.It 81The SQLITE_FCNTL_LOCKSTATE opcode is used for 82debugging. 83This opcode causes the xFileControl method to write the current state 84of the lock (one of SQLITE_LOCK_NONE, SQLITE_LOCK_SHARED, 85SQLITE_LOCK_RESERVED, SQLITE_LOCK_PENDING, 86or SQLITE_LOCK_EXCLUSIVE) into an integer that 87the pArg argument points to. 88This capability is used during testing and is only available when the 89SQLITE_TEST compile-time option is used. 90.It 91The SQLITE_FCNTL_SIZE_HINT opcode is used by 92SQLite to give the VFS layer a hint of how large the database file 93will grow to be during the current transaction. 94This hint is not guaranteed to be accurate but it is often close. 95The underlying VFS might choose to preallocate database file space 96based on this hint in order to help writes to the database file run 97faster. 98.It 99The SQLITE_FCNTL_CHUNK_SIZE opcode is used to 100request that the VFS extends and truncates the database file in chunks 101of a size specified by the user. 102The fourth argument to sqlite3_file_control() 103should point to an integer (type int) containing the new chunk-size 104to use for the nominated database. 105Allocating database file space in large chunks (say 1MB at a time), 106may reduce file-system fragmentation and improve performance on some 107systems. 108.It 109The SQLITE_FCNTL_FILE_POINTER opcode is used 110to obtain a pointer to the sqlite3_file object associated 111with a particular database connection. 112See also SQLITE_FCNTL_JOURNAL_POINTER. 113.It 114The SQLITE_FCNTL_JOURNAL_POINTER opcode 115is used to obtain a pointer to the sqlite3_file object 116associated with the journal file (either the rollback journal 117or the write-ahead log) for a particular database connection. 118See also SQLITE_FCNTL_FILE_POINTER. 119.It 120No longer in use. 121.It 122The SQLITE_FCNTL_SYNC opcode is generated internally 123by SQLite and sent to the VFS immediately before the xSync method is 124invoked on a database file descriptor. 125Or, if the xSync method is not invoked because the user has configured 126SQLite with PRAGMA synchronous=OFF it is invoked 127in place of the xSync method. 128In most cases, the pointer argument passed with this file-control is 129NULL. 130However, if the database file is being synced as part of a multi-database 131commit, the argument points to a nul-terminated string containing the 132transactions master-journal file name. 133VFSes that do not need this signal should silently ignore this opcode. 134Applications should not call sqlite3_file_control() 135with this opcode as doing so may disrupt the operation of the specialized 136VFSes that do require it. 137.It 138The SQLITE_FCNTL_COMMIT_PHASETWO opcode 139is generated internally by SQLite and sent to the VFS after a transaction 140has been committed immediately but before the database is unlocked. 141VFSes that do not need this signal should silently ignore this opcode. 142Applications should not call sqlite3_file_control() 143with this opcode as doing so may disrupt the operation of the specialized 144VFSes that do require it. 145.It 146The SQLITE_FCNTL_WIN32_AV_RETRY opcode is 147used to configure automatic retry counts and intervals for certain 148disk I/O operations for the windows VFS in order to provide robustness 149in the presence of anti-virus programs. 150By default, the windows VFS will retry file read, file write, and file 151delete operations up to 10 times, with a delay of 25 milliseconds before 152the first retry and with the delay increasing by an additional 25 milliseconds 153with each subsequent retry. 154This opcode allows these two values (10 retries and 25 milliseconds 155of delay) to be adjusted. 156The values are changed for all database connections within the same 157process. 158The argument is a pointer to an array of two integers where the first 159integer is the new retry count and the second integer is the delay. 160If either integer is negative, then the setting is not changed but 161instead the prior value of that setting is written into the array entry, 162allowing the current retry settings to be interrogated. 163The zDbName parameter is ignored. 164.It 165The SQLITE_FCNTL_PERSIST_WAL opcode is used 166to set or query the persistent Write Ahead Log setting. 167By default, the auxiliary write ahead log (WAL file) and shared 168memory files used for transaction control are automatically deleted 169when the latest connection to the database closes. 170Setting persistent WAL mode causes those files to persist after close. 171Persisting the files is useful when other processes that do not have 172write permission on the directory containing the database file want 173to read the database file, as the WAL and shared memory files must 174exist in order for the database to be readable. 175The fourth parameter to sqlite3_file_control() 176for this opcode should be a pointer to an integer. 177That integer is 0 to disable persistent WAL mode or 1 to enable persistent 178WAL mode. 179If the integer is -1, then it is overwritten with the current WAL persistence 180setting. 181.It 182The SQLITE_FCNTL_POWERSAFE_OVERWRITE 183opcode is used to set or query the persistent "powersafe-overwrite" 184or "PSOW" setting. 185The PSOW setting determines the SQLITE_IOCAP_POWERSAFE_OVERWRITE 186bit of the xDeviceCharacteristics methods. 187The fourth parameter to sqlite3_file_control() 188for this opcode should be a pointer to an integer. 189That integer is 0 to disable zero-damage mode or 1 to enable zero-damage 190mode. 191If the integer is -1, then it is overwritten with the current zero-damage 192mode setting. 193.It 194The SQLITE_FCNTL_OVERWRITE opcode is invoked 195by SQLite after opening a write transaction to indicate that, unless 196it is rolled back for some reason, the entire database file will be 197overwritten by the current transaction. 198This is used by VACUUM operations. 199.It 200The SQLITE_FCNTL_VFSNAME opcode can be used to 201obtain the names of all VFSes in the VFS stack. 202The names are of all VFS shims and the final bottom-level VFS are written 203into memory obtained from sqlite3_malloc() and the 204result is stored in the char* variable that the fourth parameter of 205sqlite3_file_control() points to. 206The caller is responsible for freeing the memory when done. 207As with all file-control actions, there is no guarantee that this will 208actually do anything. 209Callers should initialize the char* variable to a NULL pointer in case 210this file-control is not implemented. 211This file-control is intended for diagnostic use only. 212.It 213The SQLITE_FCNTL_VFS_POINTER opcode finds a 214pointer to the top-level VFSes currently in use. 215The argument X in sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) 216must be of type "sqlite3_vfs **". 217This opcodes will set *X to a pointer to the top-level VFS. 218When there are multiple VFS shims in the stack, this opcode finds the 219upper-most shim only. 220.It 221Whenever a PRAGMA statement is parsed, an SQLITE_FCNTL_PRAGMA 222file control is sent to the open sqlite3_file object corresponding 223to the database file to which the pragma statement refers. 224The argument to the SQLITE_FCNTL_PRAGMA file control 225is an array of pointers to strings (char**) in which the second element 226of the array is the name of the pragma and the third element is the 227argument to the pragma or NULL if the pragma has no argument. 228The handler for an SQLITE_FCNTL_PRAGMA file control 229can optionally make the first element of the char** argument point 230to a string obtained from sqlite3_mprintf() or the 231equivalent and that string will become the result of the pragma or 232the error message if the pragma fails. 233If the SQLITE_FCNTL_PRAGMA file control returns 234SQLITE_NOTFOUND, then normal PRAGMA processing 235continues. 236If the SQLITE_FCNTL_PRAGMA file control returns 237SQLITE_OK, then the parser assumes that the VFS has handled 238the PRAGMA itself and the parser generates a no-op prepared statement 239if result string is NULL, or that returns a copy of the result string 240if the string is non-NULL. 241If the SQLITE_FCNTL_PRAGMA file control returns 242any result code other than SQLITE_OK or SQLITE_NOTFOUND, 243that means that the VFS encountered an error while handling the PRAGMA 244and the compilation of the PRAGMA fails with an error. 245The SQLITE_FCNTL_PRAGMA file control occurs at the 246beginning of pragma statement analysis and so it is able to override 247built-in PRAGMA statements. 248.It 249The SQLITE_FCNTL_BUSYHANDLER file-control may 250be invoked by SQLite on the database file handle shortly after it is 251opened in order to provide a custom VFS with access to the connections 252busy-handler callback. 253The argument is of type (void **) - an array of two (void *) values. 254The first (void *) actually points to a function of type (int (*)(void 255*)). 256In order to invoke the connections busy-handler, this function should 257be invoked with the second (void *) in the array as the only argument. 258If it returns non-zero, then the operation should be retried. 259If it returns zero, the custom VFS should abandon the current operation. 260.It 261Application can invoke the SQLITE_FCNTL_TEMPFILENAME 262file-control to have SQLite generate a temporary filename using the 263same algorithm that is followed to generate temporary filenames for 264TEMP tables and other internal uses. 265The argument should be a char** which will be filled with the filename 266written into memory obtained from sqlite3_malloc(). 267The caller should invoke sqlite3_free() on the result 268to avoid a memory leak. 269.It 270The SQLITE_FCNTL_MMAP_SIZE file control is used 271to query or set the maximum number of bytes that will be used for memory-mapped 272I/O. 273The argument is a pointer to a value of type sqlite3_int64 that is 274an advisory maximum number of bytes in the file to memory map. 275The pointer is overwritten with the old value. 276The limit is not changed if the value originally pointed to is negative, 277and so the current limit can be queried by passing in a pointer to 278a negative number. 279This file-control is used internally to implement PRAGMA mmap_size. 280.It 281The SQLITE_FCNTL_TRACE file control provides advisory 282information to the VFS about what the higher layers of the SQLite stack 283are doing. 284This file control is used by some VFS activity tracing shims. 285The argument is a zero-terminated string. 286Higher layers in the SQLite stack may generate instances of this file 287control if the SQLITE_USE_FCNTL_TRACE compile-time 288option is enabled. 289.It 290The SQLITE_FCNTL_HAS_MOVED file control interprets 291its argument as a pointer to an integer and it writes a boolean into 292that integer depending on whether or not the file has been renamed, 293moved, or deleted since it was first opened. 294.It 295The SQLITE_FCNTL_WIN32_GET_HANDLE opcode 296can be used to obtain the underlying native file handle associated 297with a file handle. 298This file control interprets its argument as a pointer to a native 299file handle and writes the resulting value there. 300.It 301The SQLITE_FCNTL_WIN32_SET_HANDLE opcode 302is used for debugging. 303This opcode causes the xFileControl method to swap the file handle 304with the one pointed to by the pArg argument. 305This capability is used during testing and only needs to be supported 306when SQLITE_TEST is defined. 307.It 308The SQLITE_FCNTL_WAL_BLOCK is a signal to the 309VFS layer that it might be advantageous to block on the next WAL lock 310if the lock is not immediately available. 311The WAL subsystem issues this signal during rare circumstances in order 312to fix a problem with priority inversion. 313Applications should <em>not</em> use this file-control. 314.It 315The SQLITE_FCNTL_ZIPVFS opcode is implemented by 316zipvfs only. 317All other VFS should return SQLITE_NOTFOUND for this opcode. 318.It 319The SQLITE_FCNTL_RBU opcode is implemented by the special 320VFS used by the RBU extension only. 321All other VFS should return SQLITE_NOTFOUND for this opcode. 322.It 323If the SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 324opcode returns SQLITE_OK, then the file descriptor is placed in "batch 325write mode", which means all subsequent write operations will be deferred 326and done atomically at the next SQLITE_FCNTL_COMMIT_ATOMIC_WRITE. 327Systems that do not support batch atomic writes will return SQLITE_NOTFOUND. 328Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to 329the closing SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 330or SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 331SQLite will make no VFS interface calls on the same sqlite3_file 332file descriptor except for calls to the xWrite method and the xFileControl 333method with SQLITE_FCNTL_SIZE_HINT. 334.It 335The SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 336opcode causes all write operations since the previous successful call 337to SQLITE_FCNTL_BEGIN_ATOMIC_WRITE to 338be performed atomically. 339This file control returns SQLITE_OK if and only if the writes 340were all performed successfully and have been committed to persistent 341storage. 342Regardless of whether or not it is successful, this file control takes 343the file descriptor out of batch write mode so that all subsequent 344write operations are independent. 345SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without a 346prior successful call to SQLITE_FCNTL_BEGIN_ATOMIC_WRITE. 347.It 348The SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 349opcode causes all write operations since the previous successful call 350to SQLITE_FCNTL_BEGIN_ATOMIC_WRITE to 351be rolled back. 352This file control takes the file descriptor out of batch write mode 353so that all subsequent write operations are independent. 354SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without 355a prior successful call to SQLITE_FCNTL_BEGIN_ATOMIC_WRITE. 356.It 357The SQLITE_FCNTL_LOCK_TIMEOUT opcode causes 358attempts to obtain a file lock using the xLock or xShmLock methods 359of the VFS to wait for up to M milliseconds before failing, where M 360is the single unsigned integer parameter. 361.It 362The SQLITE_FCNTL_DATA_VERSION opcode is used 363to detect changes to a database file. 364The argument is a pointer to a 32-bit unsigned integer. 365The "data version" for the pager is written into the pointer. 366The "data version" changes whenever any change occurs to the corresponding 367database file, either through SQL statements on the same database connection 368or through transactions committed by separate database connections 369possibly in other processes. 370The sqlite3_total_changes() interface can be 371used to find if any database on the connection has changed, but that 372interface responds to changes on TEMP as well as MAIN and does not 373provide a mechanism to detect changes to MAIN only. 374Also, the sqlite3_total_changes() interface 375responds to internal changes only and omits changes made by other database 376connections. 377The PRAGMA data_version command provide a mechanism 378to detect changes to a single attached database that occur due to other 379database connections, but omits changes implemented by the database 380connection on which it is called. 381This file control is the only mechanism to detect changes that happen 382either internally or externally and that are associated with a particular 383attached database. 384.El 385.Pp 386.Sh SEE ALSO 387.Xr sqlite3_file 3 , 388.Xr sqlite3_file_control 3 , 389.Xr sqlite3_malloc 3 , 390.Xr sqlite3_io_methods 3 , 391.Xr sqlite3_malloc 3 , 392.Xr sqlite3_mprintf 3 , 393.Xr sqlite3_total_changes 3 , 394.Xr sqlite3_vfs 3 , 395.Xr SQLITE_FCNTL_LOCKSTATE 3 , 396.Xr SQLITE_IOCAP_ATOMIC 3 , 397.Xr SQLITE_LOCK_NONE 3 , 398.Xr SQLITE_OK 3 399