Lines Matching defs:in
10 ** This file is all you need to compile SQLite. To use SQLite in other
17 ** language. The code for the "sqlite3" command-line shell is also in a
29 ** The author disclaims copyright to this source code. In place of
65 ** In all cases, the special comment must be enclosed in the usual
89 ** compiler warnings due to subsequent content in this file and other files
92 /************** Include msvc.h in the middle of sqliteInt.h ******************/
97 ** The author disclaims copyright to this source code. In place of
132 /************** Continuing where we left off in sqliteInt.h ******************/
137 /************** Include vxworks.h in the middle of sqliteInt.h ***************/
142 ** The author disclaims copyright to this source code. In place of
173 /************** Continuing where we left off in sqliteInt.h ******************/
182 ** code in all source files.
188 ** without this option, LFS is enable. But LFS does not exist in the kernel
189 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
192 ** The previous paragraph was written in 2005. (This paragraph is written
195 ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
214 ** version numbers in clang are for "marketing" only and are inconsistent
263 ** library in use (e.g. for Windows XP).
273 ** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for
276 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
281 ** The author disclaims copyright to this source code. In place of
291 ** or constant definition does not appear in this file, then it is
295 ** Some of the definitions that are in this file are marked as
299 ** if experience from use "in the wild" suggest such changes are prudent.
302 ** from comments in this file. This file is the authoritative source
305 ** The name of this file under configuration management is "sqlite.h.in".
348 ** These no-op macros are used in front of interfaces to mark those
352 ** experimental interfaces are subject to change in point releases.
376 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
377 ** evaluates to a string literal that is the SQLite version in the
382 ** numbers used in [SQLITE_VERSION].)^
389 ** SQLite source code has been stored in the
392 ** a string which identifies a particular check-in of SQLite
394 ** string contains the date and time of the check-in (UTC) and a SHA1
412 ** programmers might include assert() statements in their application to
413 ** verify that values returned by these interfaces match the macros in
426 ** function is provided for use in DLLs since DLL users usually do not have
498 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
580 ** host languages that are garbage collected, and where the order in which
625 ** in the context of the [database connection] passed in as its 1st
643 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
651 ** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
689 ** here in order to indicate success or failure.
691 ** New error codes may be added in future versions of SQLite.
698 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
702 #define SQLITE_LOCKED 6 /* A table in the database is locked */
708 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
733 ** In its default configuration, SQLite API routines return one of 30 integer
736 ** much information about problems as programmers might like. In an effort to
809 ** These bit values are intended for use in the
811 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
847 ** mean that writes of blocks that are nnn bytes in size and
853 ** information is written to disk in the same order as calls
855 ** after reboot following a crash or power loss, the only bytes in a
931 ** An [sqlite3_file] object represents an open file in the
963 ** flag may be ORed in to indicate that only the data of the file
976 ** either in this process or in some other process, is holding a RESERVED,
984 ** point to a structure that may contain arguments or space in which to
999 ** other bytes in the file. The xDeviceCharacteristics()
1023 ** mean that writes of blocks that are nnn bytes in size and
1029 ** information is written to disk in the same order as calls
1033 ** in the unread portions of the buffer with zeros. A VFS that
1062 /* Additional methods may be added in future releases */
1088 ** file space based on this hint in order to help writes to the database
1093 ** extends and truncates the database file in chunks of a size specified
1096 ** for the nominated database. Allocating database file space in
1112 ** No longer in use.
1119 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
1120 ** of the xSync method. In most cases, the pointer argument passed with
1139 ** windows [VFS] in order to provide robustness in the presence of
1162 ** in order for the database to be readable. The fourth parameter to
1186 ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
1188 ** [sqlite3_malloc()] and the result is stored in the char* variable
1193 ** pointer in case this file-control is not implemented. This file-control
1198 ** [VFSes] currently in use. ^(The argument X in
1202 ** ^When there are multiple VFS shims in the stack, this opcode finds the
1210 ** pointers to strings (char**) in which the second element of the array
1228 ** it is able to override built-in [PRAGMA] statements.
1233 ** shortly after it is opened in order to provide a custom VFS with access
1236 ** to a function of type (int (*)(void *)). In order to invoke the connections
1237 ** busy-handler, this function should be invoked with the second (void *) in
1255 ** is an advisory maximum number of bytes in the file to memory map. The
1258 ** can be queried by passing in a pointer to a negative number. This
1265 ** The argument is a zero-terminated string. Higher layers in the
1291 ** circumstances in order to fix a problem with priority inversion.
1305 ** the file descriptor is placed in "batch write mode", which
1394 ** structure must be typedefed in order to work around compiler warnings
1404 ** in
1407 ** The value of the iVersion field is initially 1 but may be larger in
1410 ** of the sqlite3_vfs object changes in the transaction between
1416 ** a pathname in this VFS.
1421 ** in a thread-safe way. The [sqlite3_vfs_find()] interface
1425 ** The pNext field is the only field in the sqlite3_vfs
1451 ** The flags argument to xOpen() includes all bits set in
1456 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
1478 ** file will be doing page-aligned sector reads and writes in a random
1493 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1505 ** allocate the structure; it should just fill it in. Note that
1528 ** included in the VFS structure for completeness.
1537 ** Day Number multiplied by 86400000 (the number of milliseconds in
1579 ** The methods above are in version 1 of the sqlite_vfs object
1580 ** definition. Those that follow are added in version 2 or later
1584 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1591 ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1592 ** New fields may be appended in future versions. The iVersion
1607 ** (in other words, if files can be added, removed, and renamed within
1610 ** [temp_store_directory pragma], though this could change in a future
1614 ** currently unused, though it might be used in a future release of
1665 ** These routines are designed to aid in process initialization and
1707 ** of SQLite may require this. In other words, the behavior exhibited
1709 ** default behavior in some future release of SQLite.
1743 ** changes to SQLite in order to tune SQLite to the specific needs of
1764 ** in the first argument.
1779 ** [database connection] (specified in the first argument).
1797 ** This object is used in only one place in the SQLite interface.
1807 ** Note that SQLite comes with several [built-in memory allocators]
1811 ** also used during testing of SQLite in order to specify an alternative
1812 ** memory allocator that simulates memory out-of-memory conditions in
1829 ** Every memory allocation request coming in through [sqlite3_malloc()]
1873 ** New configuration options may be added in future releases of SQLite.
1883 ** [threading mode] to Single-thread. In other words, it disables
1894 ** [threading mode] to Multi-thread. In other words, it disables
1898 ** are enabled so that SQLite will be safe to use in a multi-threaded
1908 ** [threading mode] to Serialized. In other words, this option enables
1911 ** In this mode (which is the default when SQLite is compiled with
1915 ** same [prepared statement] in different threads at the same time.
1926 ** alternative low-level memory allocation routines to be used in place of
1952 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1975 ** fragmentation in low-memory embedded systems.
2018 ** the number of bytes in the memory buffer, and the minimum allocation size.
2033 ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
2092 ** In a multi-threaded application, the application-defined logger
2111 ** argument which is interpreted as a boolean in order to enable or disable
2112 ** the use of covering indices for full table scans in the query optimizer.
2134 ** in three separate circumstances, identified by the value passed as the
2141 ** third parameter is passed NULL In this case. An example of using this
2142 ** configuration option can be seen in the "test_sqllog.c" source file in
2170 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
2189 ** [Statement journals] are held in memory until their size (in bytes)
2192 ** exclusively in memory.
2233 ** New configuration options may be added in future releases of SQLite.
2247 ** may be NULL in which case SQLite will allocate the
2250 ** slots. The size of the buffer in the first argument must be greater than
2256 ** connection is not currently using lookaside memory, or in other words
2260 ** memory is in use leaves the configuration unchanged and returns
2270 ** following this call. The second parameter may be a NULL pointer, in
2280 ** following this call. The second parameter may be a NULL pointer, in
2293 ** following this call. The second parameter may be a NULL pointer, in
2310 ** be a NULL pointer, in which case the new setting is not reported back.
2316 ** which will become the new schema name in place of "main". ^SQLite
2323 ** <dd> Usually, when a database in wal mode is closed or detached from a
2359 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2379 ** part of committing a transaction (e.g. to flush data accumulated in memory
2380 ** to disk). In this case subsequent calls to this function return the rowid
2383 ** tables in this way can avoid this problem by restoring the original
2490 ** ^Changes made as part of [foreign key actions] are included in the
2510 ** called in response to a user action such as pressing "Cancel"
2528 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
2552 ** independent tokens (they are part of the token in which they are
2572 ** UTF-16 string in native byte order.
2606 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2629 ** database connection that invoked the busy handler. In other words,
2631 ** result in undefined behavior.
2678 ** There are (N+1)*M elements in the array. The first M pointers point
2681 ** in NULL pointers. All other values are in their UTF-8 zero-terminated
2701 ** in an array names azResult. Then azResult holds this content:
2715 ** semicolon-separated SQL statements in the zero-terminated UTF-8
2717 ** pointer given in its 3rd parameter.
2720 ** it must pass the result table pointer to sqlite3_free_table() in order to
2729 ** interface defined here. As a consequence, errors that occur in the
2731 ** reflected in subsequent calls to [sqlite3_errcode()] or
2784 ** All of the usual printf() formatting options apply. In addition, there
2787 ** ^(The %q option works like %s in that it substitutes a nul-terminated
2799 ** One can use this text in an SQL statement as follows:
2807 ** Because the %q format string is used, the '\'' character in zText
2825 ** the outside of the total string. Additionally, if the parameter in the
2835 ** The code above will render a correct SQL statement in the zSQL
2857 ** internal memory allocation needs. "Core" in the previous sentence
2862 ** of memory at least N bytes in length, where N is the parameter.
2878 ** memory might result in a segmentation fault or other severe error.
2892 ** of at least N bytes in size or NULL if insufficient memory is available.
2905 ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
2919 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2920 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2922 ** is no longer provided. Only built-in memory allocators can be used.
2953 ** routines, which form the built-in memory allocation subsystem.
2961 ** added by SQLite in its implementation of [sqlite3_malloc()],
2980 ** the build-in random() and randomblob() SQL functions. This interface allows
3003 ** [database connection], supplied in the first argument.
3030 ** Applications must always be prepared to encounter a NULL pointer in any
3036 ** a NULL value in place of the table column that would have
3041 ** extracted from that table (for example in a query like
3055 ** database. An authorizer could then be put in place while the
3062 ** in addition to using an authorizer.
3064 ** ^(Only a single authorizer can be in place on a database connection
3072 ** database connections for the meaning of "modify" in this paragraph.
3077 ** correct authorizer callback remains in place during the [sqlite3_step()].
3081 ** performed during statement evaluation in [sqlite3_step()], unless
3082 ** as stated in the previous paragraph, sqlite3_step() invokes
3095 ** return either [SQLITE_OK] or one of these two constants in order
3180 ** the length of [bound parameter] expansion in the output of sqlite3_trace().
3186 ** time is in units of nanoseconds, however the current implementation
3188 ** digits in the time are meaningless. Future versions of SQLite
3191 ** subject to change in future versions of SQLite.
3208 ** New tracing constants may be added in future releases.
3212 ** ^The C argument is a copy of the context pointer passed in as the
3271 ** ignored, though this may change in future releases. Callback
3320 ** database connections for the meaning of "modify" in this paragraph.
3331 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
3333 ** returned in *ppDb, even if an error occurs. The only exception is that
3344 ** created using sqlite3_open16() will be UTF-16 in the native byte order.
3360 ** <dd>The database is opened in read-only mode. If the database does not
3365 ** only if the file is write protected by the operating system. In either
3380 ** opens in the multi-thread [threading mode] as long as the single-thread
3383 ** in the serialized [threading mode] unless single-thread was
3389 ** participate in [shared cache mode] even if it is enabled.
3396 ** ^If the filename is ":memory:", then a private, temporary in-memory database
3397 ** is created for the connection. ^This in-memory database will vanish when
3408 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3413 ** set in the fourth argument to sqlite3_open_v2(), or if it has
3438 ** SQLite and its built-in [VFSes] interpret the
3454 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3460 ** set to "memory" then a pure [in-memory database] that never reads
3463 ** the flags passed in the third parameter to sqlite3_open_v2().
3467 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3470 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3479 ** which if set disables file locking in rollback journal modes. This
3491 ** property on a database file that does in fact change can result
3492 ** in incorrect query results and/or [SQLITE_CORRUPT] errors.
3497 ** ^Specifying an unknown parameter in the query component of a URI is not an
3507 ** Open the file "data.db" in the current directory.
3517 ** C:. Note that the %20 escaping in this example is not strictly
3519 ** in URI filenames.
3521 ** Open file "data.db" in the current directory for read-only access.
3526 ** that uses dot-files in place of posix advisory locking.
3587 ** value of query parameter P is one of "yes", "true", or "on" in any
3590 ** query parameter P is one of "no", "false", or "off" in any case or
3638 ** When the serialized [threading mode] is in use, it might be the
3639 ** case that a second error occurs on a separate thread in between
3649 ** was invoked incorrectly by the application. In that case, the
3700 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
3709 ** Run-time limits are intended for use in applications that manage
3722 ** New run-time limit categories may be added in future releases.
3733 ** Additional information is available at [limits | Limits in SQLite].
3737 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3740 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
3743 ** <dd>The maximum number of columns in a table definition or in the
3744 ** result set of a [SELECT] or the maximum number of columns in an index
3745 ** or in an ORDER BY or GROUP BY clause.</dd>)^
3751 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3754 ** <dd>The maximum number of instructions in a virtual machine program
3757 ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
3772 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
3820 ** is the number of bytes in the input string <i>including</i>
3824 ** past the end of the first SQL statement in zSql. These routines only
3825 ** compile the first statement in zSql, so *pzTail is left pointing to
3842 ** ^In the "v2" interfaces, the prepared statement
3845 ** behave differently in three ways:
3860 ** in order to find the underlying cause of the problem. With the "v2" prepare
3865 ** ^If the specific value bound to [parameter | host parameter] in the
3880 int nByte, /* Maximum length of zSql in bytes. */
3887 int nByte, /* Maximum length of zSql in bytes. */
3894 int nByte, /* Maximum length of zSql in bytes. */
3901 int nByte, /* Maximum length of zSql in bytes. */
3989 ** This interface can be used in combination [sqlite3_next_stmt()]
3991 ** connection that are in need of being reset. This can be used,
3992 ** for example, in diagnostic routines to search for prepared
4002 ** that can be stored in a database table. SQLite uses dynamic typing
4003 ** for the values it stores. ^Values stored in sqlite3_value objects
4019 ** or if SQLite is run in one of reduced mutex modes
4041 ** The context in which an SQL function executes is stored in an
4058 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4070 ** In the templates above, NNN represents an integer literal,
4094 ** ^(In those routines that have a fourth argument, its value is the
4095 ** number of bytes in the parameter. To be clear: the value is the
4096 ** number of <u>bytes</u> in the value, not the number of characters.)^
4117 ** information is in static, unmanaged space and does not need to be freed.
4124 ** to specify the encoding of the text in the third parameter. If
4136 ** ^A negative value for the zeroblob results in a zero-length BLOB.
4179 ** in a [prepared statement]. SQL parameters are tokens of the
4187 ** there may be gaps in the list.)^
4200 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
4204 ** In other words, the initial ":" or "$" or "@" or "?"
4213 ** always in UTF-8 encoding even if the named parameter was
4214 ** originally specified as UTF-16 in [sqlite3_prepare16()] or
4231 ** name must be given in UTF-8 even if the original statement
4251 ** CAPI3REF: Number Of Columns In A Result Set
4254 ** ^Return the number of columns in the result set returned by the
4267 ** CAPI3REF: Column Names In A Result Set
4271 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
4297 ** CAPI3REF: Source Of Data In A Query Result
4301 ** table column that is the origin of a particular result column in
4311 ** again in a different encoding.
4374 ** data stored in that column is of the declared type. SQLite is
4398 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
4426 ** [prepared statement]. ^In the "v2" interface,
4434 ** more threads at the same moment in time.
4440 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4443 ** calling [sqlite3_reset()] automatically in this circumstance rather
4449 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
4452 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
4464 ** CAPI3REF: Number of columns in a result set
4467 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4476 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
4488 ** ^(Every value in SQLite has one of five fundamental datatypes:
4500 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
4522 ** result row of a query. ^In every case the first argument is a pointer
4527 ** ^The number of columns in the result can be determined using
4553 ** routine returns the number of bytes in that BLOB or string.
4558 ** the number of bytes in that string.
4562 ** routine returns the number of bytes in that BLOB or string.
4567 ** the number of bytes in that string.
4574 ** bytes in the string, not the number of characters.
4581 ** [unprotected sqlite3_value] object. In a multithreaded environment,
4585 ** [sqlite3_column_value()] is used in any other way, including calls
4622 ** in the following cases:
4636 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
4639 ** of conversion are done in place when it is possible, but sometimes they
4640 ** are not possible and in those cases prior pointers are invalidated.
4643 ** in one of the following ways:
4651 ** In other words, you should call sqlite3_column_text(),
4703 ** The application must finalize every [prepared statement] in order to avoid
4706 ** statement after it has been finalized can result in undefined and
4759 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
4761 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
4763 ** will result in [SQLITE_MISUSE] being returned.
4789 ** deterministic. The built-in [random()] SQL function is an example of a
4819 ** the implementation that most closely matches the way in which the
4829 ** ^Built-in functions may be overloaded by new application-defined functions.
4834 ** statement in which the function is running.
4895 ** These functions are [deprecated]. In order to maintain
4929 ** object results in undefined behavior.
4936 ** in the native byte-order of the host machine. ^The
4943 ** such a conversion is possible without loss of information (in other
5020 ** In those cases, sqlite3_aggregate_context() might be called for the
5029 ** value of N in subsequent call to sqlite3_aggregate_context() within
5032 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
5043 ** This routine must be called from the same thread in which
5058 ** This routine must be called from the same thread in which
5083 ** of where this might be useful is in a regular-expression matching
5114 ** Note the last bullet in particular. The destructor X in
5121 ** ^(In practice, metadata is preserved between function calls for
5129 ** These routines must be called from the same thread in which
5139 ** These are special values for the destructor that is passed in as the
5143 ** SQLITE_TRANSIENT value means that the content will likely change in
5147 ** The typedef is necessary to work around problems in certain
5164 ** functions used to bind values to host parameters in prepared statements.
5174 ** a BLOB containing all zero bytes and N bytes in size.
5186 ** interprets the string from sqlite3_result_error16() as UTF-16 in native
5198 ** returned by SQLite as a result of an error in a function. ^By default,
5210 ** value given in the 2nd argument.
5213 ** value given in the 2nd argument.
5224 ** application-defined function to be a text string in an encoding
5238 ** in the string at a byte offset that is less than the value of the 3rd
5247 ** assumes that the text or BLOB result is in constant space and does not
5259 ** so that the [sqlite3_value] specified in the parameter may change or
5299 ** of the subtype T are preserved in current versions of SQLite;
5302 ** in future releases of SQLite.
5315 ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
5346 ** application data pointer and with two strings in the encoding specified
5420 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
5421 ** the names are passed as UTF-16 in machine native byte order.
5452 ** The code to implement this API is not available in the public release
5470 ** The code to implement this API is not available in the public release
5506 ** for at least a number of milliseconds specified in its parameter.
5517 ** in the previous paragraphs.
5526 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
5527 ** will be placed in that directory.)^ ^If this variable
5536 ** be avoided in new projects.
5538 ** It is not safe to read or modify this variable in more than one
5540 ** if a [database connection] is being used at the same time in a separate
5550 ** that this variable points to is held in memory obtained from
5585 ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
5593 ** open can result in a corrupt database.
5595 ** It is not safe to read or modify this variable in more than one
5597 ** if a [database connection] is being used at the same time in a separate
5607 ** that this variable points to is held in memory obtained from
5622 ** zero if the given database connection is or is not in autocommit mode,
5649 ** create the statement in the first place.
5660 ** connection D, or if database N is a temporary or in-memory database, then
5664 ** xFullPathname method of the [VFS]. ^In other words, the filename
5690 ** The [database connection] pointer D in a call to
5692 ** connection and in particular must not be a NULL pointer.
5722 ** or rollback hook in the first place.
5725 ** the database connections for the meaning of "modify" in this paragraph.
5752 ** to be invoked whenever a row is updated, inserted or deleted in
5758 ** row is updated, inserted or deleted in a rowid table.
5767 ** ^In the case of an update, this is the [rowid] after the update takes place.
5773 ** ^In the current implementation, the update hook
5777 ** The exceptions defined in this paragraph might change in a future
5785 ** database connections for the meaning of "modify" in this paragraph.
5811 ** In prior versions of SQLite,
5817 ** that was in effect at the time they were opened.)^
5822 ** ^Shared cache is disabled by default. But this might change in
5860 ** [sqlite3_release_memory()] interface, this interface is in effect even
5874 ** limit by reducing the number of pages held in the page cache
5878 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
5882 ** the soft heap limit prior to the call, or negative in the case of an
5890 ** ^(The soft heap limit is not enforced in the current implementation
5912 ** the page cache is the predominate memory user in SQLite, most
5917 ** changes in future releases of SQLite.
5938 ** information about column C of table T in database D
5940 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
5961 ** NULL, in which case the corresponding element of metadata is omitted.
6019 ** [SQLite extension] library contained in the file zFile. If
6027 ** ^(zProc may be 0, in which case SQLite will try to come up with an
6031 ** characters in the filename from the last "/" to the first following
6037 ** fill *pzErrMsg with error message text stored in memory
6067 ** ^So as not to open security holes in older applications that are
6150 ** to be experimental. The interface might change in incompatible ways.
6173 ** ^A virtual table module is created by filling in a persistent
6209 /* The methods above are in version 1 of the sqlite_module object. Those
6232 ** stored in aConstraint[].op using one of the
6234 ** ^(The index of the column is stored in
6240 ** and makes other simplifications to the WHERE clause in an attempt to
6245 ** ^Information about the ORDER BY clause is stored in aOrderBy[].
6250 ** zero in the order in which they appear within the CREATE TABLE statement
6255 ** set. In other words, column iCol may be required if the expression
6262 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
6271 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
6293 ** any database changes. In other words, if the xUpdate() returns
6314 int nConstraint; /* Number of entries in aConstraint */
6321 int nOrderBy; /* Number of terms in the ORDER BY clause */
6336 /* Fields below are only available in SQLite 3.8.2 and later */
6338 /* Fields below are only available in SQLite 3.9.0 and later */
6340 /* Fields below are only available in SQLite 3.10.0 and later */
6354 ** an operator that is part of a constraint term in the wHERE clause of
6446 ** This superclass exists in order to define fields of the cursor that
6471 ** must exist in order to be overloaded.)^
6486 ** to be experimental. The interface might change in incompatible ways.
6503 ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
6513 ** in row iRow, column zColumn, table zTable in database zDb;
6514 ** in other words, the same BLOB that would be selected by:
6522 ** the name that appears after the AS keyword in the [ATTACH] statement.
6531 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
6542 ** <li> ^(Row iRow is not present in the table)^,
6580 ** and the built-in [zeroblob] SQL function may be used to create a
6612 ** it must exist and there must be either a blob or text value stored in
6613 ** the nominated column.)^ ^If the new row is not present in the table, or if
6634 ** the database is in auto-commit mode and there are no other open read-write
6640 ** open blob handle results in undefined behaviour. ^Calling this routine
6652 ** ^Returns the size in bytes of the BLOB accessible via the
6653 ** successfully opened [BLOB handle] in its only argument. ^The
6659 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
6660 ** to this routine results in undefined and probably undesirable behavior.
6686 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
6687 ** to this routine results in undefined and probably undesirable behavior.
6728 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
6729 ** to this routine results in undefined and probably undesirable behavior.
6779 ** implementations are available in the SQLite core:
6788 ** that does no real locking and is appropriate for use in
6795 ** implementation is included with the library. In this case the
6830 ** not want to. SQLite will only request a recursive mutex in
6833 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
6852 ** mutex results in undefined behavior.
6860 ** In such cases, the
6897 ** does not provide a suitable implementation. In this case, the application
6950 ** If xMutexInit fails in any way, it is expected to clean up after itself
6978 ** These routines should return true if the mutex in their argument
7007 ** next. Applications that override the built-in mutex logic must be
7023 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
7032 ** serializes access to the [database connection] given in the argument
7049 ** ^A NULL pointer can be used in place of "main" to refer to the
7138 ** ^The highest recorded value is returned in *pHighwater. ^If the
7178 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
7180 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
7185 ** internal equivalents). Only the value returned in the
7197 ** value returned is in pages, not in bytes.</dd>)^
7207 ** no space was left in the page cache.</dd>)^
7211 ** handed to [pagecache memory allocator]. Only the value returned in the
7218 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
7219 ** in bytes. Since a single thread may only have one scratch allocation
7235 ** handed to [scratch memory allocator]. Only the value returned in the
7269 ** to grow in future releases of SQLite.
7290 ** New verbs may be added in future releases of SQLite. Existing verbs
7318 ** memory already being in use.
7332 ** connections.)^ In other words, if none of the pager caches associated
7370 ** wal file in wal mode databases, or the number of pages written to the
7371 ** database file in rollback mode databases. Any pages written as part of
7436 ** <dd>^This is the number of times that SQLite has stepped forward in
7443 ** A non-zero value in this counter may indicate an opportunity to
7448 ** were created automatically in order to help joins run faster.
7449 ** A non-zero value in this counter may indicate an opportunity to
7484 ** The sqlite3_pcache_page object represents a single page in the
7502 ** register an alternative page cache implementation by passing in an
7504 ** In many applications, most of the heap memory allocated by
7508 ** the amount of memory consumed by SQLite, the way in which
7515 ** The built-in page cache is recommended for most uses.
7530 ** built-in default page cache is used instead of the application defined
7543 ** in multithreaded applications.
7552 ** first parameter, szPage, is the size in bytes of the pages that must
7562 ** false if it is used for an in-memory database. The cache implementation
7566 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
7581 ** stored in the cache, both pinned and unpinned.
7584 ** The xFetch() method locates a page in the cache and returns a pointer to
7590 ** for each entry in the page cache.
7596 ** If the requested page is already in the page cache, then the page cache
7598 ** intact. If the requested page is not already in the cache, then the
7603 ** <tr><th> createFlag <th> Behavior when page is not already in cache
7613 ** failed.)^ In between the to xFetch() calls, SQLite may
7677 ** retained in the header file for backwards compatibility only.
7712 ** for copying in-memory databases to or from persistent files.
7742 ** temporary database, or the name specified after the AS keyword in
7756 ** returned and an error code and error message are stored in the
7787 ** <li> the destination database is an in-memory database and the
7795 ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
7799 ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
7803 ** there is no point in retrying the call to sqlite3_backup_step(). These
7853 ** in the source database at the conclusion of the most recent
7856 ** sqlite3_backup_step(). If the source database is modified in a way that
7858 ** those changes are not reflected in the output of sqlite3_backup_pagecount()
7877 ** backup is in progress might also also cause a mutex deadlock.
7879 ** If running in [shared cache mode], the application must
7881 ** is not accessed while the backup is running. In practice this means
7908 ** ^When running in shared-cache mode, a database operation may fail with
7933 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
7967 ** and the second is the number of entries in the array.
7990 ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
7991 ** unlock-notify callback is registered. The system is said to be in
8008 ** returned. In this case there is no "blocking connection", so invoking
8009 ** sqlite3_unlock_notify() results in the unlock-notify callback being
8015 ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
8031 ** strings in a case-independent fashion, using the same definition of "case
8042 ** ^The definition of [GLOB] pattern matching used in
8043 ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
8059 ** ^The definition of [LIKE] pattern matching used in
8061 ** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without
8093 ** will not use dynamically allocated memory. The log message is stored in
8105 ** is invoked each time data is committed to a database in wal mode.
8116 ** is the number of pages currently in the write-ahead log file,
8148 ** more frames in the [write-ahead log] file. ^Passing zero or
8178 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
8198 ** operation on database X of [database connection] D in mode M. Status
8206 ** in the log were checkpointed. ^The [busy-handler callback]
8207 ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
8215 ** snapshot. ^It then checkpoints all frames in the log file and syncs the
8234 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
8236 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
8237 ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
8240 ** because the database is not in WAL mode. ^Note that upon successful
8247 ** busy-handler configured, it will not be invoked in this case.
8256 ** checkpoint operation proceeds from that point in the same way as
8258 ** without blocking any further. ^SQLITE_BUSY is returned in this case.
8262 ** [database connection] db. In this case the
8272 ** ^If database zDb is the name of an attached database that is not in WAL
8289 int *pnLog, /* OUT: Size of WAL log in frames */
8319 ** may be added in the future.
8336 ** support constraints. In this configuration (which is the default) if
8358 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
8437 ** The select-id is the same value as is output in the first column
8472 ** ^Statistics might not be available for all loops in all statements. ^In cases
8502 ** pages in the pager-cache that are not currently in use are written out
8503 ** to disk. A dirty page may be in use if a database cursor created by an
8505 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
8512 ** in the usual manner. ^If the required lock still cannot be obtained, then
8558 ** the name given after the AS keyword in the [ATTACH] statement for attached
8579 ** to the preupdate callback results in undefined and probably undesirable
8583 ** in the row that is being inserted, updated, or deleted.
8649 ** database for some specific point in history.
8651 ** In [WAL mode], multiple [database connections] that are open on the
8655 ** as it existed for the point in time when the transaction first started.
8679 ** schema S in database connection D. ^On success, the
8688 ** in this case.
8691 ** <li> The database handle must be in [autocommit mode].
8706 ** database handle in autocommit mode but fails for some other reason,
8734 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8737 ** ^In other words, schema S must not currently be in
8744 ** schema S is in [WAL mode]. A database connection might not know
8745 ** that the database file is in [WAL mode] if there has been no prior
8749 ** database connection in order to make it ready to use snapshots.)
8839 ** The author disclaims copyright to this source code. In place of
8926 unsigned int *anQueue; /* Number of pending entries in the queue */
8929 int mxLevel; /* The largest iLevel value in the tree */
8935 /* The following fields are only available in 3.8.11 and later */
9002 ** The session object will be used to create changesets for tables in
9085 ** in the database. If additional tables are added to the database (by
9094 ** It is not an error if the named table does not exist in the database. Nor
9096 ** no changes will be recorded in either of these scenarios.
9099 ** in one or more of their PRIMARY KEY columns.
9113 ** in tables that are not attached to the Session object, the filter is called
9133 ** and *pnChangeset to the size of the changeset in bytes before returning
9145 ** is represented in a changeset as a DELETE followed by an INSERT.
9147 ** Changes are not recorded for rows that have NULL values stored in one or
9149 ** no corresponding change is present in the changesets returned by this
9150 ** function. If an existing row with one or more NULL values stored in
9152 ** only an INSERT is appears in the changeset. Similarly, if an existing row
9163 ** single table are grouped together. In other words, when iterating through
9166 ** are sorted in the same order in which they were attached (or auto-attached)
9167 ** to the sqlite3_session object. The order in which the changes related to
9181 ** updated or deleted in the lifetime of the session.
9207 ** the changeset. Or, if no such row is found in the table, a DELETE
9209 ** primary key in the database, but all fields contain their original
9215 ** will be present in the changeset. Or if a row is deleted and then later a
9225 ** the same session object is disabled, no INSERT record will appear in the
9241 ** argument, this function attaches table zTbl in the same manner as the
9253 ** <li> Has the same set of columns declared in the same order, and
9263 ** used to update the table in database zFrom (call this the "from-table")
9268 ** <li> For each row (primary key) that exists in the to-table but not in
9271 ** <li> For each row (primary key) that exists in the to-table but not in
9274 ** <li> For each row (primary key) that exists in both tables, but features
9275 ** different non-PK values in each, an UPDATE record is added to the
9288 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
9322 ** in the same way as for changesets.
9324 ** Changes within a patchset are ordered in the same way as for changesets
9326 ** a single table are grouped together, tables appear in the order in which
9344 ** changeset that contains no changes. This can happen when a row in
9387 int nChangeset, /* Size of changeset blob in bytes */
9401 ** does not point to any change in the changeset. Assuming the changeset
9403 ** point to the first change in the changeset. Each subsequent call advances
9404 ** the iterator to point to the next change in the changeset (if any). If
9407 ** Otherwise, if all changes in the changeset have already been visited,
9421 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
9430 ** set to the number of columns in the table affected by the change. If
9440 ** be trusted in this case.
9445 int *pnCol, /* OUT: Number of columns in table */
9456 ** <li> The number of columns in the table, and
9463 ** nCol is the number of columns in the table. Elements of *pabPK are set to
9468 ** in the table.
9478 int *pnCol /* OUT: Number of entries in output array */
9486 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
9493 ** of columns in the table affected by the current change. Otherwise,
9516 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
9523 ** of columns in the table affected by the current change. Otherwise,
9554 ** of columns in the table affected by the current change. Otherwise,
9575 ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
9577 ** violations in the destination database and returns SQLITE_OK.
9579 ** In all other cases this function returns SQLITE_MISUSE.
9600 ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
9601 ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
9629 ** This function does not change the order in which changes appear within
9633 ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
9674 int nA, /* Number of bytes in buffer pA */
9676 int nB, /* Number of bytes in buffer pB */
9678 int *pnOut, /* OUT: Number of bytes in output changeset */
9694 ** always in the same format as the input.
9717 ** new() and delete(), and in any order.
9728 ** Add all changes within the changeset (or patchset) in buffer pData (size
9737 ** Rows within the changeset and changegroup are identified by the values in
9738 ** their PRIMARY KEY columns. A change in the changeset is considered to
9739 ** apply to the same row as a change already present in the changegroup if
9742 ** Changes to rows that do not already appear in the changegroup are
9756 ** The INSERT change remains in the changegroup. The values in the
9774 ** If one or more of the column values in the row inserted by the
9775 ** new change differ from those in the row deleted by the existing
9790 ** in the changegroup, then the number of columns and the position of the
9795 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
9812 ** table are grouped together in the output of this function. Tables appear
9813 ** in the same order as for the very first changeset added to the changegroup.
9815 ** changes for tables that do not appear in the first changeset, they are
9816 ** appended onto the end of the output changeset, again in the order in
9822 ** pointer to the output buffer, respectively. In this case it is the
9828 int *pnData, /* OUT: Size of output buffer in bytes */
9841 ** "main" database attached to handle db with the changes found in the
9846 ** change in the changeset, the filter callback is invoked with
9859 ** <li> The table has the same name as the name recorded in the
9861 ** <li> The table has at least as many columns as recorded in the
9863 ** <li> The table has primary key columns in the same position as
9864 ** recorded in the changeset.
9870 ** one such warning is issued for each table in the changeset.
9899 ** original row values stored in the changeset. If it does, and the values
9900 ** stored in all non-primary key columns also match the values stored in
9905 ** row value stored in the changeset, the conflict-handler function is
9907 ** database table has more columns than are recorded in the changeset,
9912 ** If no row with matching primary key values is found in the database,
9944 ** original row values stored in the changeset. If it does, and the values
9945 ** stored in all modified non-primary key columns also match the values
9946 ** stored in the changeset the row is updated within the target database.
9950 ** original row value stored in the changeset, the conflict-handler function
9956 ** If no row with matching primary key values is found in the database,
9973 ** All changes made by this function are enclosed in a savepoint transaction.
9981 int nChangeset, /* Size of changeset in bytes */
10004 ** PRIMARY KEY fields is present in the database, but one or more other
10008 ** The conflicting row, in this case, is the database row with the matching
10014 ** required PRIMARY KEY fields is not present in the database.
10016 ** There is no conflicting row in this case. The results of invoking the
10022 ** in duplicate primary key values.
10024 ** The conflicting row in this case is the database row with the matching
10029 ** database in a state containing foreign key violations, the conflict
10045 ** There is no conflicting row in this case. The results of invoking the
10065 ** continues to the next change in the changeset.
10108 ** require that the entire changeset be stored in a single buffer in memory.
10111 ** Normally this is convenient. However, if an application running in a
10115 ** In order to avoid this problem, instead of a single large buffer, input
10118 ** required. In all cases, a pair of API function parameters such as
10134 ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
10139 ** error code should be returned. In all cases, if an xInput callback returns
10143 ** In the case of sqlite3changeset_start_strm(), the xInput callback may be
10150 ** return them in chunks by way of a callback function instead of via a
10151 ** pointer to a single large buffer. In this case, a pair of parameters such
10169 ** points to a buffer nData bytes in size containing the chunk of output
10172 ** it should return some other SQLite error code. In this case processing
10248 ** The author disclaims copyright to this source code. In place of
10257 ** Interfaces to extend FTS5. Using the interfaces defined in this file,
10288 int nVal, /* Number of values in apVal[] array */
10306 ** to the total number of tokens in the FTS5 table. Or, if iCol is
10307 ** non-negative but less than the number of columns in the table, return
10308 ** the total number of tokens in column iCol, considering all rows in
10312 ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
10317 ** Return the number of columns in the table.
10321 ** to the total number of tokens in the current row. Or, if iCol is
10322 ** non-negative but less than the number of columns in the table, set
10323 ** *pnToken to the number of tokens in column iCol of the current row.
10326 ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
10336 ** containing the text in utf-8 encoding, (*pn) is set to the size in bytes
10342 ** Returns the number of phrases in the current query expression.
10345 ** Returns the number of tokens in phrase iPhrase of the query. Phrases
10365 ** to the column in which it occurs and *piOff the token offset of the
10367 ** with the offsets=0 option specified. In this case *piOff is always
10390 ** phrase iPhrase of the current query is included in $p. For each
10439 ** (set to NULL) before this function returns. In this case the xDelete,
10445 ** This function is used to retrieve the total number of rows in the table.
10446 ** In other words, the same value that would be returned by:
10484 ** of iterating through all instances of a phrase in the current row, these
10485 ** APIs are used to iterate through the set of columns in the current row
10578 ** be returned. In this case, fts5 assumes that the final value of *ppOut
10616 ** For each token in the input string, the supplied callback xToken() must
10620 ** size of the token in bytes. The 4th and 5th arguments are the byte offsets
10626 ** synonyms. In this case see the discussion below for details.
10628 ** FTS5 assumes the xToken() callback is invoked for each token in the
10641 ** Custom tokenizers may also support synonyms. Consider a case in which a
10643 ** built-in tokenizers, the FTS5 query 'first + place' will match instances
10645 ** such as "1st place". In some applications, it would be better to match
10647 ** the user specified in the MATCH query text.
10649 ** There are several ways to approach this in FTS5:
10651 ** <ol><li> By mapping all synonyms to a single token. In this case, the
10652 ** In the above example, this means that the tokenizer returns the
10653 ** same token for inputs "first" and "1st". Say that token is in
10661 ** In this case, when tokenizing query text, the tokenizer may
10670 ** first token in the MATCH query and FTS5 effectively runs a query
10690 ** 'first + place' or '1st + place', as there are entires in the
10710 ** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
10714 ** In many cases, method (1) above is the best approach. It does not add
10716 ** so it is efficient in terms of disk space and query speed. However, it
10726 ** For full prefix support, method (3) may be preferred. In this case,
10759 int nToken, /* Size of token in bytes */
10827 /************** Continuing where we left off in sqliteInt.h ******************/
10837 /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
10842 ** The author disclaims copyright to this source code. In place of
10855 ** The maximum length of a TEXT or BLOB in bytes. This also
10856 ** limits the size of a row in a table or index.
10868 ** * Columns in a table
10869 ** * Columns in an index
10870 ** * Columns in a view
10871 ** * Terms in the SET clause of an UPDATE statement
10872 ** * Terms in the result set of a SELECT statement
10873 ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
10874 ** * Terms in the VALUES clause of an INSERT statement
10877 ** tell you that in a well-normalized database, you usually should
10878 ** not have more than a dozen or so columns in any table. And if
10879 ** that is the case, there is no point in having more than a few
10880 ** dozen values in any of the other situations described above.
10887 ** The maximum length of a single SQL statement in bytes.
10912 ** The maximum number of terms in a compound SELECT statement.
10915 ** if the number of terms is too large. In practice, most SQL
10917 ** any limit on the number of terms in a compount SELECT.
10924 ** The maximum number of opcodes in a VDBE program.
10939 ** The suggested maximum number of in-memory pages to use for
10952 ** The default number of frames to accumulate in the log file before
10953 ** checkpointing the database in WAL mode.
11022 ** Maximum number of pages in one database file.
11033 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
11052 /************** Continuing where we left off in sqliteInt.h ******************/
11086 ** So we have to define the macros in different ways depending on the
11163 ** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
11171 ** Exactly one of the following macros must be defined in order to
11212 ** We need to define _XOPEN_SOURCE as follows in order to enable
11227 ** assert() statements in the code. So we want the default action
11229 ** is set. Thus NDEBUG becomes an opt-in rather than an opt-out
11247 ** The testcase() macro is used to aid in coverage testing. When
11249 ** testcase() must be evaluated both true and false in order to
11251 ** to help ensure adequate test coverage in places where simple
11283 ** "Verification, Validation, and Accreditation". In other words, the
11296 ** are included in a few cases in order to enhance the resilience
11301 ** In other words, ALWAYS and NEVER are added for defensive code.
11347 ** Is the sqlite3ErrName() function needed in the build? Currently,
11368 ** to fit in 32-bits. This macro is used inside of various testcase()
11377 ** in theory, be used by the compiler to generate better code, but
11383 /************** Include hash.h in the middle of sqliteInt.h ******************/
11388 ** The author disclaims copyright to this source code. In place of
11397 ** used in SQLite.
11417 ** There are Hash.htsize buckets. Each bucket points to a spot in
11419 ** element pointed to plus the next _ht.count-1 elements in the list.
11421 ** Hash.htsize and Hash.ht may be zero. In that case lookup is done
11424 ** in the table, it is faster to do a linear search than to manage
11428 unsigned int htsize; /* Number of buckets in the hash table */
11429 unsigned int count; /* Number of entries in this table */
11437 /* Each element in the hash table is an instance of the following
11444 HashElem *next, *prev; /* Next and previous elements in the table */
11476 ** Number of entries in a hash table
11483 /************** Continuing where we left off in sqliteInt.h ******************/
11484 /************** Include parse.h in the middle of sqliteInt.h *****************/
11651 /* The token codes above must all fit in 8 bits */
11655 ** being stored in a u8: */
11659 /************** Continuing where we left off in sqliteInt.h ******************/
11670 ** should not be used in production. This is a performance measurement
11729 ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
11867 ** that can be stored in a u32 without loss of data. The value
11869 ** have to specify the value in the less intuitive manner shown:
11874 ** The datatype used to store estimates of the number of rows in a
11911 ** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
11938 ** In other words, S is a buffer and E is a pointer to the first byte after
12011 ** pointers. In that case, only verify 4-byte alignment.
12028 ** Default maximum size of memory used by memory-mapped I/O in the VFS
12120 ** A convenience macro that returns the number of elements in
12151 ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
12179 ** For example those parameters only used in assert() statements. In these
12237 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
12249 /************** Include btree.h in the middle of sqliteInt.h *****************/
12254 ** The author disclaims copyright to this source code. In place of
12263 ** subsystem. See comments in the source code for a detailed description
12307 ** NOTE: These values must match the corresponding PAGER_ values in
12311 #define BTREE_MEMORY 2 /* This is an in-memory DB */
12359 ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
12380 ** to constants so that the offset of the corresponding field in an
12389 ** The BTREE_DATA_VERSION value is not really a value stored in the header.
12414 ** TK_REGISTER nodes that refer to values stored in the array of registers
12415 ** passed as the second parameter. In other words, if Expr.op==TK_REGISTER
12416 ** then the value of the node is the value in Mem[pExpr.iTable]. Any
12417 ** TK_COLUMN node in the expression tree refers to the Expr.iColumn-th
12439 ** to be filled with content that is already in sorted order.
12443 ** selected will all have the same key. In other words, the cursor will
12447 #define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */
12465 ** alternative storage engines that might be substituted in place of this
12466 ** b-tree system. For alternative storage engines in which a delete of
12508 ** entry in either an index or table btree.
12515 ** the key and passed in the nKey field. The pKey field is zero.
12529 sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */
12624 /************** Continuing where we left off in sqliteInt.h ******************/
12625 /************** Include vdbe.h in the middle of sqliteInt.h ******************/
12630 ** The author disclaims copyright to this source code. In place of
12650 ** in the source file sqliteVdbe.c are allowed to see the insides
12656 ** The names of the following types declared in vdbeInt.h are required
12713 int nOp; /* Elements in aOp[] */
12781 ** The following macro converts a relative address in the p2 field
12792 /************** Include opcodes.h in the middle of vdbe.h ********************/
12839 #define OP_RowSetTest 43 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12909 #define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
12963 /* Properties such as "out2" or "jump" that are specified in
12964 ** comments following the "case" for each opcode in the vdbe.c
13005 /************** Continuing where we left off in vdbe.h ***********************/
13090 ** comments in VDBE programs that show key decision points in the code
13112 ** numbers in the sqlite3.c source file. VDBE branch coverage testing
13128 ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
13129 ** routine in vdbe.c, alerting the developer to the missed tag.
13155 /************** Continuing where we left off in sqliteInt.h ******************/
13156 /************** Include pager.h in the middle of sqliteInt.h *****************/
13161 ** The author disclaims copyright to this source code. In place of
13187 ** The type used to represent a page number. The first page in a file
13203 ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
13205 ** used in the journal to signify that the remainder of the journal file
13207 ** roll back. See comments for function writeMasterJournal() in pager.c
13215 ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
13218 #define PAGER_MEMORY 0x0002 /* In-memory database */
13231 ** are exposed in the API via the "PRAGMA journal_mode" command and
13239 #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
13399 /************** Continuing where we left off in sqliteInt.h ******************/
13400 /************** Include pcache.h in the middle of sqliteInt.h ****************/
13405 ** The author disclaims copyright to this source code. In place of
13423 ** Every page in the cache is controlled by an instance of the following
13445 PgHdr *pDirtyNext; /* Next element in list of dirty pages */
13446 PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
13485 /* Return the size in bytes of a PCache object. Used to preallocate
13510 /* Get a list of all dirty pages in the cache, sorted by page number */
13530 /* Return the total number of pages stored in the cache */
13534 /* Iterate through all dirty pages currently stored in the cache. This
13559 ** The spill-size is the minimum number of pages in cache before the cache
13588 /************** Continuing where we left off in sqliteInt.h ******************/
13589 /************** Include os.h in the middle of sqliteInt.h ********************/
13594 ** The author disclaims copyright to this source code. In place of
13617 /************** Include os_setup.h in the middle of os.h *********************/
13622 ** The author disclaims copyright to this source code. In place of
13678 /************** Continuing where we left off in os.h *************************/
13696 ** alphanumeric characters, and no file extension. They are stored in the
13698 ** If sqlite is being embedded in another program, you may wish to change the
13704 ** Mcafee started using SQLite in their anti-virus product and it
13705 ** started putting files with the "sqlite" name in the c:/temp folder.
13754 ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
13763 ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
13769 ** SHARED_SIZE is the number of bytes available in the pool from which
13781 ** Locking in windows is manditory. For this reason, we cannot store
13782 ** actual data in the bytes used for locking. The pager never allocates
13783 ** the pages involved in locking therefore. SHARED_SIZE is selected so
13790 ** Changing the value of PENDING_BYTE results in a subtly incompatible
13864 /************** Continuing where we left off in sqliteInt.h ******************/
13865 /************** Include mutex.h in the middle of sqliteInt.h *****************/
13870 ** The author disclaims copyright to this source code. In place of
13881 ** to all source files. We break it out in an effort to keep the code
13939 /************** Continuing where we left off in sqliteInt.h ******************/
13962 ** In other words, the zero-based numbers are used for all external interfaces
13975 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
13992 ** In shared cache mode, a single Schema object can be shared by multiple
13999 ** A thread must be holding a mutex on the corresponding Btree in order
14015 int cache_size; /* Number of pages to use in the cache */
14019 ** These macros can be used to test, set, or clear bits in the
14056 ** lookaside malloc subsystem. Each available memory allocation in
14062 ** be stored in lookaside because in shared cache mode the schema information
14069 u16 sz; /* Size of each buffer in bytes */
14079 LookasideSlot *pNext; /* Next buffer in the list of free buffers */
14083 ** A hash table for built-in function definitions. (Application-defined
14096 ** Information held in the "sqlite3" database connection object and used
14102 int nAuthPW; /* Size of the zAuthPW in bytes */
14134 ** in the style of sqlite3_trace()
14151 int nDb; /* Number of backends currently in use */
14237 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
14244 int busyTimeout; /* Busy handler timeout, in msec */
14249 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
14252 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
14265 sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
14304 #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */
14310 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
14317 #define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */
14338 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
14363 #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
14369 ** structure. For global built-in functions (ex: substr(), max(), count())
14370 ** a pointer to this structure is held in the sqlite3BuiltinFunctions object.
14372 ** structure is held in the db->aHash hash table.
14415 ** are assert() statements in the code to verify this.
14422 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
14429 #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */
14430 #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */
14431 #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */
14432 #define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */
14433 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
14438 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
14463 ** are interpreted in the same way as the first 4 parameters to
14500 ** All current savepoints are stored in a linked list starting at
14501 ** sqlite3.pSavepoint. The first element in the list is the most recently
14523 ** instance of the following structure, stored in the sqlite3.aModule
14535 ** information about each column of an SQL table is held in an instance
14544 u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */
14551 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
14574 #define SQLITE_SO_ASC 0 /* Sort in ascending order */
14575 #define SQLITE_SO_DESC 1 /* Sort in ascending order */
14617 #define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */
14622 ** An object of this type is created for each virtual table present in
14630 ** database connections, even when the rest of the in-memory database
14639 ** All VTable objects that correspond to a single table in a shared
14640 ** database schema are initially stored in a linked-list pointed to by
14645 ** sqlite3_vtab* handle in the compiled query.
14647 ** When an in-memory Table object is deleted (for example when the
14660 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
14670 VTable *pNext; /* Next in linked list (see above) */
14674 ** The schema for each SQL table and view is represented in memory
14682 FKey *pFKey; /* Linked list of all foreign keys in this table */
14685 /* ... also used as column name list in a VIEW */
14690 i16 nCol; /* Number of columns in this table */
14691 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
14692 LogEst szTabRow; /* Estimated size of each table row in bytes */
14696 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
14698 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
14705 Trigger *pTrigger; /* List of triggers stored in pSchema */
14716 ** the TF_OOOHidden attribute would apply in this case. Such tables require
14769 ** key. The "to" table is the table that is named in the REFERENCES clause.
14790 ** is held in Schema.fkeyHash with a hash key of Z.
14794 FKey *pNextFrom; /* Next FKey with the same in pFrom. Next parent of pFrom */
14798 int nCol; /* Number of columns in this key */
14803 struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
14804 int iFrom; /* Index of column in pFrom */
14805 char *zCol; /* Name of column in zTo. If NULL use PRIMARY KEY */
14812 ** causes the operation in process to fail and for the current transaction
14813 ** to be rolled back. ABORT processing means the operation in process
14816 ** the operation in progress stops and returns an error code. But prior
14861 u16 nField; /* Number of key columns in the index */
14885 ** or greater than a key in the btree, respectively. These are normally
14887 ** is in DESC order.
14891 ** multiple entries in the b-tree with the same key (when only looking
14900 ** eqSeen field will indicate whether or not an exact match exists in the
14906 u16 nField; /* Number of entries in apMem[] */
14916 ** Each SQL index is represented in memory by an
14926 ** In the Table structure describing Ex1, nCol==3 because there are
14927 ** three columns in the table. In the Index structure describing
14930 ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
14931 ** The second column to be indexed (c1) has an index of 0 in
14941 ** While parsing a CREATE TABLE or CREATE INDEX statement in order to
14944 ** of this structure may be created. In this case the Index.tnum variable is
14962 LogEst szIdxRow; /* Estimated average row size in bytes */
14964 u16 nColumn; /* Number of columns stored in the index */
14967 unsigned bUnordered:1; /* Use this index for == or IN queries only */
14974 int nSample; /* Number of elements in aSample[] */
14976 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
14979 tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */
15003 ** Each sample stored in the sqlite_stat3 table is represented in memory
15009 int n; /* Size of record in bytes */
15025 unsigned int n; /* Number of characters in this token */
15033 ** pointer to this structure. The Expr.iColumn field is the index in
15044 u8 useSortingIdx; /* In direct mode, reference the sorting index rather
15048 int nSortingColumn; /* Number of columns in the sorting index */
15051 struct AggInfo_col { /* For each column used in source tables */
15055 int iSorterColumn; /* Column number in the sorting index */
15059 int nColumn; /* Number of used entries in aCol[] */
15069 int nFunc; /* Number of entries in aFunc[] */
15076 ** it uses less memory in the Expr object, which is a big memory user
15077 ** in systems with lots of prepared statements. And few applications
15089 ** Each node of an expression in the parse tree is an instance
15095 ** to represent the greater-than-or-equal-to operator in the expression
15108 ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)".
15110 ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the
15114 ** An expression of the form ID or ID.ID refers to a column in a table.
15118 ** expression is used as a result in an aggregate SELECT, then the
15119 ** value is also stored in the Expr.iAgg column in the aggregate so that
15123 ** character '?' in the original SQL) then the Expr.iTable holds the index
15138 ** Expr objects can use a lot of memory space in database schema. To
15141 ** two or more Expr objects will be stored in a single memory allocation,
15146 ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
15148 ** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately
15160 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
15162 ** access them will result in a segfault or malfunction.
15168 ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */
15169 Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */
15172 /* If the EP_Reduced flag is set in the Expr.flags mask, then no
15174 ** access them will result in a segfault or malfunction.
15188 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
15198 ** The following are the meanings of bits in the Expr.flags field.
15200 #define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
15206 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
15210 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
15215 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
15231 ** These macros can be used to test, set, or clear bits in the
15251 ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
15266 ** name. An expr/name combination can be used in several ways, such
15267 ** as the list of "expr AS ID" fields following a "SELECT" or in the
15268 ** list of "ID = expr" items in an UPDATE. A list of expressions can
15269 ** also be used as the argument to a function, in which case the a.zName
15273 ** the expression that is used in the generation of error messages and
15274 ** column labels. In this case, Expr.zSpan is typically the text of a
15275 ** column expression as it exists in a SELECT statement. However, if
15277 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
15283 struct ExprList_item { /* For each expression in the list */
15293 u16 iOrderByCol; /* For ORDER BY, column number in result set */
15296 int iConstExprReg; /* Register in which Expr value is cached */
15298 } a[1]; /* One slot for each expression in the list */
15314 ** such as the list "a,b,c" in the following statements:
15321 ** column names after a table name in an INSERT statement. In the statement
15330 int idx; /* Index in some Table.aCol[] of a column named zName */
15339 ** tables in a join to 32 instead of 64. But it also reduces the size
15349 ** The number of bits in a Bitmask. "BMS" means "BitMask Size".
15354 ** A bit in a Bitmask
15362 ** Each table or subquery in the FROM clause is a separate element of
15367 ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
15368 ** such a table must be a simple name: ID. But in SQLite, the table can
15376 ** In the colUsed field, the high-order bit (bit 63) is set if the table
15380 int nSrc; /* Number of tables or subqueries in the FROM clause */
15381 u32 nAlloc; /* Number of entries allocated in a[] below */
15388 Select *pSelect; /* A SELECT statement used in place of a table name */
15399 unsigned isRecursive :1; /* True for recursive reference in WITH */
15402 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
15451 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
15462 ** A NameContext defines a context in which to resolve table and column
15478 ** NameContext in the parent query. Thus the process of scanning the
15503 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
15518 ** in the VDBE that record the limit and offset counters.
15521 ** These addresses must be stored so that we can go back and fill in
15523 ** the number of columns in P2 can be computed at the same time
15545 Select *pPrior; /* Prior select in a compound select statement */
15546 Select *pNext; /* Next select to the left in a compound */
15578 #define SF_IncludeHidden 0x20000 /* Include hidden columns in output */
15582 ** The results of a SELECT can be distributed in several ways, as defined
15586 ** SRT_Union Store results as a key in a temporary index
15591 ** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result
15602 ** opcode) for each row in the result set.
15606 ** in register pDest->iSDParm then abandon the rest
15610 ** row of result as the key in table pDest->iSDParm.
15612 ** results. Used to implement "IN (SELECT ...)".
15622 ** of the co-routine is stored in register pDest->iSDParm
15623 ** and the result row is stored in pDest->nDest registers
15626 ** SRT_Table Store results in temporary table pDest->iSDParm.
15632 ** SRT_DistFifo Store results in a temporary table pDest->iSDParm.
15637 ** SRT_Queue Store results in priority queue pDest->iSDParm (really
15641 ** SRT_DistQueue Store results in priority queue pDest->iSDParm only if
15645 #define SRT_Union 1 /* Store result as keys in an index */
15651 #define SRT_Queue 7 /* Store result in an queue */
15658 #define SRT_Mem 10 /* Store result in a memory cell */
15659 #define SRT_Set 11 /* Store results as keys in an index */
15682 in case inserts are done within triggers. Triggers do not
15687 AutoincInfo *pNext; /* Next info block in a list of them all */
15689 int iDb; /* Index in sqlite3.aDb[] of database holding pTab */
15703 ** statement. All such objects are stored in the linked list headed at
15709 ** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable.
15720 TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */
15747 ** the parser and down into all the parser action routine in order to
15769 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
15775 u8 nColCache; /* Number of entries in aColCache[] */
15777 int iRangeReg; /* First register in temporary register block */
15801 int nTableLock; /* Number of locks in aTableLock */
15837 ** first field in the recursive region.
15841 ynVar nVar; /* Number of '?' variables seen in the SQL so far */
15896 ** Bitfield flags for P5 value in various opcodes.
15908 /* Also used in P2 (not P5) of OP_Delete */
15913 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
15923 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
15926 * Each trigger present in the database schema is stored as an instance of
15929 * Pointers to instances of struct Trigger are stored in two ways.
15930 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
15959 ** In that cases, the constants below can be ORed together.
15968 * Instances of struct TriggerStep are stored in a singly linked list (linked
16011 TriggerStep *pNext; /* Next in the link-list */
16012 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
16025 const char *zDb; /* Make sure all objects are contained in this database */
16032 ** do not necessarily know how big the string will be in the end.
16039 u32 nAlloc; /* Amount of space allocated in zText */
16092 int szPage; /* Size of each page in pPage[] */
16093 int nPage; /* Number of pages in pPage[] */
16100 int inProgress; /* True while initialization in progress */
16190 int nCte; /* Number of CTEs in the WITH clause */
16192 struct Cte { /* For each CTE in the WITH clause.... */
16207 u8 bLine[100]; /* Draw vertical in column i if bLine[i] is true */
16263 ** needed by FTS3 when FTS3 is included in the amalgamation.
16768 ** be defined locally, but now we use the varint routines in the util.c
17027 /* Declarations for functions in fkey.c. All of these are replaced by
17028 ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign
17030 ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
17065 ** The interface to the code in fault.c used for identifying "benign"
17089 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
17090 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
17152 ** sqlite3MemdebugHasType() returns true if any of the bits in its second
17156 ** sqlite3MemdebugNoType() returns true if none of the bits in its second
17210 ** The author disclaims copyright to this source code. In place of
17269 ** The following 256 byte lookup table is used to support SQLites built-in
17291 ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
17336 /* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
17367 ** page size in bytes.
17374 ** threshold (in bytes). 0 means that statement journals are created and
17376 ** before 3.12.0). -1 means always keep the entire statement journal in
17377 ** memory. (The statement journal is also always held entirely in memory
17387 ** number of bytes in each lookaside slot (should be a multiple of 8)
17472 ** 1-gibabyte boundary) in a compatible database. SQLite never uses
17478 ** a different position in the file. This allows code that has to
17484 ** 0x40000000 results in an incompatible database file format!
17485 ** Changing the pending byte during operation will result in undefined
17496 ** from the comments following the "case OP_xxxx:" statements in
17511 ** The author disclaims copyright to this source code. In place of
17532 ** This array looks large, but in a typical installation actually uses
17539 ** for those options in which the value is meaningful. */
17950 /* Since ArraySize(azCompileOpt) is normally in single digits, a
17980 ** The author disclaims copyright to this source code. In place of
17993 /************** Include vdbeInt.h in the middle of status.c ******************/
17998 ** The author disclaims copyright to this source code. In place of
18046 /* Opaque type used by code in vdbesort.c */
18062 ** - In the main database or in an ephemeral database
18066 ** * A one-row "pseudotable" stored in a single register
18071 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
18109 i16 nField; /* Number of fields in the header */
18114 u32 payloadSize; /* Total number of bytes in the record */
18115 u32 szRow; /* Byte available in aRow */
18121 ** static element declared in the structure. nField total array slots for
18136 ** values stored in the Vdbe struct. When the sub-program is finished,
18142 ** cell in the parent (calling) frame. When the memory cell is deleted or
18145 ** list is deleted when the VM is reset in VdbeHalt(). The reason for doing
18150 ** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
18165 int nCursor; /* Number of entries in apCsr */
18166 int pc; /* Program Counter in parent (calling) frame */
18168 int nMem; /* Number of entries in aMem */
18184 double r; /* Real value used when MEM_Real is set in flags */
18185 i64 i; /* Integer value used when MEM_Int is set in flags */
18186 int nZero; /* Used when bit MEM_Zero is set in flags */
18194 int n; /* Number of characters in string value, excluding '\0' */
18199 u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
18215 ** representations of the value stored in the Mem struct.
18218 ** No other flags may be set in this case.
18221 ** Usually this is encoded in the same unicode encoding as the main
18278 ** implementation calling sqlite3_set_auxdata() is stored in an instance
18280 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
18288 AuxData *pNextAux; /* Next element in list */
18296 ** There is a typedef for this structure in sqlite.h. So all routines,
18343 ynVar nVar; /* Number of entries in aVar[] */
18346 int nCursor; /* Number of slots in apCsr[] */
18372 int nOp; /* Number of instructions in the program */
18376 u16 nResColumn; /* Number of columns in one row of the result set */
18377 u8 errorAction; /* Recovery action to do in case of an error */
18395 int nFrame; /* Number of frames in pFrame list */
18401 int nScan; /* Entries in aScan[] */
18549 /************** Continuing where we left off in status.c *********************/
18552 ** Variables in which to record status information.
18585 ** we have to locate the state vector at run-time. In the more common
18890 ** The author disclaims copyright to this source code. In place of
18901 ** There is only one exported symbol in this file - the function
18907 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
18924 ** in the following text:
18942 ** defined in "os_win.c".
18957 int tz; /* Timezone offset in minutes */
18960 char rawS; /* Raw numeric value stored in s */
18992 ** the 2-digit day which is the last integer in the set.
19045 ** of change in p->tz and return 0. If a parser error occurs,
19238 ** If the value is a valid unix timestamp, put it in p->s and set p->rawS.
19259 ** In the first form, the +/-HH:MM is always optional. The fractional
19395 ** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
19396 ** library function localtime_r() is used to assist in the calculation of
19431 ** Compute the difference (in milliseconds) between localtime and UTC
19432 ** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
19436 ** is undefined in this case.
19538 ** is in a system call (i.e. localtime()), then an error message is written
19545 int n, /* Length of zMod in bytes */
19800 ** Return the julian day number of the date specified in the arguments
20114 ** functions. This should be the only routine in this file with
20142 ** The author disclaims copyright to this source code. In place of
20452 ** error in sqlite3_os_init() by the upper layers can be tested.
20560 ** The author disclaims copyright to this source code. In place of
20598 ** we have to locate the state vector at run-time. In the more common
20650 ** The author disclaims copyright to this source code. In place of
20686 ** This routine is the only routine in this file with external linkage.
20688 ** Populate the low-level memory allocation function pointers in
20689 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
20712 ** The author disclaims copyright to this source code. In place of
20726 ** routines specified in the sqlite3_mem_methods object. The content of
20730 ** default configuration is to use memory allocation routines in this
20980 ** This routine is the only routine in this file with external linkage.
20982 ** Populate the low-level memory allocation function pointers in
20983 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
21006 ** The author disclaims copyright to this source code. In place of
21018 ** information to each allocation in order to help detect and fix memory
21022 ** routines specified in the sqlite3_mem_methods object.
21082 ** when this module is combined with other in the amalgamation.
21098 ** The number of levels of backtrace to save in new allocations.
21104 ** Title text to insert in front of each block
21340 ** allocation into a new place in memory. In this way, if the
21363 ** Populate the low-level memory allocation function pointers in
21364 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
21393 ** Return TRUE if the mask of type in eType matches the type of the
21415 ** Return TRUE if the mask of type in eType matches no bits of the type of the
21537 ** The author disclaims copyright to this source code. In place of
21557 ** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
21571 ** Maximum size (in Mem3Blocks) of a "small" chunk.
21588 ** size of the allocation in blocks if the allocation is free.
21593 ** the previous chunk in blocks if the previous chunk is on the
21598 ** We often identify a chunk by its index in mem3.aPool[]. When
21600 ** the chunk. In this way, the first chunk has an index of 1.
21606 ** Pointers to the head of the list are stored in mem3.aiSmall[]
21617 u32 prevSize; /* Size of previous chunk in Mem3Block elements */
21618 u32 size4x; /* 4x the size of current chunk in Mem3Block elements */
21621 u32 next; /* Index in mem3.aPool[] of next free chunk */
21622 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
21631 ** when this module is combined with other in the amalgamation.
21636 ** (in Mem3Blocks) pointed to by aPool less 2.
21658 ** occur off of this chunk. szMaster is the size (in Mem3Blocks)
21660 ** The master chunk is not in either the aiHash[] or aiSmall[].
21752 ** will already be held (obtained by code in malloc.c) if
21834 ** or same size hash. In other words, *pRoot is an entry in either
21841 ** the current mem3.iMaster with the new larger chunk. In order for
21881 ** Return a block of memory of at least nBytes in size.
21902 ** Look for an entry of the correct size in either the small
21903 ** chunk table or in the large chunk hash table. This is
22006 ** Return the size of an outstanding allocation, in bytes. The
22091 /* Store a pointer to the memory block in global structure mem3. */
22196 ** This routine is the only routine in this file with external
22199 ** Populate the low-level memory allocation function pointers in
22200 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
22227 ** The author disclaims copyright to this source code. In place of
22247 ** in the build only if SQLITE_ENABLE_MEMSYS5 is defined.
22258 ** This algorithm is described in: J. M. Robson. "Bounds for Some Functions
22288 ** verified in memsys5Init().
22313 ** when this module is combined with other in the amalgamation.
22319 int szAtom; /* Smallest possible allocation in bytes */
22320 int nBlock; /* Number of szAtom sized blocks in zPool */
22421 ** Return the size of an outstanding allocation, in bytes.
22434 ** Return a block of memory of at least nBytes in size.
22441 ** threads can be in this routine at the same time.
22469 ** two in order to create a new free block of size iLogsize.
22517 /* Set iBlock to the index of the block pointed to by pOld in
22677 int nMinLog; /* Log base 2 of minimum allocation size in bytes */
22694 /* boundaries on sqlite3GlobalConfig.mnReq are enforced in sqlite3_config() */
22781 ** This routine is the only routine in this file with external
22806 ** The author disclaims copyright to this source code. In place of
22978 ** The author disclaims copyright to this source code. In place of
22988 ** This implementation in this file does not provide any mutual
22989 ** exclusion and is thus suitable for use only in applications
22990 ** that use SQLite in a single thread. The routines defined
23046 ** In this implementation, error checking is provided for testing
23132 ** be entered multiple times by the same thread. In such cases the,
23196 ** The author disclaims copyright to this source code. In place of
23209 ** The code in this file is only used if we are compiling threadsafe
23256 ** deliver incorrect results. In particular, if pthread_equal() is
23279 ** and also for the implementation of xShmBarrier in the VFS in cases
23325 ** not want to. But SQLite will only request a recursive mutex in
23328 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
23431 ** be entered multiple times by the same thread. In such cases the,
23462 /* Use the built-in recursive mutexes if they are available.
23508 /* Use the built-in recursive mutexes if they are available.
23586 ** The author disclaims copyright to this source code. In place of
23602 /************** Include os_common.h in the middle of mutex_w32.c *************/
23607 ** The author disclaims copyright to this source code. In place of
23627 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
23645 /************** Include hwtime.h in the middle of os_common.h ****************/
23650 ** The author disclaims copyright to this source code. In place of
23734 /************** Continuing where we left off in os_common.h ******************/
23800 /************** Continuing where we left off in mutex_w32.c ******************/
23805 /************** Include os_win.h in the middle of mutex_w32.c ****************/
23810 ** The author disclaims copyright to this source code. In place of
23897 /************** Continuing where we left off in mutex_w32.c ******************/
23901 ** The code in this file is only used if we are compiling multithreaded
23954 ** and also for the xShmBarrier method of the VFS in cases when SQLite is
24012 /* Another thread is (in the process of) initializing the static
24065 ** not want to. But SQLite will only request a recursive mutex in
24068 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
24151 ** be entered multiple times by the same thread. In such cases the,
24278 ** The author disclaims copyright to this source code. In place of
24295 ** cache database pages that are not currently in use.
24442 ** Return true if the heap is currently under memory pressure - in other
24500 /* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
24501 ** implementation of malloc_good_size(), which must be called in debug
24583 ** xScratchMalloc(). We verify this constraint in the single-threaded
24594 ** This routine is similar to alloca() in that it is not intended
24629 ** This can only be checked in single-threaded mode.
24642 ** is outstanding at one time. (This is only checked in the
24643 ** single-threaded case since checking in the multi-threaded case
24742 ** Add the size of memory allocation "p" to the count in
24765 /* Trash all content in the buffer being freed */
24801 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
24868 ** the mallocFailed flag in the connection pointer.
24894 ** If the allocation fails, set the mallocFailed flag in
24901 ** This is an important assumption. There are many places in the
24908 ** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
24961 ** resize fails, set the mallocFailed flag in the connection object.
24998 ** and set the mallocFailed flag in the database connection.
25010 ** Make a copy of a string in memory obtained from sqliteMalloc(). These
25013 ** called via macros that record the current file and line number in the
25045 ** Free any prior content in *pz and replace it with a copy of zNew.
25121 ** The "printf" code that follows dates from the 1980's. It is in
25146 /* The rest are extensions, not normally found in printf() */
25148 #define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
25166 ** Each builtin conversion character (ex: the 'd' in "%d") is described
25236 ** 16 (the number of significant digits in a 64-bit float) '0' is
25295 int c; /* Next character in the format string */
25657 /* The sign in front of the number */
25712 /* The converted number is in buf[] and zero terminated. Output it.
25713 ** Note that the number is in the usual order, not reversed as with
25782 case etSQLESCAPE2: /* Escape ' and enclose in '...' */
25822 /* The precision in %q and %Q means how many input characters to
26039 ** zBase: An initial buffer. May be NULL in which case the initial buffer
26041 ** n: Size of zBase in bytes. If total space requirements never exceed
26132 ** are not able to use a "," as the decimal point in place of "." as
26168 ** We house it in a separate routine from sqlite3_log() to avoid using
26239 ** The author disclaims copyright to this source code. In place of
26252 ** The interfaces in this file is only available when compiling
26260 ** is not the last item in the tree.
26630 sqlite3TreeViewLine(pView, "IN");
26648 ** X is stored in pExpr->pLeft.
26649 ** Y is stored in pExpr->pList->a[0].pExpr.
26650 ** Z is stored in pExpr->pList->a[1].pExpr.
26664 ** to a column in the new.* or old.* pseudo-tables available to
26665 ** trigger programs. In this case Expr.iTable is set to 1 for the
26773 ** The author disclaims copyright to this source code. In place of
26784 ** Random numbers are used by some of the database backends in order
26808 ** we have to locate the state vector at run-time. In the more common
26843 ** Nothing in this file or anywhere else in SQLite does any kind of
26910 ** The author disclaims copyright to this source code. In place of
26928 ** or sqlite3ThreadJoin() call. This is, in fact, what happens in
26929 ** single threaded systems. Nothing in SQLite requires multiple threads.
26959 void *(*xTask)(void*), /* Routine to run in a separate thread */
26967 /* This routine is never used in single-threaded mode */
27030 void *pArg /* IN: Pointer to the SQLiteThread structure */
27054 void *(*xTask)(void*), /* Routine to run in a separate thread */
27120 ** work of the thread in the main thread, when either the thread is created
27134 void *(*xTask)(void*), /* Routine to run in a separate thread */
27187 ** The author disclaims copyright to this source code. In place of
27329 ** * Bytes in the range of 0x80 through 0xbf which occur as the first
27386 int len; /* Maximum length of output string in bytes */
27431 /* Set len to the maximum number of bytes required in the output buffer. */
27443 ** character. Two bytes are required in the output buffer for the
27521 ** UTF-16 string stored in *pMem. If one is present, it is removed and
27561 ** return the number of unicode characters in pZ up to (but not including)
27563 ** number of unicode characters in the first nByte of pZ (or up to
27584 ** Hence it is only available in debug builds.
27593 ** The translation is done in-place and aborted if the output
27614 ** Convert a UTF-16 string in the native encoding into a UTF-8 string.
27638 ** Return the number of bytes in the first nChar unicode characters
27639 ** in pZ. nChar must be non-negative.
27664 ** characters in each encoding are inverses of each other.
27720 ** The author disclaims copyright to this source code. In place of
27752 ** in places where it is difficult or expensive to do so purely by means
27789 ** -O option since it can result in incorrect output for programs
27816 ** Compute a string length that is limited to what can be stored in
27863 ** to do based on the SQLite error code in rc.
27878 ** error string in the style of the printf functions: The following
27888 ** encoded in UTF-8.
27946 ** the quote characters. The conversion is done in-place. If the
28001 ** the contents of two buffers containing UTF-8 strings in a
28043 ** The string z[] is length bytes in length (bytes, not characters) and
28048 ** are in one of these formats:
28077 *pResult = 0.0; /* Default return value, in case of an error */
28168 /* In the IEEE 754 standard, zero is signed. */
28244 ** in the values of the last digit if the only difference is in the
28283 ** length is the number of bytes in the string (bytes, not characters).
28340 /* Less than 19 digits, so we know that it fits in 64 bits */
28363 ** Transform a UTF-8 integer literal, in either decimal or hexadecimal,
28369 ** 0 Successful transformation. Fits in a 64-bit signed integer.
28394 ** If zNum represents an integer that will fit in 32-bits, then set
28537 ** inline in order to work around bugs in the RVT compiler.
28549 ** Return the number of bytes read. The value is stored in *v.
28646 /* we can skip this cause it was (effectively) done above in calc'ing s */
28713 ** Return the number of bytes read. The value is stored in *v.
28715 ** If the varint stored in p[0] is larger than can fit in a 32-bit unsigned
28766 /* A 32-bit varint is used to store size information in btrees.
28825 ** file. In that case we are not in any hurry. Use the (relatively
28946 ** misuse of the interface such as passing in db pointers that are
28990 ** the other 64-bit signed integer at *pA and store the result in *pA.
28991 ** Return 0 on success. Or if the operation would have resulted in an
29064 ** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
29065 ** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
29122 ** Convert an integer into a LogEst. In other words, compute an
29141 ** In other words, compute an approximation for 10*log2(x).
29175 ** possible to this routine is 310, resulting in a maximum x of 31 */
29222 int nName, /* Bytes of text in zName */
29227 int i; /* Index in pIn[] where zName is stored */
29252 ** Return a pointer to the name of a variable in the given VList that
29253 ** has the value iVal. Or return a NULL if there is no such variable in
29269 ** Return the number of the variable named zName, if it is in VList.
29290 ** The author disclaims copyright to this source code. In place of
29299 ** used in SQLite.
29363 HashElem *pHead; /* First element already in pEntry */
29428 /* This function (for internal use only) locates an element in an
29430 ** also computed and returned in the *pH parameter.
29519 ** The key is not copied in this instance. If a malloc fails, then
29616 /* 43 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29686 /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29749 ** The author disclaims copyright to this source code. In place of
29761 ** There are actually several different VFS implementations in this file.
29762 ** The differences are in the way that file locking is done. The default
29770 ** in the correct division and should be clearly labeled.
29917 ** kernel modules in VxWorks. */
29934 ** cannot be closed immediately. In these cases, instances of the following
29982 ** transaction counter in bytes 24-27 of database files are updated
29990 unsigned char inNormalWrite; /* True if in a normal write operation */
29995 /* In test mode, increase the size of this structure a bit so that
29996 ** it is larger than the struct CrashFile defined in test6.c.
30027 /************** Include os_common.h in the middle of os_unix.c ***************/
30032 ** The author disclaims copyright to this source code. In place of
30052 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
30070 /************** Include hwtime.h in the middle of os_common.h ****************/
30075 ** The author disclaims copyright to this source code. In place of
30159 /************** Continuing where we left off in os_common.h ******************/
30225 /************** Continuing where we left off in os_unix.c ********************/
30288 ** Different Unix systems declare open() in different ways. Same use
30466 ** On some systems, calls to fchown() will trigger a message in a security
30562 ** Do not accept any file descriptor less than this value, in order to avoid
30582 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
30774 * introspection, in which it actually means what it says */
30794 ** unique file ID in VxWorks. Each instance of this structure contains
30804 struct vxworksFileId *pNext; /* Next in a list of them all */
30825 ** Changes are made in-place. Return the new name length.
30827 ** The original filename is in z[0..n-1]. Return the number of
30828 ** characters in the simplified name.
30948 ** to synchronize access for threads in separate processes, but not
30954 ** st_dev and st_ino fields of the stat structure that fstat() fills in)
30962 ** canonical filename and implemented in the previous division.)
31001 ** in thread B. But there is no way to know at compile-time which
31010 ** per database file in the same process and (2) database connections
31073 ** It is invoked after an error occurs in an OS function and errno has been
31140 ** We assume that close() almost always works, since it is only in a
31158 ** Set the pFile->lastErrno. Do this in a subroutine as that provides
31166 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
31221 unixFile *pFile, /* Unix file with file desc used in the key */
31248 ** around this problem (we consider it a bug in OS X, not SQLite)
31252 ** in the header of every SQLite database. In this way, if there
31368 /* Check if a thread in this process holds such a lock */
31406 ** in order to coordinate access between separate database connections
31407 ** within this process, but all of that is handled in memory and the
31415 ** to fcntl() fails. In this case, errno is set appropriately (by fcntl()).
31453 ** are inserted in between. The locking might fail on one of the later
31469 ** lock transitions in terms of the POSIX advisory shared and exclusive
31472 ** slightly in order to be compatible with Windows95 systems simultaneously
31473 ** accessing the same database file, in case that is ever required.
31475 ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved
31628 /* We are trying for an exclusive lock but another thread in this
31713 ** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
31751 ** the lock in 2 blocks, so that part of the range will be covered by a
31808 /* In theory, the call to unixFileLock() cannot fail because another
31812 ** SQLITE_BUSY would confuse the upper layer (in practice it causes
31834 ** OS call only when all threads in this same process have released
31973 ** corruption if this locking mode is used in situations where multiple
32018 ** Dotfile locking works by creating a subdirectory in the same directory as
32025 ** The file suffix added to the data base filename in order to create the
32036 ** In dotfile locking, either a lock exists or it does not. So in this
32064 ** are inserted in between. The locking might fail on one of the later
32189 ** flock() locking is like dot-file locking in that the various
32191 ** a single exclusive lock. In other words, SHARED, RESERVED, and
32229 /* Check if a thread in this process holds such a lock */
32281 ** are inserted in between. The locking might fail on one of the later
32293 ** lock states in the sqlite3_file structure, but all locks SHARED or
32394 ** Semaphore locking is like dot-lock and flock in that it really only
32416 /* Check if a thread in this process holds such a lock */
32431 /* someone else has the lock when we are in NO_LOCK */
32455 ** are inserted in between. The locking might fail on one of the later
32467 ** lock states in the sqlite3_file structure, but all locks SHARED or
32619 OSTRACE(("AFPSETLOCK [%s] for %d%s in range %llx:%llx\n",
32665 /* Check if a thread in this process holds such a lock */
32676 /* if we succeeded in taking the reserved lock, unlock it to restore
32705 ** are inserted in between. The locking might fail on one of the later
32832 /* We are trying for an exclusive lock but another thread in this
32970 ** OS call only when all threads in this same process have released
33064 ** methods were defined in divisions above (one locking method per
33076 ** in any form by default, we will not attempt to define _XOPEN_SOURCE.
33144 ** file), the bytes in the locking range should never be read or written. */
33194 int nBuf, /* Size of buffer pBuf in bytes */
33230 ** Seek to the offset in id->offset then read cnt bytes into pBuf.
33257 ** file), the bytes in the locking range should never be read or written. */
33466 ** The ability to override this routine was added in support of the
33611 ** Determine the current size of a file in bytes
33626 ** writes a single byte into that file in order to work around a bug
33627 ** in the OS-X msdos filesystem. In order to avoid problems with upper
33639 ** Handler for proxy-locking file-control verbs. Defined below in the
33647 ** file-control operation. Enlarge the database to nBytes in size
33674 ** single byte to the last byte in each block that falls entirely
33944 ** Return the sector size in bytes of the underlying block device for
33949 ** if two files are created in the same file-system directory (i.e.
33964 ** file system does not always provide powersafe overwrites. (In other
33967 ** very rare. And asserting PSOW makes a large reduction in the amount
33983 ** This function should not be called directly by other code in this file.
34005 ** of this unixShmNode object. In other words, each wal-index is opened
34010 ** every open file that does not use shared memory (in other words, most
34027 ** in this structure.
34157 ** to use 64KB pages - in this case each mapping must cover at least two
34203 ** The file used to implement shared-memory is in the same directory
34209 ** Another approach to is to use files in /dev/shm or /dev/tmp or an
34210 ** some other tmpfs mount. But if a file in a different directory
34215 ** in database corruption. Nevertheless, this tmpfs file usage
34218 ** option results in an incompatible build of SQLite; builds of SQLite
34222 ** "unsupported" and may go away in a future SQLite release.
34225 ** file are currently open, in this process or in other processes, then
34230 ** that no other processes are able to read or write the database. In
34240 int nShmFilename; /* Size of the SHM filename in bytes */
34368 ** bytes in size.
34373 ** region has not been allocated (by any client, including one running in a
34442 ** last page in order to extend the file. But writing to all new
34517 ** different here than in posix. In xShmLock(), one can go from unlocked
34726 ** the three variables above are zeroed. In this case SQLite should
34737 i64 nOrig = pFd->mmapSizeActual; /* Size of pOrig region in bytes */
34799 ** in this case. */
34851 ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
34854 ** value of *pp is undefined in this case.
34956 ** to the METHOD object in the previous bullet.
35063 ** The proxy locking method is a "super-method" in the sense that it
35067 ** proxy locking is located much further down in the file. But we need
35234 ** exception is when opening the proxy "conch" file in builds that
35244 /* No locking occurs in temporary files */
35276 /* Cache zFilename in the locking context (AFP and dotlock override) for
35291 /* If an error occurred in findInodeInfo(), close the file descriptor
35293 ** in two scenarios:
35306 ** implicit assumption here is that if fstat() fails, things are in
35317 /* AFP locking uses the file path so it needs to be included in
35344 /* Dotfile locking uses the file path so it needs to be included in
35363 ** included in the semLockingContext
35404 ** Return the name of a directory in which to put temporary files.
35437 ** Create a temporary file name in zBuf. zBuf must be allocated
35469 ** Implementation in the proxy-lock division, but used by unixOpen()
35484 ** Refer to comments in the unixClose() function and the lengthy comment
35504 ** For this reason, if an error occurs in the stat() call here, it is
35561 ** In most cases, this routine sets *pMode to 0, which will become
35588 int nDb; /* Number of valid bytes in zDb */
35605 /* In the normal case (8+3 filenames disabled) the journal filename
35638 ** Previously, the SQLite OS layer used three functions in place of this
35660 sqlite3_file *pFile, /* The file descriptor to be filled in */
35695 ** a temporary file. Use this buffer to store the file name in.
35886 /* Use unixClose to clean up the resources added in fillInUnixFile
36013 ** is stored as a nul-terminated string in the buffer pointed to by
36017 ** (in this case, MAX_PATHNAME bytes). The full-path is written to
36023 int nOut, /* Size of output buffer in bytes */
36176 ** uninitialized space in zBuf - but valgrind errors tend to worry
36179 ** in the random seed.
36243 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
36247 ** Find the current time (in Universal Coordinated Time). Write into *piNow
36248 ** the current time and date as a Julian Day number times 86_400_000. In
36250 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
36284 ** Find the current time (in Universal Coordinated Time). Write the
36321 ** Proxy locking is a "uber-locking-method" in this sense: It uses the
36325 ** until late in the file (here) after all of the other I/O methods have
36331 ** The default locking schemes in SQLite use byte-range locks on the
36339 ** address in the shared range is taken for a SHARED lock, the entire
36347 ** slowdown in read performance on AFP because the AFP client disables
36380 ** host ID in it, the proxy path in the conch file will be used, otherwise
36409 ** proxy path against the values stored in the conch. The conch file is
36410 ** stored in the same directory as the database file and the file name
36475 ** and local proxy files in it
36534 ** Creates the lock file and any missing directories in lockPath
36570 ** Create a new VFS file descriptor (stored in memory obtained from
36571 ** sqlite3_malloc) and open the file named "path" in the file descriptor.
36666 /* Not always defined in the headers as it ought to be */
36847 ** lockPath means that the lockPath in the conch file will be used if the
36897 /* if the host id matches and the lock path already exists in the conch
36901 do { /* in case we need to try again for an :auto: named lock file */
36909 ** use the local lock file path that's already in there
36953 /* We are trying for an exclusive lock but another thread in this
37065 } while (1); /* in case we need to retry the :auto: lock file -
37094 ** Store the conch filename in memory obtained from sqlite3_malloc64().
37106 char *conchPath; /* buffer in which to construct conch name */
37171 ** is a string buffer at least MAXPATHLEN+1 characters in size.
37179 /* afp style keeps a reference to the db path in the filePath field
37200 ** Takes an already filled in unix file and alters it so all file locking
37202 ** are preserved in the locking context so that they can be restored and
37392 ** are inserted in between. The locking might fail on one of the later
37503 ** should be the only routines in this file that are visible from other
37558 ** All default VFSes for unix are contained in the following array.
37596 /* Register all VFSes defined in the aVfs[] array */
37606 ** Some operating systems might need to do some cleanup in this routine,
37621 ** The author disclaims copyright to this source code. In place of
37638 /************** Include os_common.h in the middle of os_win.c ****************/
37643 ** The author disclaims copyright to this source code. In place of
37663 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
37681 /************** Include hwtime.h in the middle of os_common.h ****************/
37686 ** The author disclaims copyright to this source code. In place of
37770 /************** Continuing where we left off in os_common.h ******************/
37836 /************** Continuing where we left off in os_win.c *********************/
37845 ** available in Windows platforms based on the NT kernel.
37900 ** target system. GetVersionEx was first deprecated in Win8.1.
37913 ** When compiling for Windows 10, always assume "mincore.lib" is in use.
37924 ** This constant should already be defined (in the "WinDef.h" SDK file).
37931 ** Maximum pathname length (in chars) for Win32. This should normally be
37939 ** This constant should already be defined (in the "WinNT.h" SDK file).
37946 ** Maximum pathname length (in chars) for WinNT. This should normally be
37954 ** Maximum pathname length (in bytes) for Win32. The MAX_PATH macro is in
37963 ** Maximum pathname length (in bytes) for WinNT. This should normally be
37972 ** Maximum error message length (in chars) for WinRT.
38003 ** mode or memory mapped files (e.g. these APIs are available in the Windows
38004 ** CE SDK; however, they are not present in the header file)?
38166 * data will almost certainly result in an immediate access violation.
38174 * This is the maximum possible initial size of the Win32-specific heap, in
38183 * in bytes. This value may be zero.
38190 * Calculate the maximum legal cache size, in pages, based on the maximum
38201 * This is cache size used in the calculation of the initial size of the
38213 * Make sure that the calculated cache size, in pages, cannot cause the
38215 * of memory that can be specified in the call to HeapCreate.
38239 * The extra flags to use in calls to the Win32 heap APIs. This value may be
38310 ** In order to facilitate testing on a WinNT system, the test fixture
39081 ** largest committed free block in the heap, in bytes.
39153 ** The Win32 native heap cannot be modified because it may be in use.
39371 ** Return the size of an outstanding allocation, in bytes.
39477 ** Populate the low-level memory allocation function pointers in
39478 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
39746 ** the provided arguments. The type argument must be 1 in order to set the
39747 ** data directory or 2 in order to set the temporary directory. The zValue
39783 ** is zero if the error message fits in the buffer, or non-zero
39866 ** This routine is invoked after an error occurs in an OS function.
39920 ** non-zero if the error code is transient in nature and the operation
39927 ** may be used to include additional error codes in the set that should
39928 ** result in the failing I/O operation being retried by the caller. If
39987 ** corresponding section in "date.c" cannot use it.
40040 ** Create the mutex and shared memory used for locking in the file
40096 /* If we succeeded in making the shared memory handle, map it. */
40142 /* The following blocks should probably assert in debug mode, but they
40143 are to cleanup in case any locks remained open */
40841 ** Determine the current size of a file in bytes
40987 ** are inserted in between. The locking might fail on one of the later
41124 /* Update the state of the lock has held in the file descriptor then
41227 ** corruption if this locking mode is used in situations where multiple
41395 ** Return the sector size in bytes of the underlying block device for
41400 ** if two files are created in the same file-system directory (i.e.
41457 ** point to a single instance of this object. In other words, each
41473 ** in this structure.
41491 winShmNode *pNext; /* Next in list of all winShmNode objects */
41634 ** file are currently open, in this process or in other processes, then
41642 int nName; /* Size of zName in bytes */
41913 ** bytes in size.
41918 ** region has not been allocated (by any client, including one running in a
42209 ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
42212 ** value of *pp is undefined in this case.
42391 ** operating system wants filenames in. Space to hold the result
42432 ** The pointer returned in pzBuf must be freed via sqlite3_free().
42629 ** name in the following format:
42633 ** If not, return SQLITE_ERROR. The number 17 is used here in order to
42710 void *zConverted; /* Filename in OS encoding */
42711 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
42715 ** a temporary file. Use this buffer to store the file name in.
42982 ** will open a journal file shortly after it is created in order to do
43192 ** a legal UNC name, a volume relative path, or an absolute path name in the
43221 ** bytes in size.
43226 int nFull, /* Size of output buffer in bytes */
43476 int na; /* Size of a[] in bytes */
43569 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
43573 ** Find the current time (in Universal Coordinated Time). Write into *piNow
43574 ** the current time and date as a Julian Day number times 86_400_000. In
43576 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
43591 /* 2^32 - to avoid use of LL and warnings in gcc */
43621 ** Find the current time (in Universal Coordinated Time). Write the
43647 ** is zero if the error message fits in the buffer, or non-zero
43650 ** in the output buffer.
43823 ** The author disclaims copyright to this source code. In place of
43839 ** or all of the pages in a database can get journalled. In those cases,
43852 ** Bitvec object is the number of pages in the database file at the
43858 /* Size of the Bitvec structure in bytes. */
43871 /* Size, in bits, of the bitmap element. */
43873 /* Number of elements in a bitmap array. */
43875 /* Number of bits in the bitmap array. */
43878 /* Number of u32 values in hash table. */
43880 /* Maximum number of entries in hash table before
43885 ** (an arbitrary prime)in the hash function provided
44019 /* in hash, if not, try to find a spot for it */
44025 /* we didn't find it in the hash. h points to the first */
44142 ** 5 N S X Set N bits from S increment X in array only, not in bitvec
44147 ** Opcode 5 is used to deliberately induce a fault in order to
44237 ** The author disclaims copyright to this source code. In place of
44251 ** entry in the cache holds a single page of the database file. The
44260 ** PgHdr.pDirtyNext and pDirtyPrev. The list is maintained in LRU order
44262 ** PCache.pDirty points to the first (newest) element in the list and
44269 ** to either the oldest page in the pDirty/pDirtyTail list that has a
44275 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
44276 PgHdr *pSynced; /* Last synced page in dirty page list */
44280 int szPage; /* Size of every page in this cache */
44296 ** is displayed for many operations, resulting in a lot of output.
44361 ** If NEED_SYNC had been cleared in step 2, then it would not be reset
44362 ** in step 3, and page might be written into the database without first
44368 ** in that sector are marked NEED_SYNC even if they are still CLEAN, just
44369 ** in case they are later modified, since all pages in the same sector
44415 /* If there are now no dirty pages in the cache, set eCreate to 2.
44462 ** being used for an in-memory database, this function is a no-op.
44497 ** built-in default page cache is used instead of the application defined
44511 ** Return the size in bytes of a PCache object.
44517 ** has already been allocated and is passed in as the p pointer.
44525 ** structure in the pager.
44577 ** such an object is already in cache, or if a new one is created.
44578 ** This routine returns a NULL pointer if the object was not in cache
44585 ** is not already in the cache. If createFlag is 1, then a new page
44652 ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
44688 ** In the uncommon case where the page being fetched has not been
44691 ** requires extra stack manipulation that can be avoided in the common
44717 ** must be called after sqlite3PcacheFetch() in order to get a usable
44823 ** Make every page in the cache clean.
44901 if( ALWAYS(pPage1) ){ /* Page 1 is always available in cache, because
44928 ** Merge two lists of pages connected by pDirty and in pgno order.
44958 ** Sort the list of pages in accending order by pgno. Pages are
44962 ** Since there cannot be more than 2^31 distinct pages in a database,
44964 ** One extra bucket is added to catch overflow in case something
44986 /* To get here, there need to be 2^(N_SORT_BUCKET) elements in
45001 ** Return a list of all dirty pages in the cache, sorted by page number.
45029 ** Return the total number of pages in the cache.
45084 ** in the page-cache hierarchy.
45089 ** Return the number of dirty pages currently in the cache, as a percentage
45102 ** For all dirty pages currently in the cache, invoke the specified
45119 ** The author disclaims copyright to this source code. In place of
45160 ** fragmentation" in academic literature) of allocating a few bytes more
45209 ** in memory.
45214 u8 isPinned; /* Page in use, not on the LRU list */
45217 PgHdr1 *pNext; /* Next in hash table chain */
45219 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
45220 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
45228 ** This page cache implementation works in one of two modes:
45238 ** and is therefore often faster. Mode 2 requires a mutex in order to be
45255 ** open database file (including each in-memory database and each
45281 unsigned int nRecyclable; /* Number of pages in the LRU list */
45282 unsigned int nPage; /* Total number of pages in apHash */
45283 unsigned int nHash; /* Number of slots in apHash[] */
45290 ** Free slots in the allocator used to divide up the global page cache
45327 ** All code in this file should access the global structure above via the
45420 ** such buffer exists or there is no space left in it, this function falls
45424 ** in pcache1 need to be protected via mutex.
45443 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
45613 ** allocating a new page cache entry in order to avoid stressing
45697 ** (PCache1.apHash structure) that it is currently stored in.
45756 ** cache, then there is no point in scanning the entire hash table.
45805 ** PGroup in pcache1.grp is used for all page caches (mode-2).
45809 ** * Use a unified cache in single-threaded applications that have
45846 ** Note that the static mutex allocated in xInit does
45958 ** in the header of the pcache1Fetch() procedure.
46043 ** For a non-purgeable cache (a cache used as the storage for an in-memory
46054 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
46057 ** 3. If createFlag is 1, and the page is not already in the cache, then
46104 /* Step 2: If the page was found in the hash table, then return it.
46105 ** If the page was not in the hash table and createFlag is 0, abort.
46106 ** Otherwise (page not in hash and createFlag!=0) continue with
46240 ** Discard all unpinned pages in the cache with a page number equal to
46317 ** held by the pager system. Memory in use by any SQLite pager allocated
46378 ** The author disclaims copyright to this source code. In place of
46390 ** are inserted into the RowSet in an arbitrary order. Inserts
46395 ** elements of the RowSet in sorted order. Once this extraction
46408 ** TEST checks to see if an element is already in the RowSet. SMALLEST
46412 ** allocated in chunks so most INSERTs do no allocation. There is an
46418 ** in the batch number. In other words, if an INSERT occurs between
46429 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
46435 ** be possible, but the feature was not used, so it was removed in order
46453 ** Each entry in a RowSet is an instance of the following object.
46456 ** objects. In that alternative use, pRight points to the next entry
46457 ** in the list, pLeft points to the tree, and v is unused. The
46467 ** RowSetEntry objects are allocated in large chunks (instances of the
46478 ** A RowSet in an instance of the following structure.
46480 ** A typedef of this structure if found in sqliteInt.h.
46552 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
46609 ** assumed to each already be in sorted order.
46744 ** as deep as it needs to be in order to contain the entire list.
46856 /* Test to see if the iRowid value appears anywhere in the forest.
46879 ** The author disclaims copyright to this source code. In place of
46898 /************** Include wal.h in the middle of pager.c ***********************/
46903 ** The author disclaims copyright to this source code. In place of
46913 ** the implementation of each function in log.c for further details.
46965 ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
46988 ** position in the WAL */
46991 /* Move the write position of the WAL back to iFrame. Called in
47008 int *pnLog, /* OUT: Number of frames in WAL */
47009 int *pnCkpt /* OUT: Number of backfilled frames in WAL */
47013 ** number of frames in the WAL at the point of the last commit since
47038 ** stored in each frame (i.e. the db page-size when the WAL was created).
47050 /************** Continuing where we left off in pager.c **********************/
47073 ** (c) The page number is greater than the largest page that existed in
47086 ** both the content in the database when the rollback journal was written
47087 ** and the content in the database at the beginning of the current
47091 ** in length and are aligned on a page boundary.
47094 ** an integer multiple of the page size in length or are taken from the
47105 ** all queries. Note in particular the content of freelist leaf
47116 ** the beginning of the transaction. (In some VFSes, the xTruncate
47120 ** (9) Whenever the database file is modified, at least one bit in the range
47125 ** (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
47163 ** pager may be in any one of the seven states shown in the following
47201 ** The pager starts up in this state. Nothing is guaranteed in this
47211 ** In this state all the requirements for reading the database in
47213 ** was) in exclusive-locking mode, a user-level read transaction is
47214 ** open. The database size is known in this state.
47219 ** running in locking_mode=exclusive (including temp databases) remains in
47231 ** there is no hot-journal in the file-system.
47236 ** is first opened on the database. In WRITER_LOCKED state, all locks
47240 ** In rollback mode, a RESERVED or (if the transaction was opened with
47243 ** to in this state. If the transaction is committed or rolled back while
47244 ** in WRITER_LOCKED state, all that is required is to unlock the database
47247 ** IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
47252 ** * If the connection is open in rollback-mode, a RESERVED or greater
47254 ** * If the connection is open in WAL-mode, a WAL write transaction
47265 ** first modified by the upper layer. In rollback mode the journal file
47295 ** database file. In this state the transaction may be committed simply
47296 ** by finalizing the journal file. Once in WRITER_FINISHED state, it is
47310 ** SQLITE_IOERR_NOMEM) occurs at a point in the code that makes it
47311 ** difficult to be sure that the in-memory pager state (cache contents,
47314 ** Temporary pager files may enter the ERROR state, but in-memory pagers
47318 ** the contents of the page-cache may be left in an inconsistent state.
47330 ** page-cache and any other in-memory state at the same time. Everything
47338 ** 1. An error occurs while attempting a rollback. This happens in
47342 ** following a commit in function sqlite3PagerCommitPhaseTwo().
47345 ** database file in function pagerStress() in order to free up
47348 ** In other cases, the error is returned to the b-tree layer. The b-tree
47353 ** statement executed within a transaction. In this case, if the error
47355 ** automatically attempt a rollback, as it assumes that an error in a
47356 ** read-only statement cannot leave the pager in an internally inconsistent
47362 ** * The pager is not an in-memory pager.
47367 ** * A pager is never in WRITER_DBMOD or WRITER_FINISHED state if the
47368 ** connection is open in WAL mode. A WAL connection is always in one
47371 ** * Normally, a connection open in exclusive mode is never in PAGER_OPEN
47395 ** the operation was successful. In these circumstances pagerLockDb() and
47408 ** in the file-system that needs to be rolled back (as part of an OPEN->SHARED
47417 ** doesn't know it because of a previous error in xUnlock). If this happens
47419 ** transaction in another process, causing SQLite to read from the database
47423 ** database in the ERROR state, Pager.eLock is set to UNKNOWN_LOCK. It
47431 ** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in
47461 ** savepoint and statement transaction in the system. All such structures
47462 ** are stored in the Pager.aSavepoint[] array, which is allocated and
47474 i64 iOffset; /* Starting offset in main journal */
47476 Bitvec *pInSavepoint; /* Set of pages in this savepoint */
47477 Pgno nOrig; /* Original number of pages in file */
47478 Pgno iSubRec; /* Index of first record in sub-journal */
47505 ** For a temporary or in-memory database (neither of which require any
47511 ** In some (obscure) circumstances, this variable may also be set to
47528 ** This mechanism means that when running in exclusive mode, a connection
47539 ** the way in which the journal file is finalized after the transaction is
47540 ** committed or rolled back when running in "journal_mode=PERSIST" mode.
47545 ** running in "journal_mode=truncate" mode.
47561 ** to the file-system in order to free up memory).
47565 ** The SPILLFLAG_ROLLBACK case is done in a very obscure case that
47568 ** while it is being traversed by code in pager_playback(). The SPILLFLAG_OFF
47574 ** is larger than the database page-size in order to prevent a journal sync
47575 ** from happening in between the journalling of two pages on the same sector.
47580 ** is opened as an in-memory journal file. If false, then in-memory
47581 ** sub-journals are only used for in-memory pager files.
47588 ** Variable dbSize is set to the number of pages in the database file.
47589 ** It is valid in PAGER_READER and higher states (all states except for
47595 ** is not an integer multiple of the page-size, the value stored in
47597 ** Except, any file that is greater than 0 bytes in size is considered
47602 ** dbSize are modified in the cache, dbSize is updated accordingly.
47606 ** Variables dbOrigSize and dbFileSize are valid in states
47613 ** the file on disk in pages. It is set to a copy of dbSize when the
47623 ** dbFileSize is not used when rolling back a transaction. In this case
47625 ** a call to xFilesize() that is not strictly required). In either case,
47642 ** The Pager.errCode variable is only ever used in PAGER_ERROR state. It
47643 ** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
47659 u8 noLock; /* Do not lock (except in WAL mode) */
47665 ** routine operation. Class members not in this block are either fixed
47677 u8 subjInMemory; /* True to use in-memory sub-journals */
47680 Pgno dbSize; /* Number of pages in the database */
47682 Pgno dbFileSize; /* Number of pages in the database file */
47688 Bitvec *pInJournal; /* One bit for each page in the database file */
47692 i64 journalOff; /* Current write offset in the journal file */
47696 int nSavepoint; /* Number of elements in aSavepoint[] */
47707 u16 nExtra; /* Add this many bytes to each in-memory page */
47711 int pageSize; /* Number of bytes in a page */
47749 ** testing purposes only. These variables do not exist in
47769 ** written, semi-random garbage data might appear in the journal
47772 ** sanity checking data is an attempt to discover the garbage in the
47778 ** This cksum is initialized to a 32-bit random value that appears in the
47781 ** data that was once in other files that have now been deleted. If the
47791 ** The size of the of each page record in the journal is given by
47803 ** The macro MEMDB is true if we are dealing with an in-memory database.
47872 ** This function runs many asserts to try to find inconsistencies in
47901 /* Check that MEMDB implies noSync. And an in-memory journal. Since
47902 ** this means an in-memory pager performs no IO at all, it cannot encounter
47904 ** a journal file. (although the in-memory journal implementation may
47906 ** is therefore not possible for an in-memory pager to enter the ERROR
47995 ** in ERROR state. Otherwise the pager should have already dropped
48009 ** Return a pointer to a human readable string in a static buffer
48012 ** to "print *pPager" in gdb:
48091 ** * The bit corresponding to the page-number is not set in
48110 ** Return true if the page is already in the journal file.
48119 ** that is read in *pRes. Return SQLITE_OK if everything worked, or an
48134 ** Write a 32-bit integer into a string buffer in big-endian byte order.
48214 ** returned in this case.
48306 ** name in the journal is longer than nMaster bytes (including a
48308 ** were present in the journal.
48323 u32 len; /* Length in bytes of master journal name */
48324 i64 szJ; /* Total size in bytes of journal file pJrnl */
48362 ** following the value in pPager->journalOff, assuming a sector
48394 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
48395 ** zero the 28-byte header at the start of the journal file. In either case,
48396 ** if the pager is not in no-sync mode, sync the journal file immediately
48401 ** journal file in bytes is larger than this value, then truncate the
48450 ** - 4 bytes: Number of records in journal, or -1 no-sync mode is on.
48487 ** if in full-sync mode), the zero is overwritten with the true number
48497 ** * When the pager is in no-sync mode. Corruption can follow a
48498 ** power failure in this case anyway.
48532 /* In theory, it is only necessary to write the 28 bytes that the
48535 ** record is written to the following sector (leaving a gap in the file
48536 ** that will be implicitly filled in by the OS).
48544 ** The loop is required here in case the sector-size is larger than the
48546 ** bytes in size, more than one call to sqlite3OsWrite() may be required
48561 ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
48562 ** file. The current location in the journal file is given by
48568 ** database before the transaction began, in pages. Also, pPager->cksumInit
48570 ** in this case.
48579 i64 journalSize, /* Size of the open journal file in bytes */
48599 /* Read in the first 8 bytes of the journal header. If they do not match
48637 ** journal header to zero. In this case, assume that the Pager.pageSize
48645 ** are within range. To be 'in range', both values need to be a power
48653 /* If the either the page-size or sector-size in the journal-header is
48655 ** crashed before the header was synced. In this case stop reading
48685 ** thing written to a journal file. If the pager is in full-sync mode, the
48690 ** + N bytes: Master journal filename in utf-8.
48691 ** + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
48695 ** The master journal page checksum is the sum of the bytes in the master
48704 i64 iHdrOff; /* Offset of header in journal file */
48720 /* Calculate the length in bytes and the checksum of zMaster */
48725 /* If in full-sync mode, advance to the next disk sector before writing
48726 ** the master journal name. This is in case the previous page written to
48748 /* If the pager is in peristent-journal mode, then the physical
48755 ** Easiest thing to do in this scenario is to truncate the journal
48767 ** Discard the entire contents of the in-memory page-cache.
48784 ** Free all structures in the Pager.aSavepoint[] array and set both
48786 ** if it is open and the pager is not in exclusive mode.
48803 ** Set the bit number pgno in the PagerSavepoint.pInSavepoint
48823 ** This function is a no-op if the pager is in exclusive mode and not
48824 ** in the ERROR state. Otherwise, it switches the pager to PAGER_OPEN
48827 ** If the pager is not in exclusive-access mode, the database file is
48832 ** If the pager is in ERROR state when this function is called, the
48834 ** the OPEN state. Regardless of whether the pager is in exclusive-mode
48835 ** or not, any journal file left in the file-system will be treated
48875 /* If the pager is in the ERROR state and the call to unlock the database
48887 ** code is cleared and the cache reset in the block below.
48896 ** it can safely move back to PAGER_OPEN state. This happens in both
48927 ** is stored in Pager.errCode. While the pager remains in the ERROR state,
48968 ** when the number of dirty pages in memory exceeds 25% of the total
48985 ** This routine is never called in PAGER_ERROR state. If it is called
48986 ** in PAGER_NONE or PAGER_SHARED state and the lock held is less
48995 ** depends on whether or not the pager is running in exclusive mode and
49000 ** in-memory journal.
49003 ** Journal file is truncated to zero bytes in size.
49007 ** the first journal header in the file, and hence the entire journal
49013 ** If the pager is running in exclusive mode, this method of finalizing
49015 ** DELETE and the pager is in exclusive mode, the method described under
49019 ** If running in non-exclusive rollback mode, the lock on the file is
49026 ** tries to unlock the database file if not in exclusive mode. If the
49087 ** a hot-journal was just rolled back. In this case the journal
49089 ** the database file, it will do so using an in-memory journal.
49128 /* Drop the WAL write-lock, if any. Also, if the connection was in
49135 /* This branch is taken when committing a transaction in rollback-journal
49168 ** call to pager_unlock() will discard all in-memory pages, unlock
49170 ** means that there is a hot-journal left in the file-system, the next
49204 ** Changing the formula used to compute this checksum results in an
49240 ** Make sure the number of reserved bits is the same in the destination
49241 ** pager as it is in the source. This comes up when a VACUUM changes the
49256 ** value is increased to the start of the next page in the journal.
49276 ** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
49297 PgHdr *pPg; /* An existing page in the cache */
49298 Pgno pgno; /* The page number of a page in journal */
49305 ** the codec. It is false for pure in-memory journals. */
49321 ** is in state OPEN and holds an EXCLUSIVE lock. Hot-journal rollback
49373 /* If the pager is in CACHEMOD state, then there must be a copy of this
49374 ** page in the pager cache. In this case just update the pager cache,
49375 ** not the database file. The page is left marked dirty in this case.
49377 ** An exception to the above rule: If the database is in no-sync mode
49379 ** not be in the pager cache. Later: if a malloc() or IO error occurs
49380 ** during a Movepage() call, then the page may not be in the cache
49381 ** either. So the condition described in the above paragraph is not
49384 ** If in WRITER_DBMOD, WRITER_FINISHED or OPEN state, then we update the
49386 ** not dirty. Since this code is only executed in PAGER_OPEN state for
49388 ** if the pager is in OPEN state.
49396 ** journal. Otherwise, a power loss might leave modified data in the
49397 ** database file without an entry in the rollback journal that can
49401 ** in the main journal either because the page is not in cache or else
49435 ** is if the data was just read from an in-memory sub-journal. In that
49462 ** the database and the page is not in-memory, there is a potential
49468 ** obscure. When running in synchronous mode, this can only happen
49472 ** The solution is to add an in-memory page to the cache containing
49487 /* No page should ever be explicitly rolled back that is in use, except
49488 ** for page 1 which is held in use in order to keep the lock on the
49490 ** of an internal error resulting in an automatic call to
49587 ** sufficient space (in zMasterPtr) to hold the names of master
49653 ** file in the file-system. This only happens when committing a transaction,
49656 ** If the main database file is not open, or the pager is not in either
49735 ** might change if a crash occurs while writing to a single byte in
49749 ** may not have been opened yet, in which case the OsSectorSize()
49759 ** the state it was in before we started making changes.
49765 ** in the journal. If this value is 0xffffffff, then compute the
49772 ** is this many bytes in size.
49781 ** Each entry in the journal is an instance of the 8th item.
49784 ** valid page entries in the journal. In most cases, you can compute the
49788 ** the extra entries had not yet made it safely to disk. In such a case,
49790 ** that reason, we always use the nRec value in the header.
49795 ** in this case. But for things like temporary table (which will be
49816 i64 szJ; /* Size of the journal file in bytes */
49817 u32 nRec; /* Number of Records in the journal */
49819 Pgno mxPg = 0; /* Size of the original file in pages */
49826 /* Figure out how many records are in the journal. Abort early if
49864 ** not enough bytes left in the journal file for a complete header, or
49877 ** working in no-sync mode. This means that the rest of the journal
49887 ** process and if this is the final header in the journal, then it means
49895 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
49934 ** not completely written and synced prior to a crash. In that
49935 ** case, the database should have never been written in the
49954 /* Following a rollback, the database file should be back in its original
49968 ** modification may just have been reverted. If this happens in exclusive
49971 ** problems for other processes at some point in the future. So, just
49972 ** in case this has happened, clear the changeCountDone flag now.
50050 ** zero or the size of the database in page. Bytes 32..35 and 35..39
50077 ** Update the value of the change-counter at offsets 24 and 92 in
50091 /* Also store the SQLite version number in bytes 96..99 and in
50105 ** If page iPg is present in the cache, and has no outstanding references,
50154 /* For all pages in the cache that are currently dirty or have already
50189 int nList; /* Number of pages in pList */
50195 /* Verify that the page list is in accending order */
50203 /* If a WAL transaction is being committed, there is no point in writing
50245 ** makes a snapshot of the database at the current point in time and preserves
50246 ** that snapshot for use by the reader in spite of concurrently changes by
50257 ** transaction in locking_mode=EXCLUSIVE. So call it now. If we
50258 ** are in locking_mode=NORMAL and EndRead() was previously called,
50276 ** in pages (assuming the page size currently stored in Pager.pageSize).
50279 ** in pages is stored in *pnPage. Otherwise, an error code (perhaps
50297 /* If the number of pages in the database is not available from the
50303 i64 n = 0; /* Size of db file in bytes */
50311 /* If the current number of pages in the file is greater than the
50330 ** in WAL mode. If the database is empty or if no *-wal file exists and
50383 ** performed in the order specified:
50399 ** corresponding bit is set in a bitvec structure (variable pDone in the
50401 ** rolled back the first time it is encountered in either journal.
50404 ** journal file. There is no need for a bitvec in this case.
50406 ** In either case, before playback commences the Pager.dbSize variable
50439 in
50448 ** There might be records in the main journal that have a page number
50478 ** test is related to ticket #2565. See the discussion in the
50494 ** previously rolled back out of the main journal (and are hence in pDone)
50520 ** Change the maximum number of in-memory pages that are allowed
50528 ** Change the maximum number of in-memory pages that are allowed
50567 ** Adjust settings of the pager to those specified in the pgFlags parameter.
50569 ** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness
50581 ** in a state which would cause damage to the database
50586 ** of the journal header - being written in between the two
50601 ** an ordinary commit in NORMAL mode with WAL. FULL means that the WAL
50602 ** file is synced following each commit operation, in addition to the
50738 ** is passed in *pPageSize.
50740 ** If the pager is in the error state when this function is called, it
50751 ** * the database is either not an in-memory database or it is
50752 ** an in-memory database that currently consists of zero pages.
50759 ** In all other cases, SQLITE_OK is returned.
50762 ** conditions above is not true, the pager was in error state when this
50773 ** At one point this function returned an error if the pager was in
50852 ** errors in places where we do not care about errors.
50878 ** opened on a file less than N bytes in size, the output buffer is
50910 ** the pager. It returns the total number of pages in the database.
50912 ** However, if the file is between 1 and <page-size> bytes in size, then
50957 ** following is true for all dirty pages currently in the page-cache:
50960 ** current database image, in pages, OR
50971 ** content of the page. However, since this content is not present in either
50990 ** Truncate the in-memory database file image to nPage pages. This
51007 ** if one or more savepoints are open, present in the savepoint
51108 ** Free all PgHdr objects stored in the Pager.pMmapFreelist list.
51123 ** If a transaction was in progress when this routine is called, that
51127 ** result in a coredump.
51131 ** a hot journal may be left in the filesystem but no error is returned
51208 ** Sync the journal. In other words, make sure all the pages that have
51210 ** disk and can be restored in the event of a hot-journal rollback.
51216 ** * If the journal file is an in-memory journal file, no action need
51222 ** been written following it. If the pager is operating in full-sync
51228 ** Or, in pseudo-code:
51230 ** if( NOT <in-memory journal> ){
51239 ** page currently held in memory before returning SQLITE_OK. If an IO
51262 ** that wrote to this database was operating in persistent-journal
51264 ** than Pager.journalOff bytes. If the next thing in the journal
51300 /* Write the nRec value into the journal file header. If in
51306 ** SAFE_APPEND property. Because in this case it is not possible
51343 /* Unless the pager is in noSync mode, the journal file was just
51354 ** The argument is the first in a linked list of dirty pages connected
51356 ** in-memory pages in the list to the database file. The argument may
51357 ** be NULL, representing an empty list. In this case this function is
51370 ** the pages are written out to the database file in list order. Writing
51378 ** in Pager.dbFileVers[] is updated to match the new value stored in
51388 /* This function is only called for rollback pagers in WRITER_DBMOD state. */
51419 /* If there are dirty pages in the page cache with page numbers greater
51441 ** the value now stored in the database file. If writing this
51495 ** If successful, set the bit corresponding to pPg->pgno in the bitvecs
51500 ** SQLITE_NOMEM if a malloc fails while setting a bit in a savepoint
51556 ** (cast as a void*). The pager is always 'purgeable' (not an in-memory
51588 ** Spilling is also prohibited when in an error state since that could
51589 ** lead to database corruption. In the current implementation it
51591 ** while in the error state, hence it is impossible for this routine to
51592 ** be called in the error state. Nevertheless, we include a NEVER()
51667 ** in *ppPager. The pager should eventually be freed by passing it
51674 ** all information is held in cache. It is never written to disk.
51675 ** This can be used to implement an in-memory database.
51701 int nExtra, /* Extra bytes append to each in-memory page */
51709 int tempFile = 0; /* True for temp files (incl. in-memory files) */
51710 int memDb = 0; /* True if this is an in-memory file */
51714 int nPathname = 0; /* Number of bytes in zPathname */
51725 /* Set the output variable to NULL in case an error occurs. */
51740 /* Compute and store the full pathname in an allocated buffer pointed
51764 ** bytes in length. This means the database cannot be opened,
51778 ** file name. The layout in memory is as follows:
51812 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
51841 ** choose a default page size in case we have to create the
51883 ** In this case we accept the default page size and delay actually
51886 ** This branch is also run for an in-memory database. An in-memory
51888 ** disk and uses an in-memory rollback journal.
51895 pPager->eLock = EXCLUSIVE_LOCK; /* Pretend we are in EXCLUSIVE mode */
52013 ** PAGER_SHARED state. It tests if there is a hot journal present in
52018 ** * The journal file exists in the file system, and
52020 ** * The database file itself is greater than 0 bytes in size, and
52025 ** database with the same name. In this case the journal file is
52031 ** does not exist, then the journal file is not really hot. In this
52068 ** in fact there is none. This results in a false-positive which will
52073 Pgno nPage; /* Number of pages in database file */
52078 /* If the database is zero pages in size, that means that either (1) the
52082 ** In either case, the journal file can be deleted. However, take care
52115 /* If we cannot open the rollback journal file in order to see if
52117 ** it might be due to the race condition described above and in
52143 ** 1) If the pager is currently in PAGER_OPEN state (no lock held
52152 ** 2) If the pager is running in exclusive-mode, and there are currently
52153 ** no outstanding references to any pages, and is in the error state,
52167 ** be OPEN or READER. READER is only possible if the pager is or was in
52210 ** this point in the code and fail to obtain its own EXCLUSIVE lock
52213 ** Unless the pager is in locking_mode=exclusive mode, the lock is
52223 ** in exclusive-access mode the file descriptor will be kept open
52225 ** is usually required to finalize the journal in journal_mode=persist
52229 ** other connection managed to get in and roll it back before
52231 ** may mean that the pager was in the error-state when this
52279 ** In order to get pager_unlock() to do this, set Pager.eState to
52281 ** to ERROR state in the state diagram at the top of this file,
52285 ** to be in ERROR state when there are zero outstanding page
52302 ** occurring on the very first access to a file, in order to save a
52309 ** a codec is in use.
52337 ** In this case there may exist a Pager.pMap mapping that appears
52346 /* If there is a WAL file in the file-system, open this database in WAL
52380 ** Except, in locking_mode=EXCLUSIVE when there is nothing to in
52399 ** getPageError() -- Used if the pager is in an error state
52402 ** If the requested page is already in the cache, it is returned.
52404 ** read from the database file. In some cases, the pcache module may
52410 ** already in the cache when this function is called, then the extra
52415 ** requested page is not already stored in the cache, then no
52416 ** actual disk read occurs. In this case the memory image of the
52420 ** the contents of the page. This occurs in two scenarios:
52430 ** to pgno in Pager.pInJournal (bitvec of pages already written to the
52433 ** point in the future, using a call to sqlite3PagerWrite(), its contents
52436 ** The acquisition might fail for several reasons. In all cases,
52440 ** to find a page in the in-memory cache first. If the page is not already
52441 ** in memory, this routine goes to disk to read it in whereas Lookup()
52481 /* In this case the pcache already contains an initialized copy of
52508 /* Failure to set the bits in the InJournal bit-vectors is benign.
52512 ** a bit in a bit vector.
52567 ** temporary or in-memory database. */
52579 ** test in the previous statement, and avoid testing pgno==0 in the
52652 ** Acquire a page if it is already in the in-memory cache. Do
52654 ** or 0 if the page is not in cache.
52658 ** in the page if the page is not already in cache. This routine
52659 ** returns NULL if the page is not in cache or if a disk I/O error
52707 ** If the journal file is already open (as it may be in exclusive mode),
52726 /* If already in the error state, this function is a no-op. But on
52727 ** the other hand, this routine is never called if we are already in
52800 ** within this transaction will be opened as an in-memory file. This
52802 ** running in exclusive mode) or if the transaction does not require a
52804 ** sub-journal is implemented in-memory if pPager is an in-memory database,
52852 ** This is because in those states the code to roll back savepoint
52854 ** file as well as into the page cache. Which would be incorrect in
52893 ** page in the block above, set the need-sync flag for the page.
52894 ** Otherwise, when the transaction is rolled back, the logic in
52896 ** in the database file. And if an IO error occurs while doing so,
52929 ** one of the journals, the corresponding bit is set in the
52939 ** It is never called in the ERROR state.
52956 ** an error might occur and the pager would end up in WRITER_LOCKED state
52957 ** with pages marked as dirty in the cache.
52969 /* If a rollback journal is in use, them make sure the page that is about
52970 ** to change is in the rollback journal, or if the page is a new page off
53000 /* If the statement journal is open and the page is not in it,
53018 ** a sector need to be journalled in case of a power loss in the middle of
53021 ** Usually, the sector size is less than or equal to the page size, in which
53022 ** case pages can be individually written. This routine only runs in the
53027 Pgno nPageCount; /* Total number of pages in database file */
53113 ** fit on a single disk sector. In this case all co-resident pages
53138 ** Return TRUE if the page given in the argument was previously passed
53139 ** to sqlite3PagerWrite(). In other words, return TRUE if it is ok
53163 ** have been dirty at the start of the transaction. In that case, if
53165 ** to be written out to disk so that it may be read back in if the
53193 ** page data. In this case the file will be updated when the current
53197 ** with the SQLITE_ENABLE_ATOMIC_WRITE macro defined. In this case,
53211 ** atomic-write optimization is enabled in this build, then isDirect
53217 ** 'isDirect' below, as well as the block enclosed in the
53238 ** operating in direct-mode, make page 1 writable. When not in
53239 ** direct mode, page 1 is always held in cache and hence the PagerGet()
53250 /* If running in direct mode, write the contents of page 1 to the file. */
53279 ** Sync the database file to disk. This is a no-op for in-memory databases
53301 ** This function may only be called while a write-transaction is active in
53302 ** rollback. If the connection is in WAL mode, this call is a no-op.
53307 ** successful, or the connection is in WAL mode, SQLITE_OK is returned.
53351 ** journal file in this case.
53382 /* If this is an in-memory db, or no pages have been written to, or this
53384 ** backup in progress needs to be restarted. */
53429 ** * Exactly one page has been modified and store in the journal file.
53433 ** counter in 'indirect-mode'. If the optimization is compiled in but
53436 ** pager_incr_changecounter() to update the change-counter in indirect
53441 ** in 'direct' mode. In this case the journal file will never be
53456 ** following call will modify the in-memory representation of page 1
53493 ** journal requires a sync here. However, in locking_mode=exclusive
53495 ** not the case. In this case it is likely enough that the redundant
53502 /* The pager is now in DBMOD state. But regardless of what happens
53527 ** last page in the db image moved to the free-list. In this case the
53556 ** synced to disk. The journal file still exists in the file-system
53572 ** But if (due to a coding error elsewhere in the system) it does get
53583 ** this transaction, the pager is running in exclusive-mode and is
53590 ** header. Since the pager is in exclusive mode, there is no need
53614 ** If the pager is already in PAGER_ERROR state when this function is called,
53615 ** it returns Pager.errCode immediately. No work is performed in this case.
53617 ** Otherwise, in rollback mode, this function performs two functions:
53620 ** in-memory cache pages to the state they were in when the transaction
53624 ** rollback at any point in the future.
53629 ** In WAL mode, all cache-entries containing data modified within the
53638 /* PagerRollback() is a no-op if called in READER or OPEN state. If
53639 ** the pager is already in the ERROR state, the rollback is not
53682 ** if the database is (in theory) writable.
53762 ** Return true if this is an in-memory or temp-file backed pager.
53789 ** if the allocation fails. Otherwise, zero the new portion in case a
53790 ** malloc failure occurs while populating it in the for(...) loop below.
53857 ** In any case, all savepoints with an index greater than iSavepoint
53880 ** operation. Store this value in nNew. Then free resources associated
53890 ** the sub-journal to zero bytes in size. */
53893 /* Only truncate if it is an in-memory sub-journal. */
53903 ** not yet been opened. In this case there have been no changes to
53914 ** back journal_mode=off, put the pager in the error state. This way,
53934 ** Except, if the pager is in-memory only, then return an empty string if
53938 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
53939 ** participate in shared-cache.
54026 ** Move the page pPg to location pgno in the file.
54030 ** in cache. If the page previously located at pgno is not already
54031 ** in the rollback journal, it is not put there by by this routine.
54034 ** meta-data associated with pPg (i.e. data stored in the nExtra bytes
54044 ** is being committed. In this case, it is guaranteed that the database page
54062 /* In order to be able to rollback, an in-memory database must journal
54076 ** <journal page X, then modify it in memory>
54100 ** be written to, store pPg->pgno in local variable needSyncPgno.
54124 /* Do not discard pages from an in-memory database since we might
54136 /* For an in-memory database, make sure the original page continues
54137 ** to exist, in case the transaction needs to roll back. Use pPgOld
54148 ** Currently, no such page exists in the page-cache and the
54154 ** to a malloc() or IO failure), clear the bit in the pInJournal[]
54155 ** array. Otherwise, if the page is loaded and written again in
54157 ** it is synced into the journal file. This way, it may end up in
54242 ** * An in-memory database can only have its journal_mode set to _OFF
54273 /* Do allow the journalmode of an in-memory database to be set to
54290 ** mode except WAL, unless the pager is in locking_mode=exclusive mode,
54303 /* In this case we would like to delete the journal file. If it is
54309 ** while it is in use by some other client.
54352 ** Return TRUE if the pager is in a state where it is OK to change the
54379 ** in backup.c maintains the content of this variable. This module
54389 ** Unless this is an in-memory or temporary database, clear the pager cache.
54410 int *pnLog, /* OUT: Final number of frames in log */
54458 ** Call sqlite3WalOpen() to open the WAL handle. If the pager is in
54461 ** in. Otherwise, use the normal shared-memory.
54469 /* If the pager is already in exclusive-mode, the WAL module will use
54498 ** file (not a temp file or an in-memory database), and the WAL file
54502 ** not modified in either case.
54504 ** If the pager is open on a temp-file (or in-memory database), or if
54552 /* If the log file is not already open, but does exist in the file-system,
54632 ** the pager is in WAL mode and the WAL file currently contains one or more
54633 ** frames, return the size in bytes of the page images stored within the
54650 ** The author disclaims copyright to this source code. In place of
54659 ** This file contains the implementation of a write-ahead log (WAL) used in
54670 ** transferred back into the database file in an operation called a
54673 ** A single WAL file can be used multiple times. In other words, the
54680 ** The WAL header is 32 bytes in size and consists of the following eight
54698 ** 4: For commit records, the size of the database image in pages
54708 ** (1) The salt-1 and salt-2 values in the frame-header match
54709 ** salt values in the wal-header
54711 ** (2) The checksum values in the final 8 bytes of the frame-header
54717 ** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
54719 ** The checksum values are always stored in the frame header in a
54731 ** in reverse order (the largest fibonacci weight occurs on the first element
54742 ** value is randomized. This prevents old and new frames in the WAL from
54757 ** valid frame in the WAL. The reader uses this recorded "mxFrame" value
54761 ** of the database from a single point in time. This technique allows
54765 ** The reader algorithm in the previous paragraphs works correctly, but
54782 ** be) reconstructed from the original WAL file. In fact, the VFS is required
54787 ** as big endian, the wal-index can store multi-byte values in the native
54792 ** last frame in the wal before frame M for page P in the WAL, or return
54793 ** NULL if there are no frames for page P in the WAL prior to M.
54799 ** in the mxFrame field.
54805 ** first index block are the same size as all other index blocks in the
54812 ** for the first index block) 32-bit page numbers. The first entry in the
54814 ** first frame in the WAL file. The first entry in the second index block
54815 ** in the WAL file corresponds to the (HASHTABLE_NPAGE_ONE+1)th frame in
54818 ** The last index block in a wal-index usually contains less than the full
54832 ** HASHTABLE_NSLOT = 2*HASHTABLE_NPAGE, and there is one entry in the
54833 ** hash table for each page number in the mapping section, so the hash
54836 ** 1-based index of an entry in the mapping section of the same
54837 ** index block. Let K be the 1-based index of the largest entry in
54843 ** To look for page P in the hash table, first compute a hash iKey on
54856 ** no hash slot such that aHash[i]==p) then page P is not in the
54863 ** average, only two or three slots in each index block need to be
54864 ** examined in order to either find the last entry for page P, or to
54865 ** establish that no such entry exists in the block. Each index block
54868 ** comparisons (on average) suffice to either locate a frame in the
54869 ** WAL or to establish that the frame does not exist in the WAL. This
54872 ** Note that entries are added in order of increasing K. Hence, one
54877 ** the correct result. There may be entries in the hash table with
54879 ** slots in the hash table and so the first reader will get an answer as
54881 ** in the first place - which is what reader one wants. Meanwhile, the
54908 ** values in the wal-header are correct and (b) the version field is not
54941 ** The actual header in the wal-index consists of two copies of this
54949 ** added in 3.7.1 when support for 64K pages was added.
54956 u8 bigEndCksum; /* True if checksums in WAL are big-endian */
54957 u16 szPage; /* Database page size in bytes. 1==64K */
54958 u32 mxFrame; /* Index of last valid frame in the WAL */
54959 u32 nPage; /* Size of database in pages */
54960 u32 aFrameCksum[2]; /* Checksum of last frame in log */
54966 ** A copy of the following object occurs in the wal-index immediately
54970 ** nBackfill is the number of frames in the WAL that have been written
54988 ** There is one entry in aReadMark[] for each reader lock. If a reader
54989 ** holds read-lock K, then the value in aReadMark[K] is no greater than
55004 ** in use (that is, every aReadMark[j] for which there is a corresponding
55009 ** in the WAL has been backfilled into the database) then new readers
55017 ** (in other words, if there are no WAL_READ_LOCK(i) where i>0) then
55021 ** We assume that 32-bit loads are atomic and so no locks are needed in
55042 /* Size of header before each frame in wal */
55050 ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
55051 ** big-endian format in the first 4 bytes of a WAL file.
55061 ** Return the offset of frame iFrame in the write-ahead log file,
55081 volatile u32 **apWiData; /* Pointer to wal-index content in memory */
55085 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
55086 u8 writeLock; /* True if in a write transaction */
55096 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
55127 ** all frames in the WAL in database page order. Where two or more frames
55129 ** frame most recently written to the WAL (in other words, the frame with
55142 int nSegment; /* Number of entries in aSegment[] */
55144 int iNext; /* Next slot in aIndex[] not yet returned */
55145 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
55147 int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
55149 } aSegment[1]; /* One for every 32KB page in the wal-index */
55153 ** Define the parameters of the hash tables in the wal-index file. There
55154 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
55165 ** The block of page numbers associated with the first hash-table in a
55225 ** Return a pointer to the WalCkptInfo structure in the wal-index.
55233 ** Return a pointer to the WalIndexHdr structure in the wal-index.
55253 ** Generate or extend an 8 byte checksum based on the data in
55264 int nByte, /* Bytes of content in a[]. Must be a multiple of 8. */
55306 ** Write the header information in pWal->hdr into the wal-index.
55329 ** 4: For commit records, the size of the database image in pages
55363 ** Check to see if the frame with header in aFrame[] and content
55364 ** in aData[] is valid. If it is a valid frame, fill *piPage and
55379 /* A frame is only valid if the salt values in the frame-header
55380 ** match the salt values in the wal-header.
55395 ** and the frame-data matches the checksum in the last 8
55444 ** In locking_mode=EXCLUSIVE, all of these routines become no-ops.
55483 ** the hash to the next value in the event of a collision.
55500 ** in the wal-index file. Set *piZero to one less than the frame
55502 ** slot in the hash table is set to N, it refers to frame number
55503 ** (*piZero+N) in the log.
55558 ** Return the page number associated with frame iFrame in this WAL.
55585 in aPgno[] */
55614 /* Zero the entries in the aPgno array that correspond to frames with
55621 /* Verify that the every entry in the mapping region is still reachable
55639 ** Set an entry in the wal-index that will map database page number
55669 /* If the entry in aPgno[] is already set, then the previous writer
55670 ** must have exited unexpectedly in the middle of a transaction (after
55689 /* Verify that the number of entries in the hash table exactly equals
55690 ** the number of entries in the mapping region.
55694 int nEntry = 0; /* Number of entries in the hash table */
55699 /* Verify that the every entry in the mapping region is reachable
55738 /* Obtain an exclusive lock on all byte in the locking range not already
55766 int szFrame; /* Number of bytes in buffer aFrame[] */
55775 /* Read in the WAL header. */
55929 int bNoShm, /* True to run in heap-memory mode */
55940 /* In the amalgamation, the os_unix.c and os_win.c source files come before
55942 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
56004 ** Find the smallest page number out of all pages held in the WAL that
56010 ** Return 0 on success. If there are no pages in the WAL with a page
56054 ** of indices such that the aRight[] contains every index that appears in
56067 const u32 *aContent, /* Pages in wal - keys for the sort */
56068 ht_slot *aLeft, /* IN: Left hand input list */
56069 int nLeft, /* IN: Elements in array *paLeft */
56070 ht_slot **paRight, /* IN/OUT: Right hand input list */
56071 int *pnRight, /* IN/OUT: Elements in *paRight */
56074 int iLeft = 0; /* Current index in aLeft */
56075 int iRight = 0; /* Current index in aRight */
56076 int iOut = 0; /* Current index in output buffer */
56107 ** Sort the elements in list aList using aContent[] as the sort key.
56111 ** The aList[] entries are indices into aContent[]. The values in
56124 const u32 *aContent, /* Pages in wal */
56126 ht_slot *aList, /* IN/OUT: List to sort */
56127 int *pnList /* IN/OUT: Number of elements in aList[] */
56130 int nList; /* Number of elements in aList */
56135 int nMerge = 0; /* Number of elements in list aMerge */
56192 ** pages in the WAL in ascending order. The caller must hold the checkpoint
56205 u32 iLast; /* Last frame in log */
56212 ** it only runs if there is actually content in the log (mxFrame>0).
56247 int nEntry; /* Number of entries in this segment */
56300 ** Return the page-size in bytes used by the database.
56319 ** The value of parameter salt1 is used as the aSalt[1] value in the
56341 ** in response to an sqlite3_wal_checkpoint() request or the equivalent.
56347 ** All I/O barrier operations (a.k.a fsyncs) occur in this routine when
56348 ** SQLite is in WAL-mode in synchronous=NORMAL. That means that if
56354 ** in the WAL and can be recovered following a power-loss or hard reset.
56358 ** it safe to delete the WAL since the new content will persist in the
56367 ** checkpoint is running (in any other thread or process) at the same
56403 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
56406 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
56408 ** overwrite database pages that are in use by active readers and thus
56415 ** as some other thread may be in the process of updating the value
56531 ** In theory, it might be safe to do this without updating the
56532 ** wal-index header in shared memory, as all subsequent reader or
56535 ** as it would leave the system in a state where the contents of
56553 ** If the WAL file is currently larger than nMax bytes in size, truncate
56587 ** the database. In this case checkpoint the database and unlink both
56608 ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
56613 ** completed and fsynced (rc==SQLITE_OK) and we are in persistent
56641 ** The wal-index is in shared memory. Another thread or process might
56643 ** read it, which might result in inconsistency. A dirty read is detected
56657 WalIndexHdr volatile *aHdr; /* Header in shared memory */
56663 ** same area of shared memory on a different CPU in a SMP,
56668 ** When reading, read [0] first then [1]. Writes are in the reverse order.
56705 ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
56810 ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1)
56825 ** update values of the aReadMark[] array in the header, but if it does
56830 volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */
56846 ** during the few nanoseconds that it is holding the lock. In that case,
56857 int nDelay = 1; /* Pause time in microseconds */
56869 /* If there is not a recovery running in another thread or process
56881 ** modules may return SQLITE_BUSY due to a race condition in the
56923 ** it finished. Leaving a corrupt image in the database file.
56981 ** value in the aReadMark[] array or the contents of the wal-index
56988 ** that occur later in the log than pWal->hdr.mxFrame may have been
56995 ** since it was read, set Wal.minFrame to the first frame in the wal
57001 ** nBackfill and checking that the wal-header in shared-memory still
57002 ** matches the one cached in pWal->hdr, it is guaranteed that the
57004 ** header newer than that cached in pWal->hdr. If it were, that could
57008 ** page later in the wal file. But if version B happens to like past
57056 i64 szDb; /* Size of db file in bytes */
57070 u32 pgno; /* Page number in db file */
57111 ** instant in time. The current thread will continue to use this snapshot.
57150 ** In this case, the salt will have changed.
57164 ** snapshot X, where X is later in the wal file than pSnapshot, but
57220 ** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
57232 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
57241 ** in this case as an optimization. Likewise, if pWal->readLock==0,
57254 ** This code might run concurrently to the code in walIndexAppend()
57264 ** For the reasons above, the if(...) condition featured in the inner
57325 ** (which is nOut bytes in size). Return SQLITE_OK if successful, or an
57331 int nOut, /* Size of buffer pOut in bytes */
57346 ** Return the size of the database in pages (or zero, if unknown).
57365 ** returns SQLITE_BUSY in that case and no write transaction is started.
57436 ** was in before the client began writing to the database.
57445 ** is passed as the second argument is (a) in the cache and
57467 ** point in the event of a savepoint rollback (via WalSavepointUndo()).
57479 ** the values in the aWalData[] array. aWalData must point to an array
57532 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
57537 ** In theory it would be Ok to update the cache of the header only
57579 ** In other words, if iSyncPoint is in between iOffset and iOffset+iAmt,
57616 u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-header in */
57642 u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-headers in */
57689 int szPage, /* Database page-size in bytes */
57698 PgHdr *pLast = 0; /* Last frame in list */
57701 i64 iOffset; /* Next byte to write in WAL file */
57738 u8 aWalHdr[WAL_HDRSIZE]; /* Buffer to assemble wal-header in */
57765 ** an out-of-order write following a WAL restart could result in
57866 /* If this frame set completes the first transaction in the WAL and
57882 ** be in use by existing readers is being overwritten.
57925 ** callback. In this case this function runs a blocking checkpoint.
57936 int *pnLog, /* OUT: Number of frames in WAL */
57937 int *pnCkpt /* OUT: Number of backfilled frames in WAL */
57948 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
57962 ** it will not be invoked in this case.
58033 ** number of frames in the WAL at the point of the last commit since
58052 ** on the pWal->readLock byte. If the WAL is already in locking_mode=NORMAL
58061 ** WAL is already in exclusive-locking mode - meaning that this
58077 ** happen if the connection is actually in exclusive mode (as no xShmLock
58078 ** locks are taken in this case). Nor should the pager attempt to
58092 /* Already in locking_mode=NORMAL */
58119 ** in the object.
58157 /* aSalt[0] is a copy of the value stored in the wal file header. It
58192 ** The author disclaims copyright to this source code. In place of
58202 ** This code really belongs in btree.c. But btree.c is getting too
58206 /************** Include btreeInt.h in the middle of btmutex.c ****************/
58211 In place of
58240 ** disk where M is the number of entries in the tree.
58242 ** In this implementation, a single file can hold one or more separate
58266 ** 16 2 Page size in bytes. (1 means 65536)
58276 ** 36 4 Number of freelist pages in the file
58298 ** space in a page that can be consumed by a single cell for standard
58309 ** except that it applies to leaf nodes in a LEAFDATA tree. The maximum
58311 ** not specified in the header.
58346 ** which is stored in the key size entry of the cell header rather than in
58351 ** offsets from the beginning of the page to the cell content in the cell
58352 ** content area. The cell pointers occur in sorted order. The system strives
58360 ** freeblocks. Each freeblock is at least 4 bytes in size. The byte offset
58361 ** to the first freeblock is given in the header. Freeblocks occur in
58362 ** increasing order. Because a freeblock must be at least 4 bytes in size,
58363 ** any group of 3 or fewer unused bytes in the cell content area cannot
58365 ** a fragment. The total number of bytes in all fragments is recorded.
58366 ** in the page header at offset 7.
58370 ** 2 Bytes in this freeblock
58372 ** Cells are of variable length. Cells are stored in the cell content area at
58373 ** the end of the page. Pointers to the cells are in the cell pointer array
58375 ** contiguous or in order, but cell pointers are contiguous and in order.
58383 ** allows a 64-bit integer to be encoded in 9 bytes.
58394 ** bytes of key and data in a btree cell.
58413 ** Freelist pages come in two subtypes: trunk pages and leaf pages. The
58414 ** file header points to the first in a linked list of trunk page. Each trunk
58433 ** plus 2 bytes for the index to the cell in the page header). Such
58445 ** SQLite database in order to identify the file as a real database.
58470 ** page that has been loaded into memory. The information in this object
58478 ** stored in MemPage.pBt->mutex.
58492 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
58495 u16 cellOffset; /* Index in aData of first cell pointer */
58523 BtLock *pNext; /* Next in BtShared.pLock list */
58539 ** shared between multiple connections. In that case, each connection
58545 ** All fields in this structure are accessed under sqlite3.mutex.
58547 ** in the referenced BtShared that point back to this Btree since those
58582 ** A single database file can be in use at the same time by two
58589 ** Fields in this structure are accessed under the BtShared.mutex
58609 ** while in the 'pending-lock' state, no connection may start a new
58631 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
58632 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
58633 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
58634 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
58638 u32 nPage; /* Number of pages in the database */
58665 ** about a cell. The parseCellPtr() function fills in this structure
58691 ** The entry is identified by its MemPage and the index in
58698 ** Fields in this structure are accessed under the BtShared.mutex
58725 i8 iPage; /* Index of current page in apPage */
58728 u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */
58762 ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
58769 ** cursor. The error has left the cache in an inconsistent state.
58771 ** should return the error code stored in BtCursor.skipNext
58788 ** page number to look up in the pointer map.
58805 ** each child page in the database file. The parent page is the page that
58806 ** contains a pointer to the child. Every page in the database contains
58807 ** 0 or 1 parent pages. (In this context 'database page' refers
58813 ** position in the file to another as part of autovacuum. When a page
58814 ** is moved, the pointer in its parent must be updated to point to the
58818 ** used in this case.
58821 ** is not used in this case.
58823 ** PTRMAP_OVERFLOW1: The database page is the first page in a list of
58827 ** PTRMAP_OVERFLOW2: The database page is the second or later page in a list of
58829 ** page in the overflow page list.
58832 ** identifies the parent page in the btree.
58864 ** in order to keep track of some global state information.
58866 ** The aRef[] array is allocated so that there is 1 bit for each page in
58867 ** the database. As the integrity-check proceeds, for each page used in
58876 u8 *aPgRef; /* 1 bit per page in the db (see above) */
58877 Pgno nPage; /* Number of pages in the database */
58882 int v1, v2; /* Values for up to two %d fields in zPfx */
58898 ** cell addresses in a btree header.
58911 /************** Continuing where we left off in btmutex.c ********************/
58953 ** But we keep a reference count in Btree.wantToLock so the behavior
58956 ** To avoid deadlocks, multiple Btrees are locked in the same order
58966 ** connected by pNext and pPrev should be in sorted order by
58996 ** in the common case.
59001 /* In most cases, we should be able to acquire the lock we
59013 ** the other BtShared locks that we used to hold in ascending
59074 ** Enter the mutexes in accending order by BtShared pointer address
59076 ** two or more btrees in common both try to lock all their btrees
59161 ** in single threaded applications that use shared cache. Except for
59162 ** these two routines, all mutex operations are no-ops in that case and
59163 ** are null #defines in btree.h.
59166 ** the ones below, are no-ops and are null #defines in btree.h.
59208 ** The author disclaims copyright to this source code. In place of
59272 ** in shared cache. This variable has file scope during normal builds,
59305 ** manipulate entries in the BtShared.pLock linked list used to store
59333 ** When writing to an index that resides in a sharable database, the
59385 ** useful in that case. */
59481 /* The condition (pIter->eLock!=eLock) in the following if(...)
59487 ** may hold a WRITE_LOCK on any table in this file (since there can
59534 ** by a connection in read-uncommitted mode is on the sqlite_master
59535 ** table, and that lock is obtained in BtreeBeginTrans(). */
59618 ** than the writer must be about to drop to zero. In this case
59622 ** be zero already. So this next line is harmless in that case.
59659 ** database connetion. This is important in shared-cache mode. If the database
59697 ** table is about to be deleted. In this case invalidate all incrblob
59701 ** rowid iRow is being replaced or deleted. In this case invalidate
59754 ** may be lost. In the event of a rollback, it may not be possible
59759 ** set in the bitvec. Whenever a leaf page is extracted from the free-list,
59761 ** set in BtShared.pHasContent. The contents of the bitvec are cleared
59815 ** function saves the current cursor key in variables pCur->nKey and
59820 ** (the rowid) is stored in pCur->nKey and pCur->pKey is left set to
59822 ** set to point to a malloced buffer pCur->nKey bytes in size containing
59855 ** Save the current cursor position in the variables BtCursor.nKey
59890 ** the location in the btree is remembered in such a way that it can be
59893 ** table, for example in BtreeDelete() or BtreeInsert().
59897 ** routine enforces that rule. This routine only needs to be called in
59905 ** need to be saved. It calls out to saveCursorsOnList() in the (unusual)
59906 ** event that cursors are in
59958 ** In this version of BtreeMoveto, pKey is a packed index record
59993 ** Restore the cursor to the position it was in (or as close to as possible)
60132 int offset; /* Offset in pointer map page */
60184 int offset; /* Offset of entry in pointer map */
60242 CellInfo *pInfo /* Fill in this structure */
60248 ** in between minLocal and maxLocal.
60250 ** Warning: changing the way overflow payload is distributed in any
60251 ** way will result in an incompatible file format.
60274 ** Parse a cell content block and fill in the CellInfo structure.
60287 CellInfo *pInfo /* Fill in this structure */
60304 CellInfo *pInfo /* Fill in this structure */
60372 CellInfo *pInfo /* Fill in this structure */
60409 CellInfo *pInfo /* Fill in this structure */
60418 ** Compute the total number of bytes that a Cell needs in the cell
60529 ** present in the page after this routine returns.
60533 ** unused bytes are contained in the unallocated space region, and all
60566 ** or fewer fragmented bytes. In this case it is faster to move the
60568 ** offsets to each pointer in the cell-pointer array than it is to
60576 ** in order of offset within the page, and that no block extends
60619 /* These conditions have already been verified in btreeInitPage()
60661 ** Search the free-list on page pPg for space to store a cell nByte bytes in
60685 /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
60693 ** in bytes, including the 4-byte header. */
60702 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
60703 ** number of bytes in fragments may not exceed 60. */
60731 ** allocation. This routine might need to defragment in order to bring
60734 ** allocation is being made in order to insert a new cell, so we will
60758 ** However, that integer is too large to be stored in a 2-byte unsigned
60759 ** integer, so a value of 0 is used in its place. */
60801 /* Allocate memory from the gap in between the cell pointer array
60831 u8 nFrag = 0; /* Reduction in fragmentation */
60851 /* The list of freeblocks must be in ascending order. Find the
60885 ** pointer in the page header) then check to see if iStart should be
61080 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
61096 return SQLITE_CORRUPT_BKPT; /* Freeblock not in ascending order */
61179 ** to fetch the content. Just fill in the content with zeros for now.
61180 ** If in the future we call sqlite3PagerWrite() on this page, that
61187 MemPage **ppPage, /* Return the page in this parameter */
61203 ** already in the pager cache return NULL. Initialize the MemPage.pBt and
61217 ** Return the size of the database file in pages. If there is any kind of
61233 ** call. Do additional sanity checking on the page in this case.
61314 ** * If the page is already in use for some other purpose, immediately
61321 MemPage **ppPage, /* Return the page in this parameter */
61356 ** or ptrmap page or a free page. In those cases, the following
61360 ** the call for every page that comes in for re-initing. */
61381 ** be exclusively in memory, or it might use a disk-based memory cache.
61385 ** If zFilename is ":memory:" then an in-memory database is created
61391 ** If the database is already opened in the same database connection
61392 ** and we are in shared cache mode, then the open will fail with an
61394 ** objects in the same database connection since doing so will lead
61415 /* Set the variable isMemdb to true for an in-memory database, or
61429 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
61513 /* In debug mode, we mark all persistent databases as sharable
61568 /* If the magic name ":memory:" will create an in-memory database, then
61572 ** regular file-name. In this case the auto-vacuum applies as per normal.
61621 ** The list is kept in ascending order by pBt address.
61734 ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
61824 ** Change the "soft" limit on the number of pages in the cache.
61826 ** pages in the cache exceeds this soft limit. But the size of the
61828 ** dirty pages or pages still in active use.
61840 ** Change the "spill" limit on the number of pages in the cache.
61842 ** the pager might attempt to "spill" pages to the journal early in
61875 ** Change the way data is synced to disk in order to increase or decrease
61958 ** This is useful in one special case in the backup API code where it is
61960 ** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
62107 int nPage; /* Number of pages in the database */
62108 int nPageFile = 0; /* Number of pages in the database file */
62109 int nPageHeader; /* Number of pages in the database according to hdr */
62132 ** with the following 16 bytes (in hex): 53 51 4c 69 74 65 20 66 6f 72 6d
62154 ** in WAL mode. If the log is not already open, open it now. Then
62157 ** required as the version of page 1 currently in the page1 buffer
62158 ** may not be the latest version - there may be a newer one in the log
62201 /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
62229 ** be less than 480. In other words, if the page size is 512, then the
62278 ** in assert() expressions, so it is only compiled if NDEBUG is not
62300 ** If there are no outstanding cursors and we are not in the middle
62305 ** If there is a transaction in progress, this routine is a no-op.
62402 ** returned when there is already a read-lock in order to avoid a deadlock.
62419 /* If the btree is already in a write-transaction, or it
62420 ** is already in a read-transaction and a read-transaction
62475 ** file is not pBt->pageSize. In this case lockBtree() will update
62561 int nCell; /* Number of cells in page pPage */
62602 ** overflow page in the list.
62608 /* The pointer is always the first 4 bytes of the page in this case. */
62657 ** Move the open database page pDbPage to location iFreePage in the
62743 ** SQLITE_OK. If there is no work to do (and therefore no point in
62748 ** that the last page of the file currently in use is no longer in use.
62785 ** if bCommit is non-zero. In that case, the free-list will be
62851 ** nOrig pages in size containing nFree free pages. Return the expected
62852 ** size of the database in pages following an auto-vacuum operation.
62920 ** pages are in use.
62931 Pgno nFin; /* Number of pages in database after autovacuuming */
63065 ** Commit the transaction currently in progress.
63072 ** routine has to do is delete or truncate or zero the header in the
63080 ** transaction. In this case, the transaction has already been committed
63082 ** functions return code. So, even if an error occurs in the pager layer,
63147 ** tripped. In general, writeOnly is false if the transaction being
63148 ** rolled back modified the database schema. In this case b-tree root
63192 ** Rollback the transaction in progress.
63197 ** a tripped cursor will result in an error.
63297 ** SAVEPOINT_ROLLBACK, then iSavepoint may also be -1. In this case the
63342 ** are also met. These are the conditions that must be met in order
63348 ** but which are not in the READ_UNCOMMITTED state may not have
63351 ** the read cursors in the other database connection.
63361 ** this implementation. But in a hypothetical alternative storage engine
63362 ** in which index entries are automatically deleted when corresponding table
63412 /* Now that no other errors can occur, finish filling in the BtCursor
63453 ** Return the size of a BtCursor object in bytes.
63512 ** Make sure the BtCursor* given in the argument has a valid
63514 ** btreeParseCell() to fill it in.
63516 ** BtCursor.info is a cache of the information in the current cell.
63543 ** that is currently pointing to a row in a (non-empty) table.
63575 ** valid entry. In other words, the calling procedure must guarantee
63586 ** Given the page number of an overflow page in the database (parameter
63587 ** ovfl), this function finds the page number of the next page in the
63593 ** The page number of the next overflow page in the linked list is
63594 ** written to *pPgnoNext. If page ovfl is the last page in its linked
63600 ** on *ppPage to free the reference. In no reference was obtained (because
63618 /* Try to find the next page in the overflow list using the
63619 ** autovacuum pointer-map pages. Guess that the next page in
63715 ** the cursor is moved to a different row. Additionally, in auto-vacuum
63719 ** * A commit in auto_vacuum="full" mode,
63782 ** in the overflow chain. The page number of the first overflow page is
63783 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
63823 ** number for the next page in the overflow chain. The page
63855 ** 5) the page is not in the WAL file
63917 ** to a valid row in the table. For sqlite3BtreePayloadChecked(), the
63934 ** in the CURSOR_VALID state. It is only used by the sqlite3_blob_read()
64013 ** in the common case where no overflow pages are used.
64051 ** cell in page pParent. Or, if iIdx is equal to the total number of
64052 ** cells in pParent, that page number iChild is the right-child of
64057 ** in a corrupt database */
64164 ** in such a way that page pRoot is linked into a second b-tree table
64196 ** in ascending order.
64221 ** key in ascending order.
64242 /* Move the cursor to the first entry in the table. Return SQLITE_OK
64265 /* Move the cursor to the last entry in the table. Return SQLITE_OK
64279 ** to the last entry in the b-tree. */
64338 ** exists an entry in the table that exactly matches pIdxKey.
64417 u8 *pCell; /* Pointer to current cell in pPage */
64467 int nCell; /* Size of the pCell cell in bytes */
64493 /* The record flows over onto one or more overflow pages. In
64500 ** bytes of padding is allocated at the end of the buffer in
64580 ** past the last entry in the table or sqlite3BtreePrev() moves past
64584 /* TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
64592 ** Return an estimate for the number of rows in the table that pCur is
64616 ** Advance the cursor to the next entry in the database. If
64618 ** was already pointing to the last entry in the database before
64672 ** only happen if the database is corrupt in such a way as to link the
64726 ** Step the cursor to the back to the previous entry in the database. If
64728 ** was already pointing to the first entry in the database before
64826 ** The new page is marked as dirty. (In other words, sqlite3PagerWrite()
64832 ** an error. *ppPage is set to NULL in the event of an error.
64835 ** locate a page close to the page number "nearby". This can be used in an
64836 ** attempt to keep related pages close to each other in the database file,
64837 ** which in turn can make database access faster.
64914 ** is the page number of the next freelist trunk page in the list or
64983 ** page in this case.
65095 in the event of a rollback. In this case, do
65205 /* If the database supports auto-vacuum, write an entry in the pointer-map
65215 ** trunk page in the free-list is full, then this page will become a
65217 ** first trunk page in the current free-list. This block tests if it
65236 /* In this case there is room on the trunk page to insert the page
65241 ** coded. But due to a coding error in versions of SQLite prior to
65243 ** usableSize/4 - 8 entries will be reported as corrupt. In order
65246 ** for now. At some point in the future (once everyone has upgraded
65251 ** avoid using the last six entries in the freelist trunk page array in
65270 ** the page being freed as a leaf page of the first trunk in the free-list.
65272 ** first trunk in the free-list is full. Either way, the page being freed
65273 ** will become the new first trunk page in the free-list.
65356 ** caller is iterating through or using in some other way, this
65376 ** allocated and filled in as necessary. The calling procedure
65382 ** be constructed in this temporary area then copied into pPage->aData
65410 /* Fill in the header. */
65426 /* Fill in the payload */
65449 ** nPayload Total payload size in bytes
65491 ** then the optimistic overflow chain processing in clearCell()
65560 ** "sz" must be the number of bytes in the cell.
65610 ** in pPage->apOvfl[] and make it point to the cell content (either
65611 ** in pTemp or the original pCell) and also record its index.
65612 ** Allocating a new entry in pPage->aCell[] implies that
65621 int sz, /* Bytes of content in pCell */
65626 int idx = 0; /* Where to write new cell content in data[] */
65629 u8 *pIns; /* The point in pPage->aCellIdx[] where no cell inserted */
65642 ** the term after the || in the following assert(). */
65654 ** as a contingency. In other words, never need more than 3 overflow
65660 /* When multiple overflows occur, they are always sequential and in
65665 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
65712 int nCell; /* Number of cells in apCell[] */
65715 u16 *szCell; /* Local size of all cells in apCell[] */
65754 ** szCell[] array contains the size in bytes of each cell. This function
65758 ** Some of the cells in apCell[] may currently be stored in pPg. This
65811 ** contains the size in bytes of each such cell. This function attempts to
65812 ** add the cells stored in the array to page pPg. If it cannot (because
65817 ** Argument pCellptr points to the first entry in the cell-pointer array
65820 ** cell in the array. It is the responsibility of the caller to ensure
65831 ** area must be extended to before this point in order to accomodate all
65832 ** cells in apCell[], then the cells do not fit and non-zero is returned.
65837 u8 **ppData, /* IN/OUT: Page content -area pointer */
65873 ** contains the size in bytes of each such cell. This function adds the
65874 ** space associated with each cell in the array that is currently stored
65926 ** apCell[] and szCell[] contains pointers to and sizes of all cells in the
66033 ** in a balancing operation. NN is the number of neighbors on either side
66034 ** of the page that participate in the balancing operation. NB is the
66039 ** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
66040 ** in exchange for a larger degradation in INSERT and UPDATE performance.
66044 #define NB (NN*2+1) /* Total pages involved in the balance */
66051 ** tree, in other words, when the new entry will become the largest
66052 ** entry in the tree.
66055 ** a new page to the right-hand side and put the one new entry in
66061 ** pPage is the leaf page which is the right-most page in the tree.
66067 ** byte page number followed by a variable length integer. In other
66069 ** least 13 bytes in size.
66127 ** record-length (a variable length integer at most 32-bits in size)
66202 ** parent page stored in the pointer map is page pTo. If pFrom contained
66206 ** If pFrom is currently carrying any overflow cells (entries in the
66260 ** page are used in the balancing, though both siblings might come from one
66264 ** participate in the balancing.
66267 ** one or two in an effort to keep pages nearly full but not over full.
66270 ** might not actually be stored in MemPage.aData[]. This can happen
66274 ** In the course of balancing the page and its siblings, cells may be
66281 ** in a corrupted state. So if this routine fails, the database should
66298 int iParentIdx, /* Index of "the page" in pParent */
66305 int nNew = 0; /* Number of pages in apNew[] */
66306 int nOld; /* Number of pages in apOld[] */
66308 int nxDiv; /* Next divider slot in pParent->aCell[] */
66312 int usableSpace; /* Bytes in pPage beyond the header */
66319 u8 *pRight; /* Location in parent of right-sibling pointer */
66320 u8 *apDiv[NB-1]; /* Divider cells in pParent */
66321 int cntNew[NB+2]; /* Index in b.paCell[] of cell after i-th page */
66322 int cntOld[NB+2]; /* Old index in b.apCell[] */
66325 Pgno pgno; /* Temp var to store a page number in */
66355 /* Find the sibling pages to balance. Also locate the cells in pParent
66363 ** overflow cells in the parent page, since if any existed they will
66413 ** But not if we are in secure-delete mode. In secure-delete mode,
66415 ** In this case, temporarily copy the cell into the aOvflSpace[]
66435 /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
66467 ** into aSpace1[]. In this way, all cells in b.apCell[] are without
66468 ** child pointers. If siblings are not leaves, then all cell in
66469 ** b.apCell[] include child pointers. Either way, all cells in b.apCell[]
66494 /* Load b.apCell[] with pointers to all cells in pOld. If pOld
66495 ** constains overflow cells, include them in the b.apCell[] array
66496 ** in the correct spot.
66502 ** adjacent and are inserted in order. There is an assert() tagged
66503 ** with "NOTE 1" in the overflow cell insertion loop to prove this
66506 ** This must be done in advance. Once the balance starts, the cell
66570 ** Store this number in "k". Also compute szNew[] which is the total
66572 ** in b.apCell[] of the cell that divides page i from page i+1.
66579 ** cntNew[i]: Index in b.apCell[] and b.szCell[] for the first cell to
66651 int r; /* Index of right-most cell in left sibling */
66725 ** Reassign page numbers so that the new pages are in ascending order.
66726 ** This helps to keep entries in the disk file in order so that a scan
66727 ** of the table is closer to a linear scan through the file. That in turn
66744 ** we do the detection here in order to avoid populating the pager
66787 ** originally in the same field of the right-most old sibling page. */
66799 ** entry associated with the first page in the overflow chain, and
66867 ** then there is no divider cell in b.apCell[]. Instead, the divider
66886 ** This can only happen for b-trees used to evaluate "IN (SELECT ...)"
66903 /* Now update the actual sibling pages. The order in which they are updated
66905 ** cells may still to be read. In practice, this means:
66917 ** The iPg value in the following loop starts at nNew-1 goes down
66973 ** sub-algorithm in some documentation.
67055 ** page and SQLITE_OK is returned. In this case the caller is required
67107 ** The page that pCur currently points to has just been modified in
67131 /* The root page of the b-tree is overfull. In this case call the
67168 ** happens, the overflow cell is stored in the aBalanceQuickSpace[]
67174 ** of the aBalanceQuickSpace[] might sneak in.
67182 /* In this case, call balance_nonroot() to redistribute cells
67189 ** are stored in the pSpace buffer allocated immediately below.
67245 ** key is an arbitrary byte sequence stored in pX.pKey,nKey. The
67250 ** been performed. In other words, if seekResult!=0 then the cursor
67257 ** In that case, this routine must seek the cursor to the correct insertion
67301 ** In some cases, the call to btreeMoveto() below is a no-op. For
67305 ** data into the intkey B-Tree. In this case btreeMoveto() recognizes
67425 ** is advantageous to leave the cursor pointing to the last entry in
67427 ** entry in the table, and the next row inserted has an integer key
67469 ** But if that bit is set, then the cursor is left in a state such that
67490 int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
67511 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
67515 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
67516 ** before or after the deleted entry. In this case set bSkipnext to true. */
67531 ** the cursor to the largest entry in the tree that is smaller than
67566 ** is currently pointing to the largest entry in the sub-tree headed
67591 ** then the cursor still points to that page. In this case the first
67599 ** be either under or overfull. In this case run the balancing algorithm
67601 ** tree that we can be sure that any problem in the internal node has
67640 ** following values of flags are currently in use. Other values for
67668 ** to make room for the new tables root page. In case this page turns
67710 /* Save the positions of any open cursors. This is required in
67761 /* When the new root page was allocated, page 1 was made writable in
67856 ** Delete all information from a single table in the database. iTable is
67866 ** entries in the table.
67897 ** Erase all information in a table and add the root of the table to
67905 ** root page in the database file, then the last root page
67906 ** in the database file is moved into the slot formerly occupied by
67908 ** is added to the freelist instead of iTable. In this say, all
67911 ** page number that used to be the last root page in the file before
67913 ** The last root page is recorded in meta[3] and the value of
67945 ** number in the database, put the root page on the free list.
67954 ** number in the database. So move the page that does into the
67978 /* Set the new 'max-root-page' value in the database header. This
68012 ** is the number of free pages currently in the database. Meta[1]
68022 ** from the pager. The BTREE_DATA_VERSION value is not actually stored in the
68042 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
68084 ** number of entries in the b-tree and write the result to *pnEntry.
68091 i64 nEntry = 0; /* Value to return in *pnEntry */
68101 ** page in the B-Tree structure (not including overflow pages).
68104 int iIdx; /* Index of child node in parent */
68118 ** the next page in the tree that has not yet been visited. The
68120 ** of the page, or to the number of cells in the page if the next page
68123 ** If all pages in the tree have been visited, return SQLITE_OK to the
68195 ** Return non-zero if the bit in the IntegrityCk.aPgRef[] array that
68204 in the IntegrityCk.aPgRef[] array that corresponds to page iPg.
68218 ** Also check that the page number is in bounds.
68236 ** Check that the entry in the pointer-map for page iChild maps to
68272 int iPage, /* Page number for first page in the list */
68273 int N /* Expected number of pages in the list */
68320 ** page in this overflow list, check that the pointer-map entry for
68333 checkAppendMsg(pCheck, "free-page count in header is too small");
68348 ** root node aHeap[1] is always the minimum value currently in the heap.
68352 ** removes the root element from the heap (the minimum value in the heap)
68400 ** 2. Make sure integer cell keys are in order.
68451 /* Clear MemPage.isInit to make sure the corruption detection code in
68492 /* For leaf pages, the coverage check will occur in the same loop
68598 ** big-endian integer which is the offset in the b-tree page of the next
68599 ** freeblock in the chain, or zero if the freeblock is the last on the
68602 /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
68609 ** freeblocks, and counting the number of untracked bytes in nFrag.
68616 ** The loop below pulls entries from the min-heap in order and compares
68634 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
68635 ** is stored in the fifth field of the b-tree page header.
68660 ** a table. nRoot is the number of entries in aRoot.
68665 ** Write the number of error seen in *pnErr. Except for some memory
68666 in memory obtained from
68673 int nRoot, /* Number of entries in aRoot[] */
68742 /* Make sure every page in the file is referenced
68784 ** an empty string if the database is in-memory or a TEMP database.
68954 ** required in case any of them are holding references to an xFetch
68994 ** "write version" (single byte at byte offset 19) fields in the database
69072 ** The author disclaims copyright to this source code. In place of
69092 u32 iDestSchema; /* Original schema cookie in destination */
69120 ** structure, in that order.
69123 ** invoked by the pager layer to report various state changes in
69137 ** Non-sharable Btrees (in-memory databases for example), do not have
69143 ** in connection handle pDb. If such a database cannot be found, return
69191 ** message in database handle db.
69195 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
69203 ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
69207 ** stored in database handle pDestDb.
69225 ** handle is not locked in this routine, but it is locked in
69229 ** database connection while a backup is in progress may cause
69322 /* Catch the case where the destination is an in-memory database and the
69331 ** and a codec is in use.
69436 int nSrcPage = -1; /* Size of source db in pages */
69439 /* If the source pager is currently in a write-transaction, return
69460 ** is especially important on ZipVFS systems, as in that case it is
69475 /* Do not allow backup if the destination database is in WAL mode
69485 ** source pager for the number of pages in the database.
69511 /* Update the schema version field in the destination database. This
69512 ** is to make sure that the schema-version really does change in
69534 /* Set nDestTruncate to the final number of pages in the destination
69539 ** round up. In this case the call to sqlite3OsTruncate() below will
69541 ** sqlite3PagerTruncateImage() here so that any pages in the
69566 ** pending-byte page in the source database may need to be
69584 ** database has been stored in the journal for pDestPager and the
69586 ** the database file in any way, knowing that if a power failure
69733 ** Return the total number of pages in the source database as of the most
69790 ** connection. In this case there is no way of knowing which of the
69846 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
69875 ** The author disclaims copyright to this source code. In place of
69885 ** stores a single value in the VDBE. Mem is an opaque structure visible
69905 /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
69908 ** That saves a few cycles in inner loops. */
69925 ** (1) Memory in Mem.zMalloc and managed by the Mem object
69989 ** in pMem->z is discarded.
70038 ** Any prior string or blob content in the pMem object may be discarded.
70059 ** Change pMem so that its MEM_Str or MEM_Blob value is stored in
70088 ** blob stored in dynamically allocated space.
70153 ** keys are strings. In the former case a NULL pointer is returned the
70226 ** invoking the external callback in Mem.xDel, then this routine
70257 ** by p->xDel and memory in p->zMalloc.
70259 ** This is a helper routine invoked by sqlite3VdbeMemRelease() in
70260 ** the unusual case where there really is memory in p that needs
70361 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70376 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70400 ** The second and third terms in the following conditional enforces
70462 ** Cast the datatype of the value in pMem according to the affinity
70463 ** "aff". Casting is different from applying affinity in that a cast
70464 ** is forced. In other words, the value is converted into the desired
70465 ** affinity even if that results in loss of data. This routine is
70519 ** Delete any previous value and set the value stored in *pMem to NULL.
70567 ** Delete any previous value and set the value stored in *pMem to val,
70581 ** Delete any previous value and set the value stored in *pMem to val,
70699 ** Transfer the contents of pFrom to pTo. Any existing value in pTo is
70727 ** is required to store the string, then value of pMem is unchanged. In
70733 int n, /* Bytes in string, or negative */
70768 ** also sets a flag in local variable "flags" to indicate the memory
70827 ** to read from the disk) then the pMem is left in an inconsistent state.
70833 Mem *pMem /* OUT: Return data in this Mem structure. */
70854 Mem *pMem /* OUT: Return data in this Mem structure. */
70918 ** external API. It works in a similar way to sqlite3_value_text(),
70919 ** except the data returned is in the encoding specified by the second
71122 ** Extract a value from the supplied expression in the manner described
71129 ** in all cases.
71167 /* Handle negative integers in a single step. This is needed in the
71280 ** This is used to convert the value stored in the 'sample' column of the
71315 ** Register built-in functions used to help read ANALYZE data.
71331 ** A value is extracted in the following cases:
71333 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
71389 ** in the sqlite_stat4 table.
71395 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
71423 UnpackedRecord **ppRec, /* IN/OUT: Probe record */
71463 ** is undefined in this case.
71475 ** Extract the iCol-th column from the nRec-byte record in pRec. Write
71485 int nRec, /* Size of buffer pRec in bytes */
71490 int nHdr; /* Size of the header in the record */
71565 ** The sqlite3ValueBytes() routine returns the number of bytes in the
71594 ** The author disclaims copyright to this source code. In place of
71634 ** Change the error string stored in Vdbe.zErrMsg
71688 ** SQLITE_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain
71739 ** Add a new instruction to the list of instructions current in the
71831 ** One register is initialized for each characgter in zTypes[]. For each
71832 ** "s" character in zTypes[], the register is a string if the argument is
71834 ** in zTypes[], the register is initialized to an integer.
71999 ** in a Vdbe main program and each of the sub-programs (triggers) it may
72017 int nSub; /* Number of entries in apSub */
72066 ** Check if the program stored in the VM associated with pParse may
72082 ** part of an assert statement in the compiler. Similar to:
72118 ** true for this case to prevent the assert() in the callers frame
72133 ** and store that value in *pMaxFuncArgs.
72156 /* Only JUMP opcodes and the short list of special opcodes in the switch
72236 ** Verify that at least N opcode slots are available in p without
72252 ** by code in pragma.c to ensure that the implementation of certain
72253 ** pragmas comports with the flags specified in the mkpragmatab.tcl
72271 ** Before returning, *pnOp is set to the number of entries in the returned
72273 ** the number of entries in the Vdbe.apArg[] array required to execute the
72532 ** the Vdbe. In these cases we can just copy the pointer.
72595 ** P4 must not be P4_INT32. Use sqlite3VdbeChangeP4() in either of
72632 ** in a production build.
72716 ** The Synopsis: field in comments in the vdbe.c source file gets converted
72717 ** to an extra string that is appended to the sqlite3OpcodeName(). In the
72730 int nTemp /* Space available in zTemp[] */
72802 ** that can be displayed in the P4 column of EXPLAIN output.
72997 ** The prepared statements need to know in advance the complete set of
72999 ** is maintained in p->btreeMask. The p->lockMask value is the subset of
73015 ** that may be accessed by the VM passed as an argument. In doing so it also
73028 ** statement p will ever use. Let N be the number of bits in p->btreeMask
73163 ** allocated by the OP_Program opcode in sqlite3VdbeExec().
73179 ** Give a listing of the program in the virtual machine.
73187 ** are shown in a different format. p->explain==2 is used to implement
73225 ** nRow is the sum of the number of rows in the main program, plus
73226 ** the sum of the number of rows in all trigger subprograms encountered
73263 /* The output line number is small enough that we are still in the
73290 ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
73430 ** memory on success. If insufficient memory is available in the
73462 ** Rewind the VDBE back to the beginning in preparation for
73526 int nArg; /* Number of arguments in subprograms */
73568 /* Memory for registers, parameters, cursor, etc, is allocated in one or two
73572 ** pass will fill in the remainder using a fresh memory allocation.
73652 ** Close all cursors in the current frame.
73668 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
73696 ** Also release any dynamic memory held by the VM in the Vdbe.aMem memory
73698 ** pointers to VdbeFrame objects, which may in turn contain pointers to
73820 ** virtual module tables written in this transaction. This has to
73878 ** string, it means the main database is :memory: or a temp file. In
73895 ** but could happen. In this case abandon processing and return the error.
73960 /* Write the name of each database file in the transaction into the new
73997 /* Sync all the db files involved in the transaction. The same call
73998 ** sets the master journal pointer in each individual journal. If
74004 ** in case the master journal file name was written into the journal
74058 ** matches the number of vdbe's in the list sqlite3.pVdbe that are
74179 ** has made changes and is in autocommit mode, then commit those
74184 ** call this on a VM that is in the SQLITE_MAGIC_HALT state.
74205 ** Then the internal cache might have been left in an inconsistent
74243 ** pagerStress() in pager.c), the rollback is required to restore
74389 ** in p->rc. This routine sets that result back to SQLITE_OK.
74476 ** called), set the database error in this case as well.
74554 ** * the corresponding bit in argument mask is clear (where the first
74732 ** encapsulate the code that serializes values for storage in SQLite
74737 ** In an SQLite index record, the serial type is stored directly before
74738 ** the blob of data that it corresponds to. In a table record, all serial
74761 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
74766 ** Return the serial-type for the value stored in pMem.
74864 ** float in the wrong order. And that error has been propagated
74889 static u64 floatSwap(u64 in){
74896 u.r = in;
74908 ** Write the serialized data blob for the value stored in pMem into
74912 ** nBuf is the amount of space left in buf[]. The caller is responsible
74917 ** of bytes in the zero-filled tail is included in the return value only
74918 ** if those bytes were zeroed in buf[].
74967 ** and store the result in pMem. Return the number of bytes read.
74971 ** routine so that in most cases the overhead of moving the stack pointer
75052 /* Work around a sign-extension bug in the HP compiler for HP/UX */
75069 /* These use local variables, so do them in a separate routine
75070 ** to avoid having to move the frame pointer in the common case */
75082 /* EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in
75084 ** EVIDENCE-OF: R-28401-00140 Value is a string in the text encoding and
75085 ** (N-13)/2 bytes in length. */
75125 ** Given the nKey-byte encoding of a record in pKey[], populate the
75137 u32 idx; /* Offset in aKey[] to read from */
75166 ** This function compares two index or table record keys in the same way
75170 ** in assert() statements to ensure that the optimized code in
75183 u32 szHdr1; /* Number of bytes in header */
75199 ** But in fact, mem1.u.i will never actually be used uninitialized, and doing
75216 /* Read the serial types for the next element in each key. */
75223 ** sqlite3VdbeSerialTypeLen() in the common case.
75271 ** Count the number of fields (a.k.a. columns) in the record given by
75309 ** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
75318 /* The strings are already in the correct encoding. Call the
75559 ** fields that appear in both keys are equal, then pPKey2->default_rc is
75574 u32 szHdr1; /* Size of record header in bytes */
75575 u32 idx1; /* Offset of first type in header */
75583 ** two elements in the keys are equal. Fix the various stack variables so
75764 ** size-of-header varint at the start of (pKey1/nKey1) fits in a single
75849 ** fields. Return pPKey2->default_rc in this case. */
75862 ** at the start of (pKey1/nKey1) fits in a single byte.
75928 ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
75933 ** limit the size of the header to 64 bytes in cases where the first field
75965 ** Read the rowid (the last field in the record) and store it in *rowid.
75981 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
75988 /* Read in the complete content of the index entry */
76039 ** the key string in pUnpacked. Write into *pRes a number
76090 ** Set a flag in the vdbe to update the change counter when it is finalised
76148 ** in a better query plan.
76162 ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
76163 ** in memory obtained from sqlite3DbMalloc).
76180 ** with the memory cells in the p->aMem[] array. Also free the UnpackedRecord
76184 ** the vdbeUnpackRecord() function found in vdbeapi.c.
76270 ** The author disclaims copyright to this source code. In place of
76289 ** execution environment changes in a way that would alter the program
76409 ** Set all the parameters in the compiled SQL statement to NULL.
76482 /* EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five
76568 int n, /* Bytes in string, or negative */
76802 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
76894 ** be one of the values in the first assert() below. Variable p->rc
76904 ** error has occurred, then return the error code in p->rc to the
76905 ** caller. Set the error code in the database handle to the same value.
76992 ** of the amount of time that elapses between invocations. In other words,
77013 ** fails with an error message stating that the function is used in the
77028 "unable to use function %s in the requested context", zName);
77171 ** Return the number of columns in the result set for the statement pStmt.
77250 ** column value (i.e. a value returned by evaluating an SQL expression in the
77284 ** in the result set.
77496 ** Routines used to attach values to wildcards in a compiled SQL statement.
77499 ** Unbind the value bound to variable i in virtual machine p. This is the
77506 ** The error code stored in database p->db is overwritten with the return
77507 ** value in any case.
77533 /* If the bit corresponding to this variable in Vdbe.expmask is set, then
77537 ** parameter in the WHERE clause might influence the choice of query plan
77820 ** in the argument belongs. This is the same database handle that was
77822 ** the statement in the first place.
77837 ** Return true if the prepared statement is in need of being reset.
77921 ** record in nKey/pKey. Return a pointer to the new UnpackedRecord structure
78002 ** the number of columns in the row being updated, deleted or inserted.
78178 ** The author disclaims copyright to this source code. In place of
78199 ** bytes in this text up to but excluding the first character in
78201 ** the total number of bytes in the text.
78223 ** This function returns a pointer to a nul-terminated string in memory
78238 ** ALGORITHM: Scan the input string looking for host parameters in any of
78243 ** parameter index is known, locate the value in p->aVar[]. Then render
78244 ** the value as a literal in place of the host parameter name.
78312 int nOut; /* Number of bytes of the string text to include in output */
78345 int nOut; /* Number of bytes of the blob to include in output */
78375 ** The author disclaims copyright to this source code. In place of
78383 ** The code in this file implements the function that runs the
78386 ** Various scripts scan this source file in order to generate HTML
78388 ** of the code in this file is, therefore, important. See other comments
78389 ** in this file for details. If in doubt, do not deviate from existing
78400 ** is changed while the copy is still in use, the string or blob might
78423 ** each instruction in the VDBE. When it reaches zero, the u1.isInterrupted
78424 ** field of the sqlite3 structure is set in order to simulate an interrupt.
78427 ** in an ordinary build.
78503 ** source code is in a single file (the amalgamation). Special values 1
78541 ** string that the register itself controls. In other words, it
78558 int nField, /* Number of fields in the table or index */
78568 ** purposes in a vdbe program. The different uses might require
78611 ** do so without loss of information. In other words, if the string
78877 /************** Include hwtime.h in the middle of vdbe.c *********************/
78882 ** The author disclaims copyright to this source code. In place of
78966 /************** Continuing where we left off in vdbe.c ***********************/
78974 ** the number of non-transaction savepoints currently in the
79177 ** separate instruction in the virtual machine. If we follow the usual
79181 ** big comment (similar to this one) will mark the point in the code where
79193 ** Other keywords in the comment that follows each case are used to
79200 ** comment lines are used in the generation of the opcode.html documentation
79206 ** Do not deviate from the formatting style currently in use.
79272 /* Most jump operations do a goto to this spot in order to update
79281 ** Jump to the next instruction after the address in register P1. After
79317 ** The instruction at the address in register P1 is a Yield.
79338 ** Swap the program counter with the value in register P1. This
79364 ** Check the value in register P3. If it is NULL then Halt using
79366 ** value in register P3 is not NULL, then this routine is a no-op.
79421 ** an IGNORE exception. In this case jump to the address specified
79449 sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg);
79545 ** The string value P4 of length P1 (bytes) is stored in register P2.
79550 ** of a string, as if it had been CAST. In other words:
79577 ** NULL into register P3 and every register in between P2 and P3. If P3
79623 ** blob in register P2.
79639 ** If the parameter is named, then its name appears in P4.
79660 ** Move the P3 values in register P1..P1+P3-1 over into
79754 ** Transfer the integer value held in register P1 into register P2.
79804 /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
79809 ** In case this is such a statement, close any statement transaction
79855 ** Add the text in register P1 onto the end of the text in
79856 ** register P2 and store the result in register P3.
79857 ** If either the P1 or P2 text are NULL then store NULL in P3.
79903 ** Add the value in register P1 to the value in register P2
79904 ** and store the result in register P3.
79911 ** Multiply the value in register P1 by the value in register P2
79912 ** and store the result in register P3.
79918 ** Subtract the value in register P1 from the value in register P2
79919 ** and store the result in register P3.
79925 ** Divide the value in register P1 by the value in register P2
79926 ** and store the result in register P3 (P3=P2/P1). If the value in
79934 ** register P1 and store the result in register P3.
79935 ** If the value in register P1 is zero the result is NULL.
79993 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
80032 ** be returned. This is used by the built-in min(), max() and nullif()
80041 ** publicly. Only built-in functions have access to this feature.
80056 ** successors. The result of the function is stored in register P3.
80074 ** in register P3. Register P3 must not be one of the function inputs.
80086 ** changed to this OP_Function opcode. In this way, the initialization of
80120 /* If this function is inside of a trigger, the register array in aMem[]
80165 ** Take the bit-wise AND of the values in register P1 and P2 and
80166 ** store the result in register P3.
80172 ** Take the bit-wise OR of the values in register P1 and P2 and
80173 ** store the result in register P3.
80179 ** Shift the integer value in register P2 to the left by the
80180 ** number of bits specified by the integer in register P1.
80181 ** Store the result in register P3.
80187 ** Shift the integer value in register P2 to the right by the
80188 ** number of bits specified by the integer in register P1.
80189 ** Store the result in register P3.
80218 /* If shifting by a negative amount, shift in the other direction */
80247 ** Add the constant P2 to the value in register P1.
80262 ** Force the value in register P1 to be an integer. If the value
80263 ** in P1 is not an integer and cannot be converted into an integer
80308 ** Force the value in register P1 to be the type defined by P2.
80340 ** Compare the values in register P1 and P3. If reg(P3)==reg(P1) then
80341 ** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5, then
80342 ** store the result of comparison in register P2.
80355 ** are text, then the appropriate collating function specified in
80362 ** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
80370 ** In other words, a prior r[P2] value will not be overwritten by 1 (true).
80376 ** the operands in registers P1 and P3 are not equal. See the Eq opcode for
80381 ** In other words, a prior r[P2] value will not be overwritten by 0 (false).
80386 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
80387 ** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5 store
80405 ** are text, then the appropriate collating function specified in
80549 ** is only used in contexts where either:
80595 ** Set the permutation used by the OP_Compare operator in the next
80596 ** instruction. The permutation is stored in the P4 operand.
80599 ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should
80602 ** The first integer in the P4 integer array is the length of the array
80616 ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
80617 ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
80622 ** OPFLAG_PERMUTE bit is clear, then register are compared in sequential
80691 ** in the most recent OP_Compare instruction the P1 vector was less than
80708 ** Take the logical AND of the values in registers P1 and P2 and
80718 ** Take the logical OR of the values in register P1 and P2 and
80719 ** store the answer in register P3.
80762 ** Interpret the value in register P1 as a boolean value. Store the
80763 ** boolean complement in register P2. If the value in register P1 is
80764 ** NULL, then a NULL is stored in P2.
80782 ** a NULL then store a NULL in P2.
80807 ** For subprograms, there is a bitmask in the VdbeFrame that determines
80835 ** Jump to P2 if the value in register P1 is true. The value
80837 ** in P1 is NULL then take the jump if and only if P3 is non-zero.
80841 ** Jump to P2 if the value in register P1 is False. The value
80843 ** in P1 is NULL then take the jump if and only if P3 is non-zero.
80869 ** Jump to P2 if the value in register P1 is NULL.
80883 ** Jump to P2 if the value in register P1 is not NULL.
80919 ** values in the record, extract a NULL.
80921 ** The value extracted is stored in register P3.
81041 ** parsed and valid information is in aOffset[] and pC->aType[].
81044 /* If there is more header available for parsing in the record, try
81058 /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */
81189 ** memory cell in the range.
81212 ** use as a data record in a database table or as a key
81213 ** in an index. The OP_Column opcode can decode the record later.
81220 ** macros defined in sqliteInt.h.
81231 int nVarint; /* Number of bytes in a varint */
81235 int nField; /* Number of fields in the record */
81238 int i; /* Space used in zNewRecord[] header */
81239 int j; /* Space used in zNewRecord[] content */
81322 ** which determines the total number of bytes in the header. The varint
81323 ** value is the size of the header in bytes including the size varint
81361 /* EVIDENCE-OF: R-64536-51728 The values for each column in the record
81383 ** Store the number of entries (an integer value) in the table or index
81384 ** opened by cursor P1 in register P2
81436 sqlite3VdbeError(p, "cannot open savepoint - SQL statements in progress");
81494 "SQL statements in progress");
81554 ** constraint violations present in the database to the value stored
81609 "SQL statements in progress");
81660 ** connection is currently not in autocommit mode, or if there are other
81671 ** cookie in P3 differs from the schema cookie in the database header or
81672 ** if the schema generation counter in P4 differs from the current
81742 ** stored with the in-memory representation of the schema, do
81745 ** If virtual-tables are in use, this is not just an optimization.
81746 ** Often, v-tables store their data in other SQLite tables, which
81821 /* Record changes in the file format */
81838 ** P2 in a database file. The database file is determined by P3.
81861 ** value, it is set to the number of columns in the table.
81870 ** number of P2 and if it is this opcode becomes a no-op. In other words,
81890 ** value, it is set to the number of columns in the table, or to the
81894 ** in read/write mode. For a given table, there can be one or more read-only
82043 ** P2 is the number of columns in the ephemeral table.
82046 ** that defines the format of keys in the index.
82049 ** in btree.h. These flags control aspects of the operation of
82059 ** indices in joins.
82156 ** Synopsis: P3 columns in r[P2]
82160 ** register P2. In other words, cursor P1 becomes an alias for the
82161 ** MEM_Blob content contained in register P2.
82168 ** P3 is the number of fields in the records that will be stored by
82203 ** (P4_INT64) in which the first 63 bits are one for each of the
82221 ** use the value in register P3 as the key. If cursor P1 refers
82222 ** to an SQL index, then P3 is the first in an array of P4 registers
82236 ** This opcode leaves the cursor configured to move in forward order,
82237 ** from the beginning toward the end. In other words, the cursor is
82246 ** use the value in register P3 as a key. If cursor P1 refers
82247 ** to an SQL index, then P3 is the first in an array of P4 registers
82254 ** This opcode leaves the cursor configured to move in forward order,
82255 ** from the beginning toward the end. In other words, the cursor is
82264 ** use the value in register P3 as a key. If cursor P1 refers
82265 ** to an SQL index, then P3 is the first in an array of P4 registers
82272 ** This opcode leaves the cursor configured to move in reverse order,
82273 ** from the end toward the beginning. In other words, the cursor is
82282 ** use the value in register P3 as a key. If cursor P1 refers
82283 ** to an SQL index, then P3 is the first in an array of P4 registers
82290 ** This opcode leaves the cursor configured to move in reverse order,
82291 ** from the end toward the beginning. In other words, the cursor is
82311 int nField; /* Number of columns or fields in the key */
82313 int eqOnly; /* Only interested in == results */
82337 /* The input value in P3 might be of any type: integer, real, string,
82478 ** is a prefix of any entry in P1 then a jump is made to P2 and
82481 ** This operation leaves the cursor in a state where it can be
82482 ** advanced in the forward direction. The Next instruction will work,
82495 ** is not the prefix of any entry in P1 then a jump is made to P2. If P1
82500 ** This operation leaves the cursor in a state where it cannot be
82501 ** advanced in either direction. In other words, the Next and Prev
82515 ** record are not-NULL then a check is done to determine if any row in the
82523 ** This operation leaves the cursor in a state where it cannot be
82524 ** advanced in either direction. In other words, the Next and Prev
82629 ** This opcode leaves the cursor in a state where it cannot be advanced
82630 ** in either direction. In other words, the Next and Prev opcodes will
82646 ** P3 register to contain a non-integer value, in which case the jump is
82652 ** This opcode leaves the cursor in a state where it cannot be advanced
82653 ** in either direction. In other words, the Next and Prev opcodes will
82727 ** The record number is not previously used as a key in the database
82731 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds
82756 ** thing) is obtained in a two-step algorithm.
82764 ** it already exists in the table. If it does not exist, we have
82833 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
82862 ** entry is overwritten. The data is the value MEM_Blob stored in register
82863 ** number P2. The key is stored in register P3. The key must
82898 ** integer value P3, not the value of the integer stored in register P3.
82993 ** record in the table. If it is left pointing at the next record, then
82994 ** the next Next instruction will be a no-op. As a result, in this case
82997 ** left in an undefined state.
83011 ** If P4 is not NULL then it points to a Table object. In this case either
83013 ** have been positioned using OP_NotFound prior to invoking this opcode in
83016 ** P4 is not NULL, and the OPFLAG_NCHANGE flag is set in P2.
83018 ** If the OPFLAG_ISUPDATE flag is set in P2, then P3 contains the address
83133 ** record blob in register P3 against a prefix of the entry that
83137 ** If either P3 or the sorter contains a NULL in one of their significant
83195 ** it is found in the database file.
83207 ** position in order that they can write to the same table. If P3==0
83212 ** in OP_Result and any OP_Result will invalidate the P2 register content.
83236 ** would fail. Should this ever change (because of changes in the code
83263 ** Store in register P2 an integer which is the key of the table entry that
83335 ** will refer to the last entry in the database table or index.
83340 ** This opcode leaves the cursor configured to move in reverse order,
83341 ** from the end toward the beginning. In other words, the cursor is
83345 ** for the purpose of appending a new entry onto the btree. In that
83385 ** Estimate the number of rows in the table P1. Jump to P2 if that
83444 ** will refer to the first entry in the database table or index.
83449 ** This opcode leaves the cursor configured to move in forward order,
83450 ** from the beginning toward the end. In other words, the cursor is
83486 ** Advance cursor P1 so that it points to the next key/data pair in its
83507 ** number P5-1 in the prepared statement is incremented.
83518 ** Back up cursor P1 so that it points to the previous key/data pair in its
83540 ** number P5-1 in the prepared statement is incremented.
83617 ** If P4 is not zero, then it is the number of values in the unpacked
83618 ** key of reg(P2). In that case, P3 is the index of the first register
83729 ** one entry for each column in the P3 table. If array entry a(i)
83732 ** from P1. This information is stored in P3 and used to redirect
83739 ** Write into register P2 an integer which is the last entry in the record at
83891 ** Delete an entire database table or index whose root page in the database
83894 ** The table being destroyed is in the main database file if P3==0. If
83895 ** P3==1 then the table to be clear is in the auxiliary database file
83899 ** might be moved into the newly deleted root page in order to keep all
83902 ** is stored in register P2. If no page movement was required (because the
83903 ** table being dropped was already the last one in the database) then a
83904 ** zero is stored in register P2. If AUTOVACUUM is disabled then a zero
83905 ** is stored in register P2.
83909 ** updating existing cursors when a root page is moved in an AUTOVACUUM
83911 ** db in order to avoid introducing an incompatibility between autovacuum
83951 ** in the database file is given by P1. But, unlike Destroy, do not
83954 ** The table being clear is in the main database file if P2==0. If
83955 ** P2==1 then the table to be clear is in the auxiliary database file
83959 ** intkey table (an SQL table, not an index). In this case the row change
83960 ** count is incremented by the number of rows in the table being cleared.
83961 ** If P3 is greater than zero, then the value stored in register P3 is
83962 ** also incremented by the number of rows in the table being cleared.
84015 ** Allocate a new table in the main database file if P1==0 or in the
84016 ** auxiliary database file if P1==1 or in an attached database if
84029 ** Allocate a new index in the main database file if P1==0 or in the
84030 ** auxiliary database file if P1==1 or in an attached database if
84063 ** Run the SQL statement or statements specified in the P4 string.
84148 ** Remove the internal (in-memory) data structures that describe
84149 ** the table named P4 in database P1. This is called after a table
84150 ** is dropped from disk (using the Destroy opcode) in order to keep
84161 ** Remove the internal (in-memory) data structures that describe
84162 ** the index named P4 in database P1. This is called after an index
84164 ** in order to keep the internal representation of the
84174 ** Remove the internal (in-memory) data structures that describe
84175 ** the trigger named P4 in database P1. This is called after a trigger
84176 ** is dropped from disk (using the Destroy opcode) in order to keep
84189 ** Do an analysis of the currently open database. Store in
84191 ** If no problems are found, store a NULL in register P1.
84195 ** In other words, the analysis stops as soon as reg(P1) errors are
84198 ** The root page numbers of all tables in the database are integers
84199 ** stored in P4_INTARRAY argument.
84246 ** held in register P1.
84265 ** Extract the smallest value from the RowSet object in P1
84290 ** Synopsis: if r[P3] in rowset(P1) goto P2
84294 ** the value held in P3, jump to register P2. Otherwise, insert the
84295 ** integer in P3 into the RowSet and continue on to the
84299 ** are inserted in distinct phases, which each set contains no duplicates.
84321 /* If there is anything other than a rowset object in memory cell P1,
84350 ** cell in an array of values used as arguments to the sub-program. P2
84353 ** of a memory cell in this (the parent) VM that is used to allocate the
84365 Mem *pEnd; /* Last memory cell in new array */
84366 VdbeFrame *pFrame; /* New vdbe frame to execute in */
84380 ** disabled. In some cases a single trigger may generate more than one
84403 ** program stored in SubProgram.aOp. As well as these, one memory
84478 ** This opcode is only ever present in sub-programs called via the
84479 ** OP_Program instruction. Copy a value currently stored in a memory
84480 ** cell of the calling (parent) frame to cell P2 in the current frames
84484 ** The address of the cell in the parent frame is determined by adding
84548 ** P1 is a register in the root frame of this VM (the root frame is
84551 ** its current value and the value in register P2.
84580 ** value in P1 and jump to P2.
84602 ** of the LIMIT and OFFSET and stores that value in r[P2]. The r[P2]
84604 ** visited in order to complete the query.
84625 ** also loop forever. This is undocumented. In fact, one could argue
84641 ** initially greater than zero, then decrement the value in register P1.
84659 ** Register P1 must hold an integer. Decrement the value in P1
84695 ** the FuncDef stored in P4 is converted into an sqlite3_context and
84696 ** the opcode is changed. In this way, the initialization of the
84731 /* If this function is inside of a trigger, the register array in aMem[]
84805 ** Checkpoint database P1. This is a no-op if P1 is not currently in
84808 ** SQLITE_BUSY or not, respectively. Write the number of pages in the
84810 ** in the WAL that have been checkpointed after the checkpoint
84884 ** in temporary storage or if the VFS does not support shared memory
85010 ** P1 is the index of the database in sqlite3.aDb[] of the database
85062 ** P2 is a register that holds the name of a virtual table in database
85091 in database P1. Call the xDestroy method
85108 ** table and stores that cursor in P1.
85158 ** by P1. The integer query plan parameter to xFilter is stored in register
85260 ** Advance virtual table P1 to the next row in its result set and
85304 ** in register P1 is passed as the zName argument to the xRename method.
85337 ** invocation. The value in register (P3+P2-1) corresponds to the
85345 ** rowid for itself. The subsequent elements in the array are
85346 ** the values of columns in the new row.
85356 ** apply in the case of a constraint failure on an insert or update.
85415 ** Write the current number of pages in database P1 to memory cell P2.
85428 ** Try to set the maximum page count for database P1 to the value in P3.
85432 ** Store the maximum page count after the change in register P2.
85458 ** the UTF-8 string contained in P4 is emitted on the trace callback.
85536 ** satisfy the Expr in P4. TK_REGISTER terms in the P4 expression refer
85537 ** to values currently held in registers. TK_COLUMN terms in the P4
85538 ** expression refer to columns in the b-tree to which cursor P1 is pointing.
85564 ** the same as a no-op. This opcodesnever appears in a real VM program.
85676 ** The author disclaims copyright to this source code. In place of
85698 int nByte; /* Size of open blob, in bytes */
85699 int iOffset; /* Byte offset of blob in cursor data */
85716 ** contain a value of type TEXT or BLOB in the column nominated when the
85731 /* Set the value of register r[1] in the SQL statement to integer iRow.
85800 int iCol; /* Index of zColumn in row-record */
85983 ** we can invoke OP_Column to fill in the vdbe cursors type
86068 ** already been invalidated. Return SQLITE_ABORT in this case.
86087 ** SQLITE_UPDATE where the PK columns do not change is handled in the
86162 ** already been invalidated. Return SQLITE_ABORT in this case.
86188 ** The author disclaims copyright to this source code. In place of
86196 ** This file contains code for the VdbeSorter object, used in concert with
86211 ** object. The row is a binary blob in the
86214 ** in the case of a SELECT w/ ORDER BY, or
86216 ** in the case of a CREATE INDEX.
86232 ** Used to enforce uniqueness in a
86242 ** The interfaces above must be called in a particular order. Write() can
86243 ** only occur in between Init()/Reset() and Rewind(). Next(), Rowkey(), and
86244 ** Compare() can only occur in between Rewind() and Close()/Reset(). i.e.
86256 ** unsorted in main memory. Assuming the amount of memory used never exceeds
86258 ** an in-memory merge sort. In this case, no temporary files are required
86262 ** If the amount of space used to store records in main memory exceeds the
86263 ** threshold, then the set of records currently in memory are sorted and
86264 ** written to a temporary file in "Packed Memory Array" (PMA) format.
86273 ** that returned by "PRAGMA main.cache_size", in bytes.
86275 ** If the sorter is running in single-threaded mode, then all PMAs generated
86276 ** are appended to a single temporary file. Or, if the sorter is running in
86278 ** N is the configured number of worker threads. In this case, instead of
86284 ** The sorter is running in multi-threaded mode if (a) the library was built
86289 ** When Rewind() is called, any data remaining in memory is flushed to a
86290 ** final PMA. So at this point the data is stored in some number of sorted
86293 ** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the
86294 ** sorter is running in single-threaded mode, then these PMAs are merged
86296 ** MergeEngine object, described in further detail below, performs this
86299 ** Or, if running in multi-threaded mode, then a background thread is
86308 ** If there are more than SORTER_MAX_MERGE_COUNT PMAs in total when
86315 ** If running in multi-threaded mode and there are more than
86327 ** messages to stderr that may be helpful in understanding the performance
86328 ** characteristics of the sorter in multi-threaded mode.
86335 ** Hard-coded maximum amount of data to accumulate in memory before flushing
86348 typedef struct SortSubtask SortSubtask; /* A sub-task in the sort process */
86350 typedef struct SorterList SorterList; /* In-memory list of records */
86355 ** stored in the file.
86359 i64 iEof; /* Bytes of data stored in pFd */
86363 ** An in-memory list of objects to be sorted.
86367 ** are stored in the aMemory[] bulk memory, one right after the other, and
86373 int szPMA; /* Size of pList as PMA in bytes */
86379 ** combined into one big PMA in order to be able to step through the sorted
86380 ** records in order.
86386 ** actually N elements in size, where N is the smallest power of 2 greater
86390 ** The aTree[] array is also N elements in size. The value of N is stored in
86422 ** be advanced to the next key in its segment. Say the next key is
86436 ** In other words, each time we advance to the next sorter element, log2(N)
86448 ** This object represents a single thread of control in a sort operation.
86458 ** each thread requries its own UnpackedRecord object to unpack records in
86474 ** In both cases, the effects of the main thread seeing (bDone==0) even
86485 int nPMA; /* Number of PMAs currently in file */
86499 ** largest record in the sorter.
86502 int mnPmaSize; /* Minimum PMA size, in bytes */
86503 int mxPmaSize; /* Maximum PMA size, in bytes. 0==no limit */
86511 SorterList list; /* List of in-memory records */
86512 int iMemory; /* Offset of free space in list.aMemory */
86513 int nMemory; /* Size of list.aMemory allocation in bytes */
86527 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
86538 int nKey; /* Number of bytes in key */
86543 int nBuffer; /* Size of read buffer in bytes */
86558 ** and aFile[1]. Neither file is allowed to grow to more than mxSz bytes in
86594 ** size. But I/O is more efficient if it occurs in page-sized blocks where
86599 int eFWErr; /* Non-zero if in an error state */
86601 int nBuffer; /* Size of write buffer in bytes */
86604 i64 iWriteOff; /* Offset of start of buffer in file */
86610 ** held in memory and prior to being written out as part of a PMA.
86613 ** by this module. If using a separate allocation for each in-memory record
86621 ** has finished passing records to the sorter, or when the in-memory buffer
86627 int nVal; /* Size of the record in bytes */
86629 SorterRecord *pNext; /* Pointer to next record in list */
86667 ** The buffer returned in *ppOut is only valid until the
86676 int nAvail; /* Bytes of data available in buffer */
86688 ** than p->nBuffer bytes remaining in the PMA, read all remaining data. */
86710 /* The requested data is available in the in-memory buffer. In this
86716 /* The requested data is not all available in the in-memory buffer.
86717 ** In this case, allocate space at p->aAlloc[] to copy the requested
86732 /* Copy as much data as is available in the buffer into the start of
86795 ** *pp is undefined in this case.
86818 i64 iOff /* Offset in pFile */
86858 ** Advance PmaReader pReadr to the next key in its PMA. Return SQLITE_OK if
86863 u64 nRec = 0; /* Size of record in bytes */
86900 ** Initialize PmaReader pReadr to scan through the PMA stored in file pFile
86902 ** leaves the PmaReader pointing to the first key in the PMA (or EOF if the
86911 i64 iStart, /* Start offset in pFile */
86913 i64 *pnByte /* IN/OUT: Increment this value by PMA size */
86924 u64 nByte = 0; /* Size of PMA in bytes */
86960 ** If IN/OUT parameter *pbKey2Cached is true when this function is called,
87099 ** statement. In this case, keys are always delivered to the sorter in
87105 ** The sorter can guarantee a stable sort when running in single-threaded
87106 ** mode, but not in multi-threaded mode.
87112 int nField, /* Number of key fields in each record */
87119 int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
87120 int sz; /* Size of pSorter in bytes */
87173 i64 mxCache; /* Cache size in bytes*/
87180 ** KiB in size. */
87315 void *(*xTask)(void*), /* Routine to run in a separate thread */
87458 ** is guaranteed to be nByte bytes or smaller in
87459 ** attempts to extend the file to nByte bytes in size and to ensure that
87719 ** Write the current contents of in-memory linked-list pList to a level-0
87720 ** PMA in the temp file belonging to sub-task pTask. Return SQLITE_OK if
87726 ** in the PMA (not including the varint itself).
87728 ** * One or more records packed end-to-end in order of ascending keys.
87730 ** key). The varint is the number of bytes in the blob of data.
87815 ** advanced (iPrev) and the one next to it in the array. */
87820 /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
87833 ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
87834 ** case there is no cache of pReadr2 in pTask->pUnpacked, so set
87895 /* Select a sub-task to sort and flush the current list of in-memory
87896 ** records to disk. If the sorter is running in multi-threaded mode,
87978 ** already in memory and (b) the new value will not fit in memory.
87983 ** * The total memory allocated for the in-memory list is greater
87986 ** * The total memory allocated for the in-memory list is greater
88053 ** of the data stored in aFile[1] is the same as that used by regular PMAs,
88076 ** In either case exit the loop. */
88126 ** aFile[0] and aFile[1] in place. If the contents of pMerger have not
88168 ** If an OOM condition is encountered, return NULL. In this case free the
88210 int iOut /* Store the result in pMerger->aTree[iOut] */
88257 ** Only INCRINIT_NORMAL is valid in single-threaded builds (when
88275 ** MergeEngine object in the usual fashion.
88280 ** set the PmaReader objects up to read from it. In this case all that is
88299 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
88308 /* PmaReaders should be normally initialized in order, as if they are
88310 ** However, in the INCRINIT_ROOT case, if PmaReader aReadr[nTask-1] is
88311 ** in use it will block the vdbePmaReaderNext() call while it uses
88335 ** in the sub-tree headed by pReadr are also initialized. Data is then
88337 ** the first key in its range.
88340 ** to be a multi-threaded PmaReader and this function is being called in a
88341 ** background thread. In this case all PmaReaders in the sub-tree are
88348 ** in the INCRINIT_TASK case is that vdbePmaReaderNext() assumes that it has
88356 ** In this case vdbePmaReaderNext() is called on all child PmaReaders and
88357 ** the current PmaReader set to point to the first key in its range.
88367 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
88403 ** then this function is already running in background thread
88406 ** If this is the INCRINIT_ROOT object, then it is running in the
88425 ** The main routine for vdbePmaReaderIncrMergeInit() operations run in
88482 i64 *piOffset, /* IN/OUT: Readr offset in pTask->file */
88667 ** all records stored in the sorter.
88715 ** in single-threaded mode. This is important, as the
88751 ** in sorted order.
88763 ** from the in-memory list. */
88774 /* Write the current in-memory list to a PMA. When the VdbeSorterWrite()
88799 ** Advance to the next element in the sorter.
88840 int *pnKey /* OUT: Size of current key in bytes */
88883 ** Compare the key in memory cell pVal with the key that the sorter cursor
88892 ** key in pVal is smaller than, equal to or larger than the current sorter
88895 ** This routine forms the core of the OP_SorterCompare opcode, which in
88939 ** The author disclaims copyright to this source code. In place of
88948 ** This file contains code use to implement an in-memory rollback journal.
88949 ** The in-memory rollback journal is used to journal transactions for
88952 ** Update: The in-memory journal is also used to temporarily cache
88955 in memory, thus reducing the number of file I/O calls, and
88958 ** in the common case, they are usually small and no file I/O needs to
88971 ** The zChunk array is always at least 8 bytes in size - usually much more.
88972 ** Its actual size is stored in the MemJournal.nChunkSize variable.
88975 FileChunk *pNext; /* Next chunk in the journal */
89005 int nChunkSize; /* In-memory chunk-size */
89008 int nSize; /* Bytes of data currently in memory */
89009 FileChunk *pFirst; /* Head of in-memory chunk-list */
89019 ** Read data from the in-memory journal file. This is the implementation
89107 /* No error has occurred. Free the in-memory buffers. */
89113 ** the original before returning. This way, SQLite uses the in-memory
89146 /* If the contents of this write should be stored in memory */
89148 /* An in-memory journal file should only ever be appended to. Random
89150 ** the in-memory journal is being used by a connection using the
89151 ** atomic-write optimization. In this case the first 28 bytes of the
89202 ** is still in main memory but is being truncated to zero bytes in size,
89231 ** syncing an in-memory journal is a no-op.
89239 ** Query the size of the file in bytes.
89278 ** all content is always stored in main-memory. Finally, if nSpill is a
89279 ** positive value, then the journal file is initially created in-memory
89280 ** but may be flushed to disk later on. In this case the journal file is
89281 ** flushed to disk either when it grows larger than nSpill bytes in size,
89294 ** it using the sqlite3OsOpen() function of the underlying VFS. In this
89295 ** case none of the code in this module is executed as a result of calls
89318 ** Open an in-memory journal file.
89328 ** in-memory-only journal file (i.e. is one that was opened with a +ve
89340 ** paths are complex, so it seems prudent to leave the test in as
89341 ** a NEVER(), in case our analysis is subtly flawed. */
89356 ** Return true if this "journal file" is currently stored in heap memory,
89376 ** The author disclaims copyright to this source code. In place of
89394 ** of the expression, while descending. (In other words, the callback
89433 ** Call sqlite3WalkExpr() for every expression in list p or until
89465 ** Walk the parse trees associated with all subqueries in the
89468 ** and on any subqueries further down in the tree. Return
89493 ** Call sqlite3WalkExpr() for every expression in Select statement p.
89494 ** Invoke sqlite3WalkSelect() for subqueries in the FROM clause and
89540 ** The author disclaims copyright to this source code. In place of
89580 ** result set in pEList.
89600 int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
89641 ** Return TRUE if the name zCol occurs anywhere in the USING clause.
89658 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
89688 ** that name in the set of source tables in pSrcList and make the pExpr
89692 ** pExpr->iDb Set the index in db->aDb[] of the database X
89711 ** in pParse and return WRC_Abort. Return WRC_Prune on success.
89728 NameContext *pTopNC = pNC; /* First namecontext in the list */
89735 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
89743 /* Translate the schema name in zDb into a pointer to the corresponding
89745 ** resulting in an appropriate error message toward the end of this routine
89808 ** is for the right-hand table of a NATURAL JOIN or is in a
89907 ** we are resolving names in the WHERE clause of the following command:
89911 ** In cases like this, replace pExpr with a copy of the expression that
89912 ** forms the result set entry ("a+b" in the example) and return immediately.
89913 ** Note that the expression in the result set should have already been
89916 ** The ability to use an output result-set column in the WHERE, GROUP BY,
89917 ** or HAVING clauses, or as part of a larger expression in the ORDER BY
89961 ** If X and Y are NULL (in other words if only the column name Z is
89962 ** supplied) and the value of Z is enclosed in double-quotes, then
89963 ** Z is a string literal if it doesn't match any column names. In that
89968 ** fields are not changed in any context.
89994 /* If a column from a table in pSrcList is referenced, then record
89995 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
89997 ** column number is greater than the number of bits in the bitmask
90039 ** from datasource iSrc in SrcList pSrc.
90077 sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
90099 ** node in the expression tree. Return 0 to continue the search down
90130 ** column in the FROM clause. This is used by the LIMIT and ORDER BY
90153 ** be one call to lookupName(). Then the compiler will in-line
90192 int nId; /* Number of characters in function name */
90256 ** in an index. */
90365 ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
90369 ** elements in pEList, corresponding to the matching entry. If there is
90397 ** pE is a pointer to an expression which is a single term in the
90405 ** Attempt to match pE against result set columns in the left-most
90408 ** The left-most column is 1. In other words, the value returned is the
90409 ** same integer value that would be used in the SQL statement to indicate
90429 /* Resolve all names in the ORDER BY term expression
90445 ** in the result set. Return an 1-based index of the matching
90473 ** Analyze the ORDER BY clause in a compound SELECT statement. Modify
90475 ** and N where N is the number of columns in the compound SELECT.
90502 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
90568 "column in the result set", i+1);
90576 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
90599 sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType);
90619 ** pOrderBy is an ORDER BY or GROUP BY clause in SELECT statement pSelect.
90625 ** number of columns in the result set of the SELECT) then the expression
90626 ** in the resolution is a copy of the I-th result-set expression. If
90629 ** result-set expression. Otherwise, the expression is resolved in
90633 ** an appropriate error message might be left in pParse. (OOM errors
90646 int nResult; /* Number of terms in the result set */
90692 ** Resolve names in the SELECT statement p and all of its descendants.
90720 ** this routine in the correct order.
90735 /* Resolve the expressions in the LIMIT and OFFSET clauses. These
90747 ** In this case the ORDER BY clause (p->pOrderBy) should be resolved
90759 /* Recursively resolve names in all subqueries
90769 ** parent contexts. After resolving references to expressions in
90793 /* Resolve names in the result set. */
90796 /* If there are no aggregate functions in the result-set, and no GROUP BY
90797 ** expression, do not allow aggregates in any of the other expressions.
90816 ** other expressions in the SELECT statement. This is so that
90817 ** expressions in the WHERE clause (etc.) can refer to expressions by
90818 ** aliases in the result set.
90827 /* Resolve names in table-valued-function arguments */
90837 /* The ORDER BY and GROUP BY clauses may not refer to terms in
90884 sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
90892 ** number of expressions in the select list. */
90926 ** Y: The name of a table in a FROM clause. Or in a trigger
90929 ** Z: The name of a column in table Y.
90935 ** Expr.iColumn The column index in X.Y. -1 for the rowid.
90941 ** size of an AS clause in the result-set of a SELECT. The Z expression
90944 ** tree. For example, in:
90959 ** An error message is left in pParse if anything is amiss. The number
90963 NameContext *pNC, /* Namespace to resolve expressions in. */
91003 ** Resolve all names for all expression in an expression list. This is
91008 NameContext *pNC, /* Namespace to resolve expressions in. */
91021 ** Resolve all names in all expressions of a SELECT and in all
91023 ** subqueries in expressions, and subqueries used as FROM clause
91049 ** Resolve names in expressions that can only reference a single table:
91057 ** Any errors cause an error message to be set in pParse.
91088 ** The author disclaims copyright to this source code. In place of
91097 ** for generating VDBE code that evaluates expressions in SQLite.
91121 ** i.e. the WHERE clause expressions in the following statements all
91162 ** If a memory allocation error occurs, that fact is recorded in pParse->db
91236 ** a TK_COLUMN but was previously evaluated and cached in a register */
91325 ** pExpr is a comparison expression, eg. '=', '<', IN(...) etc.
91328 ** the comparison in pExpr.
91361 ** Argument pRight (but not pLeft) may be a null pointer. In this case,
91411 ** A vector is defined as any expression that results in two or more
91423 ** return the number of expressions in the vector. Or, if the expression
91424 ** is a sub-select, return the number of columns in the sub-select. For
91473 ** In that case, this routine works like sqlite3ExprDup().
91500 ** iColumn: Index of a column in pVector
91502 ** pLeft->iTable: First in an array of register holding result, or 0
91527 ** it. Return the register in which the result is stored (or, if the
91528 ** sub-select returns more than one column, the first in an array
91529 ** of registers in which the result is stored).
91550 ** already been generated using the exprCodeSubselect() routine. In this
91551 ** case parameter regSelect should be the first in an array of registers
91555 ** is generated. In this case (*pRegFree) may be set to the number of
91565 int regSelect, /* First in array of registers */
91675 ** expression depth allowed. If it is not, leave an error message in
91728 ** Set the Expr.nHeight variable in the structure passed as an
91753 ** leave an error in pParse.
91802 ** stored in u.zToken. Instead, the integer values is written
91870 ** In that case, delete the subtrees pLeft and pRight.
91951 ** boolean values in different circumstances (a false positive.)
92015 ** in the original SQL statement.
92141 ** to store a copy of an expression or expression tree. They differ in
92196 ** This function returns the space in bytes required to store the copy
92217 ** space to duplicate all Expr nodes in the tree formed by Expr.pLeft
92297 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
92305 /* Fill in pNew->pLeft and pNew->pRight. */
92375 ** part of the in-memory representation of the database schema.
92594 ** expression list pList. In the case of a subquery on the RHS, append
92614 ** wildcards ("*") in the result set of the SELECT must be expanded before
92638 /* Store the SELECT statement in pRight so it will be deleted when
92643 /* Remember the size of the LHS in iTable so that we can check that
92720 ** leave an error message in pParse.
92731 sqlite3ErrorMsg(pParse, "too many columns in %s", zObject);
92755 ** Return the bitwise-OR of all Expr.flags fields in the given
92784 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
92788 ** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
92840 /* A bound parameter in a CREATE statement that originates from
92892 ** for any single row of the table with cursor iCur. In other words, the
92932 ** in pGroupBy that sort with the BINARY collation sequence.
92935 ** be promoted into the WHERE clause. In order for such a promotion to work,
92939 ** grouping than binary. In other words (A=B COLLATE binary) implies
92940 ** A=B in every other collating sequence. The requirement that the
92991 ** to fit in a 32-bit integer, return 1 and put the value of the integer
92992 ** in *pValue. If the expression is not an integer or if it is too big
92993 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
92999 /* If an expression is an integer literal that fits in a signed 32-bit
93035 ** (returning TRUE when in fact the expression can never be NULL) might
93038 ** will likely result in an incorrect answer. So when in doubt, return
93063 ** unchanged by OP_Affinity with the affinity given in the second
93067 ** can be omitted. When in doubt return FALSE. A false negative
93068 ** is harmless. A false positive, however, can result in the wrong
93112 ** pX is the RHS of an IN operator. If pX is a SELECT statement
93140 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
93179 ** The argument is an IN operator with a list (not a subquery) on the
93195 ** This function is used by the implementation of the IN (...) operator.
93196 ** The pX parameter is the expression on the RHS of the IN operator, which
93200 ** be used either to test for membership in the RHS set or to iterate through
93203 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
93213 ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be
93221 ** If the RHS of the IN operator is a list or a more complex subquery, then
93230 ** IN index will be used to loop over all values of the RHS of the
93231 ** IN operator.
93245 ** if the RHS of the IN operator is a list (not a subquery) then this
93247 ** testing is too expensive and return IN_INDEX_NOOP. In that case, the
93248 ** calling routine should implement the IN operator using a sequence
93252 ** might need to know whether or not the RHS side of the IN operator
93259 ** If a register is allocated and its location stored in *prRhsHasNull, then
93260 ** the value in that register will be NULL if the b-tree contains one or more
93266 ** of the IN(...) operator. The i'th entry of the array is populated with the
93270 ** (?,?,?) IN (SELECT a, b, c FROM t1)
93278 Expr *pX, /* The right-hand side (RHS) of the IN operator */
93283 Select *p; /* SELECT to the right of IN operator */
93292 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
93295 ** to NOT NULL constraints in the schema). If no NULL values are possible,
93330 /* The "x IN (SELECT rowid FROM table)" case */
93344 ** comparison is the same as the affinity of each column in table
93345 ** on the RHS of the IN operator. If it not, it is not possible to
93361 ** and for the term on the LHS of the IN to have no affinity. */
93370 /* Search for an existing index that will work for this IN operator */
93384 continue; /* This index is not unique over the IN RHS columns */
93417 sqlite3MPrintf(db, "USING INDEX %s FOR IN-OPERATOR",pIdx->zName),
93444 /* If no preexisting index is available for the IN clause
93446 ** and the RHS of the IN operator is a list, not a subquery
93449 ** the IN operator so return IN_INDEX_NOOP.
93491 ** Argument pExpr is an (?, ?...) IN(...) expression. This
93537 ** Expression pExpr is a vector that has been used in a context where
93560 ** or IN operators. Examples:
93564 ** x IN (4,5,11) -- IN operator with list on right-hand side
93565 ** x IN (SELECT a FROM b) -- IN operator with subquery on the right
93567 ** The pExpr parameter describes the expression that contains the IN
93571 ** to be of the form "<rowid> IN (?, ?, ?)", where <rowid> is a reference
93572 ** to some integer key column of a table B-Tree. In this case, use an
93573 ** intkey B-Tree to store the set of IN(...) values instead of the usual
93576 ** If rMayHaveNull is non-zero, that means that the operation is an IN
93583 ** result. For a multi-column SELECT, the result is stored in a contiguous
93585 ** result column. Return 0 for IN operators or if an error occurs.
93590 Expr *pExpr, /* The IN, SELECT, or EXISTS operator */
93591 int rHasNullFlag, /* Register that records whether NULLs exist in RHS */
93592 int isRowid /* If true, LHS of IN operator is a rowid */
93600 /* The evaluation of the IN/EXISTS/SELECT must be repeated every time it
93628 Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
93635 /* Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)'
93654 /* Case 1: expr IN (SELECT ...)
93663 /* If the LHS and RHS of the IN operator do not match, that
93672 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
93691 /* Case 2: expr IN (exprlist)
93694 ** store it in the temporary table. If <expr> is a column, then use
93698 char affinity; /* Affinity of the LHS of the IN */
93713 /* Loop through each expression in <exprlist>. */
93770 ** In both cases, the query is augmented with "LIMIT 1". Any
93771 ** preexisting limit is discarded in place of the new LIMIT 1.
93826 ** Expr pIn is an IN(...) expression. This function checks that the
93827 ** sub-select on the RHS of the IN() operator has the same number of
93828 ** columns as the vector on the LHS. Or, if the RHS of the IN() is not
93848 ** Generate code for an IN expression.
93850 ** x IN (SELECT ...)
93851 ** x IN (value, value, ...)
93856 ** match the number of columns in the vector on the LHS. If the RHS is
93859 ** The IN operator is true if the LHS value is contained within the RHS.
93860 ** The result is false if the LHS is definitely not in the RHS. The
93861 ** result is NULL if the presence of the LHS in the RHS cannot be
93866 ** is contained in the RHS then jump to destIfNull. If the LHS is contained
93869 ** See the separate in-operator.md documentation file in the canonical
93874 Expr *pExpr, /* The IN expression */
93875 int destIfFalse, /* Jump here if LHS is not contained in the RHS */
93885 int nVector; /* Size of vectors for this IN operator */
93887 Expr *pLeft; /* The LHS of the IN operator */
93889 int destStep2; /* Where to jump when NULLs seen in step 2 */
93891 int addrTruthOp; /* Address of opcode that determines the IN is true */
93892 int destNotNull; /* Jump here if a comparison is not true in step 6 */
93910 VdbeNoopComment((v, "begin IN expr"));
93928 /* Code the LHS, the <expr> from "<expr> IN (...)". If the LHS is a
93929 ** vector, then it is stored in an array of nVector registers starting
93933 ** so that the fields are in the same order as an existing index. The
93952 ** suitable for evaluating the IN operator, then evaluate using a
93955 ** This is step (1) in the in-operator.md optimized algorithm.
94019 /* In this case, the RHS is the ROWID of table b-tree and so we also
94091 /* Jumps here in order to return true. */
94097 VdbeComment((v, "end IN expr"));
94181 ** Record in the column cache that a particular column from a
94182 ** particular table is stored in a particular register.
94203 ** that the object will never already be in cache. Verify this guarantee.
94267 ** the previous sqlite3ExprCachePush operation. In other words, restore
94268 ** the cache to the state it was in prior the most recent Push.
94291 ** register might be in the cache in multiple places, so be sure to
94312 int regOut /* Store the index column value in this register */
94357 ** table pTab and store the column value in a register.
94359 ** An effort is made to store the column value in register iReg. This
94360 ** is not garanteeed for GetColumn() - the result can be stored in
94361 ** any register. But the result is guaranteed to land in register iReg
94364 ** There must be an open cursor to pTab in iTable when this routine
94448 ** Return true if any register in the range iFrom..iTo (inclusive)
94452 ** and does not appear in a normal build.
94480 ** the result in continguous temporary registers. Return the index of
94516 ** expression. Attempt to store the results in register "target".
94520 ** be stored in target. The result might be stored in some other
94528 int inReg = target; /* Results stored in register inReg */
94568 in the index refer to the table to which the index belongs */
94796 /* Attempt a direct implementation of the built-in COALESCE() and
94889 ** see if it is a column in a virtual table. This is done because
94893 ** "glob(B,A). We want to use the A in "A glob B" to test
94894 ** for function overloading. But we use the B term in "glob(B,A)".
94962 ** X is stored in pExpr->pLeft.
94963 ** Y is stored in pExpr->pList->a[0].pExpr.
94964 ** Z is stored in pExpr->pList->a[1].pExpr.
94978 ** to a column in the new.* or old.* pseudo-tables available to
94979 ** trigger programs. In this case Expr.iTable is set to 1 for the
94988 ** set to (n+1), where n is the number of columns in each pseudo-table.
94989 ** For a reference to any other column in the new.* pseudo-table, p1
95059 ** X (if it exists) is in pExpr->pLeft.
95060 ** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
95061 ** odd. The Y is also optional. If the number of elements in x.pList
95063 ** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
95097 ** The value in regFree1 might get SCopy-ed into the file result.
95168 ** If regDest>=0 then the result is always stored in that register and the
95177 int regDest /* Store the value in this register */
95213 ** code to fill the register in the initialization section of the
95214 ** VDBE program, in order to factor it out of the evaluation loop.
95240 ** results in register target. The results are guaranteed to appear
95241 ** in register target.
95272 ** results in register target. The results are guaranteed to appear
95273 ** in register target. If the expression is constant, then this routine
95286 ** in register target.
95320 ** The SQLITE_ECEL_REF flag means that expressions in the list with
95322 ** in registers at srcReg, and so the value can be copied from there.
95384 ** NULL: Store the boolean result in reg[dest]
95397 Expr exprAnd; /* The AND operator in x>=y AND x<=z */
95426 ** for clarity, but we are out of bits in the Expr.flags field so we
95455 ** operation. Special comments in vdbe.c and the mkopcodeh.awk script in
95456 in the code
95749 ** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
95759 ** can be sure the expressions are the same. In the places where
95761 ** just might result in some slightly slower code. But returning
95809 ** non-zero if they differ in any way.
95812 ** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
95863 ** When in doubt, return false. Returning true might give a performance
95898 ** Check to see if there are references to columns in table
95917 ** that are not found in the index pIdx.
95942 ** to count references to table columns in the arguments of an
95943 ** aggregate function, in order to implement the
95947 SrcList *pSrc; /* One particular FROM clause in a nested query */
95948 int nThis; /* Number of references to columns in pSrcList */
95949 int nOther; /* Number of references to columns in other FROM clauses */
95959 ** sqlite3FunctionUsesThisSrc() is used differently in the future, the
95982 ** references columns but not columns of tables found in pSrcList.
96047 /* Check to see if the column is in one of the tables in the FROM
96056 ** that is in the FROM clause of the aggregate query.
96058 ** Make an entry for the column in pAggInfo->aCol[] if there
96097 /* There is now an entry for pExpr in pAggInfo->aCol[] (either
96117 ** function that is already in the pAggInfo structure
96126 /* pExpr is original. Make a new entry in pAggInfo->aFunc[]
96186 ** Call sqlite3ExprAnalyzeAggregates() for every expression in an
96299 ** The author disclaims copyright to this source code. In place of
96313 ** The code in this file only exists if we are not omitting the
96322 ** CREATE INDEX command. The second is a table name. The table name in
96350 /* The principle used to locate the table name in the CREATE TABLE
96361 /* Store the token that zCsr points to in tname. */
96365 /* Advance zCsr to the next token. Store that token type in 'token',
96366 ** and its length in 'len' (to be used next iteration of this loop).
96449 ** statement. The second is a table name. The table name in the CREATE
96472 /* The principle used to locate the table name in the CREATE TRIGGER
96485 /* Store the token that zCsr points to in tname. */
96489 /* Advance zCsr to the next token. Store that token type in 'token',
96490 ** and its length in 'len' (to be used next iteration of this loop).
96514 ** in the CREATE TRIGGER statement.
96524 ** Register built-in functions used to help implement ALTER TABLE
96552 ** In this case zWhere is passed to sqlite3DbFree() before returning.
96586 ** table pTab has no temporary triggers, or is itself stored in the
96594 /* If the table is not located in the temp-db (in which case NULL is
96597 ** expression being built up in zWhere.
96618 ** Argument zName is the name of the table in the database schema at
96655 /* Now, if the table is not stored in the temp database, reload any temp
96656 ** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.
96668 ** in pParse->zErr (system tables may not be altered) and returns non-zero.
96694 int nTabName; /* Number of UTF-8 characters in zTabName */
96719 ** in database iDb. If so, this is an error.
96789 /* figure out how many UTF-8 characters are in zName */
96834 /* If the sqlite_sequence table exists in this database, then update
96846 ** table. Don't do this if the table being ALTERed is itself located in
97012 ** This function is called by the parser after the table-name in
97061 /* Put a copy of the Table struct in Parse.pNewTable for the
97110 ** The author disclaims copyright to this source code. In place of
97131 ** Additional tables might be added in future releases of SQLite.
97140 ** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is
97150 ** name in the idx column. The tbl column is the name of the table to
97151 ** which the index belongs. In each such row, the stat column will be
97152 ** a string consisting of a list of integers. The first integer in this
97153 ** list is the number of rows in the index. (This is the same as the
97154 ** number of rows in the table, except for partial indices.) The second
97155 ** integer is the average number of rows in the index that have the same
97156 ** value in the first column of the index. The third integer is the average
97157 ** number of rows in the index that have the same value for the first two
97158 ** columns. The N-th integer (for N>1) is the average number of rows in
97160 ** a K-column index, there will be K+1 integers in the stat column. If
97163 ** The list of integers in the stat column can optionally be followed
97171 ** rows in the table identified by sqlite_stat1.tbl.
97180 ** the index belongs. There are usually 10 rows in the sqlite_stat2
97184 ** inclusive are samples of the left-most key value in the index taken at
97186 ** (10 in the standard build) and let C be the number of rows in the index.
97208 ** to aid the query planner in choosing good indices based on the values
97209 ** that indexed columns are compared against in the WHERE clauses of
97218 ** of entries in the index whose left-most column exactly matches
97219 ** the left-most column of the sample. The second integer in nEq
97220 ** is the approximate number of entries in the index where the
97224 ** integer in nLt contains the number of entries in the index where the
97226 ** The K-th integer in the nLt entry is the number of index entries
97229 ** number of distinct entries in the index that are less than the
97243 ** of a blob encoding of the complete index key as is found in
97246 ** integer in the equivalent columns in sqlite_stat4.
97274 ** or it may be a NULL pointer. If it is not NULL, then all entries in
97280 int iDb, /* The database we are looking in */
97323 ** of the new table in register pParse->regRoot. This is important
97379 i64 iRowid; /* Rowid in main table of the key */
97389 tRowcnt nRow; /* Number of rows in the entire table */
97391 int nCol; /* Number of columns in index + pk/rowid */
97397 int iMin; /* Index in a[] of entry with minimum score */
97399 int nMaxEqZero; /* Max leading 0 in anEq[] for any a[] entry */
97481 ** N: The number of columns in the index including the rowid/pk (note 1)
97482 ** K: The number of columns in the index excluding the rowid/pk.
97483 ** C: The number of rows in the index (note 2)
97485 ** Note 1: In the special case of the covering index that implements a
97487 ** total number of columns in the table.
97492 ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
97496 ** This routine allocates the Stat4Accum object in heap memory. The return
97507 int nCol; /* Number of columns in index being sampled */
97600 ** In other words, if we assume that the cardinalities of the selected
97665 ** values in the anEq[] array of any sample in Stat4Accum.a[]. In
97675 /* This sample is being added because the prefix that ends in column
97676 ** iCol occurs many times in the table. However, if we have already
97716 ** for the last sample in the p->a[] array. Otherwise, the samples would
97728 /* Zero the first nEqZero entries in the anEq[] array. */
97799 /* Or if it is a non-periodic sample. Add it in this case too. */
97824 ** statistical data and/or samples in the Stat4Accum object about the
97954 /* Return the value to store in the "stat" column of the sqlite_stat1
97958 ** the index. The first integer in the list is the total number of
97959 ** entries in the index. There is one additional integer in the list
97962 ** a key with the corresponding number of fields. In other words,
98144 int nCol; /* Number of columns in pIdx. "N" */
98212 ** (1) the number of columns in the index including the rowid
98214 ** (2) the number of columns in the key without the rowid/pk
98215 ** (3) the number of rows in the index,
98438 ** Generate code that will do an analysis of a single table in
98440 ** in pTab that should be analyzed.
98469 ** Form 1 causes all indices in all attached databases to be analyzed.
98484 ** and code in pParse and return NULL. */
98538 int nOut, /* Number of slots in aOut[] */
98604 ** Entries for which argv[1]==NULL simply record the number of rows in
98637 ** sqlite_stat1 entries for this index. In that case just clobber
98693 ** stored in pIdx->aSample[].
98714 tRowcnt nRow; /* Number of rows in index */
98716 i64 nDist100; /* Number of distinct values in index */
98729 ** occur in the stat4 table for this index. Set sumEq to the sum of
98790 Index *pPrevIdx = 0; /* Previous index in the loop */
98791 IndexSample *pSample; /* A slot in pIdx->aSample[] */
98803 int nIdxCol = 1; /* Number of columns in stat4 records */
98818 ** loaded from the stat4 table. In this case ignore stat3 data. */
98861 int nCol = 1; /* Number of columns in index */
98868 ** the sqlite_stat4 table. In this case ignore stat3 data. */
98881 ** This is in case the sample record is corrupted. In that case, the
98936 ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
98937 ** is returned. In this case, even if SQLITE_ENABLE_STAT3/4 was defined
98942 ** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
98943 ** returned. However, in this case, data is read from the sqlite_stat1
98989 /* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
99024 ** The author disclaims copyright to this source code. In place of
99123 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
99128 /* Allocate the new entry in the db->aDb[] array and initialize the schema
99468 ** was left unspecified in the original SQL statement. The pFix structure
99472 ** view in one database does not refer to objects in a different database.
99473 ** (Exception: indices, triggers, and views in the TEMP database are
99475 ** to an object in a different database, an error message is added to
99493 "%s %T cannot reference objects in database %s",
99610 ** The author disclaims copyright to this source code. In place of
99626 ** All of the code in this file may be omitted by defining a single
99703 ** table zTab in database zDb. This function assumes that an authorization
99708 ** is treated as SQLITE_DENY. In this case an error is left in pParse.
99741 ** is in pTabList or else it is the NEW or OLD table of a trigger.
99757 int iSrc; /* Index in pTabList->a[] of table being read */
99759 int iCol; /* Index of column in table */
99802 ** is returned, then the error count and error message in pParse are
99886 ** The author disclaims copyright to this source code. In place of
99895 ** when syntax rules are reduced. The routines in this file handle the
99924 ** The table to be locked has root page iTab and is found in database iDb.
100122 ** Run the parser and code generator recursively in order to generate
100169 ** Locate the in-memory structure that describes a particular database
100212 ** Locate the in-memory structure that describes a particular database
100215 ** error message in pParse->zErrMsg.
100218 ** routine leaves an error message in pParse->zErrMsg where
100222 Parse *pParse, /* context in which to report errors */
100230 ** and code in pParse and return NULL. */
100240 /* If zName is the not the name of a table in the schema created using
100291 ** Locate the in-memory structure that describes
100337 ** For the index called zIdxName which is found in the database iDb,
100368 ** Look through the list of open database files in db->aDb[] and if
100412 ** since TEMP might be holding triggers that reference tables in the
100477 ** contains lookaside memory. (Table objects in the schema do not use
100486 /* Record the number of outstanding lookaside allocations in schema Tables
100578 ** Open the sqlite_master table stored in database number iDb for
100593 ** function returns the index of the named database in db->aDb[], or
100613 ** index of the named database in db->aDb[], or -1 if the named db
100643 Token *pName1, /* The "xxx" in the name "xxx.yyy" or "xxx" */
100644 Token *pName2, /* The "yyy" in the name "xxx.yyy" */
100674 ** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
100709 ** Begin constructing a new table representation in memory. This is
100710 ** the first of several action routines that get called in response
100711 ** to a CREATE TABLE statement. In particular, this routine is called
100713 ** flag is true if the table should be stored in the auxiliary database
100714 ** file instead of in the main database file. This is normally the case
100715 ** when the "TEMP" or "TEMPORARY" keyword occurs in between
100718 ** The new table record is initialized and put in pParse->pNewTable.
100737 int iDb; /* Database number to create the table in */
100786 ** index or table name in the same database. Issue an error message if
100788 ** to an sqlite3_declare_vtab() call. In that case only the column names
100829 ** then record a pointer to this table in the main database structure
100840 ** the SQLITE_MASTER table. Note in particular that we must go ahead
100861 /* If the file format and encoding in the database have not been set,
100876 /* This just creates a place-holder record in the sqlite_master table.
100878 ** by the real entry in code generated at sqlite3EndTable().
100880 ** The rowid for the new entry is left in register pParse->regRowid.
100881 ** The root page number of the new table is left in reg pParse->regRoot.
100928 ** in a CREATE TABLE statement. sqlite3StartTable() gets called
100990 ** This routine is called by the parser while in the middle of
101008 ** substrings in the following table. If one of the substrings is
101025 ** If none of the substrings in the above table are found,
101097 ** This routine is called by the parser while in the middle of
101133 ** Historical versions of SQLite accepted strings as column names in
101134 ** indexes and PRIMARY KEY constraints and in UNIQUE constraints. Example:
101141 ** the expression given in its argument from a TK_STRING into a TK_ID
101304 ** in the database native encoding, the collation factory is invoked to
101306 ** and the sequence is available in another text encoding, then that is
101348 ** 1 chance in 2^32. So we're safe enough.
101382 ** to the specified offset in the buffer and updates *pIdx to refer
101557 ** (4) Set the Index.tnum of the PRIMARY KEY Index object in the
101650 /* Update the in-memory representation of all UNIQUE indices by converting
101703 ** An entry for the table is made in the master table on disk, unless
101707 ** recently changed, so the entry for this table already exists in
101718 Token *pEnd, /* The ')' before options in the CREATE TABLE */
101724 int iDb; /* Database in which the table lives */
101768 /* Resolve names in all CHECK constraint expressions.
101782 ** in the SQLITE_MASTER table of the database.
101816 ** new table is in register pParse->regRoot.
101818 ** Once the SELECT has been coded by sqlite3Select(), it is in a
101882 /* A slot for the record has already been allocated in the
101923 /* Add the table to the in-memory representation of the database.
101955 ** The parser calls this routine in order to create a new VIEW
101977 sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
102025 ** The Table structure pTable is really a VIEW. Fill in the names of
102026 ** the columns of the view in the pTable structure. Return the number
102027 ** of errors. If an error is seen leave an error message in pParse->zErrMsg.
102063 ** in the following:
102077 ** "*" elements in the results set of the view and will assign cursors
102100 ** The names of the columns in the table are taken from
102101 ** arglist which is stored in pTable->pCheck. The pCheck field
102141 ** Clear the column names from every VIEW in database idx.
102164 ** root-page of a table or index in database iDb has changed from iFrom
102176 ** in order to be certain that we got the right one.
102216 /* OP_Destroy stores an in integer r1. If this integer
102221 ** The "#NNN" in the SQL is a special constant that means whatever value
102222 ** is in register NNN. See grammar rules associated with the TK_REGISTER
102235 ** in case a root-page belonging to another table is moved by the btree layer
102249 ** table and index root-pages in order, starting with the numerically
102258 ** and root page 5 happened to be the largest root-page number in the
102293 ** Remove entries from the sqlite_statN tables (for N in (1,2,3))
102350 ** at the btree level, in case the sqlite_sequence table needs to
102351 ** move as a result of the drop (can happen in auto-vacuum mode).
102365 ** created in the temp database that refers to a table in another
102493 ** in the current table point to the foreign key. If pFromCol==0 then
102496 ** of tables in the parent pTo table. flags contains all
102498 ** in the ON DELETE, ON UPDATE and ON INSERT clauses.
102501 ** under construction in the pParse->pNewTable field.
102508 ExprList *pFromCol, /* Columns in this table that point to other table */
102510 ExprList *pToCol, /* Columns in the other table */
102537 "number of columns in foreign key does not match the number of "
102538 "columns in the referenced table");
102575 "unknown column \"%s\" in foreign key definition",
102640 ** content of an index in response to a REINDEX command.
102652 int iSorter; /* Cursor opened by OpenSorter (if in use) */
102733 ** pointer to this extra space in *ppExtra.
102737 i16 nCol, /* Total number of columns in the index */
102791 int nName; /* Number of characters in zName */
102794 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
102938 ** "sqlite3_butoindex..." in order to make the names distinct.
103023 ** report any errors. In the common case where the expression is exactly
103024 ** a table column, store that column in aiColumn[]. For general expressions,
103025 ** populate pIndex->aColExpr and store XN_EXPR (-2) in aiColumn[].
103042 sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and "
103147 ** the constraint occur in different orders, then the constraints are
103148 ** considered distinct and both result in separate indices.
103170 ** constraint specified somewhere in the CREATE TABLE statement.
103191 ** in-memory database structures.
103214 ** the index in the sqlite_master table and populate the index with
103220 ** or UNIQUE index in a CREATE TABLE statement. Since the table
103235 ** doing so, code a Noop instruction and store its address in
103236 ** Index.tnum. This is required in case this index is actually a
103237 ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
103258 /* Add an entry in sqlite_master for this index
103287 ** processing (in sqlite3GenerateConstraintChecks()) as part of
103319 ** aiRowEst[0] is supposed to contain the number of elements in the index.
103321 ** number of rows in the table that match any particular value of the
103331 ** are based on typical values found in actual indices.
103343 /* Set the first entry (number of rows in the index) to the estimated
103344 ** number of rows in the table, or half the number of rows in the table
103430 ** pArray is a pointer to an array of objects. Each object in the
103431 ** array is szEntry bytes in size. This routine uses sqlite3DbRealloc()
103435 ** the array (in entries - so the allocation is ((*pnEntry) * szEntry) bytes
103436 ** in total).
103441 ** returned. *pIdx is set to the index of the new array entry in this case.
103449 int szEntry, /* Size of each object in the array */
103450 int *pnEntry, /* Number of objects currently in use */
103512 ** Return the index in pList of the identifier named zId. Return -1
103547 int iStart /* Index in pSrc->a[] of first new slot */
103593 ** need be. A new entry is created in the SrcList even if pTable is NULL.
103608 ** In other words, if call like this:
103618 ** then so is B. In other words, we never have a case where:
103663 ** Assign VdbeCursor index numbers to all tables in a SrcList
103706 ** are the name of the table and database named in the FROM clause term.
103723 Select *pSubquery, /* A subquery used in place of a table name */
103797 ** When building up a FROM clause in the parser, the join operator
103808 ** in p->a[0] and p->a[1], respectively. The parser initially stores the
103902 ** the number of errors. Leave any error messages in the pParse structure.
103992 ** inserting multiple rows in a table, or inserting a row and index entries.)
104003 ** possible to abort a statement prior to completion. In order to
104012 ** makes it more difficult to prove that the code is correct (in
104137 ** Recompute all indices of all tables in all databases where the
104146 HashElem *k; /* For looping over tables in pDb */
104147 Table *pTab; /* A table in the database */
104168 ** Form 1 causes all indices in all attached databases to be rebuilt.
104169 ** Form 2 rebuilds all indices in all databases that use the named
104178 in the database */
104185 ** and code in pParse and return NULL. */
104278 ** not, store an error in the Parse structure. */
104335 ** The author disclaims copyright to this source code. In place of
104352 ** in the encoding enc of name zName, length nName.
104378 ** collation function in the best encoding but there may be other versions
104402 ** requested collation sequence is not available in the desired encoding.
104407 ** The return value is either the collation sequence to be used in database
104474 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
104479 ** the collation sequence name. A pointer to this string is stored in
104505 /* If a malloc() failure occurred in sqlite3HashInsert(), it will
104555 ** matches the request for a function with nArg arguments in a system
104560 ** is also -1. In other words, we are searching for a function that
104706 /* If no match is found, search the built-in functions.
104708 ** If the SQLITE_PreferBuiltin flag is set, then search the built-in
104710 ** priority to built-in functions.
104715 ** new function. But the FuncDefs for built-in functions are read-only.
104823 ** The author disclaims copyright to this source code. In place of
104832 ** in order to generate code for DELETE FROM statements.
104837 ** While a SrcList can in general represent multiple tables and subqueries
104838 ** (as in the FROM clause of a SELECT statement) in this case it contains
104839 ** the name of a single table, as one might find in an INSERT, DELETE,
104840 ** or UPDATE statement. Look up that table in the symbol table and
104844 ** The following fields are initialized appropriate in pSrc:
104880 ** In either case leave an error message in pParse and return non-zero.
104904 ** Evaluate a view and store its result in an ephemeral table. The
104906 ** set of rows in the view that are to be added to the ephemeral table.
104955 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
104981 ** DELETE FROM table_a WHERE rowid IN (
105004 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
105043 NameContext sNC; /* Name context to resolve expressions in */
105052 i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
105054 i16 nKey; /* Number of memory cells in the row key */
105061 ** subqueries in the WHERE clause */
105076 ** put in an SrcList structure because some of the subroutines we
105151 /* Resolve the column names in the WHERE clause.
105258 ** one, so just keep it in its register(s) and fall through to the
105312 /* Set up a loop over the rowids/primary-keys that were found in the
105391 ** they may interfere with compilation of other functions in this file
105392 ** (or in another file, if this file becomes part of the amalgamation). */
105409 ** in the case of a rowid table, or the PRIMARY KEY index in the case
105415 ** 3. The primary key for the row to be deleted must be stored in a
105417 ** that a search record formed from OP_MakeRecord is contained in the
105428 ** of a ONEPASS delete that affects multiple rows. In this case, if
105455 int iOld = 0; /* First register in OLD.* array */
105476 ** use for the old.* references in the triggers. */
105478 u32 mask; /* Mask of OLD.* columns in use */
105531 ** a view (in which case the only effect of the DELETE statement is to
105558 ** handle rows (possibly in other tables) that refer via a foreign key
105626 ** Generate code that will assemble an index key and stores it in register
105632 ** Return a register number which is the first in a block of
105637 ** If *piPartIdxLabel is not NULL, fill it in with a label and jump
105650 ** a column in common, then the register corresponding to that column already
105695 ** might be stored in the table as an integer (using a compact
105730 ** The author disclaims copyright to this source code. In place of
105739 ** functions of SQLite. (Some function, and in particular the date and
105903 ** in haystack and returns the number of previous characters plus 1,
105907 ** the number of bytes in haystack prior to the first occurrence of needle,
105908 ** or 0 if needle never occurs in haystack.
106029 ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
106099 /* If Y==0 and X will fit in a 64-bit int,
106191 ** routines in the function table. The noopFunc macro provides this.
106212 ** in a way that is testable, mask the sign bit off of negative
106213 ** values, resulting in a positive value. Then take the
106308 ** character is exactly one byte in size. Also, provde the Utf8Read()
106309 ** macro for fast reading of the next character in the common case where
106340 ** SQLITE_NOWILDCARDMATCH: No match in spite of having * or % wildcards.
106351 ** [^...] Matches one character not in the enclosed list.
106354 ** in the list by making it the first character after '[' or '^'. A
106357 ** it the last character in the list.
106370 ** This routine is usually quick, but can be N**2 in the worst case.
106386 /* Skip over multiple "*" characters in the pattern. If there
106402 ** recursive search in this case, but it is an unusual case. */
106414 ** pattern string past the "*". Search in the input string for the
106419 ** c but in the other case and search the input string for either
106524 ** the build-in LIKE operator. The first argument to the function is the
106560 ** of deep recursion and N*N behavior in patternCompare().
106714 ** "NULL". Otherwise, the argument is enclosed in single quotes with
106991 int nIn; /* Number of bytes in input */
106994 unsigned char *aLen = 0; /* Length of each character in zCharSet */
106995 unsigned char **azChar = 0; /* Individual characters in zCharSet */
106996 int nChar; /* Number of characters in zCharSet */
107067 ** The "unknown" function is automatically substituted in place of
107072 ** involving application-defined functions to be examined in a generic
107194 ** 0.0 in that case. In addition, TOTAL always returns a float where
107243 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
107385 ** of the built-in functions above are part of the global function set.
107408 ** Register the built-in LIKE and GLOB functions. The caseSensitive
107455 ** the first three statements in the compareInfo structure. The
107467 ** All of the FuncDef structures in the aBuiltinFunc[] array above
107476 ** defined in this file.
107581 #if 0 /* Enable to print out how the built-in functions are hashed */
107602 ** The author disclaims copyright to this source code. In place of
107622 ** Foreign keys in SQLite come in two flavours: deferred and immediate.
107657 ** row in the parent table. Decrement the counter for each row
107664 ** deleted row in the child table. If such a row is not found,
107669 ** in the parent table. For each found increment the counter.
107692 ** statement that inserts a single row only (no triggers). In this case,
107743 ** A foreign key constraint requires that the key columns in the parent
107755 ** N is the number of columns in the parent key. The first element of the
107757 ** constraint to the parent table column stored in the left-most column
107775 ** consists of a different number of columns to the child key in
107783 Parse *pParse, /* Parse context to store any error in */
107787 int **paiCol /* OUT: Map of index columns in pFKey */
107791 int nCol = pFKey->nCol; /* Number of columns in parent key */
107845 ** map to an explicit list of columns in table pParent. Check if this
107850 i16 iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
107858 ** unusable. Bail out early in this case. */
107899 ** row in the parent table that corresponds to the row being inserted into
107902 ** found in the parent table:
107914 ** These operations are identified in the comment at the top of this file
107921 Index *pIdx, /* Unique index on parent key columns in pTab */
107937 ** Check if any of the key columns in the child table row are NULL. If
107939 ** search for a matching row in the parent table. */
108113 ** the number of FK violations in the db) or +1 when deleting one (as this
108116 ** The code generated by this function scans through the rows in the child
108134 ** These operations are identified in the comment at the top of this file
108177 i16 iCol; /* Index of column in child table */
108178 const char *zCol; /* Name of column in child table */
108198 ** for WITHOUT ROWID tables. In the second form, the primary key is
108226 /* Resolve the references in the WHERE clause. */
108232 /* Create VDBE to loop through the entries in pSrc that match the WHERE
108296 ** constraint violations in the database,
108355 ** actually updated, the corresponding element in the aChange[] array
108382 ** actually updated, the corresponding element in the aChange[] array
108438 ** first register in an array of (pTab->nCol+1) registers containing the
108441 ** zero in this case.
108479 Index *pIdx = 0; /* Index on key columns in pTo */
108494 ** on the parent key columns in the parent table. If either of these
108495 ** schema items cannot be located, set an error in pParse and return
108506 /* If isIgnoreErrors is true, then a table is being dropped. In this
108508 ** before actually dropping it in order to check FK constraints.
108551 ** in the parent table. */
108592 ** an immediate foreign key violation. So do nothing in this case. */
108621 ** So do not set the "may-abort" flag in this case.
108632 ** child table to fire. In these cases the fk constraint counters
108650 ** row contained in table pTab.
108680 ** row contained in table pTab. If the operation is a DELETE, then
108682 ** to an array of size N, where N is the number of columns in table pTab.
108684 ** entry in the aChange[] array is set to -1. If the column is modified,
108710 ** table in question is either the child or parent table for any
108751 ** For example, if pFKey is the foreign key and pTab is table "p" in
108786 int nFrom; /* Length in bytes of zFrom */
108802 Token tFromCol; /* Name of column in child table */
108803 Token tToCol; /* Name of column in parent table */
108804 int iFromCol; /* Idx of column in child table */
108893 sizeof(TriggerStep) + /* Single step in trigger program */
109003 /* EV: R-30323-21917 Each foreign key constraint in SQLite is
109025 ** The author disclaims copyright to this source code. In place of
109034 ** to handle INSERT statements in SQLite.
109050 int iDb, /* The database index in sqlite3.aDb[] */
109075 ** pIdx. A column affinity string has one character for each column in
109087 ** rowid that appears as the last column in every index.
109181 ** Return non-zero if the table pTab in database iDb or any of its indices
109182 ** have been opened at any point in the VDBE program. This is used to see if
109223 ** which is in database iDb. Return the register number for the register
109238 ** (3) Register to hold the rowid in sqlite_sequence of pTab
109266 pToplevel->nMem++; /* Rowid in sqlite_sequence */
109329 ** larger than the maximum rowid in the memId memory cell, then the
109411 ** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST
109435 ** in other words if the SELECT pulls all columns from a single table
109445 ** transfer all records in <table2> over to <table>
109461 ** loop over the rows in the SELECT
109475 ** that is also read as part of the SELECT. In the third form,
109482 ** loop over the tables in the SELECT
109512 int nColumn; /* Number of columns in the data */
109520 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
109523 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
109526 u8 bIdListInOrder; /* True if IDLIST is in table order */
109632 /* If this is an AUTOINCREMENT table, look up the sequence number in the
109633 ** sqlite_sequence table and store it in memory cell regAutoinc.
109653 ** is named in the IDLIST, then record in the ipkColumn variable
109655 ** the index of the primary key as it appears in IDLIST, not as
109656 ** is appears in the original table. (The index of the INTEGER
109657 ** PRIMARY KEY in the original table is pTab->iPKey.)
109722 ** temp table in the case of row triggers.
109777 ** column index in the original table definition.
109783 /* Make sure the number of columns in the source data matches the number
109976 ** in its place. Hence, fill this column with a NULL to avoid
110029 ** parent table in a foreign key constraint. It is safe to set the
110030 ** flag in the second case as if any REPLACE constraint is hit, an
110098 ** they may interfere with compilation of other functions in this file
110099 ** (or in another file, if this file becomes part of the amalgamation). */
110111 ** Meanings of bits in of pWalker->eCode for checkConstraintUnchanged()
110141 ** changing columns (or the rowid if it is changing). In other words,
110143 ** the new row in the UPDATE statement.
110167 ** The regNewData parameter is the first register in a range that contains
110169 ** pTab->nCol+1 registers in this range. The first register (the one
110170 ** that regNewData points to) will contain the new rowid, or NULL in the
110171 ** case of a WITHOUT ROWID table. The second register in the range will
110194 ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
110203 ** for the first index in the pTab->pIndex list. Cursors for other indices
110227 ** any IGNORE The attempt in insert or update the current
110239 ** CHECK REPLACE Illegal. The results in an exception.
110252 int regNewData, /* First register in a range holding values to insert */
110270 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
110284 ** normal rowid tables. nPkField is the number of key fields in the
110285 ** pPk index or 1 for a rowid table. In other words, nPkField is the
110286 ** number of fields in the true primary key of the table. */
110381 ** exist in the table.
110386 /* Figure out what action to take in case of a rowid collision */
110417 /* Check to see if the new rowid already exists in the table. Skip
110528 ** the insert or update. Store that record in the aRegIdx[ix] register
110555 /* In an UPDATE operation, if this index is the PRIMARY KEY index
110564 /* Find out what action to take in case there is a uniqueness conflict */
110614 ** store it in registers regR..regR+nPk-1 */
110698 ** to be the number of columns in table pTab that must not be NULL-trimmed.
110812 ** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
110813 ** ROWID table) is returned in *piDataCur. The first index cursor is
110814 ** returned in *piIdxCur. The number of indices is returned.
110821 ** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
110849 ** can detect if they are used by mistake in the caller. */
110897 ** for index pDest in an insert transfer optimization. The rules
110924 return 0; /* Different expressions in the index */
110949 ** performance. Raw index records are transferred in the same way.
110953 ** embedded in the code for details.
110957 ** is empty - a factor that can only be determined at run-time. In that
110960 ** xfer optimization code if the test fails. In that case, this routine
110976 Table *pSrc; /* The table in the FROM clause of SELECT */
111050 ** correct syntactic form to participate in this optimization. Now
111073 return 0; /* Number of columns must be the same in tab1 and tab2 */
111117 return 0; /* pDestIdx has no corresponding index in pSrc */
111163 /* In some circumstances, we are able to run the xfer optimization
111238 ** index will be populated by inserting keys in strictly sorted
111239 ** order. In this case, instead of seeking within the b-tree as part
111247 ** a VACUUM command. In that case keys may not be written in strictly
111288 ** The author disclaims copyright to this source code. In place of
111296 ** Main file for the SQLite library. The routines in this file
111297 ** implement the programmer interface to the library. Routines in
111309 ** If the SQL is a query, then for each row in the query result
111436 ** The author disclaims copyright to this source code. In place of
111449 #define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
111451 /************** Include sqlite3ext.h in the middle of loadext.c **************/
111456 ** The author disclaims copyright to this source code. In place of
111478 ** WARNING: In order to maintain backwards compatibility, add new
111480 ** interfaces in the middle of this structure, then older different
111743 ** is also defined in the file "loadext.c".
112019 /************** Continuing where we left off in loadext.c ********************/
112123 ** in order to preserve backwards compatibility.
112430 ** Attempt to load an SQLite extension library contained in the file
112431 ** zFile. The entry point is zProc. zProc may be 0 in which case a
112514 ** character in the filename after the last "/" upto the first ".",
112548 "no entry point [%s] in shared library [%s]", zEntry, zFile);
112597 ** Call this routine when the database connection is closing in order
112611 ** default so as not to open security holes in older applications.
112635 u32 nExt; /* Number of entries in aExt[] */
112641 ** we have to locate the state vector at run-time. In the more common
112751 ** If anything goes wrong, set an error in the database connection.
112797 ** The author disclaims copyright to this source code. In place of
112820 ** object. This ensures that the aPragmaName[] table is arranged in
112822 ** Do not edit pragma.h directly. Edit and rerun the script in at
112824 /************** Include pragma.h in the middle of pragma.c *******************/
112944 /* Definitions of all built-in pragmas */
112949 u8 iPragCName; /* Start of column names in pragCName[] */
113444 /************** Continuing where we left off in pragma.c *********************/
113523 ** backed temporary databases, 2 for the Red-Black tree in memory database
113669 ** defined in pager.h. This function returns the associated lowercase
113692 ** Locate a pragma in the aPragmaName[] array.
113715 ** held in register regResult. Decrement the result count and halt if
113766 ** index of the database this pragma is being applied to in db.aDb[]. */
113802 ** file control is an array of pointers to strings (char**) in which the
113830 /* Locate the pragma in the lookup table */
113856 ** pages in the page cache. The second form sets both the current
113858 ** stored in the database file.
113907 ** database page size in bytes. The second form sets the
113960 ** maximum number of pages in the database file. The
113970 ** Return the number of pages in the specified database.
114004 ** of the PRAGMA command. In this case the locking-mode must be
114110 ** incr-vacuum flags. This is required in case this connection
114117 ** "incremental", write the value of meta[6] in the database
114176 ** number of pages in the cache. If N is negative, then the
114203 ** number of pages in the cache. If N is negative, then the
114243 ** The parameter N is measured in bytes.
114452 ** in auto-commit mode. */
114683 Index *pIdx; /* Index in the parent table */
114686 HashElem *k; /* Loop counter: Next table in schema */
114748 ** row cannot cause an FK violation. Jump directly to addrOk in
114836 ** In this case, the integrity of database iDb only is verified by
114840 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
114877 ** for all tables and indices in the database.
114908 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
114953 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
114975 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
115023 sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
115034 sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
115075 ** In its first form, this pragma returns the encoding of the main
115079 ** has not already been initialized. In this case it sets the default
115084 ** In all cases new databases created using the ATTACH command are
115089 ** In the second form this pragma sets the text encoding to be used in
115159 ** stored in the database header.
115215 ** Return the names of all compile-time options used in this build,
115260 ** after accumulating N frames in the log. Or query for the current value
115292 ** Attempt to optimize the database. All schemas are optimized in the first
115293 ** two forms, and only the specified schema is optimized in the latter two.
115297 ** this pragma will perform new optimizations in future releases.
115309 ** information from the current session in the
115323 ** In the current implementation, a table is analyzed if only if all of
115333 ** the number of rows in the table has increased by 25 times or more
115336 ** The rules for when tables are analyzed are likely to change in
115344 Table *pTab; /* A table in the schema */
115364 /* If table pTab has not been used in a way that would benefit from
115856 ** The author disclaims copyright to this source code. In place of
116005 /* Construct the in-memory representation schema tables (sqlite_master or
116062 ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
116127 /* Ticket #2804: When we open a database in the newer file format,
116169 ** the schema loaded, even if errors occurred. In this situation the
116204 ** bit is set in the flags field of the Db structure. If the database
116227 ** schema may contain references to objects in other databases.
116267 ** Check schema cookies in all databases. If any cookie is out
116297 ** value stored as part of the in-memory schema representation,
116315 ** which database file in db->aDb[] the schema refers to.
116323 /* If pSchema is NULL, then return -1000000. This happens when code in
116325 ** created by a sub-select). In this case the return value of this
116346 ** Free all memory allocations in the pParse object
116367 int nBytes, /* Length of zSql in bytes. */
116387 ** some other database connection is holding a write-lock, which in
116393 ** back and different changes are made in their place, then when this
116398 ** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
116518 int nBytes, /* Length of zSql in bytes. */
116584 ** Two versions of the official API. Legacy and new use. In the legacy
116585 ** version, the original SQL text is not saved in the prepared statement
116587 ** sqlite3_step(). In the new version, the original SQL text is retained
116594 int nBytes, /* Length of zSql in bytes. */
116606 int nBytes, /* Length of zSql in bytes. */
116624 int nBytes, /* Length of zSql in bytes. */
116631 ** tricky bit is figuring out the pointer to return in *pzTail.
116672 ** Two versions of the official API. Legacy and new use. In the legacy
116673 ** version, the original SQL text is not saved in the prepared statement
116675 ** sqlite3_step(). In the new version, the original SQL text is retained
116682 int nBytes, /* Length of zSql in bytes. */
116694 int nBytes, /* Length of zSql in bytes. */
116711 ** The author disclaims copyright to this source code. In place of
116720 ** to handle SELECT statements in SQLite.
116810 ExprList *pEList, /* which columns to include in the result */
116883 ** Return a pointer to the right-most SELECT statement in a compound.
116893 ** in terms of the following bit values:
116905 ** a join type, but put an error in the pParse structure.
116914 u8 i; /* Beginning of keyword text in zKeyText[] */
116915 u8 nChar; /* Length of the keyword in characters */
116965 ** Return the index of a column in a table. Return -1 if the column
116966 ** is not contained in the table.
116977 ** Search the first N tables in pSrc, from left to right, looking for a
116987 int N, /* Number of tables in pSrc->a[] to search */
116992 int i; /* For looping over tables in pSrc */
117016 ** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the
117022 SrcList *pSrc, /* List of tables in FROM clause */
117023 int iLeft, /* Index of first table to join in pSrc */
117024 int iColLeft, /* Index of column in first table */
117025 int iRight, /* Index of second table in pSrc */
117026 int iColRight, /* Index of column in second table */
117028 Expr **ppWhere /* IN/OUT: The WHERE clause to add to */
117055 ** And set the Expr.iRightJoinTable to iTable for every term in the
117060 ** join restriction specified in the ON or USING clause and not a part
117063 ** originated in the ON or USING clause.
117067 ** explicitly mentioned in the expression. That information is needed
117073 ** term until after the t2 loop of the join. In that way, a
117076 ** after the t1 loop and rows with t1.x!=5 will never appear in
117101 ** The terms of a FROM clause are contained in the Select.pSrc structure.
117102 ** The left most table is the first entry in Select.pSrc. The right-most
117103 ** table is the last entry. The join operator is held in the entry to
117111 SrcList *pSrc; /* All tables in the FROM clause */
117128 ** every column that the two tables have in common.
117137 char *zName; /* Name of column in the right table */
117139 int iLeftCol; /* Matching column in the left table */
117149 /* Disallow both ON and USING clauses in the same join
117153 "clauses in the same join");
117167 ** in the USING clause. Example: If the two tables to be joined are
117170 ** Report an error if any column mentioned in the USING clause is
117171 ** not contained in both tables to be joined.
117176 char *zName; /* Name of the term in the USING clause */
117187 "not present in both tables", zName);
117207 ** Generate code that will push the record in registers regData
117216 int nData, /* Number of elements in the data array */
117222 int nBase = nExpr + bSeq + nData; /* Fields in sorter record */
117303 ** fills up, delete the least entry in the sorter after each insert.
117304 ** Thus we never hold more than the LIMIT+OFFSET rows in memory at once */
117315 ** the same iteration of the inner loop are in sorted order, then
117345 ** seen combinations of the N values. A new entry is made in iTab
117375 ** are evaluated in order to get the data for this row. If srcTab is
117398 /* Usually, regResult is the first cell in an array of memory cells
117399 ** containing the current result row. In this case regOrig is set to the
117402 ** from this array. In this case regOrig is set to zero. */
117430 ** there are columns in the table on the left. The error will be caught
117432 ** to avoid other spurious errors in the meantime. */
117453 /* For each expression in pEList that is a copy of an expression in
117536 /* In this mode, write each query result to the key of the temporary
117575 ** in the index, do not write it to the output. If not, add the
117599 /* If we are creating a set for an "expr IN (SELECT ...)" construct,
117606 ** ORDER BY in this case since the order of entries in the set
117607 ** does not matter. But there might be a LIMIT clause, in which
117623 /* If any row exist in the result set, record that fact and abort.
117632 ** store the results in the appropriate memory cell or array of
117667 ** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
117728 ** there is a sorter, in which case the sorter has already limited
117791 ** the collating sequence for each expression in that expression list.
117866 ** in sqlite3Select() to assign values to structure member variables that
117917 ** then the results were placed in a sorter. After the loop is terminated
118053 ** result in *pEstWidth.
118058 ** is considered a column can be complex in the presence of subqueries. The
118059 ** result-set expression in all of the following SELECT statements is
118102 ** extracted from in NameContext.pSrcList. This table may be real
118107 int iCol = pExpr->iColumn; /* Index of column in pTab */
118131 ** when columnType() is called on the expression "t1.col" in the
118132 ** sub-select. In this case, set the column type to NULL, even
118144 /* The "table" is actually a sub-select or a view in the FROM clause
118193 ** origin info for the single column in the result set of the SELECT
118223 ** in the result set.
118247 ** column specific strings, in case the schema is reset before this
118264 ** in the result set. This information is used to provide the
118265 ** azCol[] values in the callback.
118345 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
118357 int nCol; /* Number of columns in the result set */
118360 int nName; /* Size of name in zName[] */
118445 ** This routine requires that all identifiers in the SELECT
118531 ** If an error occurs, return NULL and leave a message in pParse.
118552 ** that appear in the original SQL statement after the LIMIT and OFFSET
118692 ** There is exactly one reference to the recursive-table in the FROM clause
118698 ** extracted row (now in the iCurrent table) becomes the content of the
118708 ** If the query has an ORDER BY, then entries in the Queue table are kept in
118725 int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
118766 ** the Distinct table must be exactly one greater than Queue in order
118797 /* Store the results of the setup-query in Queue. */
118803 /* Find the next row in the Queue and output that row */
118806 /* Transfer the next row in Queue over to Current */
118815 /* Output the single row in Current */
118826 /* Execute the recursive SELECT taking the single row in Current as
118827 ** the value for the recursive-table. Store the results in the Queue.
118908 ** in which case this routine will be called recursively.
118925 ** The arrows in the diagram above represent the Select.pPrior pointer.
118927 ** pPrior will be the t2 query. p->op will be TK_UNION in this case.
118949 ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
118987 /* Make sure all SELECTs in the statement have the same number of elements
118988 ** in their result sets.
119110 /* Query flattening in sqlite3Select() might refill p->pOrderBy.
119125 /* Convert the data in the temporary table into whatever form
119237 int nCol; /* Number of columns in result set */
119296 ** The data to be output is contained in pIn->iSdst. There are
119303 ** If regPrev>0 then it is the first register in a vector that
119309 ** If the LIMIT found in p->iLimit is reached, jump immediately to
119365 /* If we are creating a set for an "expr IN (SELECT ...)".
119381 ** store the results in the appropriate memory cell and break out
119392 /* The results are stored in a sequence of registers
119409 ** For SRT_Output, results are stored in a sequence of registers.
119445 ** co-routines. Then run the co-routines in parallel and merge the results
119446 ** into the output. In addition to the two coroutines (called selectA and
119455 ** appears only in B.)
119483 ** In the AltB, AeqB, and AgtB subroutines, an EOF on A following nextA
119488 ** Duplicate removal in the UNION, EXCEPT, and INTERSECT cases is handled
119558 int nOrderBy; /* Number of terms in the ORDER BY clause */
119733 ** are exhausted and only data in select B remains.
119747 ** are exhausted and only data in select A remains.
119805 /* Jump to the this point in order to terminate the query.
119829 ** All references to columns in table iTable are to be replaced by corresponding
119830 ** expressions in pEList.
119846 ** a column in table number iTable with a copy of the iColumn-th
119847 ** entry in pEList. (But leave references to the ROWID column
119851 ** whose result set is defined by pEList appears as entry in the
119859 Expr *pExpr /* Expr in which substitution occurs */
119910 ExprList *pList /* List to scan and in which to make substitutes */
119920 Select *p, /* SELECT statement in which to make substitutions */
119956 ** subquery first and store the results in a temporary table, then
120057 ** appear as unmodified result columns in the outer query. But we
120058 ** have other optimizations in mind to deal with that case.
120068 ** recursive queries in multiSelect().
120070 ** (24) The subquery is not an aggregate that uses the built-in min() or
120076 ** In this routine, the "p" parameter is a pointer to the outer query.
120089 int iFrom, /* Index in p->pSrc->a[] of the inner subquery */
120096 Select *pSub1; /* Pointer to the rightmost select in sub-query */
120194 ** every reference to any result column from subquery in a join, even though
120254 ** using UNION ALL operators. In this case N is the number of simple
120255 ** select statements in the compound sub-query.
120311 ** in the outer query.
120345 /* The following loop runs once for each term in a compound-subquery
120352 ** the cursor number for the original outer query FROM element in
120356 ** elements we are now copying in.
120362 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
120378 ** query. If the subquery has more than one element in its FROM clause,
120386 ** The outer query has 3 slots in its FROM clause. One slot of the
120389 ** The middle slot is expanded to two slots in order to make space
120390 ** for the two elements in the FROM clause of the subquery.
120412 ** references to the iParent in the outer query.
120420 ** We look at every expression in the outer query and every place we see
120427 ** do not necessarily correspond to columns in SELECT statement pParent,
120521 ** (1) The inner query is an aggregate. (In that case, we'd really want
120534 ** (5) The WHERE clause expression originates in the ON or USING clause
120548 Select *pX; /* For looping over compound SELECTs in pSubq */
120664 ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
120704 ** there are COLLATE terms in the ORDER BY.
120758 ** arguments. If it does, leave an error message in pParse and return
120806 ** WITH clause will never be popped from the stack. In this case it
120807 ** should be freed along with the Parse object. In other cases, when
120833 ** occurs. If an error does occur, an error message is stored in the
120857 ** recursive reference to CTE pCte. Leave an error in pParse and return
120859 ** In this case, proceed. */
120939 pCte->zCteErr = "recursive reference in a subquery: %s";
120981 ** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
120982 ** defines FROM clause. When views appear in the FROM clause,
120992 ** (4) Scan the list of columns in the result set (pEList) looking
120994 in every table
120995 ** and TABLE.* to be every column in TABLE.
121021 /* Make sure cursor numbers have been assigned to all entries in
121026 /* Look up every table named in the FROM clause of the select. If
121042 /* A sub-query in the FROM clause of a SELECT */
121057 /* An ordinary table or view name in the FROM clause */
121098 /* For every "*" that occurs in the column list, insert the names of
121099 ** all columns in all tables. And for every TABLE.* insert the names
121100 ** of all columns in TABLE. The parser inserted a special expression
121101 ** with the TK_ASTERISK operator for each "*" that it found in the column
121103 ** expressions and expand each one to the list of all columns in
121120 ** in the result set and expand them one by one.
121201 /* In a NATURAL join, omit the join columns from the
121206 /* In a join with a USING clause, omit columns in the
121261 sqlite3ErrorMsg(pParse, "too many columns in result set");
121275 ** subquery in the parser tree.
121287 ** Expanding a SELECT statement is the first step in processing a
121339 /* A sub-query in the FROM clause of a SELECT */
121353 ** the Table structures of all FROM-clause subqueries in a
121377 ** * Wildcards "*" and "TABLE.*" in result sets are expanded.
121378 ** * Identifiers in expression are matched to tables.
121404 ** routine generates code that stores NULLs in all of those memory
121446 ** in the AggInfo structure.
121520 ** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
121582 ** Otherwise, return WRC_Prune. In this case, also check if the
121645 SrcList *pTabList, /* Search for self-joins in this FROM clause */
121666 ** Generate code for the SELECT statement given in the p argument.
121669 ** See comments in sqliteInt.h for further information.
121672 ** encountered, then an appropriate error message is left in
121675 ** This routine does NOT free the Select structure passed in. The
121727 /* If ORDER BY makes no difference in the output then neither does
121757 /* Try to flatten subqueries in the FROM clause up into the main query
121767 /* Catch mismatch in the declared columns of a view and the number of
121768 ** columns in the SELECT on the RHS */
121807 /* For each term in the FROM clause, do two things:
121824 ** have a column named by the empty string, in which case there is no way to
121836 /* Generate code for all sub-queries in the FROM clause
121842 ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
121843 ** for example. In that case, do not regenerate the code to manifest
121867 /* Make copies of constant WHERE-clause terms in the outer query down
121979 ** can be rewritten as a GROUP BY. In other words, this:
122012 ** being unused if the data can be extracted in pre-sorted order.
122113 int groupBySort; /* Rows come from source in GROUP BY order */
122124 struct ExprList_item *pItem; /* For looping over expression in a list */
122142 ** in the correct order. It also may not - the GROUP BY might use a
122154 /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
122155 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
122228 /* Begin a loop that will extract all source rows in GROUP BY order.
122229 ** This might involve two separate loops with an OP_Sort in between, or
122231 ** in the right order to begin with.
122239 /* The optimizer is able to deliver rows in group by order so
122245 /* Rows are coming out in undetermined order. We have to push
122247 ** then loop over the sorting index in order to get the output
122248 ** in sorted order
122299 ** will naturally deliver rows in the order required by the ORDER BY
122312 /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
122315 ** from the previous row currently stored in a0, a1, a2...
122337 ** Changes in the GROUP BY are detected by the previous code
122340 ** This code copies current group by terms in b0,b1,b2,...
122342 ** and resets the aggregate accumulator registers in preparation
122359 VdbeComment((v, "indicate data in accumulator"));
122384 ** increments the iAbortFlag memory location before returning in
122444 ** (2013-10-03) Do not count the entries in a partial index.
122446 ** In practice the KeyInfo structure will not be used. It is only
122480 ** If it is, then ask the code in where.c to attempt to sort results
122482 ** If where.c is able to produce results sorted in this order, then
122495 ** + The optimizer code in where.c (the thing that decides which
122497 ** satisfying the 'ORDER BY' clause than it does in other cases.
122498 ** Refer to code and comments in where.c for details.
122568 /* The SELECT has been coded. If there is an error in the Parse structure,
122592 ** The author disclaims copyright to this source code. In place of
122604 ** These routines are in a separate files so that they will not be linked
122619 u32 nRow; /* Number of rows in the result */
122620 u32 nColumn; /* Number of columns in the result */
122621 u32 nData; /* Slots used in azResult[]. (nRow+1)*nColumn */
122626 ** This routine is called once for each row in the result table. Its job
122627 ** is to fill in the TabResult structure appropriately, allocating new
122632 int need; /* Slots needed in p->azResult[] */
122636 /* Make sure there is enough space in p->azResult to hold everything
122699 ** The result that is written to ***pazResult is held in memory obtained
122708 int *pnRow, /* Write the number of rows in the result here */
122792 ** The author disclaims copyright to this source code. In place of
122826 ** All of the triggers on pTab that are in the same database as pTab
122828 ** triggers on pTab in the TEMP schema. This routine prepends all
122834 ** pTab as well as the triggers lised in pTab->pTrigger.
122865 ** in pParse->pNewTrigger. After the trigger actions have been parsed, the
122885 int iDb; /* The database to store the trigger in */
122902 /* Figure out the db that the trigger will be created in */
122926 ** then set iDb to 1 to create the trigger in the temporary database.
122952 ** drop so the trigger cannot be dropped. This results in an
123055 ** in order to complete the process of building the trigger.
123093 /* Make an entry in the sqlite_master table */
123134 ** The parser calls this routine when it finds a SELECT statement in
123183 IdList *pColumn, /* List of columns in pTableName to insert into */
123382 ** in pEList is of the format <id>=<expr>. If any of the entries
123383 ** in pEList have an <id> which matches an identifier in pIdList,
123402 ** least one of the columns in pChanges is being modified.
123408 ExprList *pChanges, /* Columns that change in an UPDATE statement */
123435 ** forming the SrcList. This prevents a trigger in one database from
123436 ** referring to a target in another database. An exception is when the
123437 ** trigger is in TEMP in which case it can refer to any other database it
123542 ** program. It is not used in production code, only for debugging.
123702 /* It may be that this trigger has already been coded (or is in the
123705 ** in the Parse.pTriggerPrg list. Search for such an entry. */
123722 ** function are the same as those described in the header function for
123738 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
123767 ** The reg argument is the address of the first in an array of registers
123769 ** in the trigger program. If N is the number of columns in table pTab
123786 ** Similarly, for ON INSERT triggers the values stored in the OLD.* registers
123804 int reg, /* The first in an array of registers (see above) */
123817 ** always defined. The trigger must be in the same schema as the table
123835 ** Triggers may access values stored in the old.* or new.* pseudo-table.
123844 ** are more than 32 columns in the table, and at least one of the columns
123855 ** included in the returned mask if the TRIGGER_BEFORE bit is set in the
123857 ** included in the returned mask if the TRIGGER_AFTER bit is set in tr_tm.
123895 ** The author disclaims copyright to this source code. In place of
123914 ExprList *pChanges, /* The columns to change in the UPDATE statement */
123916 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
123927 ** The default value of a column is specified by a DEFAULT clause in the
123930 ** command. If the latter, then the row-records in the table btree on disk
123949 ** stored in place of an 8-byte floating point value in order to save
123982 SrcList *pTabList, /* The table in which we should change things */
123999 int *aRegIdx = 0; /* First register in array assigned to each index */
124000 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
124004 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
124005 u8 chngRowid; /* Rowid changed in a normal table */
124009 NameContext sNC; /* The name-context to resolve expressions in */
124024 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
124035 int regNew = 0; /* Content of the NEW.* table in triggers */
124036 int regOld = 0; /* Content of OLD.* table in triggers */
124080 ** allocate enough space, just in case.
124109 /* Resolve the column names in all the expressions of the
124111 ** for each column to be updated in the pChanges array. For each
124163 ** So reset the colUsed mask. Unless this is a virtual table. In that
124171 /* There is one entry in the aRegIdx[] array for each index on the table
124172 ** being updated. Fill in aRegIdx[] with a register number that will hold
124203 ** indexes in case they are needed to delete records. */
124242 /* Resolve the column names in all the expressions in the
124313 /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
124314 ** mode, write the rowid into the FIFO. In either of the one-pass modes,
124315 ** leave it in register regOldRowid. */
124321 /* Read the PK of the current row into an array of registers. In
124322 ** ONEPASS_OFF mode, serialize the array into a record and store it in
124323 ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
124325 ** is not required) and leave the PK fields in the array of registers. */
124452 ** a new.* reference in a trigger program.
124471 /* The row-trigger may have deleted the row being updated. In this
124474 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
124488 ** registers in case this has happened.
124565 ** handle rows (possibly in other tables) that refer via a foreign key
124625 ** they may interfere with compilation of other functions in this file
124626 ** (or in another file, if this file becomes part of the amalgamation). */
124647 ** (C) The content of every column in the row.
124653 ** stores the same values (A, B and C above) in a register array and
124660 ExprList *pChanges, /* The columns to change in the UPDATE statement */
124662 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
124673 int regArg; /* First register in VUpdate arg array */
124674 int regRec; /* Register in which to assemble record */
124682 ** create and open the ephemeral table in which the records created from
124765 ** The author disclaims copyright to this source code. In place of
124775 ** Most of the code in this file may be omitted by defining the
124833 ** in PostgreSQL. The VACUUM command works as follows:
124848 ** Two writes per page are required in step (3) because the original
124856 ** And a power loss in between deleting the original and renaming the
124909 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
125003 ** in the temporary database.
125021 /* Loop through the tables in the main database. For each, do
125044 " WHERE type IN('view','trigger')"
125060 /* This array determines which meta meta values are preserved in the
125079 /* GetMeta() and UpdateMeta() cannot fail in this context because
125136 ** The author disclaims copyright to this source code. In place of
125169 sqlite3 *db, /* Database in which module is registered */
125204 sqlite3 *db, /* Database in which module is registered */
125229 sqlite3 *db, /* Database in which module is registered */
125244 sqlite3 *db, /* Database in which module is registered */
125303 ** Table p is a virtual table. This function moves all elements in the
125307 ** connection db is left in the p->pVTable list.
125318 ** database connection that may have an entry in the p->pVTable list.
125344 ** list in p->pVTab. It also decrements the VTable ref count. This is
125368 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
125375 ** 1) By this function. In this case, all BtShared mutexes and the mutex
125379 ** the sqlite3.pDisconnect list. In this case either the BtShared mutex
125380 ** associated with the database the virtual table is stored in is held
125381 ** or, if the virtual table is stored in a non-sharable database, then
125415 ** in the list are moved to the sqlite3.pDisconnect list of the associated
125461 int iDb; /* The database the table is being created in */
125500 ** in pParse->zArg[] and appends it to the list of arguments on the
125501 ** virtual table currently under construction in pParse->pTable.
125526 ** first time (in other words if the virtual table is actually being
125529 ** in the sqlite_master table.
125544 /* A slot for the record has already been allocated in the
125549 ** entry in the sqlite_master table tht was created for this vtab
125576 /* If we are rereading the sqlite_master table create the in-memory
125578 ** the first time the virtual table is used in an SQL statement. This
125598 ** of an argument to the module name in a CREATE VIRTUAL TABLE statement.
125608 ** in an argument to the module name in a CREATE VIRTUAL TABLE statement.
125751 ** and an error left in pParse.
125819 ** of the virtual table named zTab in database iDb.
125823 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
125946 ** of the virtual table named zTab in database iDb. This occurs
125983 ** of each of the virtual tables in the sqlite3.aVTrans array. The method
125985 ** the offset of the method to call in the sqlite3_module structure.
126011 ** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
126015 ** If an error message is available, leave it in p->zErrMsg.
126036 ** Invoke the xRollback method of all virtual tables in the
126045 ** Invoke the xCommit method of all virtual tables in the
126059 ** in the sqlite3.aVTrans array.
126068 ** virtual module tables in this case, so return SQLITE_LOCKED.
126081 /* If pVtab is already in the aVTrans array, return early */
126157 ** If pExpr is a column in a virtual table, then let the virtual
126184 /* Check to see the left operand is a column in a virtual table */
126228 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
126230 ** array if it is missing. If pTab is already in the array, this routine
126260 ** statement in order to come into existance. Eponymous virtual table
126307 ** sqlite3DeleteTable() routine will know that it is not stored in
126316 ** Return the ON CONFLICT resolution mode in effect for the virtual
126317 ** table update operation currently in progress.
126378 ** The author disclaims copyright to this source code. In place of
126389 ** This file was split off from where.c on 2015-06-06 in order to reduce the
126395 /************** Include whereInt.h in the middle of wherecode.c **************/
126400 ** The author disclaims copyright to this source code. In place of
126410 ** planner logic in "where.c". These definitions are broken out into
126445 ** loop in WHERE clause.
126453 ** each term in the FROM clause (which is to say, for each of the
126463 int addrNxt; /* Jump here to start the next IN combination */
126472 u8 iFrom; /* Which entry in the FROM clause */
126477 int nIn; /* Number of entries in aInLoop[] */
126479 int iCur; /* The VDBE cursor used by this IN operator */
126480 int addrInTop; /* Top of the IN loop */
126481 u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
126482 } *aInLoop; /* Information about each nested IN operator */
126483 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
126513 u8 iTab; /* Position in FROM clause of table for this loop */
126535 u16 nLTerm; /* Number of entries in aLTerm[] */
126541 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
126546 ** subquery on one operand of an OR operator in the WHERE clause.
126569 ** Think of each WhereLoop object as a node in a graph with arcs
126580 ** number of nodes in the FROM clause. The best (lowest cost) WherePath
126584 Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
126619 ** In this second case, wtFlag has the TERM_ORINFO bit set and eOperator==WO_OR
126623 ** If a term in the WHERE clause does not match either of the two previous
126626 ** but no other fields in the WhereTerm object are meaningful.
126630 ** cursor number into bits and the translated bit is stored in the prereq
126631 ** fields. The translation is used in order to maximize the number of
126632 ** bits that will fit in a Bitmask. The VDBE cursor numbers might be
126636 ** beginning with 0 in order to make the best possible use of the available
126637 ** bits in the Bitmask. So, in the example above, the cursor numbers
126640 ** The number of terms in a join is limited by the number of bits
126641 ** in prereqRight and prereqAll. The default is 64 bits, hence SQLite
126653 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
126654 int iField; /* Field in (?,?,?) IN (SELECT...) vector */
126656 int leftColumn; /* Column number of X in "X <op> <expr>" */
126686 ** terms in the WHERE clause that are useful to the query planner.
126694 unsigned char nEquiv; /* Number of entries in aEquiv[] */
126695 unsigned char iEquiv; /* Next unused slot in aEquiv[] */
126698 int aiCur[11]; /* Cursors in the equivalence class */
126699 i16 aiColumn[11]; /* Corresponding column number in the eq-class */
126719 int nSlot; /* Number of entries in a[] */
126734 Bitmask indexable; /* Bitmask of all indexable tables in the clause */
126747 ** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
126749 ** The VDBE cursor numbers are small integers contained in
126752 ** contain gaps in the numbering sequence. But we want to make maximum
126753 ** use of the bits in our bitmasks. This structure provides a mapping
126764 ** Note that the mapping is not necessarily ordered. In the example
126793 int nRecValid; /* Number of valid fields currently in pRec */
126814 SrcList *pTabList; /* List of tables in the join */
126837 WhereLevel a[1]; /* Information about each nest loop in WHERE */
126932 ** These are definitions of bits in the WhereLoop.wsFlags field.
126933 ** The particular combination of bits in each WhereLoop help to
126938 #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
126948 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
126957 /************** Continuing where we left off in wherecode.c ******************/
127012 ** rows scanned by the strategy in the form of an SQL expression.
127052 ** is added to the output to describe the table scan strategy in pLevel.
127190 ** Disable a term in the WHERE clause. Except, do not disable the term
127191 ** if it controls a LEFT OUTER JOIN and it did not originate in the ON
127194 ** Consider the term t2.z='ok' in the following queries:
127200 ** The t2.z='ok' is disabled in the in (2) because it originates
127201 ** in the ON clause. The term is disabled in (3) because it is not part
127202 ** of a LEFT OUTER JOIN. In (1), the term is not disabled.
127204 in the inner loop
127206 ** by indices, we disable them to prevent redundant tests in the inner
127209 ** as we can without disabling too much. If we disabled in (1), we'd get
127213 ** automatically disabled. In this way, terms get disabled if derived
127220 ** Only the parent term was in the original WHERE clause. The child1
127256 ** beginning and end of zAff are ignored. If all entries in zAff are
127297 ** * the affinity change in zAff is guaranteed not to change the value.
127301 int n, /* Number of vector elements in comparison */
127317 ** term can be either X=expr or X IN (...). pTerm is the term to be
127320 ** The current value for the constraint is left in a register, the index
127321 ** of which is returned. An attempt is made store the result in iTarget but
127323 ** constraint is a TK_EQ or TK_IS, then the current value might be left in
127326 ** For a constraint of the form X=expr, the expression is evaluated in
127327 ** straight-line code. For constraints of the form X IN (...)
127335 int bRev, /* True for reverse-order IN operations */
127336 int iTarget /* Attempt to leave results in this register */
127452 if( pLevel->u.in.nIn==0 ){
127456 i = pLevel->u.in.nIn;
127457 pLevel->u.in.nIn += nEq;
127458 pLevel->u.in.aInLoop =
127459 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
127460 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
127461 pIn = pLevel->u.in.aInLoop;
127463 int iMap = 0; /* Index in aiMap[] */
127486 pLevel->u.in.nIn = 0;
127496 ** Generate code that will evaluate all == and IN constraints for an
127500 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
127501 ** The index has as many as three equality constraints, but in this
127504 ** a==5 and b IN (1,2,3). The current values for a and b will be stored
127505 ** in consecutive registers and the index of the first register is returned.
127507 ** In the example above nEq==2. But this subroutine works for any value
127513 ** are == or IN and are covered by the nEq. nExtraReg is 1 if there is
127514 ** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
127518 ** the index of the first memory cell in that range. The code that
127521 ** key value of the loop. If one or more IN operators appear, then
127527 ** sqlite3DbMalloc(). Except, entries in the copy of the string associated
127534 ** In the example above, the index on t1(a) has TEXT affinity. But since
127537 ** a key to search the index. Hence the first byte in the returned affinity
127538 ** string in this example would be set to SQLITE_AFF_BLOB.
127543 int bRev, /* Reverse the order of IN operators */
127547 u16 nEq; /* The number of == or IN constraints to code */
127617 ** from the RHS of an "? IN (SELECT ...)" expression. The
127712 ** should be included in the cursor-hint for a table that is on the rhs
127778 /* An aggregate function in the WHERE clause of a query means this must
127780 ** the parent context. Do not walk the function arguments in this case.
127783 ** expression, as the result of the expression must be stored in a
127836 ** Say there is a single row in t2 that matches (t1.a=t2.b), but its
127862 /* All terms in pWLoop->aLTerm[] except pEndRange are used to initialize
127873 /* For an index scan, make sure referenced columns are actually in
127901 ** rowid stored in register iRowid.
127913 ** does not appear in the index at all, the array entry is set to 0.
127950 ** If the expression is not a vector, then nReg must be passed 1. In
127952 ** result in register iReg.
127979 ** mapping from an expression on table columns into a column in an index
128009 ** For an indexes on expression X, locate every instance of expression X in pExpr
128017 WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
128042 ** Generate code for the start of the iLevel-th loop in the WHERE clause
128052 int addrNxt; /* Where to jump to continue with the next IN case */
128054 int bRev; /* True if we need to scan in reverse order */
128066 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
128090 ** When there is an IN operator, we also have a "addrNxt" label that
128091 ** means to continue with the next IN value combination. When
128092 ** there are no IN operators in the constraints, the "addrNxt" label
128131 int iIn; /* Counter for IN constraints */
128158 iIn = pLevel->u.in.nIn;
128166 VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
128171 ** encoding of the value in the register, so it *must* be reloaded. */
128172 assert( pLevel->u.in.aInLoop!=0 || db->mallocFailed );
128175 pOp = sqlite3VdbeGetOp(v, pLevel->u.in.aInLoop[--iIn].addrInTop);
128184 ** the IN constraint is not satisfied */
128199 /* These registers need to be preserved in case there is an IN operator
128215 ** we reference multiple rows using a "rowid IN (...)"
128341 ** terms ("==" or "IN" operators) that refer to the N
128346 ** use the "==" and "IN" operators. For example, if the
128366 ** constraints but an index is selected anyway, in order
128385 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
128411 ** should not have a NULL value stored in 'x'. If column 'x' is
128412 ** the first one after the nEq equality constraints in the index,
128434 /* Like optimization range constraints always occur in pairs */
128444 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
128479 /* Generate code to evaluate all constraint terms using == or IN
128480 ** and store the values of those terms in an array of registers
128624 ** all the expressions in pWInfo and try to transform matching expressions
128661 ** In the example, there are three indexed terms connected by OR.
128664 ** Null 1 # Zero the rowset in reg 1
128679 ** Null 1 # Zero the rowset in reg 1
128717 /* Set up a new SrcList in pOrTab containing the table being scanned
128718 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
128719 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
128741 ** capable of holding primary keys in the case of a WITHOUT ROWID.
128745 ** is required in a few obscure LEFT JOIN cases where control jumps
128746 ** over the top of the loop into the body of it. In this case the
128767 ** That way, terms in y that are factored into the disjunction will
128771 ** the "interesting" terms of z - terms that did not originate in the
128776 ** is not contained in the ON clause of a LEFT JOIN.
128828 ** row will be skipped in subsequent sub-WHERE clauses.
128851 ** the row has already been included in the result set and
128857 ** is zero, assume that the key cannot already be present in
128896 ** If the call to sqlite3WhereBegin() above resulted in a scan that
128943 /* Tables marked isRecursive have only a single row that is stored in
129076 ** The author disclaims copyright to this source code. In place of
129089 ** analyzing Expr objects in the WHERE clause.
129116 ** The index in pWC->a[] of the new WhereTerm is returned on success.
129118 ** allocation error. The memory allocation failure will be recorded in
129171 ** "=", "<", ">", "<=", ">=", "IN", "IS", and "IS NULL"
129255 ** In order for the operator to be optimizible, the RHS must be a string
129258 ** that virtual tables cannot participate in the LIKE optimization.) The
129266 int *pisComplete, /* True if the only wildcard is % in the last character */
129272 int c; /* One character in z[] */
129409 ** If the pBase expression originated in the ON or USING clause of
129445 ** two subterms are in disjunction - they are OR-ed together.
129473 int idxNew; /* Index in pWC of the next virtual term */
129504 ** subterms. So in:
129509 ** This routine analyzes terms such as the middle term in the above example.
129530 ** a single table T (as shown in example B above) then create a new virtual
129531 ** term that is an equivalent IN expression. In other words, if the term
129538 ** x IN (expr1,expr2,expr3)
129548 ** The added conjunct can sometimes be helpful in query planning.
129559 ** <op> is one of "=", "<", "<=", ">", ">=", "IS NULL", or "IN".
129573 ** always prefer case 1, so in that case we pretend that case 3 is not
129582 ** to "bitmap indices" in other database engines.
129608 ** stored in a WhereClause structure containing within the WhereOrInfo
129708 ** IN operator because one or more terms in the OR clause contain
129709 ** something other than == on a column in the single table. The 1-bit
129715 ** might be possible to form an IN operator with either table1.column
129723 int okToChngToIN = 0; /* True if the conversion to IN is valid */
129724 int iColumn = -1; /* Column index on lhs of IN operator */
129729 ** other of the == operator in every subterm. That table and column
129730 ** will be recorded in iCursor and iColumn. There might not be any
129747 /* This term must be of the form t1.a==t2.b where t2 is in the
129771 ** table and column is common to every term in the OR clause */
129797 ** case 1. In that case, construct a new virtual term that is
129798 ** pTerm converted into an IN operator.
129802 ExprList *pList = 0; /* The RHS of the IN operator */
129803 Expr *pLeft = 0; /* The LHS of the IN operator */
129804 Expr *pNew; /* The complete IN operator */
129843 ** 3. Not originating in the ON clause of an OUTER JOIN
129848 ** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
129877 ** a bitmask indicating which tables are used in that expression
129904 ** in any index. Return TRUE (1) if pExpr is an indexed term and return
129967 ** "pExpr" field filled in. The job of this routine is to analyze the
130178 ** lower-case (upper-case is less than lower-case in ASCII) so that
130300 /* If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create
130302 ** used by each such virtual term is pExpr (the full vector IN(...)
130374 ** This routine identifies subexpressions in the WHERE clause where
130376 ** operator specified in the op parameter. The WhereClause structure
130383 ** The original WHERE clause in pExpr is unaltered. All this routine
130386 ** In the previous sentence and in the diagram, "slot[]" refers to
130443 ** a bitmask indicating which tables are used in that expression
130476 ** Call exprAnalyze on all terms in a WHERE clause.
130498 ** a HIDDEN column in the table.
130538 ** The author disclaims copyright to this source code. In place of
130581 ** Return TRUE if the WHERE clause returns rows in ORDER BY order.
130590 ** returns rows in ORDER BY order for complete run of the inner loop.
130601 ** Return the VDBE address or label to jump to in order to continue
130610 ** Return the VDBE address or label to jump to in order to break
130696 ** iCursor is not in the set.
130712 ** There is one cursor per table in the FROM clause. The number of
130713 ** tables in the FROM clause is limited by a test early in the
130866 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
130875 ** The term returned might by Y=<expr> if there is another constraint in
130877 ** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
130879 ** slots in aiCur[]/aiColumn[] so that means we can look for X plus up to 10
130883 ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
130884 ** then try for the one with no dependencies on <expr> - in other words where
130886 ** the form "X <op> Y" where Y is a column in another table if no terms of
130921 ** If such an expression is found, its index in pList->a[] is returned. If
130973 ** A DISTINCT list is redundant if any subset of the columns in the
130987 /* If there is more than one table or sub-select in the FROM clause of
131008 ** 2. All of the columns in the index are either part of the pDistinct
131042 ** Convert OP_Column opcodes to OP_Copy in previously generated code.
131051 ** value stored in its output register.
131057 int iRegister, /* The first column is in this register */
131073 /* Increment the value stored in the P2 operand of the OP_Rowid. */
131140 Bitmask notReady /* Tables in outer loops of the join */
131168 int nKeyCol; /* Number of columns in the constructed index */
131179 int mxBitCol; /* Maximum column in pSrc->colUsed */
131402 /* If the ORDER BY clause contains only columns in the current
131430 ** changing them. We have to do some funky casting in order to
131463 /* The direct assignment in the previous line is possible only because
131498 ** comes in as the 3rd argument to this function.
131545 ** Estimate the location of a particular key among all keys in an
131546 ** index. Store the results in aStat as follows:
131554 ** based on the contents of aSample[] and the number of fields in record
131565 int iCol; /* Index of required stats in anEq[] etc. */
131571 int nField; /* Number of fields in pRec */
131583 ** is simply the aSample[] array. If the samples in aSample[] contain more
131587 ** samples in aSample[] (truncated to N fields), the search also has to
131589 ** in aSample is:
131612 ** For each sample in the aSample[] array, N samples are present in the
131613 ** effective sample array. In the above, samples 0 and 1 are based on
131618 ** equal to the previous sample in the array. For example, in the above,
131620 ** appears that it should be 1 field in size. However, that would make it
131629 int iSamp; /* Index in aSample[] of test sample */
131630 int n; /* Number of fields in test sample */
131676 ** all samples in the aSample[] array, pRec must be smaller than the
131685 ** in the aSample[] array. Otherwise, if (iCol>0) then pRec must
131710 ** is larger than all samples in the array. */
131792 ** extracted from pLower and pUpper with the corresponding column in each
131863 ** using the method described in the header comment for this function. */
131896 ** If either of the upper or lower bound is not present, then NULL is passed in
131899 ** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index
131916 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
131919 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
131946 /* Variable iLower will be set to the estimate of the number of rows in
131950 ** columns of the index, and $L is the value in pLower.
131954 ** range is $P. Due to a quirk in the way whereKeyStats() works, even
131980 ** have been requested when testing key $P in whereEqualScanEst(). */
132035 ** the estimated selectivity more in line with what it would be
132065 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
132088 ** an equality constraint x=VALUE and where that VALUE occurs in
132101 ** in the pParse structure.
132106 Expr *pExpr, /* Expression for VALUE in the x=VALUE constraint */
132153 ** an IN constraint where the right-hand side of the IN operator
132156 ** WHERE x IN (1,2,3,4)
132165 ** in the pParse structure.
132170 ExprList *pList, /* The value list on the RHS of "x IN (v1,v2,v3,...)" */
132192 WHERETRACE(0x10,("IN row estimate: est=%d\n", nRowEst));
132390 sqlite3DbFree(db, pLevel->u.in.aInLoop);
132481 ** Search the list of WhereLoops in *ppPrev looking for one that can be
132485 ** pTemplate, in other words if pTemplate does not belong on the list.
132505 /* In the current implementation, the rSetup value is either zero
132568 ** information is gathered in the pBuilder->pOrSet object. This special
132695 ** value corresponds to -1 in LogEst notation, so this means decrement
132701 ** of rows in the table. In other words, assume that x==EXPR will filter
132704 ** on the "x" column and so in that case only cap the output row estimate
132710 LogEst nRow /* Number of rows in the entire table */
132734 /* In the absence of explicit truth probabilities, use heuristics to
132755 ** in the vector can be optimized using column nEq of the index. This
132767 ** then this function would be invoked with nEq=1. The value returned in
132845 LogEst nInMul /* log(Number of iterations due to IN) */
132863 LogEst rSize; /* Number of rows in the table */
132900 LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
132917 ** right table of a LEFT JOIN. Only constraints in the ON clause are
132952 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
132956 /* The expression may actually be of the form (x, y) IN (SELECT...).
132957 ** In this case there is a separate term for each of (x) and (y).
132960 ** first such term in use, and sets nIn back to 0 if it is not. */
132965 /* "x IN (value, value, ...)" */
132968 ** changes "x IN (?)" into "x=?". */
132996 ** always used in pairs. */
133021 ** values of nIn and nInMul. In other words, assuming that all
133022 ** "x IN(...)" terms are replaced with "x = ?". This block updates
133078 /* Set rCostIdx to the cost of visiting selected rows in index. Add
133081 ** visiting the rows in the main table. */
133122 ** number of repeats in the left-most terms is at least 18.
133126 ** contains fewer than 2^17 rows we assume otherwise in other parts of
133144 /* TUNING: Because uncertainties in the estimates for skip-scan queries,
133160 ** Return True if it is possible that pIndex might be useful in
133161 ** implementing the ORDER BY clause in pBuilder.
133164 ** if there is no way for pIndex to be useful in implementing that
133216 ** in the current query. Return true if it can be and false if not.
133261 ** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when
133262 ** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans.
133267 ** log(nRow) factor is omitted from a non-covering index scan in order to
133268 ** bias the scoring in favor of using an index, since the worst-case
133287 LogEst rSize; /* number of rows in the table */
133288 LogEst rLogSize; /* Logarithm of the number of rows in the table */
133306 /* There is no INDEXED BY clause. Create a fake Index object in local
133308 ** fake index the first in a chain of Index objects with all of the real
133355 ** estimated to be X*N*log2(N) where N is the number of rows in
133368 /* TUNING: Each index lookup yields 20 rows in the table. This
133446 /* If this is a non-covering index scan, add in the cost of
133514 ** * It is not one of the operators specified in the mExclude mask passed
133515 ** as the fourth argument (which in practice is either WO_IN or 0).
133518 ** virtual table in question. These are added to the plans prerequisites
133531 int *pbIn /* OUT: True if plan uses an IN(...) op */
133608 /* A virtual table that is constrained by an IN clause may not
133609 ** consume the ORDER BY clause because (1) the order of IN terms
133611 ** (2) Multiple outputs from a single IN value will not merge
133657 ** If there are no LEFT or CROSS JOIN joins in the query, both mPrereq and
133659 ** entries that occur before the virtual table in the FROM clause and are
133671 ** All the tables in mPrereq must be scanned before the current virtual
133673 ** mPrereq may be specified as "usable" in all calls to xBestIndex.
133674 ** Conversely, all tables in mUnusable must be scanned after the current
133689 int nConstraint; /* Number of constraints in p */
133690 int bIn; /* True if plan uses IN(...) operator */
133721 ** then there is no point in making any further calls to xBestIndex()
133726 int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */
133730 /* If the plan produced by the earlier call uses an IN(...) term, call
133731 ** xBestIndex again, this time with IN(...) terms disabled. */
133733 WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n"));
133745 ** in the set of terms that apply to the current virtual table. */
133769 /* If the calls to xBestIndex() in the above loop did not find a plan
133780 ** that requires no source tables at all and does not use an IN(...)
133783 WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n"));
133935 /* Loop over the tables in the join, from left to right */
133975 ** parameters) to see if it outputs rows in the requested ORDER BY
133985 ** and DISTINCT do not require rows to appear in any particular order as long
133987 ** the pOrderBy terms can be matched in any order. With ORDER BY, the
133988 ** pOrderBy terms must be matched in strict left-to-right order.
133995 u16 nLoop, /* Number of entries in pPath->aLoop[] */
133997 Bitmask *pRevMask /* OUT: Mask of WhereLoops to run in reverse order */
134006 u16 nKeyCol; /* Number of key columns in pIndex */
134007 u16 nColumn; /* Total number of ordered columns in the index */
134008 u16 nOrderBy; /* Number terms in the ORDER BY clause */
134009 int iLoop; /* Index of WhereLoop in pPath being processed */
134030 ** Every one-row WhereLoop will have the WHERE_ONEROW bit set in wsFlags.
134033 ** that WhereLoop that are in the ORDER BY clause are different for every
134035 ** order-distinct. A WhereLoop that has no columns in the ORDER BY clause
134042 ** rowid appears in the ORDER BY clause, the corresponding WhereLoop is
134074 /* Mark off any ORDER BY term X that is a column in the table of
134075 ** the current loop for which there is term in the WHERE
134088 /* IN terms are only valid for sorting in the ORDER BY LIMIT
134126 ** that are not constrained by == or IN.
134139 /* Skip over == and IS and ISNULL terms. (Also skip IN terms when
134142 ** If the current term is a column of an ((?,?) IN (SELECT...))
134169 /* Get the column number in the table (iColumn) and sort order
134221 /* Make sure the sort order is compatible in an ORDER BY clause.
134281 ** If the WHERE_GROUPBY flag is set in the mask passed to sqlite3WhereBegin(),
134286 ** Normally, in this case it is not possible for the caller to determine
134287 ** whether or not the rows are really being delivered in sorted order, or
134288 ** just in some other order that provides the required grouping. However,
134291 ** true if the rows really will be sorted in the specified order, or false
134323 ** nOrderby columns and that the first nSorted columns are already in
134365 ** will be nRowEst (in the 10*log2 representation). Or, ignore sorting
134373 int nLoop; /* Number of terms in the join */
134382 int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
134403 /* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
134431 ** the ORDER BY clause are already in order, where X is the array
134448 /* If nLoop is zero, then there are no FROM terms in the query. Since
134449 ** in this case the query may return a maximum of one row, the results
134450 ** are already in the requested order. Set isOrdered to nOrderBy to
134533 ** paths currently in the best-so-far buffer. So discard
134823 ** in order to complete the WHERE clause processing.
134827 ** The basic idea is to do a nested loop, one loop for each table in
134829 ** same as a SELECT with only a single table in the FROM clause.) For
134836 ** foreach row1 in t1 do \ Code generated
134837 ** foreach row2 in t2 do |-- by sqlite3WhereBegin()
134838 ** foreach row3 in t3 do /
134844 ** Note that the loops might not be nested in the order in which they
134845 ** appear in the FROM clause if a different order is better able to make
134846 ** use of indices. Note also that when the IN operator appears in
134847 ** the WHERE clause, it might result in additional nested loops for
134848 ** scanning through all values on the right-hand side of the IN.
134856 ** in pTabList pointing at their appropriate entries. The [...] code
134862 ** the tables have indices and there are terms in the WHERE clause that
134868 ** make it to the "..." in the middle of the loop. After each "foreach",
134869 ** terms of the WHERE clause that use only terms in that loop and outer
134878 ** foreach row1 in t1 do
134880 ** foreach row2 in t2 do
134894 ** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
134902 ** the first cursor in an array of cursors for all indices. iIdxCur should
134912 u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
134917 int nTabList; /* Number of elements in pTabList */
134923 WhereLevel *pLevel; /* A single level in pWInfo->a[] */
134954 /* The number of tables in the FROM clause is limited by the number of
134955 ** bits in a Bitmask
134959 sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS);
134963 /* This function normally generates a nested loop for all tables in
134965 ** only generate code for the first table in pTabList and assume that
135036 /* Assign a bit from the bitmask to every term in the FROM clause.
135045 ** Note that bitmasks are created for all pTabList->nSrc tables in
135203 /* Open all tables in the pTabList and any indices selected for
135425 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
135429 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
135493 ** the co-routine into OP_Copy of result contained in a register.
135504 ** from the index instead of from the table where possible. In some cases
135508 ** Calls to the code generator in between sqlite3WhereBegin and
135565 ** The author disclaims copyright to this source code. In place of
135578 ** interstitial "-" characters) contained in this template is changed into
135592 ** Disable all error recovery processing in the parser push-down
135609 ** In the amalgamation, the parse.c file generated by lemon and the
135610 ** tokenize.c file are concatenated. In that case, sqlite3RunParser()
135612 ** engine can be allocated from stack. In that case, only the
135659 ** all elements in the list. And make sure list length does not exceed
135674 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
135798 ** in a format understandable to "makeheaders". This section is blank unless
135817 ** that indicate what to do in response to the next
135830 ** which is sqlite3ParserTOKENTYPE. The entry in the union
135841 ** YYNRULE the number of rules in the grammar
135898 ** Applications can choose to define yytestcase() in the %include section
135899 ** to a macro that can assist in verifying code coverage. For production
135930 ** slots in the yy_action[] table.
135948 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
135949 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
135952 ** The following are the tables generated in this section:
135955 ** yy_lookahead[] A table containing the lookahead for each entry in
136429 ** appears in the grammar, then ID becomes a fallback token for X, Y,
136434 ** This feature can be used, for example, to cause some keywords in a language
136435 ** to revert to identifiers if they keyword does not apply in the context where
136518 ** (In other words, the "major" token.)
136521 ** the information used by the action routines in the grammar.
136529 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
136537 /* The state of the parser is completely contained in an instance of
136612 "IS", "BETWEEN", "IN", "ISNULL",
136852 /* 188 */ "in_op ::= IN",
136853 /* 189 */ "in_op ::= NOT IN",
137035 ** putting an appropriate #define in the %include section of the input
137076 ** A pointer to a parser. This pointer is used in subsequent calls
137229 ** is defined in a %include section of the input grammar) then it is
137393 int yyNewState, /* The new state to shift in */
137394 int yyMajor, /* The major token to shift in */
137395 sqlite3ParserTOKENTYPE yyMinor /* The minor token to shift in */
137435 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
138035 case 189: /* in_op ::= NOT IN */ yytestcase(yyruleno==189);
138149 ** objects in a complex query.
138477 /* When doing a nested parse, one can include terms in an expression
138479 ** in the virtual machine. #N is the N-th register. */
138615 case 188: /* in_op ::= IN */ yytestcase(yyruleno==188);
138637 ** expr1 IN ()
138638 ** expr1 NOT IN ()
138648 ** expr1 IN (?1)
138649 ** expr1 NOT IN (?2)
138660 ** the semantics would be subtly different from IN or NOT IN.
139149 ** user wants (and specified in the grammar) and is available for
139325 ** The author disclaims copyright to this source code. In place of
139344 ** In the sqlite3GetToken() function, a switch() on aiClass[c] is implemented
139351 #define CC_KYWD 1 /* Alphabetics or '_'. Usable in a keyword */
139352 #define CC_ID 2 /* unicode characters usable in IDs */
139461 ** mkkeywordhash.c, located in the tool subdirectory of the distribution.
139466 /************** Include keywordhash.h in the middle of tokenize.c ************/
139470 ** The code in this file has been automatically generated by
139474 ** The code in this file implements a function that determines whether
139483 /* zText[] encodes 834 bytes of keywords in 554 bytes */
139710 testcase( i==93 ); /* IN */
139755 /************** Continuing where we left off in tokenize.c *******************/
139759 ** If X is a character that can be used in an identifier then
139763 ** allowed in an identifier. For 7-bit characters,
139769 ** Ticket #1066. the SQL standard does not allow '$' in the
139771 ** SQLite will allow '$' in identifiers for compatibility.
139803 ** Return the length (in bytes) of the token that begins at z[0].
139804 ** Store the token type in *tokenType before returning.
140039 /* This token started out using characters that can appear in keywords,
140081 ** passed in. An SQLITE_ status code is returned. If an error occurs
140131 ** with tokens TK_SEMI and 0, in that order. */
140205 ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
140233 ** The author disclaims copyright to this source code. In place of
140252 ** This is defined in tokenize.c. We just have to import the definition.
140281 ** Return TRUE if the given SQL string ends in a semicolon.
140292 ** returns 1 if it ends in the START state and 0 if it ends
140293 ** in any other state.
140295 ** (2) NORMAL We are in the middle of statement which ends with a single
140305 ** (5) TRIGGER We are in the middle of a trigger definition that must be
140308 ** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at
140334 u8 state = 0; /* Current state, using numbers defined in header comment */
140409 case '[': { /* Microsoft-style identifiers in [...] */
140526 ** The author disclaims copyright to this source code. In place of
140534 ** Main file for the SQLite library. The routines in this file
140535 ** implement the programmer interface to the library. Routines in
140542 /************** Include fts3.h in the middle of main.c ***********************/
140547 ** The author disclaims copyright to this source code. In place of
140572 /************** Continuing where we left off in main.c ***********************/
140575 /************** Include rtree.h in the middle of main.c **********************/
140580 ** The author disclaims copyright to this source code. In place of
140605 /************** Continuing where we left off in main.c ***********************/
140608 /************** Include sqliteicu.h in the middle of main.c ******************/
140613 ** The author disclaims copyright to this source code. In place of
140639 /************** Continuing where we left off in main.c ***********************/
140814 ** the pInitMutex mutex. Return an error in either case. */
140829 ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
140909 ** while any part of SQLite is otherwise in use in any thread. This
140945 ** this function resulted in the heap subsystem actually being shutdown.
140973 ** the SQLite library is in use. */
140979 /* Mutex configuration options are only available in a threadsafe
141028 ** low-level memory allocation routines to be used in place of the memory
141073 ** in SQLITE_CONFIG_PAGECACHE. */
141118 ** number of bytes in the memory buffer, and the minimum allocation size.
141194 ** boolean in order to enable or disable the use of covering indices for
141195 ** full table scans in the query optimizer. */
141268 ** The sz parameter is the number of bytes in each lookaside slot.
141368 ** Flush any dirty pages in the pager-cache for any attached database
141420 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
141480 /* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
141490 ** spaces at the end of either string do not change the result. In other
141492 ** differ only in the number of spaces at the end.
141502 ** Another built-in collating sequence: NOCASE.
141506 ** extends only to the 26 characters used in the English language.
141553 ** Return the number of changes in the most recent call to sqlite3_exec().
141679 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
141781 /* Tell the code in notify.c that the connection no longer holds any
141849 ** any write cursors are invalidated ("tripped" - as in "tripping a circuit
141852 ** but are "saved" in case the table pages are moved around.
141862 ** This is important in case the transaction being rolled back has
141864 ** here, then another shared-cache connection might sneak in between
141866 ** corruption reports in some cases. */
141901 ** specified in the argument.
142009 ** Return a static string that describes the kind of error specified in the
142062 ** an integer number of milliseconds passed in as the first
142211 ** that if a malloc() fails in sqlite3_create_function(), an error code
142407 ** A global function must exist in order for name resolution to work
142616 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
142638 ** more frames in the log file. Passing zero or a negative value as the
142698 int *pnLog, /* OUT: Size of WAL log in frames */
142711 /* Initialize the output variables to -1 in case an error occurs. */
142765 ** not currently open in WAL mode.
142943 ** Return a string that describes the kind of error specified in the
143029 ** initializer must be kept in sync with the SQLITE_LIMIT_*
143030 ** #defines in sqlite3.h.
143107 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
143148 ** the default flags to open the database handle with. The value stored in
143152 ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
143166 unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */
143248 /* This branch is taken when "%00" appears within the URI. In this
143249 ** case we ignore all text in the remainder of the path, name or
143261 /* If ENABLE_URI_00_ERROR is defined, "%00" in a URI is an error. */
143262 *pzErrMsg = sqlite3_mprintf("unexpected %%00 in uri");
143420 /* Only allow sensible combinations of bits in the flags argument.
143423 ** assert() statements in deeper layers. Sensible combinations
143458 ** dealt with in the previous code block. Besides these, the only
143541 ** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
143597 /* Register all built-in functions, but do not attempt to read the
143606 /* Register any built-in FTS5 module before loading the automatic
143757 char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
143909 ** Test to see whether or not the database connection is in autocommit
143929 ** 1. Serve as a convenient place to set a breakpoint in a debugger
143977 ** See comment in sqlite3.h (sqlite.h.in) for details.
144016 /* Locate the table in question */
144045 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
144103 /* This function works in milliseconds, but the underlying OsSleep()
144259 ** Set the PENDING byte to the value in the argument, if X>0.
144263 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
144265 ** while any database connection is open results in undefined and
144368 ** is obtained in every case.
144382 ** This test feature is only available in the amalgamation since
144383 ** the SQLITE_N_KEYWORD macro is not defined in this file if SQLite
144426 ** testing causes certain assert() statements in the code to be activated
144436 ** too big to test in a reasonable amount of time, so this control is
144484 ** run a single CREATE TABLE statement to construct the imposter table in
144717 ** The author disclaims copyright to this source code. In place of
144760 ** 1) Each entry in the list has a non-NULL value for either
144763 ** 2) All entries in the list that share a common value for
144766 ** 3) If the argument db is not NULL, then none of the entries in the
144845 ** (call it pOther) in the same process was busy using the same shared
144879 ** blocking transaction. In either case, invoke the notify callback
144925 ** This function loops through each entry in the blocked connections
144941 int nArg = 0; /* Number of entries in aArg[] */
144950 /* This loop runs once for each entry in the blocked-connections list. */
145052 ** The author disclaims copyright to this source code. In place of
145065 ** The code in this file is only compiled if:
145068 ** (in which case SQLITE_CORE is not defined), or
145071 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
145074 /* The full-text index is stored in a series of b+tree (-like)
145076 ** structures are like b+trees in layout, but are constructed from the
145077 ** bottom up in optimal fashion and are not updatable. Since trees
145084 ** varint. We encode variable-length integers in little-endian order
145096 ** This is similar in concept to how sqlite encodes "varints" but
145098 ** are are limited to 9 bytes in length whereas FTS3 varints are
145099 ** little-endian and can be up to 10 bytes in length (in theory).
145135 ** Here, array { X } means zero or more occurrences of X, adjacent in
145136 ** memory. A "position" is an index of a token in the token stream
145138 ** in the same logical place as the position element, and act as sentinals
145147 ** The 123 value is the first docid. For column zero in this document
145185 ** Here, array { X } means zero or more occurrences of X, adjacent in
145188 ** Leaf nodes are broken into blocks which are stored contiguously in
145189 ** the %_segments table in sorted order. This means that when the end
145190 ** of a node is reached, the next term is in the node with the next
145195 ** larger than STANDALONE_MIN (default 1024) is placed in a standalone
145231 ** means zero or more occurrences of X, adjacent in memory.
145253 ** The segment directory in table %_segdir stores meta-information for
145265 ** The meta-information in the segment directory is:
145280 ** merged in batches. Each increase in level represents exponentially
145291 ** A segment merge traverses all segments at a given level in
145293 ** leaf nodes are written in to the %_segments table in order, this
145301 ** a tiny bit slower (perhaps due to more overhead in merge-time
145339 /************** Include fts3Int.h in the middle of fts3.c ********************/
145344 ** The author disclaims copyright to this source code. In place of
145385 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
145424 ** implementation. The xCreate() function in turn returns an
145446 ** Create a new tokenizer. The values in the argv[] array are the
145500 ** of this buffer in bytes. The input text that generated the token is
145501 ** identified by the byte offsets returned in *piStartOffset and
145503 ** byte of the token in the input buffer. *piEndOffset should be set
145504 ** to the index of the first byte just past the end of the token in
145518 int *piStartOffset, /* OUT: Byte offset of token in input buffer */
145519 int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */
145550 /************** Continuing where we left off in fts3Int.h ********************/
145551 /************** Include fts3_hash.h in the middle of fts3Int.h ***************/
145556 ** The author disclaims copyright to this source code. In place of
145565 ** used in SQLite. We've modified it slightly to serve as a standalone
145587 int count; /* Number of entries in this table */
145589 int htsize; /* Number of buckets in the hash table */
145596 /* Each element in the hash table is an instance of the following
145603 Fts3HashElem *next, *prev; /* Next and previous elements in the table */
145613 ** is respected in comparisons.
145660 ** Number of entries in a hash table
145667 /************** Continuing where we left off in fts3Int.h ********************/
145689 ** This is the maximum amount of data (in bytes) to store in the
145691 ** populated as documents are inserted/updated/deleted in a transaction
145699 ** Macro to return the number of elements in an array. SQLite has a
145701 ** a collision when building an amalgamation with built-in FTS3.
145721 ** in the document set and zero or more prefix indexes. All indexes are stored
145722 ** as one or more b+-trees in the %_segments and %_segdir tables.
145725 ** value stored in the "%_segdir.level" column. Given this value L, the index
145726 ** that the b+-tree belongs to is (L<<10). In other words, all b+-trees with
145730 ** It is considered impossible for an index to use more than 1024 levels. In
145841 int nColumn; /* number of named columns in virtual table */
145863 u8 bDescIdx; /* True if doclists are in reverse order */
145873 ** The current language id is stored in variable iPrevLangid.
145876 ** there is an entry in the aIndex[] array. Index 0 is an index of all the
145877 ** terms that appear in the document set. Each subsequent index in aIndex[]
145925 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
145928 int nPhrase; /* Number of matchable phrases in query */
145934 u8 bDesc; /* True to sort in descending order */
145936 int nRowAvg; /* Average size of database rows, in pages */
145937 sqlite3_int64 nDoc; /* Documents in table */
145940 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
145952 ** of the column to be searched. For example, in
145979 int nAll; /* Size of a[] in bytes */
145989 ** A "phrase" is a sequence of one or more tokens that must match in
145991 ** For a sequence of tokens contained in double-quotes (i.e. "one two three")
145992 ** nToken will be the number of tokens in the string.
145996 int n; /* Number of bytes in buffer z */
146001 ** parsed (by code in fts3_expr.c). Below this point the variables are
146021 int nToken; /* Number of tokens in the phrase */
146023 Fts3PhraseToken aToken[1]; /* One entry for each token in the phrase */
146031 ** of this phrase query in FTS3 doclist format. As usual, the initial
146032 ** "Length" field found in doclists stored on disk is omitted from this
146037 ** where nCol is the number of columns in the queried FTS table. The array
146062 int iPhrase; /* Index of this phrase in matchinfo() results */
146068 ** four values is in order of precedence when parsing expressions. For
146150 char *aBuffer; /* Buffer to merge doclists in */
146151 int nBuffer; /* Allocated size of aBuffer[] in bytes */
146162 int nTerm; /* Size of zTerm in bytes */
146164 int nDoclist; /* Size of aDoclist[] in bytes */
146243 /************** Continuing where we left off in fts3.c ***********************/
146287 q[-1] &= 0x7f; /* turn off high bit in final byte */
146302 ** The value is stored in *v.
146364 ** the quote characters. The conversion is done in-place. If the
146429 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
146487 sqlite3 *db, /* Database in which to run SQL */
146537 ** Otherwise, if an error occurs, an SQLite error code is stored in *pRc
146654 ** Store the current database page-size in bytes in p->nPgsz.
146657 ** Otherwise, if an error occurs, an SQLite error code is stored in *pRc
146720 int *pRc, /* IN/OUT: Error code */
146721 char **pz, /* IN/OUT: Pointer to string buffer */
146743 ** Return a copy of input string zInput enclosed in double-quotes (") and
146773 ** could be used in a SELECT statement such as the following:
146777 ** to return the docid, followed by each column of text data in order
146833 ** of columns in the %_content table (one for the docid plus one for each
146915 ** the allocated array. *pnIndex is set to the number of elements in the
146922 const char *zParam, /* ABC in prefix=ABC parameter to parse */
146927 int nIndex = 1; /* Number of entries in array */
146981 ** the name of the corresponding column in table xxx. The array
147069 int argc, /* Number of elements in argv array */
147081 int nCol = 0; /* Number of columns in the FTS table */
147133 ** + If there is a tokenizer specification included in the arguments,
147342 /* Fill in the zName and zDb fields of the vtab structure. */
147351 /* Fill in the azColumn array */
147366 /* Fill in the abNotindexed array */
147390 sqlite3Fts3ErrMsg(pzErr, "missing %s parameter in fts4 constructor", zMiss);
147396 /* If this is an xCreate call, create the underlying tables in the
147410 /* Figure out the page-size for the database. This is required in order to
147443 ** work is done in function fts3InitVtab().
147448 int argc, /* Number of elements in argv array */
147458 int argc, /* Number of elements in argv array */
147469 ** support estimatedRows. In that case this function is a no-op.
147480 ** Set the SQLITE_INDEX_SCAN_UNIQUE flag in pIdxInfo->flags. Unless this
147482 ** support index-info flags. In that case this function is a no-op.
147494 ** are three possible strategies, in order of preference:
147524 ** function MATCH in the requested context" error. To discourage
147549 ** it would lead to an "unable to use function MATCH in the requested
147603 /* Regardless of the strategy selected, FTS can deliver rows in rowid (or
147725 ** table is missing a row that is present in the full-text index.
147744 ** passed in zTerm/nTerm.
147757 int nTerm, /* Size of term zTerm in bytes */
147778 ** not make this guarantee explicitly, but in practice there are always
147864 ** left-most leaf node in the tree that may contain the specified term.
147880 int nTerm, /* Size of term zTerm in bytes */
147887 int iHeight; /* Height of this node in tree */
147897 int nBlob = 0; /* Size of zBlob in bytes */
147926 char **pp, /* IN/OUT: Output pointer */
147927 sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
147941 ** a single document record of a doclist. So, in other words, this
147942 ** routine advances *ppPoslist so that it points to the next docid in
147961 ** last byte in the position-list.
148025 ** called, *pp may point to the start of the next varint in the position-list
148027 ** (in which case **pp will be a terminator bytes POS_END (0) or
148037 ** in the position-list. Because positions are delta-encoded, the value
148038 ** of the previous position is needed in order to compute the value of
148042 char **pp, /* IN/OUT: Pointer into position-list buffer */
148043 sqlite3_int64 *pi /* IN/OUT: Value read from position-list */
148075 ** into *pp contains all positions of both *pp1 and *pp2 in sorted
148078 ** that there is enough space in *pp to hold the complete output.
148090 int iCol1; /* The current column index in pp1 */
148091 int iCol2; /* The current column index in pp2 */
148163 ** each position in *pp2 for which there exists one or more positions in
148171 char **pp, /* IN/OUT: Preallocated output buffer */
148172 int nToken, /* Maximum difference in token positions */
148175 char **pp1, /* IN/OUT: Left input list */
148176 char **pp2 /* IN/OUT: Right input list */
148252 ** column-number in the position list.
148287 ** expression and *pp2 to the right. As usual, the indexes in the position
148288 ** lists are the offsets of the last token in each phrase (tokens "1" and "2"
148289 ** in the example above).
148292 ** entries that are not sufficiently NEAR entries in *pp1 removed.
148297 int nRight, /* Maximum difference in token positions */
148298 int nLeft, /* Maximum difference in token positions */
148299 char **pp1, /* IN/OUT: Left input list */
148300 char **pp2 /* IN/OUT: Right input list */
148336 int anOutput[16]; /* Size each output buffer in bytes */
148343 ** has been reached. In this case *pp is set to 0 and the function returns.
148353 char **pp, /* IN/OUT: Point to read varint from */
148356 sqlite3_int64 *pVal /* IN/OUT: Integer value */
148387 char **pp, /* IN/OUT: Output pointer */
148389 sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
148390 int *pbFirst, /* IN/OUT: True after first int written */
148414 ** sorted in either ascending or descending order.
148420 ** positions contained in either argument doclist). If the docids in the
148421 ** input doclists are sorted in ascending order, parameter bDescDoclist
148422 ** should be false. If they are sorted in ascending order, it should be
148426 ** containing the output doclist and SQLITE_OK is returned. In this case
148427 ** *pnOut is set to the number of bytes in the output doclist.
148430 ** are undefined in this case.
148453 ** are delta encoded. If they are in ascending order (bDescDoclist==0),
148454 ** then the first docid in each list is simply encoded as a varint. For
148456 ** current and previous docid (a positive number - since the list is in
148460 ** same number of bytes as it is in whichever of the input lists it is
148462 ** consumes either the same or less bytes as it did in the input (since
148463 ** the difference between it and the previous value in the output must
148471 ** be larger in the output than it was in the input (since the delta value
148478 ** A symetric argument may be made if the doclists are in descending
148513 ** This function does a "phrase" merge of two doclists. In a phrase merge,
148515 ** doclist for which there is a position in the left-hand input doclist
148518 ** If the docids in the input doclists are sorted in ascending order,
148519 ** parameter bDescDoclist should be false. If they are sorted in ascending
148528 char **paRight, int *pnRight /* IN/OUT: Right/output doclist */
148588 ** Argument pList points to a position list nList bytes in size. This
148590 ** a token in position 0 (of any column). If so, it writes argument iDelta
148598 int nList, /* Size of pList in bytes */
148639 ** Merge all doclists in the TermSelect.aaOutput[] array into a single
148640 ** doclist stored in TermSelect.aaOutput[0]. If successful, delete all
148643 ** If an OOM error occurs, return SQLITE_NOMEM. In this case it is
148644 ** the responsibility of the caller to free any doclists left in the
148652 /* Loop through the doclists in the aaOutput[] array. Merge them all
148705 int nDoclist /* Size of aDoclist in bytes */
148714 ** doclists are stored in order=ASC order, this padding would not be
148716 ** than or equal to the size of [doclistA] in that case). But this is
148718 ** may be smaller than (-1), as in the first example the -1 may be stored
148719 ** as a single-byte delta, whereas in the second it must be stored as a
148722 ** Similar padding is added in the fts3DoclistOrMerge() function.
148804 int nTerm, /* Size of zTerm in bytes */
148815 ** made by an fts4aux module, not an FTS table. In this case calling
148878 int nTerm, /* Size of zTerm in bytes */
148899 ** In addition to its current configuration, have the Fts3MultiSegReader
148908 int nTerm, /* Number of bytes in zTerm */
148932 int nTerm, /* Size of zTerm in bytes */
149044 ** This function counts the total number of docids in the doclist stored
149045 ** in buffer aList[], size nList bytes.
149068 ** Advance the cursor to the next row in the %_content table that
149071 ** simply the next row in the %_content table. For a docid lookup,
149132 ** in the %_content table.
149143 int nVal, /* Number of elements in apVal */
149173 /* In case the cursor has been used before, clear it now. */
149292 /* The column value supplied by SQLite must be in range. */
149355 ** in place to remove the entries that have already been merged. This
149383 int mxLevel = 0; /* Maximum relative level value in db */
149488 ** is the first in the doclist. In this case do not skip forward 2 bytes.
149542 int nToken = 15; /* Default number of tokens in snippet */
149594 ** function merges all segments in the database to a single segment.
149707 ** PendingTermsFlush() in in case that changes.
149829 ** The fts3 built-in tokenizers - "simple", "porter" and "icu"- are
149830 ** implemented in files fts3_tokenizer1.c, fts3_porter.c and fts3_icu.c
149832 ** declared in these files used to retrieve the respective implementations.
149890 /* Load the built-in tokenizers into the hash table */
149961 ** Allocate an Fts3MultiSegReader for each token in the expression headed
149969 ** If the allocated Fts3MultiSegReader just seeks to a single entry in a
149972 ** and merged incrementally. Otherwise, it has to be merged into an in-memory
149978 int *pnToken, /* OUT: Total number of tokens in phrase. */
149979 int *pnOr, /* OUT: Total number of OR nodes in expr. */
149980 int *pRc /* IN/OUT: Error code */
150009 ** It is merged into the main doclist stored in p->doclist.aAll/nAll.
150022 int nList /* Number of bytes in pList */
150112 ** means that the phrase does not appear in the current row, doclist.pList
150120 int nPoslist = 0; /* Number of bytes in aPoslist */
150218 ** This function is called for each Fts3Phrase in a full-text query
150236 ** scanned in forward order, and the phrase consists of
150279 ** doclists in reverse and by the fts3_write.c module to iterate through
150282 ** The doclist may be sorted in ascending (parameter bDescIdx==0) or
150289 int nDoclist, /* Length of aDoclist in bytes */
150290 char **ppIter, /* IN/OUT: Iterator pointer */
150291 sqlite3_int64 *piDocid, /* IN/OUT: Docid pointer */
150345 int nDoclist, /* Length of aDoclist in
150346 char **ppIter, /* IN/OUT: Iterator pointer */
150347 sqlite3_int64 *piDocid, /* IN/OUT: Docid pointer */
150376 ** Advance the iterator pDL to the next entry in pDL->aAll/nAll. Set *pbEof
150410 ** edited in place by fts3EvalNearTrim(), then pIter may not actually
150435 ** multi-token phrase. Advance it to the next matching document in the
150484 ** Advance it to the next matching documnent in the database and populate
150505 ** one incremental token. In which case the bIncr flag is set. */
150526 /* Advance the iterator for each token in the phrase once. */
150626 ** each phrase in the expression (subject to deferred token processing).
150635 Fts3Expr *pExpr, /* Expression to initialize phrases in */
150636 int *pRc /* IN/OUT: Error code */
150660 ** of the xFilter() method). There is one element in the array for each
150661 ** token in the FTS expression.
150663 ** Tokens are divided into AND/NEAR clusters. All tokens in a cluster belong
150666 ** separately. The root of a tokens AND/NEAR cluster is stored in
150672 int iToken; /* Position of token in phrase */
150692 int *pRc /* IN/OUT: Error code */
150730 ** Determine the average document (row) size in pages. If successful,
150734 ** The average document size in pages is calculated by first calculating
150735 ** determining the average size in bytes, B. If B is less than the amount
150736 ** of data that will fit on a single leaf page of an intkey table in
150738 ** the number of overflow pages consumed by a record B bytes in size.
150748 ** varints, where nCol is the number of columns in the FTS3 table.
150749 ** The first varint is the number of documents currently stored in
150751 ** data stored in all rows of each column of the table, from left
150791 ** This function is called once for each AND/NEAR cluster in the
150804 int nTC /* Number of entries in aTC[] */
150811 int nToken = 0; /* Total number of tokens in cluster */
150825 /* Count the tokens in this AND/NEAR cluster. If none of the doclists
150827 ** only 1 token, exit early. No tokens to defer in this case. */
150836 /* Obtain the average docsize (in pages). */
150841 /* Iterate through all tokens in this AND/NEAR cluster, in ascending order
150846 ** a. The cheapest token in the entire query (i.e. the one visited by the
150853 ** contains. Set variable "nMinEst" to the smallest number of documents in
150858 ** Then, for each token, defer it if loading the doclist would result in
150889 ** overflowing the 32-bit integer it is stored in. */
150893 /* Either this is the cheapest token in the entire query, or it is
150923 ** the full-text query currently stored in pCsr->pExpr. To iterate through
150939 /* Allocate a MultiSegReader for each token in the expression. */
150942 /* Determine which, if any, tokens in the expression should be deferred. */
150999 ** Parameter nNear is passed the NEAR distance of the expression (5 in
151001 ** the position list, and *pnToken is the number of phrase tokens in, the
151006 ** All positions in the pPhrase position list that are not sufficiently
151007 ** close to a position in the *paPoslist position list are removed. If this
151011 ** associated with pPhrase. And *pnToken is set to the number of tokens in
151015 int nNear, /* NEAR distance. As in "NEAR/nNear". */
151017 char **paPoslist, /* IN/OUT: Position list */
151018 int *pnToken, /* IN/OUT: Tokens in phrase of *paPoslist */
151050 ** point to the next matching row in the database. Expressions iterate through
151051 ** matching rows in docid order. Ascending order if Fts3Cursor.bDesc is zero,
151055 ** successful, the following variables in pExpr are set:
151064 ** FTs3Expr.pPhrase->doclist.nList (length of pList in bytes)
151071 ** entirely of deferred tokens, it is assumed to match every row in
151072 ** the db. In this case the position-list is not populated at all.
151076 ** next possible match, considering only non-deferred tokens. In other
151079 ** where "*" may match any single token. The position list in this case
151091 int *pRc /* IN/OUT: Error code */
151220 ** expression, using the data currently stored in the position lists
151221 ** (Fts3Expr->pPhrase.doclist.pList/nList) for each phrase in the expression.
151224 ** phrase in the NEAR expression is edited in place to contain only those
151226 ** constraints. In this case it returns 1. If the NEAR expression does not
151238 ** which is represented in tree form as:
151251 ** no exceptions to this - it's the way the parser in fts3_expr.c works.
151309 ** the appropriate SQLite error code. In this case the returned value is
151315 int *pRc /* IN/OUT: Error code */
151329 ** all phrases involved in the NEAR. This is because the snippet(),
151405 ** * Up until this point, "NEAR" operators in the expression have been
151450 ** Advance to the next document that matches the FTS expression in
151530 ** After allocating the Fts3Expr.aMI[] array for each phrase in the
151533 ** the values in Fts3Expr.aMI[] according to the position-list currently
151534 ** found in Fts3Expr.pPhrase->doclist.pList for each of the phrase
151645 /* Caution: pRoot may iterate through docids in ascending or descending
151665 ** 1. The total number of occurrences of the phrase in each column of
151668 ** 2. For each column, the number of rows in the table for which the
151680 ** values are set to the number of documents in the table. In other
151681 ** words we assume that very common tokens occur exactly once in each
151689 ** that meet the NEAR constraint are included in the counts.
151725 ** a position-list indicating the occurrences of the phrase in column iCol
151729 ** occurrence of the phrase in the column, stored using the normal (delta+2)
151772 ** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the
151783 /* This is the descendent of an OR node. In this case we cannot use
151785 ** into memory in this case. */
151920 ** The author disclaims copyright to this source code. In place of
151976 int argc, /* Number of elements in argv array */
151991 /* The user should invoke this in one of two forms:
152078 /* This vtab delivers always results in "ORDER BY term ASC" order. */
152222 /* State 0. In this state the integer just read was a docid. */
152229 /* State 1. In this state we are expecting either a 1, indicating
152234 ** integer encountered in state 1 is not 0 or 1, then we need to
152281 int nVal, /* Number of elements in apVal */
152290 int iEq = -1; /* Index of term=? value in apVal */
152291 int iGe = -1; /* Index of term>=? value in apVal */
152292 in apVal */
152293 int iLangid = -1; /* Index of languageid=? value in apVal */
152320 /* In case this cursor is being reused, close and zero it. */
152473 ** The author disclaims copyright to this source code. In place of
152514 ** operator in a similar format to that used by the lemon parser
152557 ** FTSQUERY_PHRASE with a unary "-" attached to it. i.e. "mysql" in the
152567 int nCol; /* Number of entries in azCol[] */
152635 ** and other information (column names etc.) in pParse. Create an Fts3Expr
152735 ** is included in the buffer. This function attempts to tokenize the entire
152765 ** The first pass, in the block below, uses a tokenizer cursor to iterate
152766 ** through the tokens in the expression. This pass uses fts3ReallocOrFree()
152767 ** to assemble data in two dynamic buffers:
152775 ** The second pass, in the block that begins "if( rc==SQLITE_DONE )" below,
152776 ** appends buffer zTemp to buffer p, and fills in the Fts3Expr and Fts3Phrase
152871 unsigned char parenOnly; /* Only valid in paren mode */
152953 ** a quote character embedded in a string.
153013 ** group more tightly). For example, in the C language, the == operator
153017 ** is defined), the order of the operators in precedence from highest to
153046 ** of pNew and the existing nodes of the tree. This may result in the head
153047 ** of the tree changing, in which case *ppHead is set to the new root node.
153071 ** Parse the fts3 query expression found in buffer z, length n. This function
153088 Fts3Expr *pNotBranch = 0; /* Only used in legacy parse mode */
153128 ** an expression contained in parenthesis is required. If a
153160 ** Return an error in either case.
153246 ** an equivalent but more balanced form. The tree is modified in place.
153259 int eType = pRoot->eType; /* Type of node in this tree */
153279 /* Set $p to point to the left-most leaf in the tree of eType nodes. */
153285 /* This loop runs once for each leaf in the tree of eType nodes. */
153326 /* Set $p to point to the next leaf in the tree of eType nodes */
153427 ** in this case.
153434 int nCol, /* Number of entries in azCol[] */
153483 ** of each column in the target fts3 table, in order from left to right.
153497 int nCol, /* Number of entries in azCol[] */
153785 ** The author disclaims copyright to this source code. In place of
153793 ** This is the implementation of generic hash-tables used in SQLite.
153799 ** The code in this file is only compiled if:
153802 ** (in which case SQLITE_CORE is not defined), or
153805 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
153912 ** The C syntax in this function definition may be unfamilar to some
153933 ** For help in interpreted the obscure C code in the function definition,
153952 Fts3HashElem *pHead; /* First element already in pEntry */
153997 /* This function (for internal use only) locates an element in an
154100 ** The key is not copied in this instance. If a malloc fails, then
154109 int nKey, /* Number of bytes in the key */
154171 ** The author disclaims copyright to this source code. In place of
154184 ** The code in this file is only compiled if:
154187 ** (in which case SQLITE_CORE is not defined), or
154190 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
154216 int iOffset; /* current position in zInput */
154253 ** used to incrementally tokenize this string is returned in
154304 ** isConsonant() and isVowel() determine if their first character in
154310 ** in which case it is a vowel.
154312 ** In these routine, the letters are in reverse order. So the 'y' rule
154343 ** In prose: A word is an optional consonant followed by zero or
154348 ** Return true if the m-value for z is 1 or more. In other words,
154352 ** In this routine z[] is in reverse order. So we are really looking
154399 ** Return TRUE if the word ends in a double consonant.
154414 ** first three letters and the first one cannot be in [wxy].
154429 ** The input word *pz and zFrom are both in reverse order. zTo
154430 ** is in normal order.
154486 ** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
154490 ** Any upper-case characters in the US-ASCII character set ([A-Z])
154501 ** in [a-zA-Z] then no stemming is attempted and this routine just
154525 /* The use of a character not in [a-zA-Z] means that we fallback
154549 /* Do nothing. The work was all in the test */
154557 /* Do nothing. The work was all in the test */
154731 /* z[] is now the stemmed word in reverse order. Flip it back
154744 ** part of a token. In other words, delimiters all must have
154764 int *pnBytes, /* OUT: Number of bytes in token */
154821 ** tokenizer in *ppModule
154836 ** The author disclaims copyright to this source code. In place of
154850 ** The code in this file is only compiled if:
154853 ** (in which case SQLITE_CORE is not defined), or
154856 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
154889 ** the string <key-name> must already exist in the has table. Otherwise,
155068 ** designed to be used in concert with the Tcl testing framework. This
155078 ** list. For each token in the <input-string>, three elements are
155082 ** using the built-in "simple" tokenizer:
155147 zErr = "error in xCreate()";
155152 zErr = "error in xOpen()";
155165 zErr = "error in xClose()";
155169 zErr = "error in xDestroy()";
155235 ** This function is used for testing only, it is not included in the
155239 ** can be used as designed by the C-code in the queryTokenizer and
155241 ** in the README.tokenizer file as an example, so it is important to
155289 ** Set up SQL objects in database db used to access the contents of
155297 ** fts3TokenizerFunc() in this file for details) and, if ENABLE_TABLE is
155355 ** The author disclaims copyright to this source code. In place of
155368 ** The code in this file is only compiled if:
155371 ** (in which case SQLITE_CORE is not defined), or
155374 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
155395 int iOffset; /* current position in pInput */
155424 ** track such information in the database, then we'd only want this
155461 ** used to incrementally tokenize this string is returned in
155511 int *pnBytes, /* OUT: Number of bytes in token */
155577 ** tokenizer in *ppModule
155592 ** The author disclaims copyright to this source code. In place of
155618 ** statement and returns one row for each token in the result. With
155656 int nToken; /* Size of zToken in bytes */
155693 ** in this case. Or, if an error occurs, an SQLite error code is returned.
155694 ** The final value of *pazDequote is undefined in this case.
155697 int argc, /* Number of elements in argv[] */
155749 int argc, /* Number of elements in argv array */
155924 int nVal, /* Number of elements in apVal */
156049 ** The author disclaims copyright to this source code. In place of
156062 ** code in fts3.c.
156078 ** of it. i.e. if a full-text index node is 900 bytes in size, then a buffer
156095 ** bytes and larger. Nodes are loaded in chunks of FTS3_NODE_CHUNKSIZE bytes.
156115 ** The two values that may be meaningfully bound to the :1 parameter in
156125 ** debugging FTS only, it should not usually be turned on in production
156160 int iCol; /* Column token must occur in */
156161 Fts3DeferredToken *pNext; /* Next in list of deferred tokens */
156168 ** this structure are only manipulated by code in this file, opaque handles
156169 ** of type Fts3SegReader* are also used by code in fts3.c to iterate through
156189 sqlite3_int64 iEndBlock; /* Rowid of final block in segment (or 0) */
156204 int nTerm; /* Number of bytes in current term */
156208 int nDoclist; /* Size of doclist in current entry */
156222 ** An instance of this structure is used to create a segment b-tree in the
156232 sqlite3_int64 iFirst; /* First slot in %_segments written */
156233 sqlite3_int64 iFree; /* Next free slot in %_segments */
156235 int nTerm; /* Number of bytes in zTerm */
156239 int nData; /* Bytes of data in aData */
156257 ** the tree is assembled in memory and written out only once all leaves have
156268 int nTerm; /* Number of bytes in zTerm */
156352 /* Return segments in order from oldest to newest.*/
156378 ** of the oldest level in the db that contains at least ? segments. Or,
156379 ** if no level in the FTS index contains more than ? segments, the statement
156385 /* Estimate the upper limit on the number of leaf nodes in a new segment
156422 ** Return the largest relative level in the FTS index or indexes. */
156425 /* Return segments in order from oldest to newest.*/
156528 ** Similar to fts3SqlStmt(). Except, after binding the parameters in
156591 ** level within the index) are encoded in 64-bit integer values stored
156592 ** in the %_segdir table on disk. This function is used to convert three
156609 int iIndex, /* Index in p->aIndex[] */
156623 ** all rows in the %_segdir table, from oldest to newest. If successful,
156686 PendingList **pp, /* IN/OUT: Pointer to PendingList struct */
156726 ** Zero is always returned in this case. Otherwise, if no OOM error occurs,
156730 PendingList **pp, /* IN/OUT: PendingList structure */
156824 ** pending-terms hash-table. The docid used is that currently stored in
156834 u32 *pnWord /* IN/OUT: Incr. by number tokens inserted */
156854 ** zText==0. In this case, add zero token entries to the hash table and
156955 ** operation. It adds entries for each term in the new record to the
157022 ** defined columns in the FTS3 table, plus one for the docid field.
157040 ** In FTS3, this is an error. It is an error to specify non-NULL values
157101 ** The first element in the apVal[] array is assumed to contain the docid
157153 ** This function allocates a new level iLevel index in the segdir table.
157195 ** full, merge all segments in level iLevel into a single iLevel+1
157219 ** with the contents of the blob stored in the "block" column of the
157221 ** to the size of the blob in bytes before returning.
157228 ** This function may leave an open sqlite3_blob* handle in the
157241 char **paBlob, /* OUT: Blob data in malloc'd buffer */
157347 ** Move the iterator passed as the first argument to the next term in the
157358 int nPrefix; /* Number of bytes in term prefix */
157359 int nSuffix; /* Number of bytes in term suffix */
157460 ** Set the SegReader to point to the first docid in the doclist associated
157486 ** Advance the SegReader to point to the next docid in the doclist
157491 ** in the doclist entry (i.e. immediately past the docid varint).
157499 int *pnOffsetList /* OUT: Length of *ppOffsetList in bytes */
157509 ** Pending-terms doclists are always built up in ascending order, so
157556 /* List may have been edited in place by fts3EvalNearTrim() */
157559 /* If there are no more entries in the doclist, set pOffsetList to
157668 /* The entire segment is stored in the root node. */
157705 ** a subset of the terms stored in the Fts3Table.pendingTerms array.
157708 ** through each term in the pending-terms table. Or, if isPrefixIter is
157711 ** "firebird", then the iterator visits the following 'terms' (in the order
157764 ** objects in term order using qsort(). This uses the same comparison
157772 /* The query is a simple term lookup that matches at most one term in
157841 ** A different comparison function for SegReader structures. In this
157842 ** version, it is assumed that each SegReader points to an entry in
157845 ** 1) EOF (end of doclist in this case) is greater than not EOF.
157887 int nTerm /* Size of term zTerm in bytes */
157905 ** the final (nSegment-nSuspect) members are already in sorted order
157907 ** the array around until all entries are in sorted order.
157946 int n /* Size of buffer z in bytes */
157960 ** Find the largest relative level number in the table. If successful, set
157990 sqlite3_int64 nLeafData, /* Bytes of leaf data in segment */
157992 int nRoot /* Number of bytes in buffer zRoot */
158017 ** zNext, in bytes. For example,
158025 int nPrev, /* Size of buffer zPrev in bytes */
158027 int nNext /* Size of buffer zNext in bytes */
158041 SegmentNode **ppTree, /* IN/OUT: SegmentNode handle */
158044 int nTerm /* Size of term in bytes */
158054 int nData = pTree->nData; /* Current size of node in bytes */
158081 /* There is no prefix-length field for first term in a node */
158112 ** If this is the first node in the tree, the term is added to it.
158179 int iHeight, /* Height of this node in tree */
158181 sqlite3_int64 iFree, /* Block id of next free slot in %_segments */
158184 int *pnRoot /* OUT: Size of root node in bytes */
158241 ** and return it via the input/output variable *ppWriter in this case.
158247 SegmentWriter **ppWriter, /* IN/OUT: SegmentWriter handle */
158250 int nTerm, /* Size of term in bytes */
158252 int nDoclist /* Size of doclist in bytes */
158254 int nPrefix; /* Size of term prefix in bytes */
158255 int nSuffix; /* Size of term suffix in bytes */
158270 /* Allocate a buffer in which to accumulate data */
158275 /* Find the next free blockid in the %_segments table */
158309 ** to the database (still available in pWriter->zTerm), and
158314 ** In other words, it must be the prefix of zTerm 1 byte longer than
158433 ** The first value in the apVal[] array is assumed to contain an integer.
158462 ** Set *pnMax to the largest segment level in the database for the index
158465 ** Segment levels are stored in the 'level' column of the %_segdir table.
158529 ** Delete all entries in the %_segments table associated with the segment
158557 ** each of the SegReader objects in the array passed as the third
158616 ** If there are no entries in the input position list for column iCol, then
158625 char **ppList, /* IN/OUT: Pointer to position list */
158626 int *pnList /* IN/OUT: Size of buffer *ppList in bytes */
158661 ** Cache data in the Fts3MultiSegReader.aBuffer[] buffer (overwriting any
158689 int *pnPoslist /* OUT: Size of position list in bytes */
158756 int nTerm /* Length of zTerm in bytes */
158798 int nTerm /* Number of bytes in zTerm */
158839 ** have been made. Calling this function puts the MultiSegReader in such
158845 ** then the entire doclist for the term is available in
158894 /* Advance the first pCsr->nAdvance entries in the apSegment[] array
158895 ** forward. Then sort the list in order of current term again.
158918 ** required callbacks have been made. In this case exit early.
158957 sqlite3_int64 iPrev = 0; /* Previous docid stored in doclist */
158959 /* The current term of the first nMerge entries in the array
159069 ** by one or more space (0x20) characters. In the first case, set *piEndBlock
159070 ** to the integer value and *pnByte to zero before returning. In the second,
159121 /* Loop through all entries in the %_segdir table corresponding to
159122 ** segments in this index on levels greater than iAbsLevel. If there is
159124 ** such segments are smaller than nLimit bytes in size, they will be
159134 ** old version of FTS. In this case it is not possible to determine
159158 /* Loop through all %_segdir entries for segments in this index with
159161 ** oldest segment in the range, 1 for the next oldest, and so on.
159163 ** In other words, move all segments being promoted to level -1,
159164 ** setting the "idx" fields as appropriate to keep them in the same
159198 ** Merge all level iLevel segments in the database into a single
159201 ** currently present in the database.
159204 ** segment in the database, SQLITE_DONE is returned immediately.
159211 int iIndex, /* Index in p->aIndex[] to merge */
159239 /* This call is to merge all segments in the database to a single
159241 ** greatest segment level currently present in the database for this
159374 ** Insert the sizes (in tokens) for each column of the document
159381 u32 *aSz /* Sizes of each column, in tokens */
159384 int nBlob; /* Number of bytes in the BLOB */
159409 ** where N is the number of user defined columns in the fts3 table plus
159413 ** Varint 0: Total number of rows in the table.
159415 ** Varint 1..nCol: For each column, the total number of tokens stored in
159418 ** Varint 1+nCol: The total size, in bytes, of all text values in all
159427 int nChng /* Change in the number of documents */
159615 ** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute
159669 ** to build up nodes or other blobs of data in.
159675 int n; /* Number of valid bytes of data in a[] */
159697 int iIdx; /* Index of *output* segment in iAbsLevel+1 */
159722 int nDoclist; /* Size of doclist in bytes */
159728 ** bytes in size, extend (realloc) it to be so.
159800 ** Initialize a node-reader object to read the node in buffer aNode/nNode.
159829 ** The block id of the leaf node just written to disk may be found in
159862 ** bytes in size, write the key here. */
159911 ** stored in blob *pNode. The node need not contain any terms, but the
159921 ** If the size of the value in blob pPrev is zero, then this is the first
159937 int nTerm, /* Size of zTerm in bytes */
159939 int nDoclist /* Size of aDoclist in bytes */
159943 int nPrefix; /* Size of term prefix in bytes */
159944 int nSuffix; /* Size of term suffix in bytes */
159993 int nSpace; /* Total space in bytes required on leaf */
160017 ** to the database (still available in pLeaf->key), and
160022 ** In other words, it must be the prefix of zTerm 1 byte longer than
160071 int *pRc /* IN/OUT: Error code */
160074 int iRoot; /* Index of root in pWriter->aNodeWriter */
160078 /* Set iRoot to the index in pWriter->aNodeWriter[] of the output segment
160095 ** the node would be stored as a blob in the "root" column of the %_segdir
160096 ** table. However, this is not permitted in this case. The problem is that
160097 ** space has already been reserved in the %_segments table, and so the
160106 ** Todo: Better might be to defer allocating space in the %_segments
160151 ** Compare the term in buffer zLhs (size in bytes nLhs) with that in
160152 ** zRhs (size in bytes nRhs) using memcmp. If one term is a prefix of
160173 ** Query to see if the entry in the %_segments table with blockid iEnd is
160178 ** error code. The final value of *pbRes is undefined in this case.
160212 ** greater than the largest key currently stored in the potential
160220 int nKey, /* Number of bytes in nKey */
160232 int nRoot = 0; /* Size of aRoot[] in bytes */
160253 /* Check for the zero-length marker in the %_segments table */
160345 ** *piIdx is undefined in this case.
160370 ** In the %_segdir table, a segment is defined by the values in three
160380 ** of input segments, multiplied by two. This value is stored in stack
160389 ** In the actual code below, the value "16" is replaced with the
160417 /* Calculate the first block to use in the output segment */
160429 /* Insert the marker in the %_segments table to make sure nobody tries
160478 ** Update the 'idx' values of the remaining segments in the level so that
160487 int nIdx = 0; /* Valid entries in aIdx[] */
160552 ** This function creates a new node image in blob object *pNew by copying
160558 int nNode, /* Size of aNode in bytes */
160561 int nTerm, /* Size of zTerm in bytes */
160562 sqlite3_int64 *piBlock /* OUT: Block number in next layer down */
160603 ** Remove all terms smaller than zTerm/nTerm from segment iIdx in absolute
160605 ** table, and modifying existing entries in both the %_segments and %_segdir
160616 int nTerm /* Number of bytes in buffer zTerm */
160693 ** or modified in place so that it no longer contains those entries that
160694 ** have been duplicated in the output segment.
160711 ** somewhere in the pCsr->apSegment[] array. */
160727 ** segment to the upper level. The segment is modified in place
160745 ** Store an incr-merge hint in the database.
160764 ** exists, is stored in the rowid==1 row of the %_stat table.
160799 ** Otherwise, append an entry to the hint stored in blob *pHint. Each entry
160808 i64 iAbsLevel, /* First varint to store in hint */
160809 int nInput, /* Second varint to store in hint */
160810 int *pRc /* IN/OUT: Error code */
160824 ** If no error occurs, return SQLITE_OK. If the hint blob in *pHint does
160849 ** values for the _segdir.idx field) in the highest level that contains
160850 ** at least nMin segments. Multiple merges might occur in an attempt to
160876 int iIdx = 0; /* Largest idx in level (iAbsLevel+1) */
160896 ** last entry in it specifies a relative level smaller than or equal
160919 ** nMin segments and no hint in the %_stat table. No work to do.
160920 ** Exit early in this case. */
160926 ** segments available in level iAbsLevel. In this case, no work is
161098 int nTerm, /* Size of zTerm in bytes */
161118 ** Return a checksum of all entries in the FTS index that correspond to
161124 ** return value is undefined in this case.
161198 ** code. The final value of *pbOk is undefined in this case.
161251 int nToken = 0; /* Number of bytes in token */
161253 int iPos = 0; /* Position of token in zText */
161292 ** prefix in the document set, a 64-bit checksum is calculated (by code
161293 ** in fts3ChecksumEntry()) based on the following:
161298 ** + The language-id of the row it appears in,
161299 ** + The docid of the row it appears in,
161300 ** + The column it appears in, and
161303 ** The checksums for all entries in the index are XORed together to create
161306 ** The integrity-check code calculates the same checksum in two ways:
161381 ** Free all entries in the pCsr->pDeffered list. Entries are added to
161396 ** Generate deferred-doclists for all tokens in the pCsr->pDeferred list
161425 int nToken = 0; /* Number of bytes in token */
161427 int iPos = 0; /* Position of token in zText */
161489 int iCol /* Column that token must appear in (or -1) */
161511 ** present in the FTS3 table. If it is, delete it and adjust the contents
161517 int *pnChng, /* IN/OUT: Decrement if row is deleted */
161521 int bFound = 0; /* True if *pRowid really is in the table */
161529 /* Deleting this row means the whole table is empty. In this case
161531 ** data in the pendingTerms hash table. */
161574 int nChng = 0; /* Net change in number of documents */
161604 /* Allocate space to hold the change in document sizes */
161636 /* The new rowid is not NULL (in this case the rowid will be
161647 ** be losslessly converted to an integer. In this case, the eventual
161648 ** call to fts3InsertData() (either just below or further on in this
161705 ** Flush any data in the pending-terms hash table to disk. If successful,
161706 ** merge all segments in the database (including the new segment, if
161733 ** The author disclaims copyright to this source code. In place of
161750 ** Characters that may appear in the second argument to matchinfo().
161790 int nSnippet; /* Requested snippet length (in tokens) */
161791 int nPhrase; /* Number of phrases in query */
161797 int nToken; /* Number of tokens in phrase */
161799 int iHead; /* Next value in position list */
161801 int iTail; /* Next value in trailing position list */
161807 int iPos; /* Index of first token in snippet */
161819 int nCol; /* Number of columns in table */
161820 int nPhrase; /* Number of matchable phrases in query */
161821 sqlite3_int64 nDoc; /* Number of docs in database */
161828 ** (nElem * sizeof(u32)) bytes in size. See the MatchinfoBuffer code below
161848 int n; /* Length of z in bytes (excl. nul-term) */
161849 int nAlloc; /* Allocated size of buffer z in bytes */
161960 ** the list. *piPos contains the value of the previous entry in the list.
161996 ** Iterate through all phrase nodes in an FTS3 query, except those that
162034 ** Load the doclists for each phrase in the query associated with FTS3 cursor
162038 ** phrases in the expression (all phrases except those directly or
162040 ** pnToken is not NULL, then it is set to the number of tokens in all
162045 int *pnPhrase, /* OUT: Number of phrases in query */
162046 int *pnToken /* OUT: Number of tokens in query */
162153 u64 mHighlight = 0; /* Mask of tokens to highlight in snippet */
162227 ** (a) +1 point for each occurrence of a matchable phrase in the snippet.
162229 ** (b) +1000 points for the first occurrence of each matchable phrase in
162232 ** The selected snippet parameters are stored in structure *pFragment before
162233 ** returning. The score of the selected snippet is stored in *piScore
162241 u64 *pmSeen, /* IN/OUT: Mask of phrases seen */
162246 int nList; /* Number of phrases in expression */
162254 /* Iterate through the phrases in the expression to count them. The same
162273 ** the set of phrases in the expression to populate the aPhrase[] array.
162290 /* Loop through all candidate snippets. Store the best snippet in
162291 ** *pFragment. Store its associated 'score' in iBestScore.
162325 int nAppend /* Size of zAppend in bytes (or -1) */
162362 ** This function "shifts" the beginning of the snippet forward in the
162376 int iLangid, /* Language id to use in tokenizing */
162379 int nDoc, /* Size of buffer zDoc in bytes */
162380 int *piPos, /* IN/OUT: First token of snippet */
162381 u64 *pHlmask /* IN/OUT: Mask of tokens to highlight */
162394 /* Ideally, the start of the snippet should be pushed forward in the
162410 ** or more tokens in zDoc/nDoc.
162442 int isLast, /* True for final fragment in snippet */
162443 int nSnippet, /* Number of tokens in extracted snippet */
162452 int nDoc; /* Size of zDoc in bytes */
162481 int iBegin = 0; /* Offset in zDoc of start of token */
162482 int iFin = 0; /* Offset in zDoc of end of token */
162486 ** in the FTS code the variable that the third argument to xNext points to
162554 ** This function is used to count the entries in a column-list (a
162557 ** beginning of the first varint in the column-list (the varint that
162558 ** contains the position of the first matching term in the column data).
162560 ** the last varint in the column-list (either the 0x00 signifying the end
162562 ** the next column in the position-list).
162564 ** The number of elements in the column-list is returned.
162657 ** Y values are set to nDoc, where nDoc is the number of documents in the
162784 ** hits for a single phrase on a single row in order to calculate the
162838 ** array before returning. SQLITE_OK is returned in this case.
162851 ** contains one element for each matchable phrase in the query.
162866 int nLive = 0; /* Number of iterators in aIter not at EOF */
162926 ** pInfo->aMatchinfo[] buffer is left in is undefined.
162960 sqlite3_int64 nDoc; /* Number of rows in table */
163066 ** matchinfo function has been called for this query. In this case
163071 int nMatchinfo = 0; /* Number of u32 elements in match-info */
163074 /* Determine the number of phrases in the query */
163078 /* Determine the number of integers in the buffer returned by this call. */
163132 int nToken /* Approximate number of tokens in snippet */
163140 ** the data in the current row. The first iteration of the for(...) loop
163141 ** below attempts to locate a single fragment of text nToken tokens in
163142 ** size that contains at least one instance of all phrases in the query
163143 ** expression that appear in the current row. If such a fragment of text
163147 int nSnippet = 0; /* Number of fragments in this snippet */
163149 int nFToken = -1; /* Number of tokens in each fragment */
163184 /* Find the best snippet of nFToken tokens in column iRead. */
163198 /* If all query phrases seen by fts3BestSnippet() are present in at least
163246 int nTerm; /* Number of tokens in phrase */
163249 int iPos = 0; /* First position in position-list */
163280 int nToken; /* Number of tokens in query */
163293 /* Count the number of terms in the query */
163327 /* Retreive the text stored in column iCol. If an SQL NULL is stored
163328 ** in column iCol, jump immediately to the next iteration of the loop.
163442 ** The author disclaims copyright to this source code. In place of
163531 int nInput; /* Size of aInput[] in bytes */
163554 ** all characters in string zIn/nIn to be separators (if bAlnum==0) or
163557 ** For each codepoint in the zIn/nIn string, this function checks if the
163562 ** codepoints in the aiException[] array.
163565 ** identifies as a diacritic) occurs in the zIn/nIn string it is ignored.
163573 int nIn /* Length of z in bytes */
163594 int nNew; /* Number of valid entries in array aNew[] */
163703 ** used to incrementally tokenize this string is returned in
163709 int nInput, /* Size of string aInput in bytes */
163838 ** The author disclaims copyright to this source code. In place of
163865 /* Each unsigned integer in the following array corresponds to a contiguous
163869 ** The most significant 22 bits in each 32-bit value contain the first
163870 ** codepoint in the range. The least significant 10 bits are used to store
163871 ** the size of the range (always at least 1). In other words, the value
163990 ** in the ASCII range with a diacritic added, return the codepoint
164066 /* Each entry in the following array defines a rule for folding a range
164070 ** If the least significant bit in flags is clear, then the rule applies
164073 ** every second codepoint in the range, starting with codepoint C.
164075 ** The 7 most significant bits in flags are an index into the aiOff[]
164205 ** The author disclaims copyright to this source code. In place of
164221 ** The data structure for a single virtual r-tree table is stored in three
164222 ** native SQLite tables declared as follows. In each case, the '%' character
164223 ** in the table name is replaced with the user-supplied name of the r-tree
164230 ** The data for each node of the r-tree structure is stored in the %_node
164232 ** an entry in
164233 ** And for each row of data in the table, there is an entry in the %_rowid
164238 ** empty. The nodeno of the root node is always 1. All other nodes in the
164247 ** stored in the node.
164304 ** the number of rows in the virtual table to calculate the costs of
164319 int iNodeSize; /* Size in bytes of each node in the node table */
164329 i64 nRowEst; /* Estimated number of rows in this table */
164357 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
164386 ** represents is the iCell-th entry in the parent node.
164398 ** maximum. In Gutman's notation:
164420 ** Number of entries in the cursor RtreeNode cache. The first entry is
164434 int nConstraint; /* Number of entries in aConstraint */
164437 int nPoint; /* Number of slots used in aPoint[] */
164507 RtreeNode *pNext; /* Next node in this hash collision chain */
164510 /* Return the number of cells in a node */
164526 ** operators in order to constrain a search.
164533 ** This object is deleted automatically by the destructor mechanism in
164553 ** An instance of this structure (in the form of a BLOB) is returned by
164586 /* The testcase() macro should already be defined in the amalgamation. If
164749 ** in the Rtree.aHash table.
164832 /* Check if the requested node is already in the hash table. If so,
164958 ** If there is not enough free space in pNode, return SQLITE_FULL.
164965 int nCell; /* Current number of cells in pNode */
165046 ** Return coordinate iCoord from cell iCell in node pNode.
165254 ** Store the results in "r".
165383 ** in a coordinate pair. But make pCellData point to the lower bound.
165416 ** The op is given by p->op. The xN is p->iCoord-th coordinate in
165443 ** One of the cells in node pNode is guaranteed to have a 64-bit
165466 ** in its parent. If pNode is the root node, return -1.
165483 ** iLevel values coming first. In this way, if rScore is the same for all
165499 ** Interchange two search points in a cursor.
165823 ** return SQLITE_OK. If there is no such record in the table, set
165917 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
166006 ** table scan strategies to choose from (in order from most to
166018 ** the constraint in sqlite3_index_info.aConstraintUsage[] with
166021 ** The first of each pair of bytes in idxStr identifies the constraint
166121 ** Return the N-dimensional volumn of the cell stored in *p.
166151 ** of the objects size in each dimension.
166164 ** Store the union of cells p1 and p2 in p1.
166244 ** ChooseSubTree in r*tree terminology.
166303 ** the node pNode. This function updates the bounding box cells in
166358 ** (nIdx-1) in no particular order. This function sorts the values
166359 ** in aIdx according to the indexed values in aDistance. For
166430 ** (nIdx-1) in no particular order. This function sorts the values
166431 ** in aIdx according to dimension iDim of the cells in aCell. The
166680 ** In this case avoid the all to nodeWrite().
166801 /* Remove the entry in the parent cell. */
166830 /* Remove the node from the in-memory hash table and link it into
166878 ** the in-memory node image, so it cannot fail.
166884 ** cell in the parent node so that it tightly contains the updated
166981 /* Find a node to store this cell in. pNode->iNode currently contains
167050 /* Find a node to store this cell in. pNode->iNode currently contains
167085 int iCell; /* Index of iDelete cell in pLeaf */
167099 /* Delete the cell in question from the leaf node. */
167112 /* Delete the corresponding entry in the <rtree>_rowid table. */
167125 ** in this scenario).
167198 ** Parameter iCol is the index of the leftmost column involved in the
167265 ** In the first case, if the conflict-handling mode is REPLACE, then
167266 ** the conflicting row can be removed before proceeding. In the second
167306 /* If a rowid value was supplied, check if it is already present in
167440 ** of the number of rows in the virtual table. If possible, this is based
167609 ** table already exists. In this case the node-size is determined by inspecting
167615 ** would fit in a single node, use a smaller node-size.
167765 ** entry for each cell in the r-tree node. Each entry is itself a
167868 ** or sqlite3_rtree_query_callback(). In other words, this routine is the
168009 ** The author disclaims copyright to this source code. In place of
168054 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
168134 ** MATCH_ALL. For each MATCH_ONE, skip one character in the
168182 ** the build-in LIKE operator. The first argument to the function is the
168203 ** of deep recursion and N*N behavior in patternCompare().
168364 int nInput; /* Size of utf-16 input string in bytes */
168365 int nOut; /* Size of output buffer in bytes */
168558 ** The author disclaims copyright to this source code. In place of
168593 int nChar; /* Number of UChar elements in pInput */
168595 int *aOffset; /* Offsets of each character in utf-8 input */
168607 int argc, /* Number of entries in argv[] */
168645 ** used to incrementally tokenize this string is returned in
168651 int nInput, /* Length of zInput in bytes */
168734 int *pnBytes, /* OUT: Number of bytes in token */
168823 ** The author disclaims copyright to this source code. In place of
168836 ** SQLite database. The tables it expects to find are described in
168837 ** sqlite3rbu.h. Essentially, for each table xyz in the target database
168839 ** created in the RBU database and populated with one row for each row to
168842 ** The update proceeds in three stages:
168848 ** "<database>-oal", they go on using the original database in
168856 ** updates are done in sorted key order.
168864 ** detect the new *-wal file and read the database in wal mode. At
168868 ** 3) The new *-wal file is checkpointed. This proceeds in the same way
168872 ** the checkpoint progress is saved in the RBU database and the
168873 ** checkpoint can be resumed by another RBU client at some point in
168885 ** pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE
168895 ** collected in the rbu_xyz table. And for both UPDATEs and DELETEs all
168909 /************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
168914 ** The author disclaims copyright to this source code. In place of
168933 ** The problem is that in order to update a b-tree, the leaf page (at least)
168938 ** Additionally, because the index updates are likely to be applied in
168939 ** random order, access to pages within the database is also likely to be in
168950 ** Additionally, this extension allows the work involved in writing the
168957 ** to read from the original database snapshot. In other words, partially
168960 ** "RBU" stands for "Resumable Bulk Update". As in a large database update
168975 ** non-NULL PRIMARY KEY values. Rows with NULL values stored in PRIMARY
168993 ** containing an RBU update is an "RBU database". For each table in the
168998 ** the same type as the corresponding column in the target database.
169008 ** The order of the columns in the data_% table does not matter.
169016 ** tables within the RBU database are always processed in order sorted by
169018 ** of the RBU tables the user can therefore control the order in which they
169037 ** target table must be present in the input table. For virtual tables,
169038 ** hidden columns are optional - they are updated by RBU if present in
169057 ** do so results in an SQLITE_MISMATCH error.
169062 ** real primary key values of the row to delete should be stored in the
169063 ** corresponding columns of the data_% table. The values stored in the
169070 ** stored in the corresponding columns of the data_% table row, as should
169071 ** the new values of all columns being update. The text value in the
169073 ** there are columns in the target database table, and must consist entirely
169074 ** of 'x' and '.' characters (or in some special cases 'd' - see below). For
169087 ** for UPDATEs may also be set to 'd'. In this case, instead of updating the
169088 ** target table with the value stored in the corresponding data_% column, the
169089 ** user-defined SQL function "rbu_delta()" is invoked and the result stored in
169091 ** original value currently stored in the target table column and the
169092 ** value specified in the data_xxx table.
169102 ** Finally, if an 'f' character appears in place of a 'd' or 's' in an
169104 ** to be a "fossil delta" - a patch to be applied to a blob value in the
169105 ** format used by the fossil source-code management system. In this case
169122 ** However, RBU is more efficient if reading the rows in from each data_xxx
169123 ** table in "rowid" order is roughly the same as reading them sorted by
169124 ** the PRIMARY KEY of the corresponding target database table. In other
169149 ** update application is saved in the RBU database for later
169165 ** An RBU update may not be applied to a database in WAL mode. Attempting
169203 ** Or, if zState is non-NULL, it must be a path to a database file in which
169217 ** SQLite's built-in VFSs, including the multiplexor VFS. However it does
169229 ** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
169232 ** The second argument to this function identifies a database in which
169238 ** returned SQLITE_DONE, the vacuum state is stored in the state database.
169244 ** is the name of the target database file. In this case, on UNIX, if the
169245 ** state database is not already present in the file-system, it is created
169273 ** Accessing the underlying database handles may be useful in the
169280 ** * If the data_xxx tables in the RBU source database are virtual
169317 ** was last saved. In other words, from the most recent successful call to
169358 ** * Stage 1, in which changes are accumulated in an oal/wal file, and
169359 ** * Stage 2, in which the contents of the wal file are copied into the
169379 ** There must be one row in the table for each source (data_xxx) table within
169396 ** defined in this file. Return values should be interpreted as follows:
169441 ** The exception is for applications that also use zipvfs. In this case,
169444 ** VFS uses the RBU VFS, which in turn uses any other VFS layers in use
169466 ** that does not include the RBU layer results in an error.
169469 ** non-RBU users. There is no harm in an application accessing the
169492 /************** Continuing where we left off in sqlite3rbu.c *****************/
169541 ** cases when another client appends frames to the *-wal file in the
169546 ** Valid if STAGE==1. The current change-counter cookie value in the
169550 ** Valid if STAGE==1. The size in bytes of the *-oal file.
169587 ** These values must match the values defined in wal.c for the equivalent
169598 ** A structure to store values read from the rbu_state table in memory.
169619 ** An iterator of this type is used to iterate through all objects in
169621 ** iterator visits, in order:
169629 ** it points to an array of flags nTblCol elements in size. The flag is
169647 int bCleanup; /* True in "cleanup" state */
169657 int nCol; /* Number of columns in current object */
169695 #define RBU_UPDATE 6 /* Update a row in a main table b-tree */
169722 ** for all source tables in the RBU database, where nRow is the number
169723 ** of rows in the source table and nIndex the number of indexes on the
169730 ** for an UPDATE operation does not exist in the target table, then
169736 ** PK does not exist. In this case no operations are required on index
169744 ** stored in the rbu_state table if the RBU update is suspended.
169768 u32 iMaxFrame; /* Largest iWalFrame value in aFrame[] */
169770 int nFrame; /* Entries in aFrame[] array */
169777 /* Used in RBU vacuum mode only */
169778 int nRbu; /* Number of RBU VFS in the stack */
169807 int nShm; /* Number of entries in apShm[] array */
169837 ** in *pz and is decremented once for each character in the integer.
169907 ** binary files) so we also have to pass in the length of the delta in
169910 ** This function returns the size of the output file in bytes (excluding
170069 ** Prepare the SQL statement in buffer zSql against database handle db.
170116 ** returned. In this case, *pzErrmsg may also be set to point to an error
170121 ** In this case SQLITE_NOMEM is returned and *ppStmt set to NULL.
170205 ** left in the RBU handle passed as the first argument. A copy of the
170270 ** the name of a table in the RBU database. The second, if it is present, is 1
170320 ** left in the RBU handle passed as the first argument. A copy of the
170331 "WHERE type IN ('table', 'view') AND target IS NOT NULL "
170351 ** an error code is stored in the RBU handle passed as the first argument.
170355 ** stored error code. In this case it still calls sqlite3_free() on any
170379 ** If an error occurs, an error code and error message is stored in the
170405 ** error code in the rbu handle passed as the first argument. Or, if an
170428 ** error code in the RBU handle passed as the first argument.
170447 ** returns a copy of the string in memory obtained from sqlite3_malloc().
170510 ** if( no entry exists in sqlite_master ){
170515 ** if( the index that is the pk exists in sqlite_master ){
170655 ** an error does occur, an error code and error message are also left in
170717 /* Check that all non-HIDDEN columns in the destination table are also
170718 ** present in the input table. Populate the abTblPk[], azTblType[] and
170765 ** column names currently stored in the pIter->azTblCol[] array.
170942 ** Return an expression that can be used in a WHERE clause to match the
170988 ** is something wrong with the rbu_control value in the rbu_control value
170989 ** stored in the (p->nCol+1)'th column. Set the error code and error message
171010 ** string, an error code is left in the rbu handle passed as the first
171064 ** string, an error code is left in the rbu handle passed as the first
171213 ** in the sqlite3rbu object indicated by the first argument and returns
171222 ** An imposter table is required in all cases except RBU_PK_VTAB. Only
171280 ** The number of bound variables is equal to the number of columns in
171396 /* Create the SELECT statement to read keys in sorted order */
171558 ** is not an error. Output variable *ppStmt is set to NULL in this case.
171570 /* In case an error occurs */
171575 ** to the number of statements currently in the cache and pUp to the
171576 ** last object in the list. */
171663 ** If an error occurs, leave an error code and message in the rbu handle
171737 ** error occurs, leave an error code and message in the RBU handle.
171886 ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
171903 ** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
171904 ** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
171936 ** The checksum is store in the first page of xShmMap memory as an 8-byte
171962 ** being resumed. In this case, if the checksum of the wal-index-header
171963 ** following recovery is not the same as the checksum saved in the RbuState
171965 ** other client appends a transaction to the wal file in the middle of
171982 ** special behaviour in the rbu VFS:
171990 ** would be read/written are recorded in the sqlite3rbu.aFrame[]
172039 ** directory in which the target database and the wal file reside, in
172040 ** case it has not been synced since the rename() call in
172049 ** the rbu object is in capture mode. Record the frame number of the frame
172050 ** being read in the aFrame[] array.
172081 ** file while the rbu handle is in capture mode. Record the page number
172082 ** of the page being written in the aFrame[] array.
172146 ** The RBU handle is currently in RBU_STAGE_OAL state, with a SHARED lock
172148 ** then reopens the database file (this time in vanilla, non-oal, WAL mode).
172149 ** If an error occurs, leave an error code and error message in the rbu
172171 ** in WAL mode). So no other connection may be writing the db.
172173 ** In order to ensure that there are no database readers, an EXCLUSIVE
172241 ** message are left in the RBU handle and zero returned.
172379 ** and message is left in the RBU handle and a copy of the error code
172460 ** statement reads is page 1, which is guaranteed to be in the cache.
172475 ** value stored in the RBU_STATE_STAGE column is eStage. All other values
172534 ** In short, it copies the value of the specified PRAGMA setting from
172555 ** RBU vacuum operation, create the schema in the target db.
172706 ** this by checkpointing frames until the next page in the aFrame[]
172746 ** an rbu handle in OAL stage. If the rbu update has not started (i.e.
172751 ** If an error occurs, an error code and error message are left in the
172782 ** If there is a "*-oal" file in the file-system corresponding to the
172783 ** target database in the file-system, delete it. If an error occurs,
172784 ** leave an error code and error message in the rbu handle.
172799 ** specified a URI with a vfs=? option in place of a target database
172830 ** name of a table expected to appear in the target database. It returns
172874 ** There should be one row in the table for each data_xxx table in the
172879 ** for all rows in the rbu_count table, where nIndex is the number of
172960 ** RBU vacuum operation leaving an old wal file in the directory.
173007 ** transaction is committed in rollback mode) currently stored on
173127 ** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT,
173311 ** of a standard VFS in the following ways:
173314 ** written, the value of the change-counter cookie is stored in
173316 ** database header field is stored in
173330 ** associated with an RBU target database currently in RBU_STAGE_OAL
173335 ** target database may not be in wal mode already.
173341 ** the RBU target in RBU_STAGE_OAL stage, instead of opening the *-wal
173344 ** 3b. The *-shm pages returned by xShmMap() for a target db file in
173345 ** RBU_STAGE_OAL mode are actually stored in heap memory. This is to
173347 ** are no-ops on target database files in RBU_STAGE_OAL mode. This is
173348 ** because assert() statements in some VFS implementations fail if
173351 ** 3c. If an EXCLUSIVE lock is attempted on a target database file in any
173357 ** 3d. In RBU_STAGE_CAPTURE mode, all xRead() calls on the wal file, and
173425 ** Write an unsigned 32-bit value in big-endian format to the supplied
173483 rbuPutU32(&aBuf[28], 1); /* size of db file in pages */
173636 /* First try to find another RBU vfs lower down in the vfs stack. If
173637 ** one is found, this vfs will operate in pass-through mode. The lower
173642 /* Now search for a zipvfs instance lower down in the VFS stack. If
173678 ** Return the sector-size in bytes for an rbuVfs-file.
173746 /* If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this
173747 ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
173910 ** pair of '\0' bytes in case the VFS attempts to extract a URI
173992 ** database connection exists, and the RBU update is in RBU_STAGE_OAL,
173997 ** in wal mode, even if the first page of the database file has
174021 ** to the pathname in zPath. zOut is guaranteed to point to a buffer
174054 ** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
174093 ** Return the current time as a Julian Day number in *pTimeOut.
174210 ** The author disclaims copyright to this source code. In place of
174222 ** information from an SQLite database in order to implement the
174251 ** from. For example, the three overflow pages in a chain linked from
174255 ** '/1c2/000+000000' // First page in overflow chain
174256 ** '/1c2/000+000001' // Second page in overflow chain
174257 ** '/1c2/000+000002' // Third page in overflow chain
174260 ** the overflow pages associated with a cell will appear earlier in the
174275 " pgoffset INTEGER, /* Offset of page in file */" \
174289 int nOvfl; /* Entries in aOvfl[] */
174318 in aPage[] */
174422 /* Records are always returned in ascending order of (name, path).
174640 ** Move a statvfs cursor to the next entry in the file.
174982 int iCurrent; /* Offset in aData[] of current change */
174983 int iNext; /* Offset in aData[] of next change */
174985 int nData; /* Number of bytes in aData */
174997 SessionInput in; /* Input buffer or stream */
175003 int nCol; /* Number of columns in zTab */
175013 ** stored in a linked list starting at sqlite3_session.pTable.
175016 ** been modified in any way since the session object was attached to the
175026 int nCol; /* Number of columns in table zName */
175029 int nEntry; /* Total number of entries in hash table */
175038 ** used in SQLite database files. This format is used as part of the
175053 ** and so on in sqlite3.h. For undefined and NULL values, the field consists
175058 ** A varint containing the number of bytes in the value (encoded using
175063 ** A varint containing the number of bytes in the value, followed by
175072 ** Varint values are encoded in the same way as varints in the SQLite
175079 ** but may occur in any order (i.e. deletes, updates and inserts are all
175085 ** Varint: Number of columns in the table.
175096 ** The "old.*" and "new.*" records, if present, are N field records in the
175098 ** columns in the table. The i'th field of each record is associated with
175099 ** the i'th column of the table, counting from left to right in the order
175100 ** in which columns were declared in the CREATE TABLE statement.
175105 ** from the database. In the changeset format, the records that are part
175127 ** Varint: Number of columns in the table.
175138 ** As in the changeset format, each field of the single record that is part
175152 ** The records associated with INSERT changes are in the same format as for
175159 ** this structure stored in a SessionTable.aChange[] hash table.
175164 int nRecord; /* Number of bytes in buffer aRecord[] */
175236 int *pnWrite /* IN/OUT: Increment by bytes written */
175238 int nByte; /* Size of serialized value in bytes */
175306 ** This macro is used to calculate hash key values for data structures. In
175308 ** as a series of unsigned integers. In order to calculate a hash-key value
175317 ** In practice, the data structures this macro is used for are the primary
175365 int *pbNullPK /* OUT: True if there are NULL values in PK */
175434 ** Based on the primary key values stored in change aRecord, calculate a
175440 ** a patchset DELETE. In this case the non-PK fields are omitted entirely.
175446 int nBucket /* Assume this many buckets in hash table */
175458 ** module does not record changes for rows with NULL values stored in
175488 ** have the same values stored in the primary key columns), or false
175567 ** as to point to the next value in the record.
175571 ** pointer is returned and *pnVal is set to the number of bytes in the
175573 ** set to the number of bytes in the value at *paOne. If *paOne points
175574 ** to the "no value" placeholder, *pnVal is set to 1. In other words:
175581 u8 **paOne, /* IN/OUT: Left-hand buffer pointer */
175582 u8 **paTwo, /* IN/OUT: Right-hand buffer pointer */
175583 int *pnVal /* OUT: Bytes in returned value */
175615 u8 **paOut, /* IN/OUT: Pointer to output buffer */
175687 ** as the change stored in argument pChange. If so, it returns true. Otherwise
175724 /* A SessionChange object never has a NULL value in a PK column */
175766 ** It is possible that a non-fatal OOM error occurs in this function. In
175768 ** Growing the hash table in this case is a performance optimization only,
175808 ** zThis, in schema zDb. It is expected that the table has nCol columns. If
175813 ** of columns in the database table and variable *pzTab is set to point to a
175906 ** free any allocation made. An error code will be returned in this case.
175929 ** If an error occurs, an error code is stored in sqlite3_session.rc and
175933 ** is set to NULL in this case.
175977 /* Check the number of columns in this xPreUpdate call matches the
175978 ** number of columns in the table. */
176044 ** required values and encodings have already been cached in memory.
176045 ** It is not possible for an OOM to occur in this block. */
176283 const char *zDb1, /* Pick rows in this db only */
176284 const char *zDb2, /* But not in this one */
176400 int nCol; /* Columns in zFrom.zTbl */
176469 int nDb = sqlite3Strlen30(zDb); /* Length of zDb in bytes */
176471 /* Zero the output value in case an error occurs. */
176582 int nName; /* Number of bytes in string zName */
176599 ** simply added to the start of it in order to ensure that tables
176600 ** appear in the correct order when a changeset or patchset is
176617 ** Ensure that there is room in the buffer to append nByte bytes of data.
176712 ** called. Otherwise, append a string to the buffer. All bytes in the string
176741 int *pRc /* IN/OUT: Error code */
176750 ** called. Otherwise, append the string zStr enclosed in quotes (") and
176760 int *pRc /* IN/OUT: Error code */
176779 ** in column iCol of the row that SQL statement pStmt currently points
176786 int *pRc /* IN/OUT: Error code */
176833 ** values that were stored in the row when the session began (the old.*
176852 SessionBuffer buf2 = {0,0,0}; /* Buffer to accumulate new.* record in */
176947 int nCol, /* Number of columns in table */
176994 ** zTab in database zDb based on its primary key. i.e.
177002 int nCol, /* Number of columns in table */
177034 ** Bind the PRIMARY KEY values from the change passed in argument pChange
177043 int nCol, /* Number of columns in table */
177116 int *pRc /* IN/OUT: Error code */
177131 ** stored in output variables *pnChangeset and *ppChangeset. Or, if an error
177145 SessionBuffer buf = {0,0,0}; /* Buffer in which to accumlate changeset */
177150 /* Zero the output variables in case an error occurs. If this session
177151 ** object is already in the error state (sqlite3_session.rc != SQLITE_OK),
177167 int nCol; /* Number of columns in table */
177358 int nChangeset, /* Size of buffer pChangeset in bytes */
177366 /* Zero the output variable in case an error occurs. */
177374 pRet->in.aData = (u8 *)pChangeset;
177375 pRet->in.nData = nChangeset;
177376 pRet->in.xInput = xInput;
177377 pRet->in.pIn = pIn;
177378 pRet->in.bEof = (xInput ? 0 : 1);
177390 int nChangeset, /* Size of buffer pChangeset in bytes */
177425 ** Ensure that there are at least nByte bytes available in the buffer. Or,
177426 ** if there are not nByte bytes remaining in the input, that all available
177427 ** data is in the buffer.
177460 u8 **ppRec, /* IN/OUT: Record pointer */
177461 int nCol /* Number of values in record */
177481 ** first argument to a copy of the string or blob held in the aData[]
177488 int nData, /* Size of buffer aData[] in bytes */
177491 /* In theory this code could just pass SQLITE_TRANSIENT as the final
177503 ** Deserialize a single record from a buffer in memory. See "RECORD FORMAT"
177511 ** (in other words, it is a patchset DELETE record).
177515 ** from the corresponding position in the record. If that value is not
177516 ** included in the record (i.e. because the record is part of an UPDATE change
177524 ** The apOut[] array may have been partially populated in this case.
177528 int nCol, /* Number of values in record */
177582 ** + number of columns in table (varint)
177586 ** This function ensures that all of the above is present in the input
177620 ** the record in bytes. Otherwise, an SQLite error code is returned. The
177621 ** final value of *pnByte is undefined in this case.
177625 int nCol, /* Number of columns in record */
177626 int *pnByte /* OUT: Size of record in bytes */
177654 ** + number of columns in table (varint)
177672 rc = sessionChangesetBufferTblhdr(&p->in, &nCopy);
177676 nVarint = sessionVarintGet(&p->in.aData[p->in.iNext], &p->nCol);
177678 p->in.iNext += nVarint;
177687 memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy);
177688 p->in.iNext += nCopy;
177705 ** record is written to *paRec before returning and the number of bytes in
177709 ** successfully advanced to the next change in the changeset, an SQLite
177711 ** changes in the changeset.
177723 /* If the iterator is in the error-state, return immediately. */
177738 p->rc = sessionInputBuffer(&p->in, 2);
177742 if( p->in.iNext>=p->in.nData ){
177746 sessionDiscardData(&p->in);
177747 p->in.iCurrent = p->in.iNext;
177749 op = p->in.aData[p->in.iNext++];
177753 if( (p->rc = sessionInputBuffer(&p->in, 2)) ) return p->rc;
177754 p->in.iCurrent = p->in.iNext;
177755 op = p->in.aData[p->in.iNext++];
177759 p->bIndirect = p->in.aData[p->in.iNext++];
177774 p->rc = sessionChangesetBufferRecord(&p->in, nVal, pnRec);
177776 *paRec = &p->in.aData[p->in.iNext];
177777 p->in.iNext += *pnRec;
177783 p->rc = sessionReadRecord(&p->in, p->nCol, abPK, p->apValue);
177789 p->rc = sessionReadRecord(&p->in, p->nCol, 0, &p->apValue[p->nCol]);
177795 ** modified fields are present in the new.* record. The old.* record
177814 ** change in the changeset. This function may return SQLITE_ROW, SQLITE_DONE
177832 int *pnCol, /* OUT: Number of columns in table */
177844 ** Return information regarding the PRIMARY KEY and number of columns in
177852 int *pnCol /* OUT: Number of entries in output array */
177865 ** iVal'th value in the old.* record. Or, if that particular value is not
177866 ** included in the record (because the change is an UPDATE and the field
177893 ** iVal'th value in the new.* record. Or, if that particular value is not
177894 ** included in the record (because the change is an UPDATE and the field
177951 ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
177953 ** violations in the destination database and returns SQLITE_OK.
177955 ** In all other cases this function returns SQLITE_MISUSE.
177984 sqlite3_free(p->in.buf.aBuf);
177994 int *pnInverted, /* OUT: Number of bytes in output changeset */
177999 int nCol = 0; /* Number of cols in current table */
178007 /* Zero the output variables in case an error occurs. */
178026 ** * Number of columns in said table (a varint),
178150 int nChangeset, /* Number of bytes in input */
178152 int *pnInverted, /* OUT: Number of bytes in output changeset */
178196 u8 *abPK; /* Boolean array - true if column is in PK */
178288 ** For each column in the table, there are three variables to bind:
178430 ** See comments in the body of this function for details.
178439 ** of SQLite. If a malloc fails in an sqlite3_value_xxx() function, either
178443 /* This condition occurs when an earlier OOM in a call to
178459 ** to an array nCol elements in size. In this case only those values for
178478 ** in the code below. */
178515 int nCol; /* Number of columns in table */
178549 ** handler as the "conflicting" record. In this case the type of conflict
178605 u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent];
178606 int nBlob = pIter->in.iNext - pIter->in.iCurrent;
178648 ** to true before returning. In this case the caller will invoke this function
178655 ** before retrying. In this case the caller attempts to remove the conflicting
178692 ** * all columns of the table are PK columns (in this case there is
178735 /* Attempt the UPDATE. In the case of a NOTFOUND or DATA conflict,
178781 ** retried in some manner.
178799 ** a row with the correct PK is present in the db, but one or more other
178801 ** returned SQLITE_CHANGESET_REPLACE. In this case retry the operation,
178812 ** SQLITE_CHANGESET_REPLACE. In this case remove the conflicting row
178838 ** Retry the changes accumulated in the pApply->constraints buffer.
178917 pIter->in.bNoDiscard = 1;
179065 int nChangeset, /* Size of changeset in bytes */
179120 SessionTable *pList; /* List of tables in current patch */
179126 ** allocated and a pointer to it stored in *ppNew.
179135 int nRec, /* Number of bytes in aRec */
179248 ** Add all changes in the changeset traversed by the iterator passed as
179305 ** tables within the output of sqlite3changegroup_output() are in
179324 ** Code below may link it back in.
179365 ** buffer containing the output changeset before this function returns. In
179366 ** this case (*pnOut) is set to the size of the output buffer in bytes. It
179387 ** hash tables attached to the SessionTable objects in list p->pList.
179440 ** Add the changeset currently stored in buffer pData, size nData bytes,
179511 int nLeft, /* Number of bytes in lhs input */
179513 int nRight /* Number of bytes in rhs input */,
179515 int *pnOut, /* OUT: Number of bytes in output changeset */
179572 ** The author disclaims copyright to this source code. In place of
179587 ** a JSONB type in the future which stores a binary encoding of JSON in
179588 ** a BLOB, but there is no support for JSONB in the current implementation.
179633 ** the library isspace() function, resulting in a 7% overall performance
179657 /* Unsigned integer types. These are already defined in the sqliteInt.h,
179677 u64 nAlloc; /* Bytes of storage available in zBuf[] */
179725 u32 iKey; /* Key for ARRAY objects in json_tree() */
179742 int nJson; /* Length of the zJson string in bytes */
179748 ** This limit is needed to avoid a stack overflow in the recursive
179857 /* Append the N-byte string in zIn to the end of the JsonString string
179858 ** under construction. Enclose the string in "..." and escape
179943 /* Make the JSON in p the result of the SQL function.
179965 ** by which the JsonNode counter should increment in order to go to the
180274 ** instance to the JsonParse. Return the index in pParse->aNode[] of the
180382 /* Control characters are not allowed in strings */
180503 ** to fill in all the descendants of node i.
180530 ** Compute the parentage of all nodes in a completed parse.
180545 ** Magic number used for the JSON parse cache in sqlite3_get_auxdata()
180550 ** Obtain a complete parse of the JSON found in the first argument
180618 const char **pzErr /* Make *pzErr point to any syntax error in zPath */
180814 ** Mark all NULL entries in the Object passed in as JNODE_REMOVE.
180917 ** array that contains all values given in arguments. Or if any argument
180944 ** Return the number of elements in the top-level JSON array.
181029 u32 iTarget, /* Node of the TARGET in pParse */
181126 ** object that contains all name/value given in arguments. Or if any name
181169 ** JSON or PATH arguments result in an error.
181352 ** Return a JSON array composed of all values in the aggregate.
181396 ** Return a JSON object composed of all names and values in the aggregate.
181452 u32 i; /* Index in sParse.aNode[] of current row */
181907 ** The following routines are the only publically visible identifiers in this
181908 ** file. Call the following routines in order to register the various SQL
182013 ** The author disclaims copyright to this source code. In place of
182022 ** Interfaces to extend FTS5. Using the interfaces defined in this file,
182054 int nVal, /* Number of values in apVal[] array */
182072 ** to the total number of tokens in the FTS5 table. Or, if iCol is
182073 ** non-negative but less than the number of columns in the table, return
182074 ** the total number of tokens in column iCol, considering all rows in
182078 ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
182083 ** Return the number of columns in the table.
182087 ** to the total number of tokens in
182088 ** non-negative but less than the number of columns in the table, set
182089 ** *pnToken to the number of tokens in column iCol of the current row.
182092 ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
182102 ** containing the text in utf-8 encoding, (*pn) is set to the size in bytes
182108 ** Returns the number of phrases in the current query expression.
182111 ** Returns the number of tokens in phrase iPhrase of the query. Phrases
182131 ** to the column in which it occurs and *piOff the token offset of the
182133 ** with the offsets=0 option specified. In this case *piOff is always
182156 ** phrase iPhrase of the current query is included in $p. For each
182205 ** (set to NULL) before this function returns. In this case the xDelete,
182211 ** This function is used to retrieve the total number of rows in the table.
182212 ** In other words, the same value that would be returned by:
182250 ** of iterating through all instances of a phrase in the current row, these
182251 ** APIs are used to iterate through the set of columns in the current row
182344 ** be returned. In this case, fts5 assumes that the final value of *ppOut
182382 ** For each token in the input string, the supplied callback xToken() must
182386 ** size of the token in bytes. The 4th and 5th arguments are the byte offsets
182392 ** synonyms. In this case see the discussion below for details.
182394 ** FTS5 assumes the xToken() callback is invoked for each token in the
182407 ** Custom tokenizers may also support synonyms. Consider a case in which a
182409 ** built-in tokenizers, the FTS5 query 'first + place' will match instances
182411 ** such as "1st place". In some applications, it would be better to match
182413 ** the user specified in the MATCH query text.
182415 ** There are several ways to approach this in FTS5:
182417 ** <ol><li> By mapping all synonyms to a single token. In this case, the
182418 ** In the above example, this means that the tokenizer returns the
182419 ** same token for inputs "first" and "1st". Say that token is in
182427 ** In this case, when tokenizing query text, the tokenizer may
182436 ** first token in the MATCH query and FTS5 effectively runs a query
182456 ** 'first + place' or '1st + place', as there are entires in the
182476 ** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
182480 ** In many cases, method (1) above is the best approach. It does not add
182482 ** so it is efficient in terms of disk space and query speed. However, it
182492 ** For full prefix support, method (3) may be preferred. In this case,
182525 int nToken, /* Size of token in bytes */
182593 ** The author disclaims copyright to this source code. In place of
182649 ** directive in fts5_index.c will cause the build to fail.
182694 ** Each entry in the aiCol[] array is a column that may be matched.
182706 ** Interface to code in fts5_config.c. fts5_config.c contains contains code
182733 ** This exists in order to allow the fts5_index.c module to return a
182755 int *aPrefix; /* Sizes in bytes of nPrefix prefix indexes */
182767 int pgsz; /* Approximate page size used in %_data */
182771 int nHashSize; /* Bytes of memory for in-memory hash */
182822 ** End of interface to code in fts5_config.c.
182826 ** Interface to code in fts5_buffer.c.
182872 int n; /* Size of buffer at a[] in bytes */
182873 int i; /* Current offset in a[] */
182896 int *pi, /* IN/OUT: Offset within a[] */
182897 i64 *piOff /* IN/OUT: Current offset */
182908 /* Bucket of terms object used by the integrity-check in offsets=0 mode. */
182915 ** End of interface to code in fts5_buffer.c.
182919 ** Interface to code in fts5_index.c. fts5_index.c contains contains code
182920 ** to access the data stored in the %_data table.
182939 #define FTS5INDEX_QUERY_DESC 0x0002 /* Docs in descending rowid order */
182968 ** Argument p points to a buffer containing utf-8 text that is n bytes in
182969 ** size. Return the number of bytes in the nChar character prefix of the
182970 ** buffer, or 0 if there are less than nChar characters in total.
183014 ** For an insert, it must be called once for each token in the new document.
183016 ** unique token in the document with an iCol value less than zero. The iPos
183021 int iCol, /* Column token appears in (-ve -> delete) */
183037 ** Flush any data stored in the in-memory hash tables to the database.
183043 ** Discard any data stored in the in-memory hash tables. Do not write it
183045 ** table may have changed on disk. So any in-memory caches of %_data
183083 ** End of interface to code in fts5_index.c.
183087 ** Interface to code in fts5_varint.c.
183107 ** End of interface to code in fts5_varint.c.
183112 ** Interface to code in fts5.c.
183127 ** End of interface to code in fts5.c.
183131 ** Interface to code in fts5_hash.c.
183144 int iCol, /* Column token appears in (-ve -> delete) */
183159 int *pnDoclist /* OUT: Size of doclist in bytes */
183171 int *pnDoclist /* OUT: size of doclist in bytes */
183176 ** End of interface to code in fts5_hash.c.
183180 ** Interface to code in fts5_storage.c. fts5_storage.c contains contains
183181 ** code to access the data stored in the %_content and %_docsize tables.
183224 ** End of interface to code in fts5_storage.c.
183229 ** Interface to code in fts5_expr.c.
183240 int n; /* Size of buffer p in bytes */
183288 ** C code in this module. The interfaces below this point are called by
183289 ** the parser code in fts5parse.y. */
183337 ** End of interface to code in fts5_expr.c.
183343 ** Interface to code in fts5_aux.c.
183348 ** End of interface to code in fts5_aux.c.
183352 ** Interface to code in fts5_tokenizer.c.
183357 ** End of interface to code in fts5_tokenizer.c.
183361 ** Interface to code in fts5_vocab.c.
183367 ** End of interface to code in fts5_vocab.c.
183372 ** Interface to automatically generated code in fts5_unicode2.c.
183378 ** End of interface to code in fts5_unicode2.c.
183401 ** The author disclaims copyright to this source code. In place of
183414 ** interstitial "-" characters) contained in this template is changed into
183429 ** Disable all error recovery processing in the parser push-down
183453 ** in a format understandable to "makeheaders". This section is blank unless
183472 ** that indicate what to do in response to the next
183485 ** which is sqlite3Fts5ParserFTS5TOKENTYPE. The entry in the union
183496 ** fts5YYNRULE the number of rules in the grammar
183544 ** Applications can choose to define fts5yytestcase() in the %include section
183545 ** to a macro that can assist in verifying code coverage. For production
183576 ** slots in the fts5yy_action[] table.
183594 ** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
183595 ** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
183598 ** The following are the tables generated in this section:
183601 ** fts5yy_lookahead[] A table containing the lookahead for each entry in
183666 ** appears in the grammar, then ID becomes a fallback token for X, Y,
183671 ** This feature can be used, for example, to cause some keywords in a language
183672 ** to revert to identifiers if they keyword does not apply in the context where
183686 ** (In other words, the "major" token.)
183689 ** the information used by the action routines in the grammar.
183697 fts5YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
183705 /* The state of the parser is completely contained in an instance of
183842 ** putting an appropriate #define in the %include section of the input
183883 ** A pointer to a parser. This pointer is used in subsequent calls
183992 ** is defined in a %include section of the input grammar) then it is
184156 int fts5yyNewState, /* The new state to shift in */
184157 int fts5yyMajor, /* The major token to shift in */
184158 sqlite3Fts5ParserFTS5TOKENTYPE fts5yyMinor /* The minor token to shift in */
184198 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
184518 ** user wants (and specified in the grammar) and is available for
184692 ** The author disclaims copyright to this source code. In place of
184707 ** Object used to iterate through all "coalesced phrase instances" in
184708 ** a single column of the current row. If the phrase instances in the
184710 ** through them. Or, if they do overlap (share one or more tokens in
184734 int iStart; /* First token in coalesced phrase instance */
184735 int iEnd; /* Last token in coalesced phrase instance */
184771 ** iterate through coalesced phrase instances in column iCol.
184802 int iPos; /* Current token offset in zIn[] */
184808 int nIn; /* Size of input text in bytes */
184841 int nToken, /* Size of token in bytes */
184895 int nVal, /* Number of values in apVal[] array */
184944 int nFirst; /* Number of entries in aFirst[] */
184945 int *aFirst; /* Array of first token in each sentence */
184970 ** function. Its job is to identify tokens that are the first in a sentence.
184977 int nToken, /* Size of token in bytes */
185009 int nDocsize, /* Size of column in tokens */
185056 int nVal, /* Number of values in apVal[] array */
185066 int nPhrase; /* Number of phrases in query */
185071 int nColSize = 0; /* Total size of iBestCol in tokens */
185210 int nPhrase; /* Number of phrases in query */
185211 double avgdl; /* Average number of tokens in each row */
185217 ** Callback used by fts5Bm25GetData() to count the number of rows in the
185246 int nPhrase; /* Number of phrases in query */
185247 sqlite3_int64 nRow = 0; /* Number of rows in table */
185248 sqlite3_int64 nToken = 0; /* Number of tokens in table */
185270 /* Calculate an IDF for each phrase in the query */
185280 ** where "N" is the total number of documents in the set and nHit
185286 ** (1e-6) - roughly the same as a term that appears in just over
185312 int nVal, /* Number of values in apVal[] array */
185322 double D = 0.0; /* Total number of tokens in row */
185325 /* Calculate the phrase frequency (symbol "f(qi,D)" in the documentation)
185326 ** for each phrase in the query for the current row. */
185342 /* Figure out the total size of the current row in tokens. */
185397 ** The author disclaims copyright to this source code. In place of
185433 ** pBuf. If an OOM error occurs, set the error code in p.
185453 ** the error code in p. If an error has already occurred when this function
185473 ** though this byte is not included in the pBuf->n count.
185491 ** included in the pBuf->n count.
185547 ** the error code in p. If an error has already occurred when this function
185562 int *pi, /* IN/OUT: Offset within a[] */
185563 i64 *piOff /* IN/OUT: Current offset */
185609 ** Append position iPos to the position list being accumulated in buffer
185655 ** is non-negative, then it is the length of the string in bytes. Otherwise,
185792 ** The author disclaims copyright to this source code. In place of
185826 ** string. Return a pointer to the first character following *pIn in
185839 ** string. Return a pointer to the first character following *pIn in
185923 ** the string and, if found, dequotes the string in place and adds a new
185928 ** found, -1 is returned. If -1 is returned, the buffer is left in an
185965 ** the quote characters. The conversion is done in-place. If the
186019 ** may be left in *pzErr. It is the responsibility of the caller to
186112 *pzErr = sqlite3_mprintf("parse error in tokenize directive");
186195 ** Return a pointer to the character immediately following the last in
186209 int *pRc, /* IN/OUT: Error code */
186305 ** returned, *ppOut is set to NULL and an error message may be left in
186367 *pzErr = sqlite3_mprintf("parse error in \"%s\"", zOrig);
186390 /* If no zContent option was specified, fill in the default values. */
186481 ** The callback is invoked once for each token in the input text. The
186482 ** arguments passed to it are, in order:
186486 ** int nToken // Size of token in bytes
186489 ** int iPos // Position of token in input (first token is 0)
186515 ** Argument pIn points to the first character in what is expected to be
186544 ** + Zero or more SQL literals in a comma separated list
186754 ** The author disclaims copyright to this source code. In place of
186771 ** All token types in the generated fts5parse.h file are greater than 0.
186795 int bDesc; /* Iterate in descending rowid order */
186796 int nPhrase; /* Number of phrases in expression */
186843 Fts5ExprTerm *pSynonym; /* Pointer to first in list of synonyms */
186847 ** A phrase. One or more terms that must appear in a contiguous sequence
186853 int nTerm; /* Number of entries in aTerm[] */
186864 int nPhrase; /* Number of entries in aPhrase[] array */
186900 const char **pz, /* IN/OUT: Pointer into buffer */
187160 ** All individual term iterators in pPhrase are guaranteed to be valid and
187192 /* Initialize a term iterator for each term in the phrase */
187254 int n; /* Size of buffer a[] in bytes */
187255 int i; /* Current offset in position list */
187296 ** If in/out parameter (*pRc) is set to other than SQLITE_OK when this
187299 ** The return value is undefined in both these cases.
187407 i64 *piLast, /* IN/OUT: Lastest rowid seen so far */
187433 i64 *piLast, /* IN/OUT: Lastest rowid seen so far */
187484 /* Check that each phrase in the nearset matches the current row.
187509 ** Initialize all term iterators in the pNear object. If any term is found
187626 ** Nodes that point to values that come later in the iteration order are
187644 ** All individual term iterators in pNear are guaranteed to be valid when
187673 ** iterator skips through rowids in the default ascending order, this means
187717 ** Advance the first term iterator in the first phrase of pNear. Set output
188058 /* Initialize all term iterators in the NEAR object. */
188097 ** Begin iterating through the set of documents in index pIdx matched by
188099 ** parameter is passed a non-zero value, iteration is in descending rowid
188100 ** order. Or, if it is zero, in ascending order.
188102 ** If iterating in ascending rowid order (bDesc==0), the first document
188104 ** to parameter iFirst. Or, if iterating in ascending order (bDesc==1),
188119 /* If not at EOF but the current rowid occurs earlier than iFirst in
188273 int nToken, /* Size of token in bytes */
188359 ** string may or may not be quoted. In any case it is tokenized and a
188509 ** Token pTok has appeared in a MATCH expression where the NEAR operator
188511 ** in the pParse object.
188553 ** If an OOM error occurs, store an error code in pParse and return NULL.
188554 ** The old colset object (if any) is not freed in this case.
188561 int nCol = p ? p->nCol : 0; /* Num. columns already in colset object */
188584 /* Check that the array is in order and contains no duplicate entries. */
188675 ** Remove from colset pColset any columns that are not also in colset pMerge.
188678 int iIn = 0; /* Next input in pColset */
188679 int iMerge = 0; /* Next input in pMerge */
188680 int iOut = 0; /* Next output slot in pColset */
188803 ** OOM error), leave an error code in pParse and return NULL.
189327 ** Return the number of phrases in expression pExpr.
189334 ** Return the number of terms in the iPhrase'th phrase in pExpr.
189409 int nToken, /* Size of token in bytes */
189571 ** The author disclaims copyright to this source code. In place of
189589 ** This file contains the implementation of an in-memory hash table used
189598 int nEntry; /* Number of entries currently in hash */
189605 ** Each entry in the hash table is represented by an object of the
189607 ** its current data are stored in a single memory allocation. The
189608 ** key immediately follows the object in memory. The position list
189609 ** data immediately follows the key data in memory.
189611 ** The data that follows the key is in a similar, but not identical format
189612 ** to the doclist data stored in the database. It is:
189628 Fts5HashEntry *pScanNext; /* Next entry in sorted order */
189633 int nKey; /* Length of key in bytes */
189768 int nSz = (p->nData - p->iSzPoslist - 1); /* Size in bytes */
189789 ** Add an entry to the in-memory hash table. The key is the concatenation
189799 int iCol, /* Column token appears in (-ve -> delete) */
189946 ** each sorted in key order. This function merges the two lists into a
189991 ** in sorted order. The hash table is cleared before returning. It is
190044 int *pnDoclist /* OUT: Size of doclist in bytes */
190087 int *pnDoclist /* OUT: size of doclist in bytes */
190108 ** The author disclaims copyright to this source code. In place of
190117 ** Low level access to the FTS index stored in the database file. The
190118 ** routines in this file file implement all read and write access to the
190120 ** the interface defined in fts5Int.h.
190133 ** * all segment b-tree leaf data is stored in fixed size page records
190135 ** taken to ensure it is possible to iterate in either direction through
190136 ** the entries in a doclist, or to seek to a specific entry within a
190144 ** * extra fields in the "structure record" record the state of ongoing
190151 #define FTS5_WORK_UNIT 64 /* Number of leaf pages in unit of work */
190175 ** recorded in a single record within the %_data table. The record consists
190190 ** + number of input segments in ongoing merge.
190191 ** + total number of segments in level.
190200 ** The first value is the number of rows in the index. Then, for each column
190201 ** from left to right, the total number of tokens in the column for all
190216 ** varint: number of bytes in common with previous term
190233 ** varint: size of poslist in bytes multiplied by 2, not including
190252 ** unsigned integer fields in big-endian format. They are:
190258 ** footer is 0 bytes in size, then this field is the same as the
190259 ** size of the leaf page in bytes.
190263 ** within the page, delta-compressed against the previous value. In
190264 ** other words, the first varint in the footer is the byte offset of
190270 ** the format is changed in two ways:
190277 ** + the first term on each page is stored in the same way as the
190315 ** Rowids for the averages and structure records in the %_data table.
190322 ** and nodes. All nodes and leaves are stored in the %_data table with large
190347 ** Maximum segments permitted in a single index
190379 int nn; /* Size of record in bytes */
190389 int nWorkUnit; /* Leaf pages in a "unit" of work */
190393 ** in-memory hash tables before they are flushed to disk.
190395 Fts5Hash *pHash; /* Hash table for in-memory data */
190429 ** using an Fts5Structure record in memory. Which uses instances of the
190434 int pgnoFirst; /* First leaf page number in segment */
190435 int pgnoLast; /* Last leaf page number in segment */
190438 int nMerge; /* Number of segments in incr-merge */
190445 int nSegment; /* Total segments in this structure */
190446 int nLevel; /* Number of levels in this index */
190470 u8 bFirstRowidInDoclist; /* True if next rowid is first in doclist */
190471 u8 bFirstRowidInPage; /* True if next rowid is first in page */
190473 u8 bFirstTermInPage; /* True if next term will be first in leaf */
190493 ** pair in the segment.
190520 ** has been exhausted. Do not proceed to the next term in the segment.
190524 ** it is set, iterate through rowid in descending order instead of the
190549 ** is the offset of the first rowid in the current doclist. */
190553 int iPgidxOff; /* Next offset in pgidx */
190557 int iRowidOffset; /* Current entry in aRowidOffset[] */
190566 int nPos; /* Number of bytes in current position list */
190594 ** visiting each term/rowid pair in the merged data.
190603 ** even number, is stored in aFirst[(nSeg+N)/2]. The "result" of the
190604 ** comparison in this context is the index of the iterator that currently
190608 ** aFirst[1] contains the index in aSeg[] of the iterator that points to
190627 int bRev; /* True to iterate in reverse order */
190675 ** Allocate and return a buffer at least nByte bytes in size.
190677 ** If an OOM error is encountered, return NULL and set the error code in
190688 ** +ve if pRight is smaller than pLeft. In other words:
190708 ** +ve if pRight is smaller than pLeft. In other words:
190738 ** If an error occurs, NULL is returned and an error left in the
190748 ** rollback since it was last used. In this case a new blob handle
190773 ** table, missing row, non-blob/text in block column - indicate
190940 ** Deserialize and return the structure record currently stored in serialized
190953 int nData, /* Size of buffer pData in bytes */
191131 ** If an error occurs, NULL is returned and an error code left in the
191182 ** Return the total number of segments in index structure pStruct. This
191214 ** If an error occurs, leave an error code in the Fts5Index object. If an
191310 ** as a result. Segments are promoted in two scenarios:
191434 ** points to the first rowid in the doclist-index.
191494 ** before the buffer in memory. */
191659 ** read. Before returning, set *pnSz to the number of bytes in the position
191675 ** in the following variables:
191734 ** the first term in the segment).
191788 ** Initialize the iterator object pIter to iterate through the entries in
191803 ** fts5TrimSegments() for details. In this case leave the iterator empty.
191832 ** The iterator is in an unusual state when this function is called: the
191840 ** is in its regular state - Fts5SegIter.iLeafOffset points to the first
191911 ** In this case leave pIter->pLeaf==0, this iterator is at EOF. */
192196 ** Iterator pIter currently points to the first rowid in a doclist. This
192197 ** function sets the iterator up so that iterates in reverse order through
192231 /* The last rowid in the doclist may not be on the current page. Search
192252 ** lies on the page currently indicated by the iterator. In this case
192257 ** rowid. In this case configure the iterator so that it points to the
192316 ** iterator is left pointing to the smallest term in the segment that
192335 int iPgidx; /* Current offset in pgidx */
192350 /* Figure out how many new bytes are in this term */
192457 ** pSeg. If there is no such term in the index, the iterator is set to EOF.
192480 ** contain term (pTerm/nTerm), if it is present in the segment. */
192538 ** in-memory hash table. If there is no such term in the hash-table, the
192608 ** in *pRes is the correct result of comparing the current positions of the
192649 ** is compiled. In that case, this function is essentially an assert()
192694 ** in the pIter->aSeg[] array that is (a) not at EOF, and (b) pointing
192696 ** segment-iterator in the pSeg->aSeg[] array.
192860 int iMinset /* Minimum entry in aFirst[] to set */
192936 ** If an error occurs, an error code is left in Fts5Index.rc. It is not
193221 ** IN/OUT parameter (*pa) points to a position list n bytes in size. If
193224 ** bytes in it returned. Or, if the argument position list does not
193228 const u8 **pa, /* IN/OUT: Pointer to poslist */
193229 int n, /* IN: Size of poslist in bytes */
193456 ** The new object will be used to iterate through data in structure pStruct.
193457 ** If iLevel is -ve, then all data in all segments is merged. Or, if iLevel
193461 ** The iterator initially points to the first term/rowid entry in the
193474 int nSeg = 0; /* Number of segment-iters in use */
193533 ** to the first entry in its segment. In this case initialize the
193657 ** returned in this case.
193667 ** array is 63 elements, or 252 bytes, in size. */
193713 ** Discard all data currently cached in the hash-tables.
193724 ** Return the size of the prefix, in bytes, that buffer
193761 ** Grow the pWriter->aDlidx[] array to at least nLvl elements in size.
193786 ** If the current doclist-index accumulating in pWriter->aDlidx[] is large
193807 ** The doclist-index for that term is currently stored in-memory within the
193823 /* The following was already done in fts5WriteInit(): */
193839 ** If an error occurs, an error code is left in Fts5Index.rc. If an error
194026 /* This is the first term on a leaf that is not the leftmost leaf in
194027 ** the segment b-tree. In this case it is necessary to add a term to
194030 ** this term. In other words, a prefix of (pTerm/nTerm) that is one
194034 ** Usually, the previous term is available in pPage->term. The exception
194035 ** is if this is the first term written in an incremental-merge step.
194036 ** In this case the previous term is not available, so just write a
194083 ** rowid-pointer in the page-header. Also append a value to the dlidx
194084 ** buffer, in case a doclist-index is required. */
194140 int *pnLeaf /* OUT: Number of leaf pages in b-tree */
194183 /* Grow the two buffers to pgsz + padding bytes in size. */
194283 Fts5Structure **ppStruct, /* IN/OUT: Stucture of index */
194338 /* Read input from all segments in the input level */
194432 Fts5Structure **ppStruct, /* IN/OUT: Current structure of index */
194491 Fts5Structure **ppStruct, /* IN/OUT: Current structure of index */
194512 Fts5Structure **ppStruct /* IN/OUT: Current structure of index */
194542 ** in a 32-bit integer. Return the size of the largest prefix of this
194543 ** list nMax bytes or less in size.
194560 ** Flush the contents of in-memory hash table iHash to a new level-0
194570 int pgnoLast = 0; /* Last leaf page number in segment */
194582 Fts5Buffer *pBuf; /* Buffer in which to assemble leaf page */
194583 Fts5Buffer *pPgidx; /* Buffer in which to assemble pgidx */
194604 int nDoclist; /* Size of doclist in bytes */
194655 ** it in one go. */
194716 ** Flush any data stored in the in-memory hash tables to the database.
194743 ** In the first case, return NULL. In the second, increment the ref-count
194772 ** segment in the data structure. */
194916 i64 *piLastRowid, /* IN/OUT: Previous rowid written (if any) */
194953 ** In this case the buffers consist of a delta-encoded list of rowids only.
194999 ** If an error occurs, an error code is left in p->rc. If an error has
195119 int nToken, /* Size of buffer pToken in bytes */
195247 ** Discard any data stored in the in-memory hash tables. Do not write it
195249 ** table may have changed on disk. So any in-memory caches of %_data
195341 ** Argument p points to a buffer containing utf-8 text that is n bytes in
195342 ** size. Return the number of bytes in the nChar character prefix of the
195343 ** buffer, or 0 if there are less than nChar characters in total.
195362 ** pIn is a UTF-8 encoded string, nIn bytes in size. Return the number of
195363 ** unicode characters in the string.
195382 ** For an insert, it must be called once for each token in the new document.
195384 ** unique token in the document with an iCol value less than zero. The iPos
195389 int iCol, /* Column token appears in (-ve -> delete) */
195444 ** satisfied by scanning multiple terms in the main index.
195449 ** for internal sanity checking by the integrity-check in debug
195475 /* Scan multiple terms in the main index */
195537 ** in ascending or descending rowid order.
195571 ** the number of user defined columns in the FTS table.
195675 ** FTS functionality, or even the integrity-check, in any way.
195679 ** iSegid/iLeaf is iterated in forwards or reverse order.
195721 int n, /* Size of index key in bytes */
195723 u64 *pCksum /* IN/OUT: Checksum value */
195759 ** FTS functionality, or even the integrity-check, in any way.
195775 int nTerm = pPrev->n-1; /* Size of zTerm in bytes */
195791 ** the index is disabled are the same. In both ASC and DESC order.
195934 /* If the leaf in question has already been trimmed from the segment,
195942 ** to or larger than the split-key in zIdxTerm. Also check that if there
195950 int nTerm; /* Size of term on leaf in bytes */
196032 /* Page iter.iLeaf must now be the rightmost leaf-page in the segment */
196080 ** based on all expected entries in the FTS index (including prefix index
196086 ** while doing a linear scan of each individual index in turn.
196096 int n; /* Size of term in bytes */
196180 int *pRc, /* IN/OUT: error code */
196209 int *pRc, /* IN/OUT: error code */
196234 int *pRc, /* IN/OUT: error code */
196303 ** Buffer (pData/nData) contains a doclist in the format used by detail=none
196310 ** pBuf is undefined in this case.
196313 int *pRc, /* IN/OUT: Error code */
196362 /* Make a copy of the second argument (a blob) in aBlob[]. The aBlob[]
196448 int szLeaf; /* Offset of pgidx in a[] */
196601 ** The author disclaims copyright to this source code. In place of
196619 ** assert() conditions in the fts5 code are activated - conditions that are
196644 ** in the xSync() callback. Current versions of SQLite ignore any errors
196654 ** in-memory. It is flushed to disk whenever xSync(), xRelease() or
196660 ** is not required, but it is used in the assert() statements executed by
196677 Fts5Auxiliary *pAux; /* First in list of all aux. functions */
196678 Fts5TokenizerModule *pTok; /* First in list of all tokenizer modules */
196680 Fts5Cursor *pCsr; /* First in list of all open cursors */
196727 int nTerm; /* Size of phrase in terms */
196735 ** There is one entry in the aIdx[] array for each phrase in the query,
196743 int nIdx; /* Number of entries in aIdx[] */
196757 ** cursor iterates in ascending order of rowids, iFirstRowid is the lower
196758 ** limit of rowids to return, and iLastRowid the upper. In other words, the
196759 ** WHERE clause in the user's query might have been:
196763 ** If the cursor iterates in descending order of rowid, iFirstRowid
196769 Fts5Cursor *pNext; /* Next cursor in Fts5Cursor.pCsr list */
196790 sqlite3_stmt *pRankArgStmt; /* Origin of objects in apRankArg[] */
196794 Fts5Auxdata *pAuxdata; /* First in linked list of saved aux-data */
196843 Fts5Auxdata *pNext; /* Next object in linked list */
196957 int argc, /* Number of elements in argv array */
197017 ** work is done in function fts5InitVtab().
197022 int argc, /* Number of elements in argv array */
197032 int argc, /* Number of elements in argv array */
197051 ** Set the SQLITE_INDEX_SCAN_UNIQUE flag in pIdxInfo->flags. Unless this
197053 ** support index-info flags. In that case this function is a no-op.
197083 ** a) If an unusable MATCH operator is present in the WHERE clause, the
197117 int iConsIndex; /* Index in pInfo->aConstraint[] */
197181 /* Calculate the estimated cost based on the flags set in idxFlags. */
197194 /* Assign argvIndex values to each constraint in use. */
197345 /* nBlob==0 in detail=none mode. */
197383 ** (in the cursors sort order - ASC or DESC) than the current rowid.
197416 ** Advance the cursor to the next row in the table that matches the
197517 ** If SQLite a built-in statement cache, this wouldn't be a problem. */
197567 int n; /* Number of bytes in text at z */
197679 "parse error in rank function: %s", z
197719 int nVal, /* Number of elements in apVal */
197757 ** Note: The following set of if(...) statements must be in the same
197758 ** order as the corresponding entries in the struct at the top of
197911 ** be left in sqlite3_vtab.zErrMsg.
197954 ** This function is called to handle an FTS INSERT command. In other words,
197964 ** The commands implemented by this function are documented in the "Special
198468 int nUnused, /* Size of token in bytes */
198841 ** the current position-list for each phrase in the query associated with
198845 ** the number of phrases in the query. Following the varints are the
198846 ** concatenated position lists for each phrase, in order.
198931 ** useful in that it may be passed as the first argument to an FTS5
199047 int nName; /* Size of zName in bytes, including \0 */
199172 *pzErr = sqlite3_mprintf("error in tokenizer constructor");
199347 ** The author disclaims copyright to this source code. In place of
199366 i64 nTotalRow; /* Total number of rows in FTS table */
199550 int *pRc, /* IN/OUT: Error code */
199702 int szCol; /* Size of column value in tokens */
199712 int nToken, /* Size of token in bytes */
199727 ** If a row with rowid iDel is present in the %_content table, add the
199829 ** variables in the "averages" record on disk.
199895 ** Delete all entries in the FTS5 index.
199996 ** If the %_docsize table does not exist, SQLITE_MISMATCH is returned. In
200143 int nToken, /* Size of token in bytes */
200225 ** %_content table. This block stores the checksum in ctx.cksum. */
200373 int nCol = p->pConfig->nCol; /* Number of user columns in table */
200425 ** Flush any data currently held in-memory to disk.
200477 ** The author disclaims copyright to this source code. In place of
200709 int nFold; /* Size of aFold[] in bytes */
200972 /* Any tokens larger than this (in bytes) are passed through without
201688 ** Register all built-in tokenizers with FTS5.
201720 ** The author disclaims copyright to this source code. In place of
201745 /* Each unsigned integer in the following array corresponds to a contiguous
201749 ** The most significant 22 bits in each 32-bit value contain the first
201750 ** codepoint in the range. The least significant 10 bits are used to store
201751 ** the size of the range (always at least 1). In other words, the value
201870 ** in the ASCII range with a diacritic added, return the codepoint
201946 /* Each entry in the following array defines a rule for folding a range
201950 ** If the least significant bit in flags is clear, then the rule applies
201953 ** every second codepoint in the range, starting with codepoint C.
201955 ** The 7 most significant bits in flags are an index into the aiOff[]
202081 ** The author disclaims copyright to this source code. In place of
202142 /* A 32-bit varint is used to store size information in btrees.
202166 ** inline in order to work around bugs in the RVT compiler.
202177 ** Return the number of bytes read. The value is stored in *v.
202252 /* we can skip these cause they were (effectively) done above in calc'ing s */
202273 /* we can skip this cause it was (effectively) done above in calc'ing s */
202427 ** The author disclaims copyright to this source code. In place of
202446 ** instances of term $term in column $col (in any row of the fts5 table).
202451 ** One row for each term in the database. The value of $doc is set to
202454 ** $term in the database.
202481 int nLeTerm; /* Size of zLeTerm in bytes */
202571 ** or, for tables in the TEMP schema only.
202580 int argc, /* Number of elements in argv array */
202636 ** work is done in function fts5VocabInitVtab().
202641 int argc, /* Number of elements in argv array */
202651 int argc, /* Number of elements in argv array */
202705 /* This virtual table always delivers results in ascending order of
202709 ** are already in sorted order. */
202806 ** Advance the cursor to the next row in the table.
202928 int nUnused, /* Number of elements in apVal */