Lines Matching defs:file
2 ** This file is an amalgamation of many separate C source files from SQLite
4 ** single large file, the entire code can be compiled as a single translation
10 ** This file is all you need to compile SQLite. To use SQLite in other
11 ** programs, you need this file and the "sqlite3.h" header file that defines
13 ** the "sqlite3.h" header file at hand, you will find a copy embedded within
14 ** the text of this file. Search for "Begin file sqlite3.h" to find the start
15 ** of the embedded sqlite3.h header file.) Additional code files may be needed
18 ** separate file. This file contains only code for the core SQLite library.
29 /************** Begin file sqliteInt.h ***************************************/
83 ** Include the header file used to customize the compiler options for MSVC.
85 ** compiler warnings due to subsequent content in this file and other files
86 ** that are included by this file.
89 /************** Begin file msvc.h ********************************************/
102 ** This file contains code that is specific to MSVC.
139 /************** Begin file vxworks.h *****************************************/
152 ** This file contains code that is specific to Wind River's VxWorks
177 ** These #defines should enable >2GB file support on POSIX if the
179 ** large file support, or if the OS is windows, these should be no-ops.
185 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
263 ** For MinGW, check to see if we can include the header file containing its
265 ** header file would [only] be included automatically by other MinGW header
267 ** header file to work around binary compatibility issues (see below) and
297 ** file.
310 /************** Begin file sqlite3.h *****************************************/
322 ** This header file defines the interface that the SQLite library
324 ** or constant definition does not appear in this file, then it is
328 ** Some of the definitions that are in this file are marked as
335 ** from comments in this file. This file is the authoritative source
338 ** The name of this file under configuration management is "sqlite.h.in".
339 ** The makefile makes some minor changes to this file (such as inserting
358 ** translation of the amalgamation and its associated header file.
420 ** Ensure these symbols were not defined by some previous header file.
469 ** but are associated with the library instead of the header file. ^(Cautious
760 #define SQLITE_BUSY 5 /* The database file is locked */
769 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
781 #define SQLITE_NOTADB 26 /* File opened that is not a database file */
896 ** [sqlite3_open_v2()] does *not* cause the underlying database file
935 ** device that holds the file that the [sqlite3_io_methods]
943 ** that when data is appended to a file, the data is appended
944 ** first then the size of the file is extended, never the other
949 ** file that were written at the application level might have changed
952 ** flag indicates that a file cannot be deleted when open. The
953 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
1028 ** An [sqlite3_file] object represents an open file in the
1034 ** I/O operations on the open file.
1038 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
1044 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
1048 ** against the open file represented by the [sqlite3_file] object.
1060 ** flag may be ORed in to indicate that only the data of the file
1071 ** xLock() upgrades the database file lock. In other words, xLock() moves the
1072 ** database file lock in the direction NONE toward EXCLUSIVE. The argument to
1074 ** SQLITE_LOCK_NONE. If the database file lock is already at or above the
1076 ** xUnlock() downgrades the database file lock to either SHARED or NONE.
1081 ** PENDING, or EXCLUSIVE lock on the file. It returns true
1085 ** VFS implementations to directly control an open file using the
1091 ** locking strategy (for example to use dot-file locks), to inquire
1094 ** A [file control opcodes | list of opcodes] less than 100 is available.
1097 ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
1101 ** device that underlies the file. The sector size is the
1103 ** other bytes in the file. The xDeviceCharacteristics()
1130 ** that when data is appended to a file, the data is appended
1131 ** first then the size of the file is extended, never the other
1171 ** KEYWORDS: {file control opcodes} {file control opcode}
1188 ** layer a hint of how large the database file will grow to be during the
1191 ** file space based on this hint in order to help writes to the database
1192 ** file run faster.
1205 ** extends and truncates the database file in chunks of a size specified
1208 ** for the nominated database. Allocating database file space in large
1209 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
1219 ** to the [sqlite3_file] object associated with the journal file (either
1229 ** database file descriptor. Or, if the xSync method is not invoked
1233 ** this file-control is NULL. However, if the database file is being synced
1235 ** string containing the transactions super-journal file name. VFSes that
1252 ** anti-virus programs. By default, the windows VFS will retry file read,
1253 ** file write, and file delete operations up to 10 times, with a delay
1268 ** write ahead log ([WAL file]) and shared memory
1273 ** have write permission on the directory containing the database file want
1274 ** to read the database file, as the WAL and shared memory files must exist
1294 ** reason, the entire database file will be overwritten by the current
1304 ** all file-control actions, there is no guarantee that this will actually
1306 ** pointer in case this file-control is not implemented. This file-control
1320 ** file control is sent to the open [sqlite3_file] object corresponding
1321 ** to the database file to which the pragma statement refers. ^The argument
1322 ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
1326 ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
1330 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
1332 ** file control returns [SQLITE_OK], then the parser assumes that the
1336 ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
1340 ** file control occurs at the beginning of pragma statement analysis and so
1345 ** file-control may be invoked by SQLite on the database file handle
1356 ** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
1365 ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
1368 ** is an advisory maximum number of bytes in the file to memory map. The
1372 ** file-control is used internally to implement [PRAGMA mmap_size].
1375 ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
1377 ** This file control is used by some VFS activity tracing [shims].
1379 ** SQLite stack may generate instances of this file control if
1383 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
1385 ** on whether or not the file has been renamed, moved, or deleted since it
1390 ** underlying native file handle associated with a file handle. This file
1391 ** control interprets its argument as a pointer to a native file handle and
1396 ** opcode causes the xFileControl method to swap the file handle with the one
1405 ** Applications should <em>not</em> use this file-control.
1418 ** the file descriptor is placed in "batch write mode", which
1425 ** no VFS interface calls on the same [sqlite3_file] file descriptor
1433 ** This file control returns [SQLITE_OK] if and only if the writes were
1435 ** ^Regardless of whether or not it is successful, this file control takes
1436 ** the file descriptor out of batch write mode so that all subsequent
1445 ** ^This file control takes the file descriptor out of batch write mode
1453 ** obtain a file lock using the xLock or xShmLock methods of the VFS.
1460 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
1463 ** database file, either through SQL statements on the same database
1474 ** called. This file control is the only mechanism to detect changes that
1481 ** file to the database file.
1486 ** file to the database file, but before the *-shm file is updated to
1494 ** (void*) argument passed with this file-control should be a pointer to a
1508 ** database is not a temp db, then this file-control purges the contents
1608 ** in the name of the object stands for "virtual file system". See
1657 ** must invent its own temporary name for the file. ^Whenever the
1665 ** If xOpen() opens a file read-only then it sets *pOutFlags to
1682 ** The file I/O implementation can use the object type flags to
1685 ** the open of a journal file a no-op. Writes to this journal would
1688 ** file will be doing page-aligned sector reads and writes in a random
1698 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1707 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
1709 ** It is <i>not</i> used to indicate the file should be opened
1724 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1725 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1726 ** to test whether a file is at least readable. The SQLITE_ACCESS_READ
1728 ** VFSes of SQLite. The file is named by the second argument and can be a
1731 ** the file given in the second argument is illegal. If SQLITE_OK
1733 ** whether or not the file is accessible.
1777 int mxPathname; /* Maximum file pathname length */
1779 const char *zName; /* Name of this virtual file system */
1820 ** simply checks whether the file exists.
1829 ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
2345 ** points to a buffer containing the name of the main database file. If the
2350 ** configuration option can be seen in the "test_sqllog.c" source file in
2360 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
2429 ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
2634 ** a badly corrupted database file:
2654 ** deliberately corrupt the database file are disabled. The disabled
2727 ** the legacy file format flag. When activated, this flag causes all newly
2728 ** created database file to have a schema format version number (the 4-byte
2730 ** means that the resulting database file will be readable and writable by
2936 ** To detect changes against a database file from other database
2938 ** [SQLITE_FCNTL_DATA_VERSION] [file control].
2950 ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
3705 ** ^These routines open an SQLite database file as specified by the
3739 ** only if the file is write protected by the operating system. In either
3832 ** begins with "file:", then the filename is interpreted as a URI. ^URI
3848 ** ^SQLite uses the path component of the URI as the name of the disk file
3865 ** be used to access the database file on disk. ^If this option is set to
3897 ** storage media on which the database file resides.
3900 ** which if set disables file locking in rollback journal modes. This
3907 ** parameter that indicates that the database file is stored on
3909 ** database file cannot be changed, even by a process with higher
3912 ** property on a database file that does in fact change can result
3927 ** <tr><td> file:data.db <td>
3928 ** Open the file "data.db" in the current directory.
3929 ** <tr><td> file:/home/fred/data.db<br>
3930 ** file:///home/fred/data.db <br>
3931 ** file://localhost/home/fred/data.db <br> <td>
3932 ** Open the database file "/home/fred/data.db".
3933 ** <tr><td> file://darkstar/home/fred/data.db <td>
3936 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3937 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3941 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3942 ** Open file "data.db" in the current directory for read-only access.
3945 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
3946 ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
3948 ** <tr><td> file:data.db?mode=readonly <td>
3950 ** Use "ro" instead: "file:data.db?mode=ro".
3993 ** that check if a database file was a URI that contained a specific query
4041 ** is not a database file pathname pointer that the SQLite core passed
4046 ** parameter can also be the name of a rollback journal file or WAL file
4047 ** in addition to the main database file. Prior to version 3.31.0, these
4048 ** routines would only work if F was the name of the main database file.
4049 ** When the F parameter is the name of the rollback journal or WAL file,
4051 ** main database file.
4064 ** translating filenames between the main database file, the journal file,
4065 ** and the WAL file.
4067 ** If F is the name of an sqlite database file, journal file, or WAL file
4069 ** returns the name of the corresponding database file.
4071 ** If F is the name of an sqlite database file, journal file, or WAL file
4074 ** returns the name of the corresponding rollback journal file.
4076 ** If F is the name of an sqlite database file, journal file, or WAL file
4080 ** WAL file.
4094 ** ^If X is the name of a rollback or WAL-mode journal file that is
4097 ** object that represents the main database file.
4117 ** database filename D with corresponding journal file J and WAL file W and
4605 ** the content of the database file.
4611 ** change the database file through side-effects:
4617 ** But because the [SELECT] statement does not change the database file
4634 ** statement might change the database file. ^A false return does
4635 ** not guarantee that the statement will change the database file.
5586 ** a database file to include invocations of the function with parameters
5588 ** the database file is opened and read.
6527 ** temporary file directory.
6692 ** out of range. An N value of 0 means the main database file. An N of 1 is
6772 ** These constants define the current transaction state of a database file.
6784 ** in a read transaction. Content has been read from the database file
6785 ** but nothing in the database file has changed. The transaction state
6793 ** in a write transaction. Content has been written to the database file
6873 ** file. ^The callback is passed a copy of the generic data pointer (P),
6875 ** the size of the database file in pages, the number of free pages,
6884 ** callback is invoked separately for each file.
7228 ** ^This interface loads an SQLite extension library from the named file.
7231 ** [SQLite extension] library contained in the file zFile. If
7232 ** the file cannot be loaded directly, attempts are made to load
7809 ** For the main database file, the database name is "main". For TEMP
8332 ** KEYWORDS: {file control}
8341 ** main database file.
8354 ** the [sqlite3_file] object associated with the journal file instead of
8356 ** a pointer to the underlying [sqlite3_vfs] object for the file.
8361 ** open database file, then SQLITE_ERROR is returned. ^This error
8368 ** See also: [file control opcodes]
8844 ** wal file in wal mode databases, or the number of pages written to the
8845 ** database file in rollback mode databases. Any pages written as part of
9027 ** determine exactly which parts of a database file are cached and for
9067 ** SQLite will typically create one cache instance for each open database file,
9078 ** created will be used to cache database pages of a file stored on disk, or
9194 ** retained in the header file for backwards compatibility only.
9233 ** ^SQLite holds a write transaction open on the destination database file
9308 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
9326 ** on the destination file. ^The exclusive lock is not released until either
9399 ** that the application must guarantee that the disk file being
9633 ** is the number of pages currently in the write-ahead log file,
9666 ** more frames in the [write-ahead log] file. ^Passing zero or
9698 ** transferred into the database file and for the write-ahead log to
9723 ** readers or writers to finish, then sync the database file if all frames
9733 ** snapshot. ^It then checkpoints all frames in the log file and syncs the
9734 ** database file. ^This mode blocks new database writers while it is pending,
9739 ** that after checkpointing the log file it blocks (calls the
9741 ** until all readers are reading from the database file only. ^This ensures
9742 ** that the next writer will restart the log file from the beginning.
9748 ** addition that it also truncates the log file to zero bytes just prior
9753 ** the log file or to -1 if the checkpoint could not run because
9756 ** log file (including any that were already checkpointed before the function
9759 ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
9762 ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
9768 ** exclusive "writer" lock on the database file. ^If the writer lock cannot be
10372 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
10514 ** number that caused the most recent I/O error or failure to open a file.
10530 ** same database file can each be reading a different historical version
10531 ** of the database file. When a [database connection] begins a read
10538 ** version of the database file so that it is possible to later open a new read
10572 ** file since it was created on disk (by any connection). This means
10574 ** file immediately after it is first opened. At least one transaction
10627 ** database connection D does not know that the database file for
10629 ** that the database file is in [WAL mode] if there has been no prior
10665 ** file, the result of the comparison is undefined.
10669 ** last time the wal file was deleted. The wal file is deleted when the
10672 ** wal file was last deleted, the value returned by this function
10688 ** CAPI3REF: Recover snapshots from a wal file
10691 ** If a [WAL file] remains on disk after all database connections close
10692 ** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control]
10695 ** on that database and [WAL file], the [sqlite3_snapshot_open()] interface
10696 ** will only be able to open the last transaction added to the WAL file
10697 ** even though the WAL file contains other valid transactions.
10699 ** This function attempts to scan the WAL file associated with database zDb
10720 ** For an ordinary on-disk database file, the serialization is just a
10721 ** copy of the disk file. For an in-memory database or a "TEMP" database,
10851 /******** Begin file sqlite3rtree.h *********/
10970 /******** Begin file sqlite3session.h *********/
11285 ** file. Specifically:
12693 /******** Begin file fts5.h *********/
12706 ** Interfaces to extend FTS5. Using the interfaces defined in this file,
13289 /************** Begin file sqliteLimit.h *************************************/
13302 ** This file defines various limits of what SQLite can process.
13399 ** The default number of frames to accumulate in the log file before
13472 ** Maximum number of pages in one database file.
13872 ** macros to verify that we have tested SQLite for large-file support.
13887 /************** Begin file hash.h ********************************************/
13899 ** This is the header file for the generic hash-table implementation
13988 /************** Begin file parse.h *******************************************/
14226 ** The "file format" number is an integer that is incremented whenever
14227 ** the VDBE-level file format changes. The following macros define the
14228 ** the default file format for new databases and the maximum file format
14849 /************** Begin file os.h **********************************************/
14862 ** This header file (together with is companion C source-code file
14866 ** This header file is #include-ed by sqliteInt.h and thus ends up
14867 ** being included by every source file.
14877 /************** Begin file os_setup.h ****************************************/
14890 ** This file contains pre-processor directives related to operating system
14995 ** alphanumeric characters, and no file extension. They are stored in the
14996 ** OS's standard temporary file directory, and are deleted prior to exit.
15012 ** of the file.
15023 ** RESERVED: A single process may hold a RESERVED lock on a file at
15025 ** PENDING: A single process may hold a PENDING lock on a file at
15051 ** random so two separate readers can probably access the file at the
15055 ** a single byte of the file that is designated as the reserved lock byte.
15074 ** clients on win95, winNT, and unix all talking to the same shared file
15076 ** tool is being used for file sharing) implements locks correctly between
15090 ** file format. Depending on how it is changed, you might not notice
15157 ** sqlite3_malloc() to obtain space for the file-handle structure.
15167 /************** Begin file pager.h *******************************************/
15179 ** This header file defines the interface that the sqlite page cache
15180 ** subsystem. The page cache subsystem reads and writes a file a page
15197 ** The type used to represent a page number. The first page in a file
15203 ** Each open file is managed by a separate instance of the "Pager" structure.
15215 ** used in the journal to signify that the remainder of the journal file
15246 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
15250 #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
15278 ** The remainder of this file contains the declarations of the functions
15393 /* Functions used to truncate the database file. */
15422 /************** Begin file btree.h *******************************************/
15434 ** This header file defines the interface that the sqlite B-Tree file
15469 const char *zFilename, /* Name of database file to open */
15484 #define BTREE_SINGLE 4 /* The file contains at most 1 b-tree */
15566 ** the database file header. The incr-vacuum-flag field is located at
15841 /************** Begin file vdbe.h ********************************************/
15853 ** Header file for the Virtual DataBase Engine (VDBE)
15865 ** in the source file sqliteVdbe.c are allowed to see the insides
16004 ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
16005 ** header file that defines a number for each opcode used by the VDBE.
16008 /************** Begin file opcodes.h *****************************************/
16238 ** generated this include file strives to group all JUMP opcodes
16401 ** numbers in the sqlite3.c source file. VDBE branch coverage testing
16436 ** vdbe.c source file for additional information.
16479 /************** Begin file pcache.h ******************************************/
16491 ** This header file defines the interface that the sqlite page cache
16538 #define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */
16674 /************** Begin file mutex.h *******************************************/
16687 ** This file contains the common header for all mutex implementations.
16688 ** The sqliteInt.h header #includes this file so that it is available
16692 ** NOTE: source files should *not* #include this header file directly.
16693 ** Source files should #include the sqliteInt.h file and let that file
16782 ** Each database file to be accessed by the system is an instance
16784 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
16785 ** aDb[1] is the database file used to hold temporary tables. Additional
16790 Btree *pBt; /* The B*Tree structure for this database file */
16814 int schema_cookie; /* Database schema version number for this file */
16821 u8 file_format; /* Schema format version for this file */
17030 u8 temp_store; /* 1: file 2: memory 0: default */
17049 u8 iDb; /* Which db file is being initialized */
18148 ** analyze.c source file for additional information.
19489 sqlite3_int64 szMmap; /* mmap() space per open file */
20442 ** file.
20988 /************** Begin file os_common.h ***************************************/
21001 ** This file contains macros and a little bit of code that is common to
21005 ** This file should be #included by the os_*.c files only. It is not a
21006 ** general purpose header file.
21031 /************** Begin file hwtime.h ******************************************/
21044 ** This file contains inline asm code for retrieving "high-performance"
21189 /************** Begin file ctime.c *******************************************/
21191 ** This file is automatically generated by the script in the canonical
21195 ** which specify categories of generated conditionals in this file.
21210 ** This file implements routines used to report what compile-time options
21985 /************** Begin file global.c ******************************************/
21998 ** This file contains definitions of global variables and constants.
22322 ** for use by the VFS layers as space for managing file locks.
22325 ** a different position in the file. This allows code that has to
22331 ** 0x40000000 results in an incompatible database file format!
22350 ** the vdbe.c file.
22390 /************** Begin file status.c ******************************************/
22408 /************** Begin file vdbeInt.h *****************************************/
22420 ** This is the header file for information that is private to the
22422 ** source code file "vdbe.c". When that file became too big (over
22500 Btree *pBtx; /* Separate file holding temporary table */
22772 ** But this file is the only place where the internal details of this
22869 u8 minWriteFileFormat; /* Minimum file format for writable database files */
23503 /************** Begin file date.c ********************************************/
23515 ** This file contains the C functions that implement date and time
23518 ** There is only one exported symbol in this file - the function
23519 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
23520 ** All other code has file scope.
24838 ** functions. This should be the only routine in this file with
24863 /************** Begin file os.c **********************************************/
24876 ** This file contains OS interface code that is common to all
25011 ** The CKPT_DONE and CKPT_START file-controls are write-only signals
25043 sqlite3_file *id, /* Database file handle */
25046 int bExtend, /* True to extend file if necessary */
25313 /************** Begin file fault.c *******************************************/
25326 ** This file contains code to support the concept of "benign"
25403 /************** Begin file mem0.c ********************************************/
25416 ** This file contains a no-op memory allocation drivers for use when
25443 ** This routine is the only routine in this file with external linkage.
25446 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
25465 /************** Begin file mem1.c ********************************************/
25478 ** This file contains low-level memory allocation drivers for when
25482 ** This file contains implementations of the low-level memory allocation
25484 ** this file is only used if SQLITE_SYSTEM_MALLOC is defined. The
25488 ** file.
25546 ** The malloc.h header file is needed for malloc_usable_size() function
25556 ** the malloc.h header file.
25564 ** Include the malloc.h header file, if necessary. Also set define macro
25737 ** This routine is the only routine in this file with external linkage.
25740 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
25759 /************** Begin file mem2.c ********************************************/
25772 ** This file contains low-level memory allocation drivers for when
25778 ** This file contains implementations of the low-level memory allocation
26121 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
26232 ** Open the file indicated and write a log of all unfreed memory
26290 /************** Begin file mem3.c ********************************************/
26302 ** This file contains the C functions that implement a memory
26876 ** Open the file indicated and write a log of all unfreed memory
26953 ** This routine is the only routine in this file with external
26957 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
26980 /************** Begin file mem5.c ********************************************/
26992 ** This file contains the C functions that implement a memory
27505 ** Open the file indicated and write a log of all unfreed memory
27547 ** This routine is the only routine in this file with external
27568 /************** Begin file mutex.c *******************************************/
27580 ** This file contains the C functions that implement mutexes.
27582 ** This file contains code that is common across all mutex implementations.
27932 /************** Begin file mutex_noop.c **************************************/
27944 ** This file contains the C functions that implement mutexes.
27946 ** This implementation in this file does not provide any mutual
28150 /************** Begin file mutex_unix.c **************************************/
28162 ** This file contains the C functions that implement mutexes for pthreads
28167 ** The code in this file is only used if we are compiling threadsafe
28547 /************** Begin file mutex_w32.c ***************************************/
28559 ** This file contains the C functions that implement mutexes for Win32.
28570 ** Include the header file for the Windows VFS.
28573 /************** Begin file os_win.h ******************************************/
28586 ** This file contains code that is specific to Windows.
28592 ** Include the primary Windows SDK header file.
28668 ** The code in this file is only used if we are compiling multithreaded
29041 /************** Begin file malloc.c ******************************************/
29801 ** called via macros that record the current file and line number in the
29939 /************** Begin file printf.c ******************************************/
29946 ** This file contains code for a set of "printf"-like routines. These
31331 /************** Begin file treeview.c ****************************************/
31344 ** This file contains C code to implement the TreeView debugging routines.
31348 ** The interfaces in this file is only available when compiling
32624 /************** Begin file random.c ******************************************/
32636 ** This file contains code to implement a pseudo-random number
32784 /************** Begin file threads.c *****************************************/
32797 ** This file presents a simple cross-platform threading interface for
33061 /************** Begin file utf.c *********************************************/
33073 ** This file contains routines used to translate between UTF-8,
33599 /************** Begin file util.c ********************************************/
33613 ** This file contains functions for allocating memory, comparing
34866 ** file. In that case we are not in any hurry. Use the (relatively
35317 /************** Begin file hash.c ********************************************/
35589 /************** Begin file opcodes.c *****************************************/
35795 /************** Begin file os_kv.c *******************************************/
35808 ** This file contains an experimental VFS layer that operates on a
35839 /* A single open file. There are only two files represented by this
35845 int isJournal; /* True if this is a journal file */
35849 sqlite3_int64 szDb; /* Database file size. -1 means unknown */
35909 /* Methods for sqlite3_file objects referencing a database file
36082 ** concerns, so it does not need an iVersion member. This file is
36227 ** Decode a complete journal file. Allocate space in pFile->aJrnl
36233 ** in the decoded journal file image. This base-26 number is followed
36266 ** Read or write the "sz" element, containing the database file size.
36283 ** Close an kvvfs-file.
36295 ** Read from the -journal file.
36327 ** Read from the database file.
36384 ** Write into the -journal file.
36412 ** Write into the database file.
36442 ** Truncate an kvvfs-file.
36477 ** Sync an kvvfs-file.
36508 ** Return the current file-size of an kvvfs-file.
36528 ** Lock an kvvfs-file.
36542 ** Unlock an kvvfs-file.
36555 ** Check if another file-handle holds a RESERVED lock on an kvvfs-file.
36564 ** File control method. For custom operations on an kvvfs-file.
36585 ** Return the sector-size in bytes for an kvvfs-file.
36592 ** Return the device characteristic flags supported by an kvvfs-file.
36601 ** Open an kvvfs file handle.
36640 ** Delete the file located at zPath. If the dirSync argument is true,
36641 ** ensure the file-system modifications are synced to disk before
36770 /************** Begin file os_unix.c *****************************************/
36783 ** This file contains the VFS implementation for unix-like operating systems
36786 ** There are actually several different VFS implementations in this file.
36787 ** The differences are in the way that file locking is done. The default
36792 ** This source file is organized into divisions where the logic for various
36800 ** * Unique file ID logic used by VxWorks.
36804 ** + for dot-file locks
36817 #if SQLITE_OS_UNIX /* This file is used on unix only */
36820 ** There are various methods for file locking used for concurrency
36825 ** 3. Dot-file locking,
36874 # include <sys/file.h>
36933 ** Default permissions when creating a new file
36970 typedef struct UnixUnusedFd UnixUnusedFd; /* An unused file descriptor */
36973 ** Sometimes, after a file handle is closed by SQLite, the file descriptor
36975 ** structure are used to store the file descriptor while waiting for an
36980 int flags; /* Flags this file descriptor was opened with */
36981 UnixUnusedFd *pNext; /* Next unused file descriptor on same file */
36993 int h; /* The file descriptor */
36999 const char *zPath; /* Name of the file */
37021 struct vxworksFileId *pId; /* Unique file ID */
37027 ** occur if a file is updated without also updating the transaction
37032 unsigned char dbUpdate; /* True if any part of database file changed */
37065 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
37465 ** Do not accept any file descriptor less than this value, in order to avoid
37466 ** opening database file using file descriptors that are commonly used for
37477 ** If the file creation mode "m" is 0 then set it to the default for
37480 ** make the file creation mode be exactly m ignoring the umask.
37485 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
37509 "attempt to open \"%s\" as file descriptor %d", z, fd);
37533 ** vxworksFileId objects used by this file, all of which may be
37652 ** All calls to ftruncate() within this file should be made through
37661 ** truncate a file to any size larger than 2GiB. Silently ignore any
37675 ** and a variety of "please close the file descriptor NOW" errors into
37678 ** Errors during initialization of locks, or file system support for locks,
37693 /* random NFS retry error, unless during file system support
37709 ** On most versions of unix, we can get a unique ID for a file by concatenating
37711 ** On VxWorks, a unique file id must be based on the canonical filename.
37714 ** unique file ID in VxWorks. Each instance of this structure contains
37774 ** Find a unique file ID for the given absolute pathname. Return
37776 ** file ID.
37785 struct vxworksFileId *pNew; /* search key and new file ID */
37786 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
37799 ** the existing file ID.
37813 /* No match was found. We will make a new file ID */
37852 ** file descriptor. Consider this test case:
37857 ** Suppose ./file1 and ./file2 are really the same file (because
37861 ** fail since there was already a lock on the file due to fd1.
37864 ** file descriptors opened on different file names.
37866 ** This means that we cannot use POSIX locks to synchronize file access
37871 ** To work around the problem, SQLite has to manage file locks internally
37873 ** specific inode of the database file (the inode is determined by the
37884 ** The sqlite3_file structure for POSIX is no longer just an integer file
37885 ** descriptor. It is now a structure that holds the integer file
37892 ** file is unlocked. cnt==-1 means the file has an exclusive lock.
37893 ** cnt>0 means there are cnt shared locks on the file.
37895 ** Any attempt to lock or unlock a file first checks the locking
37902 ** If you close a file descriptor that points to a file that has locks,
37903 ** all locks on that file that are owned by the current process are
37908 ** to close() the file descriptor is deferred until all of the locks clear.
37909 ** The unixInodeInfo structure keeps a list of file descriptors that need to
37930 ** per database file in the same process and (2) database connections
37941 struct vxworksFileId *pId; /* Unique file ID for vxworks. */
37958 ** A single inode can have multiple file descriptors, so each unixFile
37983 int nLock; /* Number of outstanding file locks */
37986 UnixUnusedFd *pUnused; /* Unused file descriptors to close */
38036 ** failed (e.g. "unlink", "open") and the associated file-system path,
38093 ** Close a file descriptor.
38097 ** If it does fail, simply leak the file descriptor, but do log the
38101 ** file descriptor might have already been reused by another thread.
38121 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
38171 ** Given a file descriptor, locate the unixInodeInfo object that
38172 ** describes that file descriptor. Create a new one if necessary. The
38180 unixFile *pFile, /* Unix file with file desc used in the key */
38184 int fd; /* The file descriptor for pFile */
38186 struct stat statbuf; /* Low-level file information */
38191 /* Get low-level information about the file that we can used to
38192 ** create a unique name for the file.
38211 ** we always increase the file size to 1 by writing a single byte
38295 ** (1) There is exactly one hard link on the file
38296 ** (2) The file is not a symbolic link
38297 ** (3) The file has not been renamed or unlinked
38310 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
38314 sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
38318 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
38322 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
38330 ** file by this or any other process. If such a lock is held, set *pResOut
38395 int h, /* The file descriptor on which to take the lock */
38402 /* On systems that support some kind of blocking file lock with a timeout,
38403 ** make appropriate changes here to invoke that blocking file lock. On
38417 ** Attempt to set a system-lock on the file pFile. The lock is
38462 ** Lock the file with the lock specified by parameter eFileLock - one
38491 ** accessing the same database file, in case that is ever required.
38516 ** This property is used by the algorithm for rolling back a journal file
38651 ** assumed that there is a SHARED or greater lock on the file
38709 ** Add the file descriptor used by file handle pFile to the corresponding
38723 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
38726 ** If the locking level of the file descriptor is already at or below
38758 ** reading the database file again, make sure that the
38760 ** file changed. If the transaction counter is not updated,
38761 ** other connections to the same file might not realize that
38762 ** the file has changed and hence might not know to flush their
38871 /* Decrement the count of locks against this same file. When the
38872 ** count reaches zero, close any other file descriptors whose close
38889 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
38892 ** If the locking level of the file descriptor is already at or below
38908 ** This function performs the parts of the "close file" operation
38909 ** common to all locking schemes. It closes the directory and file
38950 ** Close a file.
38969 /* If there are outstanding locks, do not actually close the file just
38970 ** yet because that would clear those locks. Instead, add the file
38992 ** file for reading or writing.
39000 ** database connections are accessing the same database file at the same
39019 ** Close the file.
39029 ************************* Begin dot-file Locking ******************************
39051 ** The file suffix added to the data base filename in order to create the
39058 ** file by this or any other process. If such a lock is held, set *pResOut
39064 ** is held on the file and false if the file is unlocked.
39081 ** Lock the file with the lock specified by parameter eFileLock - one
39113 /* If we have any lock, then the lock file already exists. All we have
39118 /* Always update the timestamp on the old file */
39149 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
39152 ** If the locking level of the file descriptor is already at or below
39155 ** When the locking level reaches NO_LOCK, delete the lock file.
39173 ** lock state. No need to mess with the file on disk.
39180 /* To fully unlock the database, delete the lock file */
39198 ** Close a file. Make sure the lock has been released before closing.
39207 /****************** End of the dot-file lock implementation *******************
39213 ** Use the flock() system call to do file locking.
39215 ** flock() locking is like dot-file locking in that the various
39242 ** file by this or any other process. If such a lock is held, set *pResOut
39298 ** Lock the file with the lock specified by parameter eFileLock - one
39321 ** access the file.
39364 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
39367 ** If the locking level of the file descriptor is already at or below
39405 ** Close a file.
39425 ** the database file at a time. This reduces potential concurrency, but
39432 ** file by this or any other process. If such a lock is held, set *pResOut
39475 ** Lock the file with the lock specified by parameter eFileLock - one
39498 ** access the file.
39530 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
39533 ** If the locking level of the file descriptor is already at or below
39571 ** Close a file.
39612 const char *dbPath; /* Name of the open file */
39622 int fd; /* file desc to assoc this lock with */
39634 const char *path, /* Name of the file to be locked or unlocked */
39635 unixFile *pFile, /* Open file descriptor on path */
39675 ** file by this or any other process. If such a lock is held, set *pResOut
39725 ** Lock the file with the lock specified by parameter eFileLock - one
39866 ** assumed that there is a SHARED or greater lock on the file
39924 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
39927 ** If the locking level of the file descriptor is already at or below
39960 ** reading the database file again, make sure that the
39962 ** file changed. If the transaction counter is not updated,
39963 ** other connections to the same file might not realize that
39964 ** the file has changed and hence might not know to flush their
40031 ** Close a file & cleanup AFP specific locking context
40044 /* If there are outstanding locks, do not actually close the file just
40045 ** yet because that would clear those locks. Instead, add the file
40075 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
40078 ** If the locking level of the file descriptor is already at or below
40162 ** Read data from a file into a buffer. Return SQLITE_OK if all
40178 /* If this is a database file (not a journal, super-journal or temp
40179 ** file), the bytes in the locking range should never be read or written. */
40242 ** Attempt to seek the file-descriptor passed as the first argument to
40251 const void *pBuf, /* Copy data from this buffer to the file */
40300 ** Write data from a buffer into a file. Return SQLITE_OK on success
40314 /* If this is a database file (not a journal, super-journal or temp
40315 ** file), the bytes in the locking range should never be read or written. */
40324 /* If we are doing a normal write to a database file (as opposed to
40325 ** doing a hot-journal rollback or a write to some file other than a
40326 ** normal database file) then record the fact that the database
40441 ** or power failure will likely corrupt the database file.
40443 ** SQLite sets the dataOnly flag if the size of the file is unchanged.
40444 ** The idea behind dataOnly is that it should only write the file content
40445 ** to disk, not the inode. We only set dataOnly if the file size is
40446 ** unchanged since the file size is part of the inode. However,
40448 ** file size has changed. The only real difference between fdatasync()
40451 ** We only care about the file size, not the other file attributes, so
40484 ** no-op. But go ahead and call fstat() to validate the file
40501 ** file system (on OSX), so failure indicates that FULLFSYNC
40502 ** isn't supported for this file system. So, attempt an fsync
40510 /* fdatasync() on HFS+ doesn't yet flush the file size if it changed correctly
40530 ** Open a file descriptor to the directory containing file zFilename.
40531 ** If successful, *pFd is set to the opened file descriptor and
40536 ** The directory file descriptor is used for only one thing - to
40537 ** fsync() a directory to make sure file creation and deletion events
40550 ** the file descriptor *pFd using close().
40575 ** Make sure all writes to a particular file are committed to disk.
40577 ** If dataOnly==0 then both the file itself and its metadata (file
40579 ** file data is synced.
40581 ** Under Unix, also make sure that the directory entry for the file
40582 ** has been created by fsync-ing the directory that contains the file.
40585 ** SQLite to access the file will not know that the journal exists (because
40615 /* Also fsync the directory containing the file if the DIRSYNC flag
40637 ** Truncate an open file to a specified size
40645 /* If the user has configured a chunk-size for this file, truncate the
40646 ** file so that it consists of an integer number of chunks (i.e. the
40647 ** actual file size after the operation may be larger than the requested
40660 /* If we are doing a normal write to a database file (as opposed to
40661 ** doing a hot-journal rollback or a write to some file other than a
40662 ** normal database file) and we truncate the file to zero length,
40673 /* If the file was just truncated to a size smaller than the currently
40687 ** Determine the current size of a file in bytes
40702 ** writes a single byte into that file in order to work around a bug
40704 ** layers, we need to report this file size as zero even though it is
40715 ** Handler for proxy-locking file-control verbs. Defined below in the
40723 ** file-control operation. Enlarge the database to nBytes in size
40729 i64 nSize; /* Required file size */
40762 ** at offset (nSize-1), to set the size of the file correctly.
40834 ** Information and control of an open file handle.
40979 ** pFd->deviceCharacteristics are set according to the file-system
41026 SQLITE_IOCAP_SAFE_APPEND | /* growing the file does not occur until
41036 SQLITE_IOCAP_SAFE_APPEND | /* growing the file does not occur until
41045 SQLITE_IOCAP_SAFE_APPEND | /* growing the file does not occur until
41069 SQLITE_IOCAP_SAFE_APPEND | /* growing the file does not occur until
41085 ** the specified file. This is almost always 512 bytes, but may be
41089 ** if two files are created in the same file-system directory (i.e.
41090 ** a database and its journal file) that the sector size will be the
41100 ** Return the device characteristics for the file.
41104 ** file system does not always provide powersafe overwrites. (In other
41105 ** words, after a power-loss event, parts of the file that were never
41109 ** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control
41123 ** This function should not be called directly by other code in this file.
41150 ** every open file that does not use shared memory (in other words, most
41172 char *zFilename; /* Name of the mmapped file */
41173 int hShm; /* Open file descriptor */
41219 ** wal-mode transactions in other processes on database file pFile. If
41258 unixFile *pFile, /* Open connection to the WAL file */
41382 ** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
41397 ** and proceed with opening the *-shm file.
41401 ** DMS byte and truncate the *-shm file to zero bytes in size. Then
41408 ** EXCLUSIVE failed just before truncating the *-shm file, then this
41409 ** process might open and use the *-shm file without truncating it.
41410 ** And if the *-shm file has been corrupted by a power failure or
41424 /* The first connection to attach must truncate the -shm file. We
41427 ** help detect if a -shm file truncation is legitimate or is the work
41445 ** Open a shared-memory area associated with open database file pDbFd.
41448 ** The file used to implement shared-memory is in the same directory
41449 ** as the open database file and has the same name as the open database
41450 ** file with the "-shm" suffix added. For example, if the database file
41451 ** is "/home/user1/config.db" then the file that is created and mmapped
41455 ** some other tmpfs mount. But if a file in a different directory
41456 ** from the database file is used, then differing access permissions
41460 ** in database corruption. Nevertheless, this tmpfs file usage
41465 ** same database file at the same time, database corruption will likely
41469 ** When opening a new shared-memory file, if no other instances of that
41470 ** file are currently open, in this process or in other processes, then
41471 ** the file must be truncated to zero length or have its header cleared.
41473 ** If the original database file (pDbFd) is using the "unix-excl" VFS
41474 ** that means that an exclusive lock is held on the database file and
41477 ** file is created. The shared memory will be simulated with heap memory.
41481 struct unixShmNode *pShmNode; /* The underlying mmapped file */
41484 char *zShm; /* Name of the file used for SHM */
41501 struct stat sStat; /* fstat() info for database file */
41506 /* Call fstat() to figure out the permissions on the database file. If
41507 ** a new *-shm file is created, an attempt will be made to create it
41561 /* If this process is running as root, make sure that the SHM file
41604 ** shared-memory associated with the database file fd. Shared-memory regions
41622 sqlite3_file *fd, /* Handle open on database file */
41625 int bExtend, /* True to extend file if necessary */
41635 /* If the shared-memory file has not yet been opened, open it now. */
41659 int nByte = nReqRegion*szRegion; /* Minimum required file size */
41666 ** Check to see if it has been allocated (i.e. if the wal-index file is
41682 /* Alternatively, if bExtend is true, extend the file. Do this by
41685 ** last page in order to extend the file. But writing to all new
41797 sqlite3_file *fd, /* Database file holding the shared memory */
41804 unixShmNode *pShmNode; /* The underlying file iNode */
41945 sqlite3_file *fd /* Database file holding the shared memory */
41964 sqlite3_file *fd, /* The underlying database file */
41968 unixShmNode *pShmNode; /* The underlying shared-memory file */
41970 unixFile *pDbFd; /* The underlying database file */
41992 ** shared-memory file, too */
42018 ** If it is currently memory mapped, unmap file pFd.
42031 ** Attempt to set the size of the memory mapping maintained by file
42050 int h = pFd->h; /* File descriptor open on db file */
42051 u8 *pOrig = (u8 *)pFd->pMapRegion; /* Pointer to current file mapping */
42122 ** Memory map or remap the file opened by file-descriptor pFd (if the file
42124 ** there already exists a mapping for this file, and there are still
42129 ** requested size is the size of the file on disk. The actual size of the
42143 struct stat statbuf; /* Low-level file information */
42163 ** If possible, return a pointer to a mapping of file fd starting at offset
42176 unixFile *pFd = (unixFile *)fd; /* The underlying database file */
42207 unixFile *pFd = (unixFile *)fd; /* The underlying database file */
42210 /* If p==0 (unmap the entire file) then there must be no outstanding
42241 ** implement various file locking strategies. It also contains definitions
42243 ** sqlite3_io_methods object for a particular database file. The pAppData
42379 ** opens secondary file descriptors for the conch and lock files and
42380 ** it uses proxy, dot-file, AFP, and flock() locking methods on those
42382 ** proxy locking is located much further down in the file. But we need
42420 ** for the database file "filePath". It then returns the sqlite3_io_methods
42426 const char *filePath, /* name of the database file */
42427 unixFile *pNew /* open file object for the database file */
42445 /* If filePath==NULL that means we are dealing with a transient file
42462 ** assume that the file-system supports POSIX style locks.
42490 const char *filePath, /* name of the database file */
42491 unixFile *pNew /* the open file object */
42496 /* If filePath==NULL that means we are dealing with a transient file
42537 int h, /* Open file descriptor of file being opened */
42539 const char *zFilename, /* Name of the file being opened */
42582 ** zFilename remains valid until file is closed, to support */
42595 /* If an error occurred in findInodeInfo(), close the file descriptor
42603 ** file descriptors open on the same file. If there were other file
42604 ** descriptors on this file, then no malloc would be required by
42621 /* AFP locking uses the file path so it needs to be included in
42629 /* NB: zFilename exists and remains valid until the file is closed
42648 /* Dotfile locking uses the file path so it needs to be included in
42666 /* Named semaphore locking uses the file path so it needs to be
42729 ** If no suitable temporary file directory can be found, return NULL.
42751 ** Create a temporary file name in zBuf. zBuf must be allocated
42799 ** Search for an unused file descriptor that was opened on the database
42800 ** file (not a journal or super-journal file) identified by pathname
42804 ** Such a file descriptor may exist if a database connection was closed
42805 ** but the associated file descriptor could not be closed because some
42806 ** other file descriptor open on the same file is holding a file-lock.
42808 ** describing "Posix Advisory Locking" at the start of this file for
42811 ** If a suitable file descriptor is found, then it is returned. If no
42812 ** such file descriptor is located, -1 is returned.
42817 /* Do not search for an unused file descriptor on vxworks. Not because
42830 ** ignored and -1 is returned. The caller will try to open a new file
42834 ** not searching for a reusable file descriptor are not dire. */
42862 ** Find the mode, uid and gid of file zFile.
42870 struct stat sStat; /* Output of stat() on database file */
42890 ** an indication to robust_open() to create the file using
42892 ** But if the file being opened is a WAL or regular journal file, then
42893 ** this function queries the file-system for the permissions on the
42894 ** corresponding database file and sets *pMode to this value. Whenever
42896 ** as the associated database file.
42904 const char *zPath, /* Path of file (possibly) being created */
42906 mode_t *pMode, /* OUT: Permissions to open file with */
42907 uid_t *pUid, /* OUT: uid to set on the file */
42908 gid_t *pGid /* OUT: gid to set on the file */
42915 char zDb[MAX_PATHNAME+1]; /* Database file path */
42918 /* zPath is a path to a WAL or journal file. The following block derives
42919 ** the path to the associated database file from zPath. This block handles
42930 ** In normal operation, the journal file name will always contain
42949 /* If this is a main database file and the file was opened using a URI
42952 ** that file. */
42962 ** Open the file zPath.
42978 ** true, the file was configured to be automatically deleted when the
42979 ** file handle closed. To achieve the same effect using this new
42985 const char *zPath, /* Pathname of file to be opened */
42986 sqlite3_file *pFile, /* The file descriptor to be filled in */
42993 int eType = flags&0x0FFF00; /* Type of file to open */
43010 /* If creating a super- or main-file journal, this function will open
43011 ** a file-descriptor on the directory too. The first time unixSync()
43012 ** is called the directory file descriptor will be fsync()ed and close()d.
43021 ** a temporary file. Use this buffer to store the file name in.
43038 /* The main DB, main journal, WAL file and super-journal are never
43045 /* Assert that the upper layer has set one of the "file-type" flags. */
43087 /* If zName is NULL, the upper layer is requesting a temp file. */
43102 ** they may be stored as part of the file handle and used by the
43103 ** 'conch file' locking functions later on. */
43111 mode_t openMode; /* Permissions to create file with */
43112 uid_t uid; /* Userid for the file */
43113 gid_t gid; /* Groupid for the file */
43129 /* Failed to open the file for read/write access. Try read-only. */
43144 /* The owner of the rollback journal or WAL file should always be the
43145 ** same as the owner of the database file. Try to ensure that this is
43148 ** this step, if a root process opens a database file, it can leave
43262 ** Delete the file at zPath. If the dirSync argument is true, fsync()
43263 ** the directory after deleting the file.
43267 const char *zPath, /* Name of file to be deleted */
43268 int dirSync /* If true, fsync() directory after deleting file */
43304 ** Test the existence of or access permissions of file zPath. The
43307 ** SQLITE_ACCESS_EXISTS: Return 1 if the file exists
43308 ** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
43309 ** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
43315 const char *zPath, /* Path of the file to examine */
43316 int flags, /* What do we want to learn about the zPath file? */
43736 ** until late in the file (here) after all of the other I/O methods have
43743 ** database file to coordinate safe, concurrent access by multiple readers
43744 ** and writers [http://sqlite.org/lockingv3.html]. The five file locking
43757 ** This works well on the local file system, but shows a nearly 100x
43761 ** supported network file systems. NFS and AFP both observe the
43768 ** To address the performance and cache coherency issues, proxy file locking
43770 ** single host at a time and moving file locks off of the database file
43771 ** and onto a proxy file on the local file system.
43790 ** Specifying ":auto:" means that if there is a conch file with a matching
43791 ** host ID in it, the proxy path in the conch file will be used, otherwise
43794 ** actual proxy file name is generated from the name and path of the
43795 ** database file. For example:
43802 ** the above APIs (assuming the conch file is not being held by another
43809 ** Proxy file locking relies primarily on two new supporting files:
43811 ** * conch file to limit access to the database file to a single host
43814 ** * proxy file to act as a proxy for the advisory locks normally
43817 ** The conch file - to use a proxy file, sqlite must first "hold the conch"
43818 ** by taking an sqlite-style shared lock on the conch file, reading the
43820 ** proxy path against the values stored in the conch. The conch file is
43821 ** stored in the same directory as the database file and the file name
43822 ** is patterned after the database file name as ".<databasename>-conch".
43823 ** If the conch file does not exist, or its contents do not match the
43825 ** lock and the conch file contents is updated with the host ID and proxy
43830 ** The proxy file - a single-byte file used for all advisory file locks
43831 ** normally taken on the database file. This allows for safe sharing
43832 ** of the database file for multiple readers and writers on the same
43833 ** host (the conch ensures that they all use the same local lock file).
43836 ** only taken when the first request to lock database file is made.
43838 ** opening a connection to a database file does not take a lock on it.
43839 ** The shared lock and an open file descriptor are maintained until
43842 ** The proxy file and the lock file are never deleted so they only need
43850 ** Database files accessed on non-local file systems are
43857 ** Enables the logging of error messages during host id file
43873 ** force proxy locking to be used for every database file opened, and 0
43885 ** The proxyLockingContext has the path and file structures for the remote
43890 unixFile *conchFile; /* Open conch file */
43891 char *conchFilePath; /* Name of the conch file */
43892 unixFile *lockProxy; /* Open proxy lock file */
43893 char *lockProxyPath; /* Name of the proxy lock file */
43894 char *dbPath; /* Name of the open file */
43902 ** The proxy lock file path for the database at dbPath is written into lPath,
43904 ** file path.
43948 ** Creates the lock file and any missing directories in lockPath
43984 ** Create a new VFS file descriptor (stored in memory obtained from
43985 ** sqlite3_malloc) and open the file named "path" in the file descriptor.
43987 ** The caller is responsible not only for closing the file descriptor
43988 ** but also for freeing the memory associated with the file descriptor.
44003 /* 1. first try to open/create the file
44004 ** 2. if that fails, and this is a lock file (not-conch), try creating
44006 ** 3. if that fails, try to open the file read-only
44007 ** otherwise return BUSY (if lock file) or CANTOPEN for the conch file
44074 /* simulate multiple hosts by creating unique hostid file paths */
44078 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
44106 /* simulate multiple hosts by creating unique hostid file paths */
44115 /* The conch file contains the header, host id and lock file path
44118 #define PROXY_HEADERLEN 1 /* conch file header length */
44123 ** Takes an open conch file, copies the contents to a new path and then moves
44124 ** it back. The newly created file's file descriptor is assigned to the
44125 ** conch file structure and finally the original conch file descriptor is
44154 /* write it out to the temporary break file */
44185 /* Take the requested lock on the conch file and break a stale lock if the
44267 ** lockPath is non-NULL, the host ID and lock file path must match. A NULL
44268 ** lockPath means that the lockPath in the conch file will be used if the
44270 ** and written to the conch file.
44304 /* read the existing conch file */
44317 ** conch file.
44325 do { /* in case we need to try again for an :auto: named lock file */
44332 /* for auto-named local lock file, just check the host ID and we'll
44333 ** use the local lock file path that's already in there
44402 /* If we created a new conch file (not just updated the contents of a
44403 ** valid conch file), try to match the permissions of the database
44411 /* try to match the database file R/W permissions, ignore failure */
44456 /* we couldn't create the proxy lock file with the old lock file path
44466 ** from the conch file or the path was allocated on the stack
44489 } while (1); /* in case we need to retry the :auto: lock file -
44495 ** If pFile holds a lock on a conch file, then release that lock.
44500 unixFile *conchFile; /* Name of the conch file */
44517 ** Given the name of a database file, compute the name of its conch file.
44533 ** the name of the original database file. */
44553 /* append the "-conch" suffix to the file */
44561 /* Takes a fully configured proxy locking-style unix file and switches
44562 ** the local lock file path
44594 ** pFile is a file that has been opened by a prior xOpen call. dbPath
44612 ** file path */
44616 /* all other styles use the locking context to store the db file path */
44624 ** Takes an already filled in unix file and alters it so all file locking
44625 ** will be performed on the local proxy lock file. The following fields
44633 char dbPath[MAXPATHLEN+1]; /* Name of the database file */
44661 ** (c) the file system is read-only, then enable no-locking access.
44764 /* turn on proxy file locking */
44787 ** file by this or any other process. If such a lock is held, set *pResOut
44807 ** Lock the file with the lock specified by parameter eFileLock - one
44848 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
44851 ** If the locking level of the file descriptor is already at or below
44871 ** Close a file that uses proxy locks.
44927 ** should be the only routines in this file that are visible from other
44953 ** database file and tries to choose an locking method appropriate for
45052 /* Initialize temp file dir array. */
45073 /************** Begin file os_win.c ******************************************/
45086 ** This file contains code that is specific to Windows.
45089 #if SQLITE_OS_WIN /* This file is used for Windows only */
45097 ** Include the header file for the Windows VFS.
45182 ** This constant should already be defined (in the "WinDef.h" SDK file).
45197 ** This constant should already be defined (in the "WinNT.h" SDK file).
45260 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
45262 ** CE SDK; however, they are not present in the header file)?
45267 ** Two of the file mapping APIs are different under WinRT. Figure out which
45290 ** These file mapping APIs are common to both Win32 and WinRT.
45319 ** WinCE lacks native support for file locking so we have to fake it
45338 sqlite3_vfs *pVfs; /* The VFS used to open this file */
45339 HANDLE h; /* Handle for accessing the file */
45340 u8 locktype; /* Type of lock currently held on this file */
45345 winShm *pShm; /* Instance of shared memory on this file */
45347 const char *zPath; /* Full pathname of this file */
45350 LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
45354 winceLock *shared; /* Global shared lock memory for the file */
45371 const sqlite3_io_methods *pMethod; /* The file I/O methods to use. */
46719 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
47155 ** failed and the associated file-system path, if any.
47321 ** Create the mutex and shared memory used for locking in the file
47359 /* Since the names of named mutexes, semaphores, file mappings etc are
47585 ** Lock a file region.
47617 ** Unlock a file region.
47660 ** Move the current position of the file handle passed as the first
47661 ** argument to offset iOffset within the file. If successful, return 0.
47671 OSTRACE(("SEEK file=%p, offset=%lld\n", pFile->h, iOffset));
47677 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
47690 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
47694 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
47711 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
47715 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
47727 ** Close a file.
47746 OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p\n",
47781 OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
47789 ** Read data from a file into a buffer. Return SQLITE_OK if all
47802 winFile *pFile = (winFile*)id; /* file handle */
47803 DWORD nRead; /* Number of bytes actually read from file */
47810 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
47820 OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
47835 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
47850 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_READ\n",
47859 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_SHORT_READ\n",
47864 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
47870 ** Write data from a buffer into a file. Return SQLITE_OK on success
47877 sqlite3_int64 offset /* Offset into the file to begin writing at */
47888 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
47898 OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
47962 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
47967 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_WRITE\n",
47974 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
47980 ** Truncate an open file to a specified size
47990 ** pages. This is because truncating the file means temporarily unmapping
47991 ** the file, and that might delete memory out from under existing cursors.
47993 ** This can result in incremental vacuum not truncating the file,
47995 ** No real harm comes of this - the database file is not corrupted,
47996 ** though some folks might complain that the file is bigger than it
48012 OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, size=%lld, lock=%d\n",
48015 /* If the user has configured a chunk-size for this file, truncate the
48016 ** file so that it consists of an integer number of chunks (i.e. the
48017 ** actual file size after the operation may be larger than the requested
48054 OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, rc=%s\n",
48069 ** Make sure all writes to a particular file are committed to disk.
48100 OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n",
48117 OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
48140 OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
48145 OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n",
48154 ** Determine the current size of a file in bytes
48163 OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize));
48193 OSTRACE(("SIZE file=%p, pSize=%p, *pSize=%lld, rc=%s\n",
48236 OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
48262 OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
48272 OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
48286 OSTRACE(("READ-UNLOCK file=%p, result=%d\n", pFile->h, res));
48291 ** Lock the file with the lock specified by parameter locktype - one
48325 OSTRACE(("LOCK file=%p, oldLock=%d(%d), newLock=%d\n",
48333 OSTRACE(("LOCK-HELD file=%p, rc=SQLITE_OK\n", pFile->h));
48367 OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, result=%d\n",
48372 OSTRACE(("LOCK-FAIL file=%p, count=%d, rc=%s\n",
48437 /* Update the state of the lock has held in the file descriptor then
48445 OSTRACE(("LOCK-FAIL file=%p, wanted=%d, got=%d\n",
48449 OSTRACE(("LOCK file=%p, lock=%d, rc=%s\n",
48456 ** file by this or any other process. If such a lock is held, return
48464 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut));
48469 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
48476 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res));
48479 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
48485 ** Lower the locking level on file descriptor id to locktype. locktype
48488 ** If the locking level of the file descriptor is already at or below
48501 OSTRACE(("UNLOCK file=%p, oldLock=%d(%d), newLock=%d\n",
48523 OSTRACE(("UNLOCK file=%p, lock=%d, rc=%s\n",
48533 ** file for reading or writing.
48541 ** database connections are accessing the same database file at the same
48589 ** Control and query of the open file handle.
48593 OSTRACE(("FCNTL file=%p, op=%d, pArg=%p\n", pFile->h, op, pArg));
48597 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48602 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48607 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48622 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
48625 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48630 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48635 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48640 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48655 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48661 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
48681 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
48707 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
48712 OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
48718 ** the specified file. This is almost always 512 bytes, but may be
48722 ** if two files are created in the same file-system directory (i.e.
48723 ** a database and its journal file) that the sector size will be the
48741 ** Windows will only let you create file view mappings
48753 ** this file, all of which may be shared by multiple threads.
48777 ** Object used to represent a single file opened and mmapped to provide
48801 char *zFilename; /* Name of the file */
48877 OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n",
48897 OSTRACE(("SHM-LOCK file=%p, func=%s, errno=%lu, rc=%s\n",
48957 ** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
48988 ** Open the shared-memory area associated with database file pDbFd.
48990 ** When opening a new shared-memory file, if no other instances of that
48991 ** file are currently open, in this process or in other processes, then
48992 ** the file must be truncated to zero length or have its header cleared.
48996 winShmNode *pShmNode = 0; /* The underlying mmapped file */
49109 winShmNode *pShmNode; /* The underlying shared-memory file */
49129 ** shared-memory file, too */
49145 sqlite3_file *fd, /* Database file holding the shared memory */
49268 ** shared-memory associated with the database file fd. Shared-memory regions
49286 sqlite3_file *fd, /* Handle open on database file */
49289 int isWrite, /* True to extend file if necessary */
49317 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
49318 sqlite3_int64 sz; /* Current size of wal-index file */
49323 ** Check to see if it has been allocated (i.e. if the wal-index file is
49365 HANDLE hMap = NULL; /* file-mapping handle */
49436 ** Cleans up the mapped region of the specified file, if any.
49473 ** Memory map or remap the file opened by file-descriptor pFd (if the file
49475 ** there already exists a mapping for this file, and there are still
49480 ** requested size is the size of the file on disk. The actual size of the
49575 ** If possible, return a pointer to a mapping of file fd starting at offset
49588 winFile *pFd = (winFile*)fd; /* The underlying database file */
49630 winFile *pFd = (winFile*)fd; /* The underlying database file */
49632 /* If p==0 (unmap the entire file) then there must be no outstanding
49647 ** file while a mapping is held, then the following winUnmapfile() call
49814 ** Create a temporary file name and store the resulting pointer into pzBuf.
49833 /* Allocate a temporary buffer to store the fully qualified file
49834 ** name for the temporary file. If this fails, we cannot continue.
50014 ** Check that the output buffer is large enough for the temporary file
50047 ** Return TRUE if the named file is really a directory. Return false if
50078 const char *zFilename, /* Name of file to check */
50079 int flags, /* Type of test to make on this file */
50084 ** Open a file.
50088 const char *zName, /* Name of the file (UTF-8) */
50089 sqlite3_file *id, /* Write the SQLite file handle here */
50109 ** a temporary file. Use this buffer to store the file name in.
50115 int eType = flags&0xFFFFFF00; /* Type of file to open */
50147 /* The main DB, main journal, WAL file and super-journal are never
50154 /* Assert that the upper layer has set one of the "file-type" flags. */
50173 ** temporary file name to use
50213 /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
50218 /* Creates a new file, only if it does not already exist. */
50219 /* If the file exists, it fails. */
50222 /* Open existing file, or create if it doesn't exist */
50225 /* Opens a file, only if it exists. */
50319 OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name,
50345 OSTRACE(("OPEN file=%p, name=%s, access=%lx, pOutFlags=%p, *pOutFlags=%d, "
50398 ** Delete the named file.
50400 ** Note that Windows does not allow a file to be deleted if some other
50402 ** will open a journal file shortly after it is created in order to do
50404 ** file open, we will be unable to delete it. To work around this
50411 const char *zFilename, /* Name of file to delete */
50515 ** Check the existence and status of a file.
50519 const char *zFilename, /* Name of file to check */
50520 int flags, /* Type of test to make on this file */
50546 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
51271 /************** Begin file memdb.c *******************************************/
51284 ** This file implements an in-memory VFS. A database is held as a contiguous
51287 ** This file also implements interface sqlite3_serialize() and
51305 /* Storage for a memdb file.
51314 ** using "file:/name?vfs=memdb". The first character of the name must be
51342 sqlite3_int64 sz; /* Size of the file */
51344 sqlite3_int64 szMax; /* Maximum allowed size of the file */
51345 unsigned char *aData; /* content of the file */
51355 /* An open file */
51359 int eLock; /* Most recent lock against this file */
51477 ** Close an memdb-file.
51521 ** Read data from an memdb-file.
51563 ** Write data to an memdb-file.
51596 ** Truncate an memdb-file.
51600 ** the size of a file, never to increase the size.
51617 ** Sync an memdb-file.
51626 ** Return the current file-size of an memdb-file.
51637 ** Lock an memdb-file.
51695 ** Unlock an memdb-file.
51733 ** File control method. For custom operations on an memdb-file.
51762 ** Return the sector-size in bytes for an memdb-file.
51770 ** Return the device characteristic flags supported by an memdb-file.
51780 /* Fetch a page of a memory-mapped file */
51811 ** Open an mem file handle.
51895 ** Delete the file located at zPath. If the dirSync argument is true,
51896 ** ensure the file-system modifications are synced to disk before
52195 /************** Begin file bitvec.c ******************************************/
52207 ** This file implements an object that represents a fixed-length
52210 ** A bitmap is used to record which pages of a database file have been
52228 ** Bitvec object is the number of pages in the database file at the
52609 /************** Begin file pcache.c ******************************************/
52621 ** This file implements that page cache.
52627 ** entry in the cache holds a single page of the database file. The
53534 /************** Begin file pcache1.c *****************************************/
53547 ** This file implements the default page cache implementation (the
53630 ** When reading a corrupt database file, it is possible that SQLite might
53702 ** open database file (including each in-memory database and each
53777 ** All code in this file should access the global structure above via the
53870 ** Malloc function used within this file to allocate space from the buffer
54817 /************** Begin file rowset.c ******************************************/
55322 /************** Begin file pager.c *******************************************/
55336 ** The pager is used to access a database disk file. It implements
55337 ** atomic commit and rollback through the use of a journal file that
55338 ** is separate from the database file. The pager also implements file
55340 ** file simultaneously, or one process from reading the database while
55346 /************** Begin file wal.h *********************************************/
55358 ** This header file defines the interface to the write-ahead logging
55398 /* Connection to a write-ahead log (WAL) file.
55407 /* Set the limiting size of a WAL file. */
55445 /* Copy pages from the log to the database file */
55452 int sync_flags, /* Flags to sync db file with (or 0) */
55467 ** by the pager layer on the database file.
55486 /* If the WAL file is not empty, return the number of bytes of content
55492 /* Return the sqlite3_file object for the WAL file */
55516 ** is called successfully on the file containing the page.
55518 ** Definition: A page of the database file is said to be "overwriteable" if
55528 ** the database file at the start of the transaction.
55530 ** (1) A page of the database file is never overwritten unless one of the
55544 ** (3) Writes to the database file are an integer multiple of the page size
55547 ** (4) Reads from the database file are either aligned on a page boundary and
55549 ** first 100 bytes of the database file.
55551 ** (5) All writes to the database file are synced prior to the rollback journal
55554 ** (6) If a super-journal file is used, then all writes to the database file
55565 ** journal is rolled back, the resulting database file will be logically
55566 ** equivalent to the database file at the beginning of the transaction.
55569 ** is called to restore the database file to the same size it was at
55574 ** (9) Whenever the database file is modified, at least one bit in the range
55582 ** (11) A database file is well-formed at the beginning and at the conclusion
55585 ** (12) An EXCLUSIVE lock is held on the database file when writing to
55586 ** the database file.
55588 ** (13) A SHARED lock is held on the database file while reading any
55589 ** content out of the database file.
55606 ** to print out file-descriptors.
55609 ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
55656 ** state - the file may or may not be locked and the database size is
55660 ** * Any lock, or no lock at all, may be held on the database file.
55679 ** * A SHARED or greater lock is held on the database file.
55685 ** there is no hot-journal in the file-system.
55695 ** BEGIN EXCLUSIVE) EXCLUSIVE lock is obtained on the database file when
55696 ** moving to this state, but the journal file is not written to or opened
55699 ** file.
55701 ** IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
55703 ** is made to obtain an EXCLUSIVE lock on the database file.
55707 ** lock is held on the database file.
55713 ** * The journal file may or may not be open.
55719 ** first modified by the upper layer. In rollback mode the journal file
55721 ** start of it. The database file on disk has not been modified.
55724 ** * A RESERVED or greater lock is held on the database file.
55725 ** * The journal file is open and the first header has been written
55732 ** when it modifies the contents of the database file. WAL connections
55733 ** never enter this state (since they do not modify the database file,
55734 ** just the log file).
55737 ** * An EXCLUSIVE or greater lock is held on the database file.
55738 ** * The journal file is open and the first header has been written
55749 ** database file. In this state the transaction may be committed simply
55750 ** by finalizing the journal file. Once in WRITER_FINISHED state, it is
55755 ** * An EXCLUSIVE or greater lock is held on the database file.
55766 ** db size etc.) are consistent with the contents of the file-system.
55777 ** file. To avoid this hazard, the pager switches into the ERROR state
55795 ** 2. An error occurs while attempting to finalize a journal file
55799 ** database file in function pagerStress() in order to free up
55843 ** the database file: NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
55851 ** when unlocking the file, and only updated when locking the file if the
55860 ** The exception is when the database file is unlocked as the pager moves
55861 ** from ERROR to OPEN state. At this point there may be a hot-journal file
55862 ** in the file-system that needs to be rolled back (as part of an OPEN->SHARED
55882 ** lock on the database file before attempting to roll it back. See function
55931 Pgno nOrig; /* Original number of pages in file */
55957 ** For a real on-disk database, the current lock held on the database file -
55973 ** (the 4-byte header field at byte offset 24 of the database file) is
55977 ** can only happen if an exclusive lock is held on the database file.
55979 ** relinquished on the database file. Each time a transaction is committed,
55991 ** journal file before it is synced to disk.
55993 ** Whether or not a journal file contains a super-journal pointer affects
55994 ** the way in which the journal file is finalized after the transaction is
55996 ** If a journal file does not contain a super-journal pointer, it is
55998 ** it does contain a super-journal pointer the journal file is finalized
56005 ** subsequently interrupted transaction that reuses the journal file.
56007 ** The flag is cleared as soon as the journal file is finalized (either
56009 ** journal file from being successfully finalized, the setSuper flag
56016 ** to the file-system in order to free up memory).
56022 ** to allocate a new page to prevent the journal file from being written
56027 ** pagerStress() is permitted, but syncing the journal file is not.
56028 ** This flag is set by sqlite3PagerWrite() when the file-system sector-size
56035 ** is opened as an in-memory journal file. If false, then in-memory
56043 ** Variable dbSize is set to the number of pages in the database file.
56047 ** dbSize is set based on the size of the database file, which may be
56049 ** 28 of the database header by the btree). If the size of the file
56051 ** dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
56052 ** Except, any file that is greater than 0 bytes in size is considered
56053 ** to have at least one page. (i.e. a 1KB file with 2K page-size leads
56068 ** the file on disk in pages. It is set to a copy of dbSize when the
56070 ** to write or truncate the database file on disk.
56075 ** that the database file is larger than the database image (Pager.dbSize),
56077 ** to measure the database file on disk, and then truncates it if required.
56081 ** pager_truncate() may cause the file to become smaller or larger.
56108 ** file in bits 0x04 and 0x08. In other words, to get the correct sync flags
56118 u8 useJournal; /* Use a rollback journal on this file */
56124 u8 tempFile; /* zFilename is a temporary or immutable file */
56127 u8 memDb; /* True to inhibit all file I/O */
56140 u8 eLock; /* Current lock held on database file */
56149 Pgno dbFileSize; /* Number of pages in the database file */
56155 Bitvec *pInJournal; /* One bit for each page in the database file */
56159 i64 journalOff; /* Current write offset in the journal file */
56165 char dbFileVers[16]; /* Changes whenever database file changes */
56182 char *zFilename; /* Name of the database file */
56183 char *zJournal; /* Name of the journal file */
56239 ** file after power is restored. If an attempt is then made
56248 ** journal file right after the header. The random initializer is important,
56251 ** garbage data came from an obsolete journal file, the checksums might
56294 ** The argument to this macro is a file descriptor (type sqlite3_file*).
56309 ** Return true if page pgno can be read directly from the database file
56312 ** * the database file is open,
56314 ** * the desired page is not currently in the wal file.
56366 /* Regardless of the current state, a temp-file connection always behaves
56367 ** as if it has an exclusive lock on the database file. It never updates
56374 ** And if the journal-mode is "OFF", the journal file must not be open.
56382 ** a journal file. (although the in-memory journal implementation may
56383 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
56398 ** on the file.
56433 ** journal file nor the WAL file are open. This happens during
56595 ** Return true if the page is already in the journal file.
56603 ** Read a 32-bit integer from the given file descriptor. Store the integer
56625 ** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK
56635 ** Unlock the database file to level eLock, which must be either NO_LOCK
56662 ** Lock the database file to level eLock, which must be either SHARED_LOCK,
56696 ** file when it contains rollback data for exactly one page.
56785 ** When this is called the journal file for pager pPager must be open.
56786 ** This function attempts to read a super-journal file name from the
56787 ** end of the file and, if successful, copies it into memory supplied
56789 ** used to store a super-journal file name at the end of a journal file.
56798 ** If a super-journal file name is present at the end of the journal
56799 ** file, then it is copied into the buffer pointed to by zSuper. A
56801 ** super-journal file name.
56803 ** If it is determined that no super-journal file name is present
56806 ** If an error occurs while reading from the journal file, an SQLite
56812 i64 szJ; /* Total size in bytes of journal file pJrnl */
56878 ** The journal file must be open when this function is called.
56880 ** This function is a no-op if the journal file has not been written to
56884 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
56885 ** zero the 28-byte header at the start of the journal file. In either case,
56886 ** if the pager is not in no-sync mode, sync the journal file immediately
56891 ** journal file in bytes is larger than this value, then truncate the
56892 ** journal file to Pager.journalSizeLimit bytes. The journal file does
56917 ** is still held on the file. If there is a size limit configured for
56918 ** the persistent journal and the journal file currently consumes more
56920 ** to sync the file following this operation.
56934 ** The journal file must be open when this routine is called. A journal
56935 ** header (JOURNAL_HDR_SZ bytes) is written into the journal file at the
56955 assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
56982 ** rest of the journal file contains valid page records. This assumption
56984 ** file it may contain some garbage data. There are two scenarios
56991 ** that garbage data is never appended to the journal file.
57023 ** journal header consumes to the journal file here. Then increment the
57025 ** record is written to the following sector (leaving a gap in the file
57029 ** be significantly slower than contiguously writing data to the file,
57050 ** The journal file must be open when this is called. A journal header file
57052 ** file. The current location in the journal file is given by
57062 ** If the journal header file appears to be corrupted, SQLITE_DONE is
57064 ** cannot be read from the journal file an error code is returned.
57069 i64 journalSize, /* Size of the open journal file in bytes */
57077 assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
57080 ** journal file is too small for there to be a header stored at this
57146 ** the journal file here.
57173 ** Write the supplied super-journal name into the journal file for pager
57175 ** thing written to a journal file. If the pager is in full-sync mode, the
57176 ** journal file descriptor is advanced to the next sector boundary before
57194 i64 iHdrOff; /* Offset of header in journal file */
57195 i64 jrnlSize; /* Size of journal file on disk */
57224 /* Write the super-journal data to the end of the journal file. If
57239 ** journal-file may extend past the end of the super-journal name
57240 ** and 8 bytes of magic data just written to the file. This is
57241 ** dangerous because the code to rollback a hot-journal file
57246 ** file to the required size.
57316 ** If the pager is not in exclusive-access mode, the database file is
57317 ** completely unlocked. If the file is unlocked and the file-system does
57318 ** not exhibit the UNDELETABLE_WHEN_OPEN property, the journal file is
57324 ** or not, any journal file left in the file-system will be treated
57348 ** close the journal file when dropping the database lock. Otherwise
57349 ** another connection with journal_mode=delete might delete the file
57365 ** file fails, set the current lock to UNKNOWN_LOCK. See the comment
57422 ** to be replayed to restore the contents of the database file (as if
57455 ** file has been created already (via a spill on pagerStress()) and
57470 ** the journal file or writing the very first journal-header of a
57479 ** If the journal file is open, then it is "finalized". Once a journal
57480 ** file has been finalized it is not possible to use it to roll back a
57487 ** Journal file descriptor is simply closed. This destroys an
57491 ** Journal file is truncated to zero bytes in size.
57494 ** The first 28 bytes of the journal file are zeroed. This invalidates
57495 ** the first journal header in the file, and hence the entire journal
57496 ** file. An invalid journal file cannot be rolled back.
57499 ** The journal file is closed and deleted using sqlite3OsDelete().
57502 ** the journal file is never used. Instead, if the journalMode is
57507 ** If running in non-exclusive rollback mode, the lock on the file is
57511 ** any of the IO operations to finalize the journal file or unlock the
57513 ** operation to finalize the journal file fails, then the code still
57514 ** tries to unlock the database file if not in exclusive mode. If the
57521 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
57549 /* Finalize the journal file. */
57559 /* Make sure the new file size is written into the inode right away.
57576 ** file should be closed and deleted. If this connection writes to
57577 ** the database file, it will do so using an in-memory journal.
57618 ** lock held on the database file.
57624 ** mode if the database file on disk is larger than the database image.
57627 ** file. So it is safe to truncate the database file to its minimum
57651 ** database file.
57656 ** the database file and move the pager back to OPEN state. If this
57657 ** means that there is a hot-journal left in the file-system, the next
57692 ** incompatible journal file format.
57740 ** Read a single page from either the journal file (if isMainJrnl==1) or
57742 ** The page begins at offset *pOffset into the file. The *pOffset
57748 ** If the page number of the page record read from the (sub-)journal file
57758 ** If the page record is successfully read from the (sub-)journal file
57760 ** while reading the record from the (sub-)journal file or while writing
57761 ** to the database file, then the IO error code is returned. If data
57762 ** is successfully read from the (sub-)journal file but appears to be
57767 ** * If the record is being rolled back from the main journal file
57788 sqlite3_file *jfd; /* The file descriptor for the journal file */
57817 ** file. Return an error code to the caller if an IO error occurs.
57861 ** not the database file. The page is left marked dirty in this case.
57871 ** pager cache if it exists and the main file. The page is then marked
57883 ** database file without an entry in the rollback journal that can
57890 ** 2008-04-14: When attempting to vacuum a corrupt database file, it
57892 ** Do not attempt to write if database file has never been opened.
57918 /* Write the data read from the journal back into the database file.
57920 ** was encrypted before it was written to the journal file. The exception
57923 ** file. */
57950 ** will be read from the database file, which may or may not be
58005 ** Parameter zSuper is the name of a super-journal file. A single journal
58006 ** file that referred to the super-journal file has just been rolled back.
58007 ** This routine checks if it is possible to delete the super-journal file,
58013 ** When a super-journal file is created, it is populated with the names
58015 ** encoded text. The end of each child journal file is marked with a
58017 ** file for a transaction involving two databases might be:
58021 ** A super-journal file may only be deleted once all of its child
58024 ** This function reads the contents of the super-journal file into
58030 ** file zSuper
58034 ** no such child journal can be found, file zSuper is deleted from
58035 ** the file-system using sqlite3OsDelete().
58043 ** the entire contents of the super-journal file. This could be
58050 sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */
58051 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
58052 char *zSuperJournal = 0; /* Contents of super-journal file */
58053 i64 nSuperJournal; /* Size of super-journal file */
58054 char *zJournal; /* Pointer to one journal within MJ file */
58059 /* Allocate space for both the pJournal and pSuper file descriptors.
58060 ** If successful, open the super-journal file for reading.
58073 /* Load the entire super-journal file into space obtained from
58104 ** so, return without deleting the super-journal file.
58124 /* We have a match. Do not delete the super-journal file. */
58147 ** file in the file-system. This only happens when committing a transaction,
58150 ** If the main database file is not open, or the pager is not in either
58152 ** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
58153 ** If the file on disk is currently larger than nPage pages, then use the VFS
58156 ** Or, it might be the case that the file on disk is smaller than
58158 ** you try to truncate a file to some size that is larger than it
58160 ** the end of the new file instead.
58163 ** the database file, return the error code to the caller.
58199 ** Return a sanitized version of the sector-size of OS file pFile. The
58216 ** of the open database file. The sector size will be used
58227 ** If the file has the SQLITE_IOCAP_POWERSAFE_OVERWRITE property, then set
58233 ** size. For backwards compatibility of the rollback journal file format,
58243 /* Sector size doesn't matter for temporary files. Also, the file
58253 ** Playback the journal and thus restore the database file to
58256 ** The journal file format is as follows:
58280 ** value of nRec from the size of the journal file. But if a power
58282 ** case that the size of the journal file had already been increased but
58284 ** the value of nRec computed from the file size would be too large. For
58288 ** from the file size. This value is used when the user selects the
58293 ** If the file opened as the journal file is not a well-formed
58294 ** journal file then all pages up to the first corrupted page are rolled
58295 ** back (or no pages if the journal header is corrupted). The journal file
58299 ** If an I/O or malloc() error occurs, the journal-file is not deleted
58311 i64 szJ; /* Size of the journal file in bytes */
58314 Pgno mxPg = 0; /* Size of the original file in pages */
58317 char *zSuper = 0; /* Name of super-journal file if any */
58332 ** If a super-journal file name is specified, but the file is not
58359 /* Read the next journal header from the journal file. If there are
58360 ** not enough bytes left in the journal file for a complete header, or
58374 ** file consists of pages, there are no more journal headers. Compute
58386 ** size of the file.
58394 ** should be computed based on the journal file size.
58402 ** database file back to its original size.
58416 ** database file and/or page cache.
58456 /* Following a rollback, the database file should be back in its original
58458 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
58518 ** Read the content for page pPg out of the database file (or out of
58521 ** file before this function is called.
58524 ** the value read from the database file.
58558 ** that will never be a valid file version. dbFileVers[] is a copy
58612 ** written into the log file when a WAL transaction is rolled back.
58644 ** rollback involves simply truncating the log file. Therefore, if one
58662 ** been written (but not committed) to the log file, do one of the
58711 ** any pages with page numbers greater than nTruncate into the WAL file.
58782 ** to PAGER_READER state to determine the size of the database file
58795 ** available from the WAL sub-system if the log file is empty or
58806 ** the database file. If the size of the database file is not an
58810 i64 n = 0; /* Size of db file in bytes */
58818 /* If the current number of pages in the file is greater than the
58820 ** that the file can be read.
58832 ** Check if the *-wal file that corresponds to the database opened by pPager
58833 ** exists if the database is not empy, or verify that the *-wal file does
58834 ** not exist (by deleting it) if the database file is empty.
58836 ** If the database is not empty and the *-wal file exists, open the pager
58837 ** in WAL mode. If the database is empty or if no *-wal file exists and
58843 ** The caller must hold a SHARED lock on the database file to call this
58844 ** function. Because an EXCLUSIVE lock on the db file is required to delete
58855 int isWal; /* True if WAL file exists */
58861 Pgno nPage; /* Size of the database file */
58882 ** the entire super-journal file. The case pSavepoint==NULL occurs when
58893 ** file if PagerSavepoint.iHdrOffset is zero.
58897 ** PagerSavepoint.iHdrOffset to the end of the main journal file.
58899 ** * Pages are then played back from the sub-journal file, starting
58901 ** the journal file.
58909 ** journal file. There is no need for a bitvec in this case.
58944 ** journal. The actual file might be larger than this in
58971 ** of the main journal file. Continue to skip out-of-range pages and
59057 ** Change the maximum size of any memory mapping made of the database file.
59103 ** prior to the start of checkpoint and that the database file is synced
59107 ** file is synced following each commit operation, in addition to the
59161 ** attempts to open a temporary file. This information is used for
59169 ** Open a temporary file.
59171 ** Write the file descriptor into *pFile. Return SQLITE_OK on success
59173 ** delete the temporary file when it is closed.
59185 sqlite3_file *pFile, /* Write the file descriptor here */
59383 ** Read the first N bytes from the beginning of the file into memory
59386 ** If the pager was opened on a transient file (zFilename==""), or
59387 ** opened on a file less than N bytes in size, the output buffer is
59421 ** However, if the file is between 1 and <page-size> bytes in size, then
59422 ** this is considered a 1 page file.
59432 ** Try to obtain a lock of type locktype on the database file. If
59477 ** the database file. If a savepoint transaction were rolled back after
59480 ** the database file or the portion of the rollback journal and
59506 ** Truncate the in-memory database file image to nPage pages. This
59507 ** function does not actually modify the database file on disk. It
59535 ** syncs the journal file to disk, then sets pPager->journalHdr to the
59536 ** size of the journal file so that the pager_playback() routine knows
59537 ** that the entire journal file has been synced.
59635 /* Verify that the database file has not be deleted or renamed out from
59649 /* If the HAS_MOVED file-control is unimplemented, assume that the file
59700 /* If it is open, sync the journal file before calling UnlockAndRollback.
59702 ** file may be played back into the database. If a power failure occurs
59707 ** database and close the journal file without attempting to roll it
59709 ** rollback before accessing the database file.
59759 ** device characteristics of the file-system, as follows:
59761 ** * If the journal file is an in-memory journal file, no action need
59768 ** mode, then the journal file is synced before this field is updated.
59771 ** journal file is synced.
59777 ** if( <full-sync mode> ) xSync(<journal file>);
59780 ** if( NOT SEQUENTIAL ) xSync(<journal file>);
59808 ** mode, then the journal file may at this point actually be larger
59810 ** file happens to be a journal-header (written as part of the
59813 ** anything else to the journal file (or commits/rolls back its
59819 ** To work around this, if the journal file does appear to contain
59845 /* Write the nRec value into the journal file header. If in
59852 ** for garbage data to be appended to the file, the nRec field
59888 /* Unless the pager is in noSync mode, the journal file was just
59901 ** in-memory pages in the list to the database file. The argument may
59906 ** is called. Before writing anything to the database file, this lock
59908 ** SQLITE_BUSY is returned and no data is written to the database file.
59910 ** If the pager is a temp-file pager and the actual file-system file
59914 ** Once the lock has been upgraded and, if necessary, the file opened,
59915 ** the pages are written out to the database file in list order. Writing
59921 ** If writing out a page causes the database file to grow, Pager.dbFileSize
59924 ** the database file.
59939 /* If the file is a temp-file has not yet been opened, open it now. It
59949 ** file size will be.
59966 ** make the file smaller (presumably by auto-vacuum code). Do not write
59967 ** any such pages to the file.
59986 ** the value now stored in the database file. If writing this
59987 ** page caused the database file to grow, update dbFileSize.
60015 ** Ensure that the sub-journal file is open. If it is already open, this
60064 ** write the journal record into the file. */
60108 ** out to the database file, if possible. This may involve syncing the
60109 ** journal file.
60168 /* Sync the journal file if required. */
60175 /* Write the contents of the page out to the database file. */
60216 ** The zFilename argument is the path to the database file to open.
60217 ** If zFilename is NULL then a randomly-named temporary file is created
60218 ** and used as the file to be cached. Temporary files are be deleted
60236 ** If the pager object is allocated and the specified file opened
60244 sqlite3_vfs *pVfs, /* The virtual file system to use */
60246 const char *zFilename, /* Name of the database file to open */
60248 int flags, /* flags controlling this file */
60256 int memDb = 0; /* True if this is an in-memory file */
60262 int readOnly = 0; /* True if this is a read-only file */
60264 char *zPathname = 0; /* Full path to database file */
60273 /* Figure out how much space is required for each journal file-handle
60293 ** to by zPathname, length nPathname. Or, if this is a temporary file,
60327 ** as it will not be possible to open the journal file or even
60339 ** three file descriptors, the database file name and the journal
60340 ** file name. The layout in memory is as follows:
60344 ** Database file handle (pVfs->szOsFile bytes)
60345 ** Sub-journal file handle (journalFileSize bytes)
60346 ** Main journal file handle (journalFileSize bytes)
60349 ** Database file name (nPathname+1 bytes)
60385 ROUND8(pVfs->szOsFile) + /* The main db file */
60456 /* Open the pager file.
60467 /* If the file was successfully opened for read/write access,
60469 ** database file. The default page size is the maximum of:
60509 /* If a temporary file is requested, it is not opened immediately.
60511 ** opening the file until the first call to OsWrite().
60514 ** database is the same as a temp-file that is never written out to
60544 /* If an error occurred above, free the Pager structure and close the file.
60628 ** the file-system for the given pager. A hot journal is one that
60630 ** file exists if the following criteria are met:
60632 ** * The journal file exists in the file system, and
60633 ** * No process holds a RESERVED or greater lock on the database file, and
60634 ** * The database file itself is greater than 0 bytes in size, and
60635 ** * The first byte of the journal file exists and is not 0x00.
60637 ** If the current size of the database file is 0 but a journal file
60639 ** database with the same name. In this case the journal file is
60644 ** at the end of the file. If there is, and that super-journal file
60645 ** does not exist, then the journal file is not really hot. In this
60647 ** routine will discover that the journal file is not really hot and
60650 ** If a hot-journal file is found to exist, *pExists is set to 1 and
60651 ** SQLITE_OK returned. If no hot-journal file is present, *pExists is
60653 ** to determine whether or not a hot-journal file exists, the IO error
60659 int exists = 1; /* True if a journal file is present */
60687 Pgno nPage; /* Number of pages in database file */
60694 ** the database file but not the journal was deleted, or (2) the initial
60696 ** In either case, the journal file can be deleted. However, take care
60697 ** not to delete the journal file if it is already open due to
60708 /* The journal file exists and no other connection has a reserved
60709 ** or greater lock on the database file. Now check that there is
60710 ** at least one non-zero bytes at the start of the journal file.
60729 /* If we cannot open the rollback journal file in order to see if
60750 ** This function is called to obtain a shared lock on the database file.
60758 ** on the database file), then an attempt is made to obtain a
60759 ** SHARED lock on the database file. Immediately after obtaining
60760 ** the SHARED lock, the file-system is checked for a hot-journal,
60763 ** the 'change-counter' field of the database file header and
60770 ** file.
60773 ** occurs while locking the database, checking for a hot-journal file or
60774 ** rolling back a journal file, the IO error code is returned.
60789 int bHotJournal = 1; /* True if there exists a hot journal-file */
60800 /* If a journal file exists, and there is no RESERVED lock on the
60801 ** database file, then it either needs to be played back or deleted.
60815 /* Get an EXCLUSIVE lock on the database file. At this point it is
60818 ** database file, detect the RESERVED lock, and conclude that the
60823 ** other process attempting to access the database file will get to
60825 ** on the database file.
60835 /* If it is not already open and the file exists on disk, open the
60837 ** in exclusive-access mode the file descriptor will be kept open
60846 ** function was called and the journal file does not exist.
60850 int bExists; /* True if journal file exists */
60889 ** the file. If the unlock attempt fails, then Pager.eLock must be
60895 ** to ERROR state in the state diagram at the top of this file,
60916 ** occurring on the very first access to a file, in order to save a
60920 ** at offset 24 into the file. The first 4 of these 16 bytes are
60922 ** other bytes change randomly with each file change when
60943 /* Unmap the database file. It is possible that external processes
60944 ** may have truncated the database file and then extended it back
60955 /* If there is a WAL file in the file-system, open this database in WAL
61014 ** read from the database file. In some cases, the pcache module may
61041 ** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
61058 Pager *pPager, /* The pager open on the database file */
61160 Pager *pPager, /* The pager open on the database file */
61167 u32 iFrame = 0; /* Frame to read from WAL file */
61232 Pager *pPager, /* The pager open on the database file */
61248 Pager *pPager, /* The pager open on the database file */
61319 ** file when this routine is called.
61321 ** Open the journal file for pager pPager and write a journal header
61323 ** as well. This function is only used when the journal file is being
61325 ** when opening a hot journal file to roll it back.
61327 ** If the journal file is already open (as it may be in exclusive mode),
61329 ** already open file.
61331 ** Whether or not the journal file is opened by this function, the
61336 ** an IO error code if opening or writing the journal file fails.
61357 /* Open the journal file if it is not already open. */
61387 /* Write the first journal header to the journal file and open
61417 ** lock on the database file. If exFlag is true, then acquire at least
61422 ** within this transaction will be opened as an in-memory file. This
61427 ** or using a temporary file otherwise.
61451 /* Grab the write lock on the log file. If successful, upgrade to
61458 /* Obtain a RESERVED lock on the database file. If the exFlag parameter
61476 ** file as well as into the page cache. Which would be incorrect in
61505 /* We should never write to the journal file the page that
61518 ** in the database file. And if an IO error occurs while doing so,
61560 ** been started. The journal file may or may not be open at this point.
61572 /* The journal file needs to be opened. Higher level routines have already
61593 ** then end of the file, make sure it is marked as PGHDR_NEED_SYNC.
61649 Pgno nPageCount; /* Total number of pages in database file */
61708 ** journal file must contain sync()ed copies of all of them
61709 ** before any of them can be written out to the database file.
61736 ** must have been written to the journal file before returning.
61784 ** This optimization cannot be used with a temp-file, as the page may
61803 ** This routine is called to increment the value of the database file
61805 ** byte offset 24 of the pager file. The secondary change counter at
61815 ** page data. In this case the file will be updated when the current
61820 ** if isDirect is non-zero, then the database file is updated directly
61855 /* Open page 1 of the file for writing. */
61872 /* If running in direct mode, write the contents of page 1 to the file. */
61901 ** Sync the database file to disk. This is a no-op for in-memory databases
61923 ** the database file, an attempt is made to obtain one.
61947 ** Sync the database file for the pager pPager. zSuper points to the name
61948 ** of a super-journal file that should be written into the individual
61949 ** journal file. zSuper may be NULL, which is interpreted as no
61954 ** * The database file change-counter is updated,
61956 ** * all dirty pages are written to the database file,
61957 ** * the database file is truncated (if required), and
61958 ** * the database file synced.
61961 ** (delete, truncate or zero the first part of) the journal file (or
61962 ** delete the super-journal file if specified).
61967 ** If the final parameter - noSync - is true, then the database file itself
61969 ** sync the database file before calling CommitPhaseTwo() to delete the
61970 ** journal file in this case.
61975 int noSync /* True to omit the xSync on the db file */
62046 ** * The file-system supports the atomic-write property for
62048 ** * This commit is not part of a multi-file transaction, and
62049 ** * Exactly one page has been modified and store in the journal file.
62055 ** to make sure the journal file has actually been created, then call
62061 ** in 'direct' mode. In this case the journal file will never be
62075 /* Update the db file change counter via the direct-write method. The
62078 ** directly to the database file. Because of the atomic-write
62079 ** property of the host file-system, this is safe.
62101 /* Write the super-journal name into the journal file. If a
62102 ** super-journal file name has already been written to the journal file,
62108 /* Sync the journal file and write all dirty pages to the database.
62110 ** create the journal file or perform any real IO.
62158 /* If the file on disk is smaller than the database image, use
62159 ** pager_truncate to grow the file here. This can happen if the database
62162 ** last page is never written out to disk, leaving the database file
62171 /* Finally, sync the database file. */
62188 ** When this function is called, the database file has been completely
62190 ** synced to disk. The journal file still exists in the file-system
62194 ** This function finalizes the journal file, either by deleting,
62221 ** The start of the journal file currently contains a single journal
62224 ** to the database file. So there is no need to zero the journal
62253 ** 1) It rolls back the journal file, restoring all database file and
62257 ** 2) It finalizes the journal file, so that it is not used for hot
62260 ** Finalization of the journal file (task 2) is only performed if the
62315 ** Return TRUE if the database file is opened read-only. Return FALSE
62403 ** Return true if this is an in-memory or temp-file backed pager.
62416 ** occurs while opening the sub-journal file, then an IO error code is
62546 ** If this is a temp-file, it is possible that the journal file has
62548 ** the database file, so the playback operation can be skipped.
62576 ** Return the full pathname of the database file.
62601 ** Return the file handle for the database file associated
62602 ** with the pager. This might return NULL if the file has
62610 ** Return the file handle for the journal file (if it exists).
62611 ** This will be either the rollback journal or the WAL file.
62622 ** Return the full pathname of the journal file.
62657 ** into the log file.
62672 ** Move the page pPg to location pgno in the file.
62796 /* If needSyncPgno is non-zero, then the journal file needs to be
62797 ** sync()ed before any data is written to database file page needSyncPgno.
62806 ** this transaction, it may be written to the database file before
62807 ** it is synced into the journal file. This way, it may end up in
62808 ** the journal file twice, but that is not a problem.
62911 ** the logic there will never allow a temporary file to be changed
62934 ** delete the journal file.
62945 /* In this case we would like to delete the journal file. If it is
62946 ** not possible, then that is not a problem. Deleting the journal file
62949 ** Before deleting the journal file, obtain a RESERVED lock on the
62950 ** database file. This ensures that the journal file is not deleted
63057 /* This only happens when a database file is zero bytes in size opened and
63061 ** used for this since it starts transactions on every database file,
63094 ** Attempt to take an exclusive lock on the database file. If a PENDING lock
63114 ** lock on the database file and use heap-memory to store the wal-index
63126 ** file, to make sure this is safe.
63132 /* Open the connection to the log file. If this operation fails,
63148 ** The caller must be holding a SHARED lock on the database file to call
63152 ** file (not a temp file or an in-memory database), and the WAL file
63158 ** If the pager is open on a temp-file (or in-memory database), or if
63159 ** the WAL file is already open, set *pbOpen to 1 and return SQLITE_OK
63193 ** This function is called to close the connection to the log file prior
63196 ** Before closing the log file, this function attempts to take an
63197 ** EXCLUSIVE lock on the database file. If this cannot be obtained, an
63206 /* If the log file is not already open, but does exist in the file-system,
63224 ** the database file, the log and log-summary files will be deleted.
63347 ** the pager is in WAL mode and the WAL file currently contains one or more
63349 ** WAL frames. Otherwise, if this is not a WAL database or the WAL file
63361 /************** Begin file wal.c *********************************************/
63374 ** This file contains the implementation of a write-ahead log (WAL) used in
63379 ** A WAL file consists of a header followed by zero or more "frames".
63381 ** database file. All changes to the database are recorded by writing
63385 ** transferred back into the database file in an operation called a
63388 ** A single WAL file can be used multiple times. In other words, the
63469 ** the database file.
63491 ** might choose to implement the wal-index using a mmapped file. Because
63497 ** file whose name is the database name with a "-shm" suffix added. For that
63498 ** reason, the wal-index is sometimes called the "shm" file.
63501 ** be) reconstructed from the original WAL file. In fact, the VFS is required
63505 ** Hence, unlike the database and WAL file formats which store all values
63536 ** first frame in the WAL file. The first entry in the second index block
63537 ** in the WAL file corresponds to the (HASHTABLE_NPAGE_ONE+1)th frame in
63542 ** depending on the contents of the WAL file. This does not change the
63589 ** to cover a typical 10 megabyte WAL file, assuming 1K pages. 8 or 10
63629 ** If a client begins recovering a WAL file and finds that (a) the checksum
63651 ** locks are on the shm file. The WALINDEX_LOCK_OFFSET constant (which
63652 ** should be 120) is the location in the shm file for the first locking
63742 ** get all their all content directly from the database file and ignore
63766 ** wal-index file (also known as the -shm file):
63831 ** only support mandatory file-locks, we do not read or write data
63832 ** from the region of the file on which locks are applied.
63845 ** big-endian format in the first 4 bytes of a WAL file.
63848 ** file are calculated by treating all data as an array of 32-bit
63855 ** Return the offset of frame iFrame in the write-ahead log file,
63864 ** An open write-ahead log file is represented by an instance of the
63869 sqlite3_file *pDbFd; /* File handle for the database file */
63870 sqlite3_file *pWalFd; /* File handle for WAL file */
63874 int szFirstBlock; /* Size of first block written to WAL file */
63883 u8 truncateOnCommit; /* True to truncate WAL file on commit */
63890 const char *zWalName; /* Name of WAL file */
63914 #define WAL_RDONLY 1 /* The WAL file is readonly */
63915 #define WAL_SHM_RDONLY 2 /* The SHM file is readonly */
63951 ** Define the parameters of the hash tables in the wal-index file. There
64129 ** If there is the possibility of concurrent access to the SHM file
64359 ** in the wal-index file. Set pLoc->iZero to one less than the frame
64500 /* Assuming the wal-index file was successfully mapped, populate the
64574 ** Recover the wal-index by reading the write-ahead log file.
64585 i64 nSize; /* Size of log file */
64634 ** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid
64636 ** WAL file.
64680 /* Read all frames from the log file. */
64784 /* If more than one frame was recovered from the log file, report an
64787 ** checkpointing the log file.
64791 "recovered %d frames from WAL file %s",
64820 ** Open a connection to the WAL file zWalName. The database file must
64824 ** A SHARED lock should be held on the database file when this function
64826 ** client from unlinking the WAL or wal-index file. If another process
64830 ** If the log file is successfully opened, SQLITE_OK is returned and
64836 sqlite3_file *pDbFd, /* The open database file */
64837 const char *zWalName, /* Name of the WAL file */
64851 ** for the -shm file. Any change that causes one of these asserts to
64856 ** interpret hex dumps of the -shm file.
64881 ** this source file. Verify that the #defines of the locking byte offsets
64911 /* Open file handle on the write-ahead log file. */
64935 ** Change the size to which the WAL file is trucated on each reset.
65336 ** b) the entire log file has been checkpointed, and
65338 ** file - there are no readers that may attempt to read a frame from
65339 ** the log file.
65343 ** writing frames into the start of the log file.
65368 ** Copy as much content as we can from the WAL back into the database file
65384 ** Fsync is also called on the database file if (and only if) the entire
65385 ** WAL content is copied into the database file. This second fsync makes
65387 ** database file.
65469 ** about the eventual size of the db file to the VFS layer.
65473 i64 nSize; /* Current size of database file */
65479 ** database plus the amount of data in the wal file, plus the
65490 /* Iterate through the contents of the WAL, copying data to the db file */
65502 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
65541 ** entire wal file has been copied into the database file, then block
65542 ** until all readers have finished using the wal file. This ensures that
65543 ** the next process to write to the database restarts the wal file.
65558 ** truncates the log file to zero bytes just prior to a
65563 ** writer clients should see that the entire log file has been
65567 ** file-system. To avoid this, update the wal-index header to
65568 ** indicate that the log file contains zero valid frames. */
65583 ** If the WAL file is currently larger than nMax bytes in size, truncate
65601 ** Close a connection to a log file.
65614 /* If an EXCLUSIVE lock can be obtained on the database file (using the
65616 ** connection associated with this log file is the only connection to
65637 /* Try to delete the WAL file if the checkpoint completed and
65642 /* Try to truncate the WAL file to zero bytes if the checkpoint
65647 ** leave a corrupt WAL file on disk. */
65695 ** from the file. If this happens, return non-zero.
65771 ** since the shared-memory might be inconsistent with the WAL file
65842 ** indicates that a writer has fixed the SHM file for us, so retry */
65854 ** on hand to keep the shared-memory up-to-date with the WAL file.
65857 ** memory-mapping a *-shm file, where a prior writer has shut down and
65858 ** left the *-shm file on disk, and now the present connection is trying
65859 ** to use that database but lacks write permission on the *-shm file.
65864 ** The *-wal file has been read and an appropriate wal-index has been
65874 ** beginning (including attempting to map the *-shm file).
65879 i64 szWal; /* Size of wal file on disk in bytes */
65880 i64 iOffset; /* Current offset when reading wal file */
65914 ** have already checkpointed the WAL file and, while the current
65938 /* Make sure some writer hasn't come in and changed the WAL file out
65946 /* If the wal file is too small to contain a wal-header and the
65948 ** reading the database file only. However, the page cache cannot
65950 ** the db, run a checkpoint, truncated the wal file and disconnected
65957 /* Check the salt keys at the start of the wal file still match. */
65963 /* Some writer has wrapped the WAL file while we were not looking.
65982 ** wal file since the heap-memory wal-index was created. If so, the
66000 ** appended to this wal file. Set rc to WAL_RETRY and break out of
66062 ** completely and get all content directly from the database file.
66174 ** When holding READ_LOCK(0), the reader ignores the entire log file,
66175 ** which implies that the database file contains a trustworthy
66183 ** it finished. Leaving a corrupt image in the database file.
66248 ** that the log file may have been wrapped by a writer, or that frames
66257 ** file that has not yet been checkpointed. This client will not need
66258 ** to read any frames earlier than minFrame from the wal file - they
66259 ** can be safely read directly from the database file.
66269 ** page later in the wal file. But if version B happens to like past
66271 ** that it can read version A from the database file. However, since
66295 ** file, if any. Set nBackfillAttempted to the frame number of the
66296 ** first frame for which the wal file content matches the db file.
66298 ** This is only really safe if the file-system is such that any page
66317 i64 szDb; /* Size of db file in bytes */
66329 u32 pgno; /* Page number in db file */
66330 i64 iDbOff; /* Offset of db file entry */
66331 i64 iWalOff; /* Offset of wal file entry */
66399 ** snapshot X, where X is later in the wal file than pSnapshot, but
66429 ** of the wal file. Verify that pSnapshot is still valid before
66432 ** (1) The WAL file has been reset since the snapshot was taken.
66436 ** pSnapshot->mxFrame into the database file. Note that the
66444 /* Check that the wal file has not been wrapped. Assuming that it has
66461 ** from the start of the wal file. This is because, for a system
66464 ** the file because there exists a frame after iSnapshot that
66497 ** Search the wal file for page pgno. If found, set *piRead to the frame that
66498 ** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
66583 ** of the wal-index file content. Make sure the results agree with the
66604 ** Read the contents of frame iRead from the wal file into buffer pOut
66680 /* If another connection has written to the database file since the
66708 ** If any data has been written (but not committed) to the log file, this
66800 ** file (see sqlite3WalFrames()). It checks to see if, instead of appending
66801 ** to the current log file, it is possible to overwrite the start of the
66802 ** existing log file with the new frames (i.e. "reset" the log). If so,
66853 ** Information about the current state of the WAL file and where
66859 sqlite3_file *pFd; /* The WAL file to which we write */
66866 ** Write iAmt bytes of content into the WAL file beginning at iOffset.
66927 ** all frames written to the wal file by the current transaction starting
66935 u8 *aBuf; /* Buffer to load data from wal file into */
66937 u32 iRead; /* Next frame to read from wal file */
66945 ** transaction restarted the wal file), these values must be read from the
66946 ** wal-file header. Otherwise, read them from the frame header of the
66979 ** on the log file (obtained using sqlite3WalBeginWriteTransaction()).
66995 i64 iOffset; /* Next byte to write in WAL file */
67020 ** log file, instead of appending to it at pWal->hdr.mxFrame.
67027 ** header to the start of the WAL file. See comments at the top of
67028 ** this source file for a description of the WAL header format.
67080 /* Write all frames into the log file exactly once */
67084 /* Check if this page has already been written into the wal file by
67120 /* Recalculate checksums within the wal file if required. */
67127 ** the transaction and/or sync the WAL file.
67231 int sync_flags, /* Flags to sync db file with (or 0) */
67258 ** "checkpoint" lock on the database file.
67273 ** file.
67303 /* Copy data from the log to the database file. */
67375 ** lock on the main database file.
67382 ** on the main database file before invoking this operation.
67479 /* aSalt[0] is a copy of the value stored in the wal file header. It
67480 ** is incremented each time the wal file is restarted. */
67538 /* Return the sqlite3_file object for the WAL file
67547 /************** Begin file btmutex.c *****************************************/
67560 ** This file contains code used to implement mutexes on Btree objects.
67566 /************** Begin file btreeInt.h ****************************************/
67578 ** This file implements an external (disk-based) database using BTrees.
67585 ** The basic idea is that each page of the file contains N database
67601 ** In this implementation, a single file can hold one or more separate
67613 ** The file is divided into pages. The first page is called page 1,
67620 ** page contain a special header (the "file header") that describes the file.
67621 ** The format of the file header is as follows:
67635 ** 36 4 Number of freelist pages in the file
67652 ** The file change counter is incremented when the database is changed
67653 ** This counter allows other processes to know when the file has changed
67674 ** file header that occurs before the page header.
67677 ** | file header | 100 bytes. Page 1 only.
67773 ** file header points to the first in a linked list of trunk page. Each trunk
67804 ** SQLite database in order to identify the file as a real database.
67893 ** this object for every database file that it has open. This structure
67902 ** schema associated with the database file are all contained within
67957 ** An instance of this object represents a single database file.
67959 ** A single database file can be in use at the same time by two
67961 ** sharing the same database file, each connection has it own
67962 ** private Btree object for the file and each of those Btrees points
67964 ** connections currently sharing this database file.
68031 #define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
68067 ** b-tree within a database file.
68072 ** A single database file can be shared by two more database connections,
68192 ** each child page in the database file. The parent page is the page that
68200 ** position in the file to another as part of autovacuum. When a page
68594 /************** Begin file btree.c *******************************************/
68606 ** This file implements an external (disk-based) database using BTrees.
68608 ** Including a description of file format and an overview of operation.
68662 ** in shared cache. This variable has file scope during normal builds,
68916 ** transaction on this file. And, obviously, for this to be so there
68917 ** must be an open write transaction on the file itself.
68942 ** may hold a WRITE_LOCK on any table in this file (since there can
69162 Btree *pBtree, /* The database file to check */
69202 ** from the database or written to the journal file (why should it
69743 ** way will result in an incompatible file format.
70872 ** Return the size of the database file in pages. If there is any kind of
70897 BtShared *pBt, /* The database file */
71050 ** Open a database file.
71052 ** zFilename is the name of the database file. If zFilename is NULL
71072 const char *zFilename, /* Name of the file containing the BTree database */
71089 ** false for a file-based database.
71239 /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
71241 ** the beginning of the database file. */
71251 ** regular file-name. In this case the auto-vacuum applies as per normal.
71262 ** into the database file header. */
71552 ** Change the limit on the amount of the database file that may be
71597 ** of the database file used for locking (beginning at PENDING_BYTE,
71804 ** Get a reference to pPage1 of the database file. This will
71805 ** also acquire a readlock on that file.
71807 ** SQLITE_OK is returned on success. If the file is not a
71808 ** well-formed database file, then SQLITE_CORRUPT is returned.
71814 MemPage *pPage1; /* Page 1 of the database file */
71816 u32 nPageFile = 0; /* Number of pages in the database file */
71825 /* Do some checking to help insure the file we opened really is
71826 ** a valid database file.
71841 /* EVIDENCE-OF: R-43737-39999 Every valid SQLite database file begins
71869 ** file.
71898 /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
71900 ** the beginning of the database file. */
71918 ** into the database file header. */
72017 ** this routine unrefs the first page of the database file which
72035 ** If pBt points to an empty file then convert that empty file
72079 ** Initialize the first page of the database file (creating a database
72209 ** file is not pBt->pageSize. In this case lockBtree() will update
72210 ** pBt->pageSize to the page-size of the file on disk.
72267 ** client has been writing the database file), update it now. Doing
72500 ** that the last page of the file currently in use is no longer in use.
72566 ** of the file is found.
72766 ** database are written into the database file and flushed to oxide.
72774 ** Otherwise, sync the database file for the btree pBt. zSuperJrnl points to
72775 ** the name of a super-journal file that should be written into the
72776 ** individual journal file, or is NULL, indicating no super-journal file
72783 ** the write-transaction for this database file is to delete the journal.
72861 ** finalize the underlying journal file, this function returns an error and
72863 ** is non-zero then this b-tree transaction is part of a multi-file
72865 ** (by deleting a super-journal file) and the caller will ignore this
72871 ** This will release the write lock on the database file. If there
72991 ** This will release the write lock on the database file. If there
73280 ** Close a cursor. The read lock on the database file is released
73396 ** Return the offset into the database file for the start of the
73435 ** database file.
73463 BtShared *pBt, /* The database file */
73713 ** 4) the database is file-backed, and
73714 ** 5) the page is not in the WAL file
73717 ** then data can be read directly from the database file into the
74858 ** Allocate a new page from the database file.
74870 ** attempt to keep related pages close to each other in the database file,
74892 Pgno mxPage; /* Total size of the database file */
75135 ** file on disk. So the effects of disabling the no-content optimization
75137 ** database image and the end of the database file.
75149 ** at the end of the file instead of one. The first allocated page
75153 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
75176 TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
75190 ** This function is used to add page iPage to the database file free-list.
75377 ** file the database must be corrupt. */
76898 /* Sanity check: For a non-corrupt database file one of the follwing
76950 ** This helps to keep entries in the disk file in order so that a scan
76951 ** of the table is closer to a linear scan through the file. That in turn
78326 ** by extending the file), the current page at position pgnoMove
78529 ** root page in the database file, then the last root page
78530 ** in the database file is moved into the slot formerly occupied by
78533 ** root pages are kept at the beginning of the database file, which
78535 ** page number that used to be the last root page in the file before
78638 ** Read the meta-information out of a database file. Meta[0]
78650 ** database file. It is a number computed by the pager. But its access
79285 ** This routine does a complete check of the given BTree file. aRoot[] is
79412 /* Make sure every page in the file is referenced
79455 ** Return the full pathname of the underlying database file. Return
79467 ** Return the pathname of the journal file for this database. The return
79468 ** value of this routine is the same regardless of whether the journal file
79746 /************** Begin file backup.c ******************************************/
79758 ** This file contains the implementation of the sqlite3_backup_XXX()
79769 Btree *pDest; /* Destination b-tree file */
79775 Btree *pSrc; /* Source b-tree file */
80136 ** not possible to create a database file that uses one page size by
80215 ** fix the size of the file. However it is important to call
80217 ** destination file that lie beyond the nDestTruncate page mark are
80219 ** by the file truncation.
80261 ** the database file in any way, knowing that if a power failure
80263 ** journal file. */
80279 /* Write the extra pages and truncate the database file as required */
80299 /* Sync the database file to disk. */
80488 ** The size of file pTo may be reduced by this operation. If anything
80524 ** file. By passing this as the number of pages to copy to
80548 /************** Begin file vdbemem.c *****************************************/
80561 ** This file contains code use to manipulate "Mem" structure. A "Mem"
82534 /************** Begin file vdbeaux.c *****************************************/
82546 ** This file contains code used for creating, destroying, and populating
83599 int iLineno /* Source-file line number of first opcode */
84108 ** The Synopsis: field in comments in the vdbe.c source file gets converted
85292 ** write-transaction spanning more than one database file, this routine
85312 ** be done before determining whether a super-journal file is
85321 ** one database file has an open write transaction, a super-journal
85322 ** file is required for an atomic commit.
85365 /* The simple case - no more than one database file (not counting the
85370 ** string, it means the main database is :memory: or a temp file. In
85371 ** that case we do not support atomic multi-file commits, so use the
85386 ** IO error while deleting or truncating a journal file. It is unlikely,
85400 /* The complex case - There is a multi-file write-transaction active.
85401 ** This requires a super-journal file to ensure the transaction is
85415 /* Select a super-journal file name */
85453 /* Write the name of each database file in the transaction into the new
85454 ** super-journal file. If an error occurs at this point close
85455 ** and delete the super-journal file. All the individual journal files
85478 /* Sync the super-journal file. If the IOCAP_SEQUENTIAL device
85492 ** an error occurs here, do not delete the super-journal file.
85496 ** super-journal file will be orphaned. But we cannot delete it,
85497 ** in case the super-journal file name was written into the journal
85498 ** file before the failure occurred.
85513 /* Delete the super-journal file. This commits the transaction. After
85712 ** SQL statement does not read or write a database file. */
85740 ** file as part of an effort to free up cache space (see function
86252 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
87506 ** pCur might be pointing to text obtained from a corrupt database file.
87862 /************** Begin file vdbeapi.c *****************************************/
87875 ** This file contains code use to implement APIs that are part of the
90075 /************** Begin file vdbetrace.c ***************************************/
90088 ** This file contains code used to insert the values of host parameters
90270 /************** Begin file vdbe.c ********************************************/
90282 ** The code in this file implements the function that runs the
90285 ** Various scripts scan this source file in order to generate HTML
90287 ** of the code in this file is, therefore, important. See other comments
90288 ** in this file for details. If in doubt, do not deviate from existing
91212 ** file looking for lines that begin with "case OP_". The opcodes.h files
91214 ** opcode and the opcodes.c file is filled with an array of strings where
91224 ** Documentation about VDBE opcodes is generated by scanning this file
91227 ** file.
91231 ** Formatting is important to scripts that scan this file.
93114 ** Store in register r[P3] the byte offset into the database file that is the
93282 ** database file.
94233 ** P1 is the index of the database file on which the transaction is
94234 ** started. Index 0 is the main database file and index 1 is the
94235 ** file used for temporary tables. Indices of 2 or more are used for
94332 /* If the schema-cookie from the database file matches the cookie
94334 ** not reload the schema from the database file.
94365 ** the main database file and P1==1 is the database file used to store
94396 ** size, and so forth. P1==0 is the main database file and P1==1 is the
94397 ** database file used to store temporary tables.
94425 /* Record changes in the file format */
94442 ** P2 in a database file. The database file is determined by P3.
96221 ** it is found in the database file.
96994 ** file is given by P1.
96996 ** The table being destroyed is in the main database file if P3==0. If
96997 ** P3==1 then the table to be clear is in the auxiliary database file
97054 ** in the database file is given by P1. But, unlike Destroy, do not
97055 ** remove the table or index from the database file.
97057 ** The table being clear is in the main database file if P2==0. If
97058 ** P2==1 then the table to be clear is in the auxiliary database file
97116 ** Allocate a new b-tree in the main database file if P1==0 or in the
97117 ** TEMP database file if P1==1 or in an attached database if
97308 ** file, not the main database file.
98057 const char *zFilename; /* Name of database file for pPager */
98087 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
98106 /* If leaving WAL mode, close the log file. If successful, the call
98108 ** file. An EXCLUSIVE lock may still be held on the database file
98121 /* Open a transaction on the database file. Regardless of the journal
98152 ** the file into which the result of vacuum should be written. When
99257 /************** Begin file vdbeblob.c ****************************************/
99270 ** This file contains code used to implement incremental BLOB I/O.
99776 /************** Begin file vdbesort.c ****************************************/
99788 ** This file contains code for the VdbeSorter object, used in concert with
99856 ** written to a temporary file in "Packed Memory Array" (PMA) format.
99868 ** are appended to a single temporary file. Or, if the sorter is running in
99871 ** sorting the records and writing the PMA to a temporary file itself, the
99910 ** one background thread for each temporary file on disk, and one background
99941 typedef struct SorterFile SorterFile; /* Temporary file object wrapper */
99946 ** A container for a temp file handle and the current amount of data
99947 ** stored in the file.
100077 int nPMA; /* Number of PMAs currently in file */
100079 SorterFile file; /* Temp file for level-0 PMAs */
100136 u8 *aMap; /* Pointer to mapping of entire file */
100142 ** within a temp file. However, if the PmaReader.pIncr variable points to
100150 ** and aFile[1]. Neither file is allowed to grow to more than mxSz bytes in
100153 ** corresponding PmaReader object to read from that file and kicks off
100166 ** at offset iStartOff of file pTask->file2. And instead of using a
100175 i64 iStartOff; /* Offset to start writing file at */
100196 i64 iWriteOff; /* Offset of start of buffer in file */
100279 ** p->nBuffer bytes of data from the file into it. Or, if there are less
100294 /* Readr data from the file. Return early if an error occurs. */
100381 ** Attempt to memory map file pFile. If successful, set *pp to point to the
100383 ** (because the file is too large or the VFS layer is configured not to use
100402 ** Attach PmaReader pReadr to file pFile (if it is not already attached to
100403 ** that file) and seek it to offset iOff within the file. Return SQLITE_OK
100409 SorterFile *pFile, /* Sorter file to read from */
100492 ** Initialize PmaReader pReadr to scan through the PMA stored in file pFile
100497 ** If the pnByte parameter is NULL, then it is assumed that the file
100502 SorterFile *pFile, /* Sorter file to read from */
100836 if( pTask->file.pFd ){
100837 sqlite3OsCloseFree(pTask->file.pFd);
101054 ** The first argument is a file-handle open on a temporary file. The file
101056 ** attempts to extend the file to nByte bytes in size and to ensure that
101059 ** Whether or not the file does end up memory mapped of course depends on
101077 ** Allocate space for a file-handle and open a temporary file. If successful,
101078 ** set *ppFd to point to the malloc'd file-handle and return SQLITE_OK.
101083 i64 nExtend, /* Attempt to extend file to this size */
101282 ** last byte written to the file.
101312 ** PMA in the temp file belonging to sub-task pTask. Return SQLITE_OK if
101327 PmaWriter writer; /* Object used to write to the file */
101330 /* Set iSz to the expected size of file pTask->file after writing the PMA.
101332 i64 iSz = pList->szPMA + sqlite3VarintLen(pList->szPMA) + pTask->file.iEof;
101339 /* If the first temporary PMA file has not been opened, open it now. */
101340 if( pTask->file.pFd==0 ){
101341 rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
101342 assert( rc!=SQLITE_OK || pTask->file.pFd );
101343 assert( pTask->file.iEof==0 );
101347 /* Try to get the file to memory map */
101349 vdbeSorterExtendFile(db, pTask->file.pFd, pTask->file.iEof+pList->szPMA+9);
101361 vdbePmaWriterInit(pTask->file.pFd, &writer, pTask->pSorter->pgsz,
101362 pTask->file.iEof);
101372 rc = vdbePmaWriterFinish(&writer, &pTask->file.iEof);
101377 assert( rc!=SQLITE_OK || pTask->file.iEof==iSz );
101674 /* Check if the output file is full or if the input has been exhausted.
101914 ** reading from the same temp file this makes for more linear file IO.
101936 ** and/or initialize the temp file related fields of the IncrMerge
102074 ** PMAs from pTask->file. If no error occurs, set *ppOut to point to
102079 ** first PMA to read from pTask->file. Assuming no error occurs, it is
102087 i64 *piOffset, /* IN/OUT: Readr offset in pTask->file */
102101 rc = vdbePmaReaderInit(pTask, &pTask->file, iOff, pReadr, &nDummy);
102545 /************** Begin file vdbevtab.c ****************************************/
102558 ** This file implements virtual-tables for examining the bytecode content
102972 /************** Begin file memjournal.c **************************************/
102985 ** This file contains code use to implement an in-memory rollback journal.
102992 ** entirely in memory, thus reducing the number of file I/O calls, and
102993 ** more importantly, reducing temporary file creation events. If these
102995 ** in the common case, they are usually small and no file I/O needs to
103032 sqlite3_int64 iOffset; /* Offset from the beginning of the file */
103046 FilePoint endpoint; /* Pointer to the end of the file */
103051 const char *zJournal; /* Name of the journal file */
103055 ** Read data from the in-memory journal file. This is the implementation
103059 sqlite3_file *pJfd, /* The journal file from which to read */
103115 ** Flush the contents of memory to a real file on disk.
103142 /* If an error occurred while creating or writing to the file, restore
103157 ** Write data to the file.
103160 sqlite3_file *pJfd, /* The journal file into which to write */
103163 sqlite_int64 iOfst /* Begin writing at this offset into the file */
103169 /* If the file should be created now, create it and write the new data
103170 ** into the file on disk. */
103181 /* An in-memory journal file should only ever be appended to. Random
103185 ** journal file may be written as part of committing the transaction. */
103201 /* New chunk is required to extend the file. */
103230 ** Truncate the in-memory file.
103260 ** Close the file.
103269 ** Sync the file.
103271 ** If the real file has been created, call its xSync method. Otherwise,
103280 ** Query the size of the file in bytes.
103314 ** Open a journal file.
103316 ** The behaviour of the journal file depends on the value of parameter
103317 ** nSpill. If nSpill is 0, then the journal file is always create and
103320 ** positive value, then the journal file is initially created in-memory
103321 ** but may be flushed to disk later on. In this case the journal file is
103326 sqlite3_vfs *pVfs, /* The VFS to use for actual file I/O */
103327 const char *zName, /* Name of the journal file */
103328 sqlite3_file *pJfd, /* Preallocated, blank file handle */
103330 int nSpill /* Bytes buffered before opening the file */
103336 /* Zero the file-handle object. If nSpill was passed zero, initialize
103339 ** made on the journal file-handle. */
103361 ** Open an in-memory journal file.
103371 ** in-memory-only journal file (i.e. is one that was opened with a +ve
103373 ** file has not yet been created, create it now.
103398 ** The file-handle passed as the only argument is open on a journal file.
103399 ** Return true if this "journal file" is currently stored in heap memory,
103415 /************** Begin file walker.c ******************************************/
103427 ** This file contains routines used for walking the parser tree for
103675 /************** Begin file resolve.c *****************************************/
103688 ** This file contains routines used for walking the parser tree and
105813 /************** Begin file expr.c ********************************************/
105825 ** This file contains routines used for analyzing expressions and
109225 ** See the separate in-operator.md documentation file in the canonical
110624 ** The value in regFree1 might get SCopy-ed into the file result.
112326 /************** Begin file alter.c *******************************************/
112338 ** This file contains C code routines that used to generate VDBE code
112344 ** The code in this file only exists if we are not omitting the
114606 /************** Begin file analyze.c *****************************************/
114618 ** This file contains code associated with the ANALYZE command.
116546 /************** Begin file attach.c ******************************************/
116558 ** This file contains code used to implement the ATTACH and DETACH commands.
116699 /* Open the database file. If the btree is successfully opened, use
116783 /* If the file was opened successfully, read the schema for the new database.
116784 ** If this fails, or if opening the file failed, then close the file and
116915 Expr *pFilename, /* Name of database file */
117186 /************** Begin file auth.c ********************************************/
117198 ** This file contains code used to implement the sqlite3_set_authorizer()
117206 ** All of the code in this file may be omitted by defining a single
117457 /************** Begin file build.c *******************************************/
117469 ** This file contains C code routines that are called by the SQLite parser
117470 ** when syntax rules are reduced. The routines in this file handle the
117660 /* The cookie mask contains one bit for each database file open.
118674 ** file instead of in the main database file. This is normally the case
118819 /* If the file format and encoding in the database have not been set,
120244 ** file instead of into the main database file.
122677 "file for storing temporary tables");
123155 /************** Begin file callback.c ****************************************/
123168 ** This file contains functions used to access the internal hash tables
123697 /************** Begin file delete.c ******************************************/
123709 ** This file contains C code routines that are called by the parser
124380 ** they may interfere with compilation of other functions in this file
124381 ** (or in another file, if this file becomes part of the amalgamation). */
124716 /************** Begin file func.c ********************************************/
124728 ** This file contains the C-language implementations for many of the SQL
126947 ** defined in this file.
127124 /************** Begin file fkey.c ********************************************/
127135 ** This file contains code used by the compiler to add foreign key
127441 ** These operations are identified in the comment at the top of this file
127668 ** These operations are identified in the comment at the top of this file
128602 /************** Begin file insert.c ******************************************/
128614 ** This file contains C code routines that are called by the parser
129746 ** using excess space. The file format definition requires this extra
130038 ** they may interfere with compilation of other functions in this file
130039 ** (or in another file, if this file becomes part of the amalgamation). */
131763 /************** Begin file legacy.c ******************************************/
131775 ** Main file for the SQLite library. The routines in this file
131907 /************** Begin file loadext.c *****************************************/
131919 ** This file contains code used to dynamically load extensions into
131927 /************** Begin file sqlite3ext.h **************************************/
131939 ** This header file defines the SQLite interface for use by
131942 ** as extensions by SQLite should #include this file instead of
132295 ** is also defined in the file "loadext.c".
132307 ** This header file is also used by the loadext.c source file
132622 /* This case when the file really is being compiled as a loadable
132629 /* This case when the file is being statically linked into the
133158 ** Attempt to load an SQLite extension library contained in the file
133531 /************** Begin file pragma.c ******************************************/
133543 ** This file contains code used to implement the PRAGMA command.
133556 ** The "pragma.h" include file is an automatically generated file that
133563 /************** Begin file pragma.h ******************************************/
133565 ** This file is automatically generated by the script at
133687 /* 49 */ "file",
134312 ** remainder of this file is specific to PRAGMA processing. So omit
134313 ** the rest of the file if PRAGMAs are omitted from the build.
134347 ** Interpret the given string as a temp db location. Return 1 for file
134354 }else if( sqlite3StrICmp(z, "file")==0 ){
134367 ** from default, or when 'file' and the temp_store_directory has changed
134675 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
134680 ** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
134681 ** object corresponding to the database file to which the pragma
134685 ** file control is an array of pointers to strings (char**) in which the
134754 ** stored in the database file.
134860 ** maximum number of pages in the database file. The
134911 ** set on all attached databases, as well as the main db file.
135022 ** creates the database file. It is important that it is created
135029 ** file. Before writing to meta[6], check that meta[3] indicates
135151 ** database file. If this parameter is set to zero, then memory mapping
135192 ** PRAGMA temp_store = "default"|"memory"|"file"
135195 ** the local value does not make changes to the disk file and the default
135263 ** process. Database file specified with an absolute path are not impacted
135301 ** the value sets a specific file to be used for database access locks.
135324 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
135337 ** the local value does not make changes to the disk file and the
135938 /* Do an integrity check on each database file */
136314 ** The second form of this pragma is a no-op if the main database file
136316 ** encoding that will be used for the main database file if a new file
136317 ** is created. If an existing main database file is opened, then the
136550 ** database file so that it will be available to "optimize"
136738 ** Report the current state of file logs for all databases
137143 /************** Begin file prepare.c *****************************************/
137155 ** This file contains the implementation of the sqlite3_prepare()
137335 ** data structures for a single database file. The index of the
137336 ** database file is given by iDb. iDb==0 is used for the main
137487 sqlite3SetString(pzErrMsg, db, "unsupported file format");
137492 /* Ticket #2804: When we open a database in the newer file format,
137572 ** Initialize all database files - the main database file, the file
137679 ** which database file in db->aDb[] the schema refers to.
138210 /************** Begin file select.c ******************************************/
138222 ** This file contains C code routines that are called by the parser
146161 /************** Begin file table.c *******************************************/
146173 ** This file contains the sqlite3_get_table() and sqlite3_free_table()
146362 /************** Begin file trigger.c *****************************************/
146373 ** This file contains the implementation for TRIGGERs
147840 /************** Begin file update.c ******************************************/
147852 ** This file contains C code routines that are called by the parser
148993 ** they may interfere with compilation of other functions in this file
148994 ** (or in another file, if this file becomes part of the amalgamation). */
149191 /************** Begin file upsert.c ******************************************/
149203 ** This file contains code to implement various aspects of UPSERT
149510 /************** Begin file vacuum.c ******************************************/
149522 ** This file contains code used to implement the VACUUM command.
149524 ** Most of the code in this file may be omitted by defining the
149590 ** (1) Create a new transient database file
149592 ** the new transient database file
149612 ** transient would cause the database file to appear to be deleted
149673 const char *zOut; /* Name of output file */
149716 ** can be set to 'off' for this file, as it is not recovered if a crash
149727 ** to write the journal header file.
149742 sqlite3SetString(pzErrMsg, db, "output file already exists");
149769 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
149912 ** database. No locks are held on any other files (since the main file
149915 ** vacuum database. The vacuum_db journal file is deleted when the pager
149936 /************** Begin file vtab.c ********************************************/
149948 ** This file contains code used to help implement virtual tables.
151284 /************** Begin file wherecode.c ***************************************/
151299 ** This file was split off from where.c on 2015-06-06 in order to reduce the
151300 ** size of where.c and make it easier to edit. This file contains the routines
151302 ** file retains the code that does query planning and analysis.
151306 /************** Begin file whereInt.h ****************************************/
151319 ** This file contains structure and macro definitions for the query
151321 ** a separate source file for easier editing.
154697 /************** Begin file whereexpr.c ***************************************/
154712 ** This file was originally part of where.c but was split out to improve
154713 ** readability and editabiliity. This file contains utility routines for
156203 ** Routines with file scope above. Interface to the rest of the where.c
156550 /************** Begin file where.c *******************************************/
163126 /************** Begin file window.c ******************************************/
163225 ** This detail is encapsulated within this file, the code generated by
163783 ** of this file), pWin is updated here.
164081 ** at the top of this file.
166232 /************** Begin file parse.c *******************************************/
166233 /* This file is automatically generated by Lemon from input grammar
166234 ** source file "parse.y". */
166246 ** This file contains SQLite's SQL parser.
166248 ** The canonical source code to this file ("parse.y") is a Lemon grammar
166249 ** file that specifies the input grammar and actions to take while parsing.
166250 ** That input file is processed by Lemon to generate a C-language
166276 ** In the amalgamation, the parse.c file generated by lemon and the
166277 ** tokenize.c file are concatenated. In that case, sqlite3RunParser()
171678 /************** Begin file tokenize.c ****************************************/
171692 ** This file contains C code that splits an SQL input string up into
171822 ** The output of the mkkeywordhash.c program is written into a file
171823 ** named keywordhash.h and then included into this source file by
171827 /************** Begin file keywordhash.h *************************************/
171828 /***** This file contains automatically generated code ******
171830 ** The code in this file has been automatically generated by
171834 ** The code in this file implements a function that determines whether
173020 /************** Begin file complete.c ****************************************/
173034 ** This file contains C code that implements the sqlite3_complete() API.
173035 ** This code used to be part of the tokenizer.c source file. But by
173313 /************** Begin file main.c ********************************************/
173325 ** Main file for the SQLite library. The routines in this file
173334 /************** Begin file fts3.h ********************************************/
173347 ** This header file is used by programs that want to link against the
173367 /************** Begin file rtree.h *******************************************/
173380 ** This header file is used by programs that want to link against the
173404 /************** Begin file sqliteicu.h ***************************************/
173417 ** This header file is used by programs that want to link against the
175033 /* SQLITE_CANTOPEN */ "unable to open database file",
175042 /* SQLITE_NOLFS */ "large file support is disabled",
175049 /* SQLITE_NOTADB */ "file is not a database",
175134 ** lock on VFS file pFile.
175771 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
175793 ** more frames in the log file. Passing zero or a negative value as the
175969 ** a temporary file for transient pager files and statement journals.
175977 ** 0 any file (return 0)
175978 ** 1 1 file (return 0)
175980 ** 1 0 file (return 0)
175981 ** 2 1 file (return 0)
176325 ** the VFS that should be used to open the database file. *pzFile is set to
176326 ** point to a buffer containing the name of the file to open. The value
176356 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
176365 ** method that there may be extra parameters following the file-name. */
176380 ** like file://///host/path to be converted into UNCs like //host/path.
176382 ** file://host/path or file:////host/path. But 5 leading slashes is a
176408 ** 0: Parsing file-name.
176824 zFilename = "file:local?vfs=kvvfs";
176827 zFilename = "file:session?vfs=kvvfs";
177207 return sqlite3ReportError(SQLITE_CANTOPEN, lineno, "cannot open file");
177569 ** an incompatible database file format. Changing the PENDING byte
177726 ** Set or clear a flag that indicates that the database file is always well-
177867 ** file. The seek-counter is written into *pnSeek and is then reset.
177982 ** Allocate memory to hold names for a database, journal file, WAL file,
178035 ** to see if a database file was a URI that contained a specific query
178091 ** database, journal, or WAL file.
178275 ** Recover as many snapshots as possible from the wal file associated with
178367 /************** Begin file notify.c ******************************************/
178380 ** This file contains the implementation of the sqlite3_unlock_notify()
178386 /* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */
178702 /************** Begin file fts3.c ********************************************/
178719 ** The code in this file is only compiled if:
178994 /************** Begin file fts3Int.h *****************************************/
179040 /************** Begin file fts3_tokenizer.h **********************************/
179206 /************** Begin file fts3_hash.h ***************************************/
179218 ** This is the header file for the generic hash-table implementation
182884 ** even if we reach end-of-file. The fts3EofMethod() will be called
184127 u8 *pbEof /* OUT: End-of-file flag */
184182 u8 *pbEof /* OUT: End-of-file flag */
185760 /************** Begin file fts3_aux.c ****************************************/
186319 /************** Begin file fts3_expr.c ***************************************/
187615 /************** Begin file fts3_hash.c ***************************************/
187633 ** The code in this file is only compiled if:
188001 /************** Begin file fts3_porter.c *************************************/
188018 ** The code in this file is only compiled if:
188666 /************** Begin file fts3_tokenizer.c **********************************/
188680 ** This particular file implements the generic tokenizer interface.
188684 ** The code in this file is only compiled if:
189079 ** in the README.tokenizer file as an example, so it is important to
189135 ** fts3TokenizerFunc() in this file for details) and, if ENABLE_TABLE is
189189 /************** Begin file fts3_tokenizer1.c *********************************/
189206 ** The code in this file is only compiled if:
189426 /************** Begin file fts3_tokenize_vtab.c ******************************/
189439 ** This file contains code for the "fts3tokenize" virtual table module.
189887 /************** Begin file fts3_write.c **************************************/
189900 ** This file is part of the SQLite FTS3 extension module. Specifically,
189901 ** this file contains code to insert, update and delete rows from FTS3
190010 ** this structure are only manipulated by code in this file, opaque handles
190098 ** database file as soon as they are completely populated. The interior of
191080 ** on the database file for longer than necessary). Thus, any virtual table
195599 ** modify the database file.
195704 /************** Begin file fts3_snippet.c ************************************/
196646 ** file system. This is done because the full-text index doclist is required
197458 /************** Begin file fts3_unicode.c ************************************/
197488 ** from the sqlite3 source file utf.c. If this file is compiled as part
197858 /************** Begin file fts3_unicode2.c ***********************************/
198121 ** file distributed as part of the "Unicode Character Database". See
198244 /************** Begin file json.c ********************************************/
198259 ** This file began as an extension in ext/misc/json1.c in 2015. That
199157 return 0; /* End of file */
200946 /************** Begin file rtree.c *******************************************/
200958 ** This file contains code for implementations of the r-tree and r*-tree
205350 /************** Begin file geopoly.c *****************************************/
205363 ** This file implements an alternative R-Tree virtual table that
205366 ** This file is #include-ed onto the end of "rtree.c" so that it has
207349 /************** Begin file icu.c *********************************************/
207363 ** This file implements an integration between the ICU library
207437 ** code file utf8.c.
207907 /************** Begin file fts3_icu.c ****************************************/
207919 ** This file implements a tokenizer for fts3 based on the ICU library.
208172 /************** Begin file sqlite3rbu.c **************************************/
208198 ** to a *-oal file. A *-oal file is just like a *-wal file, except
208200 ** Because regular SQLite clients do not look for file named
208202 ** rollback mode while the *-oal file is being generated.
208211 ** 2) The "<database>-oal" file is moved to the equivalent "<database>-wal"
208213 ** module takes an EXCLUSIVE lock on the database file, ensuring
208217 ** detect the new *-wal file and read the database in wal mode. At
208221 ** 3) The new *-wal file is checkpointed. This proceeds in the same way
208224 ** handle is closed before the entire *-wal file is checkpointed,
208232 ** syncing the directory after renaming the file.
208234 ** When state is saved, any commit to the *-oal file and the commit to
208244 ** by delete the RBU update database and *-oal file and have the device
208263 /************** Begin file sqlite3rbu.h **************************************/
208276 ** This file contains the public interface for the RBU extension.
208522 ** database file. This means it is possible for other clients to read the
208548 ** or zRbu begin with "file:", it will be interpreted as an SQLite
208549 ** database URI, not a regular file name.
208555 ** organize removing a separate state file after the update is concluded.
208556 ** Or, if zState is non-NULL, it must be a path to a database file in which
208563 ** automatically remove any zState database file, even if it created it.
208566 ** use a VFS other than the default, an SQLite "file:" URI containing a
208581 ** Open an RBU handle to perform an RBU vacuum on database file zTarget.
208597 ** is the name of the target database file. In this case, on UNIX, if the
208598 ** state database is not already present in the file-system, it is created
208639 ** Return the current amount of temp file space, in bytes, currently used by
208737 ** * Stage 1, in which changes are accumulated in an oal/wal file, and
208738 ** * Stage 2, in which the contents of the wal file are copied into the
208775 ** defined in this file. Return values should be interpreted as follows:
208778 ** RBU is currently building a *-oal file. The next call to sqlite3rbu_step()
208779 ** may either add further data to the *-oal file, or compute data that will
208783 ** RBU has finished building the *-oal file. The next call to sqlite3rbu_step()
208784 ** will move the *-oal file to the equivalent *-wal path. If the current
208786 ** file will become visible to ordinary SQLite clients following the next
208791 ** sqlite3rbu_step() will copy a page of data from the *-wal file into
208792 ** the target database file.
208812 ** the system must at one point move the *-oal file to the equivalent *-wal
208819 ** of rename(2) when it needs to move a file within the file-system. The
208822 ** to the file to move and the third the full path to which it should be
208839 ** Create an RBU VFS named zName that accesses the underlying file-system
208841 ** then the new RBU VFS uses the default system VFS to access the file-system.
208852 ** (for example multiplexor) to access the file-system. For example,
208861 ** // access the file-system via the system default VFS, bypassing the
208877 ** file-system via "rbu" all the time, even if it only uses RBU functionality
208936 ** 1: the *-rbu file is currently under construction.
208937 ** 2: the *-rbu file has been constructed, but not yet moved
208961 ** header created by recovering the *-wal file. This is used to detect
208962 ** cases when another client appends frames to the *-wal file in the
208968 ** target db file.
208971 ** Valid if STAGE==1. The size in bytes of the *-oal file.
209015 ** locks. These are not magic numbers as they are part of the SQLite file
209140 ** file should be copied to page iDbPage of the database file.
209153 ** finish populating the *-oal file. This allows the sqlite3_bp_progress()
209154 ** API to calculate the permyriadage progress of populating the *-oal file
209245 ** Each file opened by an rbu VFS is represented by an instance of
209248 ** If this is a temporary file (pRbu!=0 && flags&DELETE_ON_CLOSE), variable
209249 ** "sz" is set to the current size of the database file.
209253 sqlite3_file *pReal; /* Underlying file handle */
209256 i64 sz; /* Size of file in bytes (temp only) */
209258 int openFlags; /* Flags this file was opened with */
209265 char *zDel; /* Delete this when closing file */
209267 const char *zWal; /* Wal filename for this main db file */
209268 rbu_file *pWalFd; /* Wal file descriptor for this main db */
209269 rbu_file *pMainNext; /* Next MAIN_DB file */
209270 rbu_file *pMainRbuNext; /* Next MAIN_DB file with pRbu!=0 */
209361 ** file and a NUL terminator at the end. The delta_output_size()
209369 ** This function returns the size of the output file in bytes (excluding
209371 ** malformed or intended for use with a source file other than zSrc,
209375 ** of the delta file format.
209378 const char *zSrc, /* The source or pattern file */
209379 int lenSrc, /* Length of the source file */
209410 /* ERROR: copy exceeds output file size */
210293 ** stage 1 of the process (while the *-oal file is being built) while
211595 p->zState = rbuMPrintf(p, "file:///%s-vacuum?modeof=%s", zFile, zFile);
211685 if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){
211693 zTarget = sqlite3_mprintf("file:%s-vactmp?rbu_memory=1%s%s",
211730 /* Mark the database file just opened as an RBU target database. If
211803 ** current wal file, and obtains the set of shm locks required to safely
211804 ** perform the copy operations directly on the file-system.
211810 ** other client appends a transaction to the wal file in the middle of
211815 /* If pState is NULL, then the wal file may not have been opened and
211833 ** * Attempts to read from the *-wal file or write to the database file
211843 ** * Attempting to xSync() the database file causes an SQLITE_INTERNAL
211850 ** data from the wal file into the database file according to the
211883 /* Call xSync() on the wal file. This causes SQLite to sync the
211884 ** directory in which the target database and the wal file reside, in
211893 ** Called when iAmt bytes are read from offset iOff of the wal file while
211926 ** file while the rbu handle is in capture mode. Record the page number
211936 ** a single frame of data from the wal file into the database file, as
211955 ** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if
212008 ** on the database file. This proc moves the *-oal file to the *-wal path,
212009 ** then reopens the database file (this time in vanilla, non-oal, WAL mode).
212030 /* Move the *-oal file to *-wal. At this point connection p->db is
212031 ** holding a SHARED lock on the target database file (because it is
212533 /* Sync the db file */
212551 ** wal file to the database file. So that one call to sqlite3rbu_step()
212635 ** If there is a "*-oal" file in the file-system corresponding to the
212636 ** target database in the file-system, delete it. If an error occurs,
212653 ** file name.
212813 /* If the first attempt to open the database file fails and the bRetry
212816 ** RBU vacuum operation leaving an old wal file in the directory.
212864 ** page 1 of the database file. */
212893 /* Open transactions both databases. The *-oal file is opened or
212901 ** generating a large journal using a temp file. */
212920 ** exclusive lock on the db file. If this fails, so be it. */
213022 /* Commit the transaction to the *-oal file. */
213027 /* Sync the db file if currently doing an incremental checkpoint */
213162 /* Sync the db file */
213238 ** 1. Whenever the first page of a main database file is read or
213244 ** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (rbu_file.pWalFd)
213245 ** member variable of the associated database file descriptor is set
213246 ** to point to the new file. A mutex protected linked list of all main
213250 ** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file
213254 ** 3a. If xAccess() is called to check if there exists a *-wal file
213256 ** stage (preparing the *-oal file), the following special handling
213259 ** * if the *-wal file does exist, return SQLITE_CANTOPEN. An RBU
213262 ** * if the *-wal file does not exist, set the output parameter to
213265 ** Then, when xOpen() is called to open the *-wal file associated with
213267 ** file, the rbu vfs opens the corresponding *-oal file instead.
213269 ** 3b. The *-shm pages returned by xShmMap() for a target db file in
213271 ** avoid creating a *-shm file on disk. Additionally, xShmLock() calls
213276 ** 3c. If an EXCLUSIVE lock is attempted on a target database file in any
213279 ** from automatically checkpointing a *-wal (or *-oal) file from within
213282 ** 3d. In RBU_STAGE_CAPTURE mode, all xRead() calls on the wal file, and
213283 ** all xWrite() calls on the target database file perform no IO.
213287 ** database file are recorded. xShmLock() calls to unlock the same
213290 ** file fail with SQLITE_INTERNAL errors.
213322 ** There are two main-db lists. One for all file descriptors, and one
213323 ** for all file descriptors with rbu_file.pDb!=0. If the argument has
213362 ** Given that zWal points to a buffer containing a wal file name passed to
213364 ** a file-handle opened by the same database connection on the corresponding
213365 ** database file.
213367 ** If parameter bRbu is true, only search for file-descriptors with
213383 ** Close an rbu file.
213408 /* Close the underlying file handle */
213442 ** Read data from an rbuVfs-file.
213470 ** SQLite will not check for a *-wal file. */
213484 rbuPutU32(&aBuf[28], 1); /* size of db file in pages */
213498 ** of the definition of the SQLite file format, which may not change. */
213508 ** Write data to an rbuVfs-file.
213541 ** of the definition of the SQLite file format, which may not change. */
213551 ** Truncate an rbuVfs-file.
213563 ** Sync an rbuVfs-file.
213577 ** Return the current file-size of an rbuVfs-file.
213586 ** check for the existance of a *-wal file. rbuVfsRead() contains
213598 ** Lock an rbuVfs-file.
213620 ** Unlock an rbuVfs-file.
213628 ** Check if another file-handle holds a RESERVED lock on an rbuVfs-file.
213636 ** File control method. For custom operations on an rbuVfs-file.
213692 ** Return the sector-size in bytes for an rbuVfs-file.
213700 ** Return the device characteristic flags supported by an rbuVfs-file.
213725 /* Prevent SQLite from taking a shm-lock on the target file when it
213746 ** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
213761 ** instead of a file on disk. */
213768 ** pages of the *-shm file. Since no other process can have run
213831 ** Open an rbu file handle.
213875 ** the name of the *-wal file this db connection will use. SQLite
213877 ** or xOpen() to operate on the *-wal file. */
213884 /* This call is to open a *-wal file. Intead, open the *-oal. */
213915 ** pointer and, if the file is a main database file, link it into the
213929 ** Delete the file located at zPath.
213952 /* If this call is to check if a *-wal file associated with an RBU target
213956 ** a) if the *-wal file does exist, return SQLITE_CANTOPEN. This
213958 ** in wal mode, even if the first page of the database file has
213961 ** b) if the *-wal file does not exist, claim that it does anyway,
213964 ** file opened instead.
214085 ** Create an RBU VFS named zName that accesses the underlying file-system
214165 ** Configure the aggregate temp file size limit for this RBU handle.
214184 /************** Begin file dbstat.c ******************************************/
214197 ** This file contains an implementation of the "dbstat" virtual table.
214262 " pgoffset INTEGER," /* 8 Offset of page in file (NULL for agg) */
215087 /************** Begin file dbpage.c ******************************************/
215100 ** This file contains an implementation of the "sqlite_dbpage" virtual table.
215103 ** pages of the database file. The pager interface is used so that
215104 ** uncommitted changes and changes recorded in the WAL file are correctly
215113 ** schema for the database file that is to be read. The default schema is
215280 ** Move a dbpagevfs cursor to the next entry in the file.
215515 /************** Begin file sqlite3session.c **********************************/
217730 ** under "CHANGESET FORMAT" at the top of the file). An update change
221342 /************** Begin file fts5.c ********************************************/
221366 ** Interfaces to extend FTS5. Using the interfaces defined in this file,
222097 ** decent error message if it encounters a file-format version it does
222804 /* This file is automatically generated by Lemon from input grammar
222805 ** source file "fts5parse.y". */
222819 ** The "lemon" program processes an LALR(1) input grammar file, then uses
222825 ** source file.
222828 ** input grammar file:
226361 "invalid fts5 file format (found %d, expected %d) - run 'rebuild'",
226393 ** All token types in the generated fts5parse.h file are greater than 0.
229466 ** This file contains the implementation of an in-memory hash table used
230018 ** Low level access to the FTS index stored in the database file. The
230019 ** routines in this file file implement all read and write access to the
237723 ** even if we reach end-of-file. The fts5EofMethod() will be called
238485 ** modifications are made to the database file. There are 4 cases:
239702 /* If SQLITE_FTS5_ENABLE_TEST_MI is defined, assume that the file
241105 ** from the sqlite3 source file utf.c. If this file is compiled as part
242472 ** file distributed as part of the "Unicode Character Database". See
244262 /************** Begin file stmt.c ********************************************/
244275 ** This file demonstrates an eponymous virtual table that returns information
244606 /************** Begin file hw_codec_openssl.h *******************************/
244619 /************** End file hw_codec_openssl.h *********************************/
244620 /************** Begin file hw_codec.h ***************************************/
244670 /************** End file hw_codec.h *****************************************/
244671 /************** Begin file hw_codec_openssl.c *******************************/
244849 /************** End file hw_codec_openssl.c *********************************/
244850 /************** Begin file hw_codec.c ***************************************/
245871 // Each configuration setting operation should be done before read/write DB file or there might be some error.
246218 /************** End file hw_codec.c *****************************************/
246286 sqlite3_log(SQLITE_WARNING, " thrad WAL Lock[%d] for DB file: %d\n", i, uFile_db->pShm->pShmNode->aLock[i]);