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
32 ** The author disclaims copyright to this source code. In place of
53 ** code in all source files.
59 ** without this option, LFS is enable. But LFS does not exist in the kernel
60 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
63 ** The previous paragraph was written in 2005. (This paragraph is written
66 ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
101 ** library in use (e.g. for Windows XP).
111 ** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for
114 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
119 ** The author disclaims copyright to this source code. In place of
129 ** or constant definition does not appear in this file, then it is
133 ** Some of the definitions that are in this file are marked as
137 ** if experience from use "in the wild" suggest such changes are prudent.
140 ** from comments in this file. This file is the authoritative source
143 ** The name of this file under configuration management is "sqlite.h.in".
173 ** These no-op macros are used in front of interfaces to mark those
177 ** experimental interfaces are subject to change in point releases.
201 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
202 ** evaluates to a string literal that is the SQLite version in the
207 ** numbers used in [SQLITE_VERSION].)^
213 ** Since version 3.6.18, SQLite source code has been stored in the
216 ** a string which identifies a particular check-in of SQLite
218 ** string contains the date and time of the check-in (UTC) and an SHA1
236 ** programmers might include assert() statements in their application to
237 ** verify that values returned by these interfaces match the macros in
250 ** function is provided for use in DLLs since DLL users usually do not have
322 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
399 ** host languages that are garbage collected, and where the order in which
443 ** in the context of the [database connection] passed in as its 1st
461 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
469 ** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
507 ** here in order to indicate success or failure.
509 ** New error codes may be added in future versions of SQLite.
516 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
520 #define SQLITE_LOCKED 6 /* A table in the database is locked */
526 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
551 ** In its default configuration, SQLite API routines return one of 30 integer
554 ** much information about problems as programmers might like. In an effort to
619 ** These bit values are intended for use in the
621 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
657 ** mean that writes of blocks that are nnn bytes in size and
663 ** information is written to disk in the same order as calls
665 ** after reboot following a crash or power loss, the only bytes in a
735 ** An [sqlite3_file] object represents an open file in the
767 ** flag may be ORed in to indicate that only the data of the file
780 ** either in this process or in some other process, is holding a RESERVED,
788 ** point to a structure that may contain arguments or space in which to
803 ** other bytes in the file. The xDeviceCharacteristics()
823 ** mean that writes of blocks that are nnn bytes in size and
829 ** information is written to disk in the same order as calls
833 ** in the unread portions of the buffer with zeros. A VFS that
862 /* Additional methods may be added in future releases */
886 ** file space based on this hint in order to help writes to the database
891 ** extends and truncates the database file in chunks of a size specified
894 ** for the nominated database. Allocating database file space in large
905 ** No longer in use.
912 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
913 ** of the xSync method. In most cases, the pointer argument passed with
932 ** windows [VFS] in order to provide robustness in the presence of
955 ** in order for the database to be readable. The fourth parameter to
979 ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
981 ** [sqlite3_malloc()] and the result is stored in the char* variable
986 ** pointer in case this file-control is not implemented. This file-control
994 ** pointers to strings (char**) in which the second element of the array
1010 ** it is able to override built-in [PRAGMA] statements.
1015 ** shortly after it is opened in
1018 ** to a function of type (int (*)(void *)). In order to invoke the connections
1019 ** busy-handler, this function should be invoked with the second (void *) in
1037 ** is an advisory maximum number of bytes in the file to memory map. The
1040 ** can be queried by passing in a pointer to a negative number. This
1047 ** The argument is a zero-terminated string. Higher layers in the
1105 ** in the name of the object stands for "virtual file system". See
1108 ** The value of the iVersion field is initially 1 but may be larger in
1111 ** of the sqlite3_vfs object changes in the transaction between
1117 ** a pathname in this VFS.
1122 ** in a thread-safe way. The [sqlite3_vfs_find()] interface
1126 ** The pNext field is the only field in the sqlite3_vfs
1152 ** The flags argument to xOpen() includes all bits set in
1157 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
1179 ** file will be doing page-aligned sector reads and writes in a random
1194 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1206 ** allocate the structure; it should just fill it in. Note that
1229 ** included in the VFS structure for completeness.
1238 ** Day Number multiplied by 86400000 (the number of milliseconds in
1280 ** The methods above are in version 1 of the sqlite_vfs object
1281 ** definition. Those that follow are added in version 2 or later
1285 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1292 ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1293 ** New fields may be appended in figure versions. The iVersion
1308 ** (in other words, if files can be added, removed, and renamed within
1311 ** [temp_store_directory pragma], though this could change in a future
1315 ** currently unused, though it might be used in a future release of
1366 ** These routines are designed to aid in process initialization and
1408 ** of SQLite may require this. In other words, the behavior exhibited
1410 ** default behavior in some future release of SQLite.
1444 ** changes to SQLite in order to tune SQLite to the specific needs of
1463 ** in the first argument.
1477 ** [database connection] (specified in the first argument).
1495 ** This object is used in only one place in the SQLite interface.
1505 ** Note that SQLite comes with several [built-in memory allocators]
1509 ** also used during testing of SQLite in order to specify an alternative
1510 ** memory allocator that simulates memory out-of-memory conditions in
1527 ** Every memory allocation request coming in through [sqlite3_malloc()]
1571 ** New configuration options may be added in future releases of SQLite.
1581 ** [threading mode] to Single-thread. In other words, it disables
1592 ** [threading mode] to Multi-thread. In other words, it disables
1596 ** are enabled so that SQLite will be safe to use in a multi-threaded
1606 ** [threading mode] to Serialized. In other words, this option enables
1609 ** In this mode (which is the default when SQLite is compiled with
1613 ** same [prepared statement] in different threads at the same time.
1623 ** alternative low-level memory allocation routines to be used in place of
1648 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1685 ** The pointer in the first argument must
1694 ** the number of bytes in the memory buffer, and the minimum allocation size.
1709 ** alternative low-level mutex routines to be used in place
1769 ** In a multi-threaded application, the application-defined logger
1787 ** a boolean in order to enable or disable the use of covering indices for
1788 ** full table scans in the query optimizer. ^The default setting is determined
1809 ** in three separate circumstances, identified by the value passed as the
1816 ** third parameter is passed NULL In this case. An example of using this
1817 ** configuration option can be seen in the "test_sqllog.c" source file in
1872 ** New configuration options may be added in future releases of SQLite.
1886 ** may be NULL in which case SQLite will allocate the
1889 ** slots. The size of the buffer in the first argument must be greater than
1895 ** connection is not currently using lookaside memory, or in other words
1899 ** memory is in use leaves the configuration unchanged and returns
1909 ** following this call. The second parameter may be a NULL pointer, in
1919 ** following this call. The second parameter may be a NULL pointer, in
1941 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2021 ** ^This function returns the number of direct row changes in the
2026 ** number of changes in the most recent INSERT, UPDATE, or DELETE
2029 ** changes in the most recently completed INSERT, UPDATE, or DELETE
2074 ** called in response to a user action such as pressing "Cancel"
2092 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
2119 ** independent tokens (they are part of the token in which they are
2139 ** UTF-16 string in native byte order.
2171 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2194 ** database connection that invoked the busy handler. In other words,
2196 ** result in undefined behavior.
2241 ** There are (N+1)*M elements in the array. The first M pointers point
2244 ** in NULL pointers. All other values are in their UTF-8 zero-terminated
2264 ** in an array names azResult. Then azResult holds this content:
2278 ** semicolon-separated SQL statements in the zero-terminated UTF-8
2280 ** pointer given in its 3rd parameter.
2283 ** it must pass the result table pointer to sqlite3_free_table() in order to
2292 ** interface defined here. As a consequence, errors that occur in the
2294 ** reflected in subsequent calls to [sqlite3_errcode()] or
2343 ** All of the usual printf() formatting options apply. In addition, there
2346 ** ^(The %q option works like %s in that it substitutes a nul-terminated
2358 ** One can use this text in an SQL statement as follows:
2366 ** Because the %q format string is used, the '\'' character in zText
2384 ** the outside of the total string. Additionally, if the parameter in the
2394 ** The code above will render a correct SQL statement in the zSQL
2410 ** internal memory allocation needs. "Core" in the previous sentence
2415 ** of memory at least N bytes in length, where N is the parameter.
2427 ** memory might result in a segmentation fault or other severe error.
2442 ** of at least N bytes in size or NULL if sufficient memory is unavailable.
2454 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2455 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2457 ** is no longer provided. Only built-in memory allocators can be used.
2485 ** routines, which form the built-in memory allocation subsystem.
2493 ** added by SQLite in its implementation of [sqlite3_malloc()],
2512 ** the build-in random() and randomblob() SQL functions. This interface allows
2532 ** [database connection], supplied in the first argument.
2563 ** a NULL value in place of the table column that would have
2578 ** database. An authorizer could then be put in place while the
2585 ** in addition to using an authorizer.
2587 ** ^(Only a single authorizer can be in place on a database connection
2595 ** database connections for the meaning of "modify" in this paragraph.
2600 ** correct authorizer callback remains in place during the [sqlite3_step()].
2604 ** performed during statement evaluation in [sqlite3_step()], unless
2605 ** as stated in the previous paragraph, sqlite3_step() invokes
2618 ** return either [SQLITE_OK] or one of these two constants in order
2699 ** the length of [bound parameter] expansion in the output of sqlite3_trace().
2705 ** time is in units of nanoseconds, however the current implementation
2707 ** digits in the time are meaningless. Future versions of SQLite
2710 ** subject to change in future versions of SQLite.
2744 ** database connections for the meaning of "modify" in this paragraph.
2754 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2756 ** returned in *ppDb, even if an error occurs. The only exception is that
2767 ** UTF-16 in the native byte order if sqlite3_open16() is used.
2783 ** <dd>The database is opened in read-only mode. If the database does not
2788 ** only if the file is write protected by the operating system. In either
2803 ** opens in the multi-thread [threading mode] as long as the single-thread
2806 ** in the serialized [threading mode] unless single-thread was
2812 ** participate in [shared cache mode] even if it is enabled.
2819 ** ^If the filename is ":memory:", then a private, temporary in-memory database
2820 ** is created for the connection. ^This in-memory database will vanish when
2831 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
2836 ** set in the fourth argument to sqlite3_open_v2(), or if it has
2876 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
2882 ** set to "memory" then a pure [in-memory database] that never reads
2885 ** the flags passed in the third parameter to sqlite3_open_v2().
2889 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
2892 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2900 ** parameter only works for the built-in unix and Windows VFSes.
2903 ** which if set disables file locking in rollback journal modes. This
2915 ** property on a database file that does in fact change can result
2916 ** in incorrect query results and/or [SQLITE_CORRUPT] errors.
2921 ** ^Specifying an unknown parameter in the query component of a URI is not an
2931 ** Open the file "data.db" in the current directory.
2941 ** C:. Note that the %20 escaping in
2943 ** in URI filenames.
2945 ** Open file "data.db" in the current directory for read-only access.
2950 ** that uses dot-files in place of posix advisory locking.
3011 ** value of query parameter P is one of "yes", "true", or "on" in any
3014 ** query parameter P is one of "no", "false", or "off" in any case or
3059 ** When the serialized [threading mode] is in use, it might be the
3060 ** case that a second error occurs on a separate thread in between
3070 ** was invoked incorrectly by the application. In that case, the
3120 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
3129 ** Run-time limits are intended for use in applications that manage
3142 ** New run-time limit categories may be added in future releases.
3153 ** Additional information is available at [limits | Limits in SQLite].
3157 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3160 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
3163 ** <dd>The maximum number of columns in a table definition or in the
3164 ** result set of a [SELECT] or the maximum number of columns in an index
3165 ** or in an ORDER BY or GROUP BY clause.</dd>)^
3171 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3174 ** <dd>The maximum number of instructions in a virtual machine program
3176 ** enforced, though that might be added in some future release of
3192 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
3233 ** is equal to the number of bytes in the input string <i>including</i>
3238 ** past the end of the first SQL statement in zSql. These routines only
3239 ** compile the first statement in zSql, so *pzTail is left pointing to
3256 ** ^In the "v2" interfaces, the prepared statement
3259 ** behave differently in three ways:
3274 ** in order to find the underlying cause of the problem. With the "v2" prepare
3279 ** ^If the specific value bound to [parameter | host parameter] in the
3294 int nByte, /* Maximum length of zSql in bytes. */
3301 int nByte, /* Maximum length of zSql in bytes. */
3308 int nByte, /* Maximum length of zSql in bytes. */
3315 int nByte, /* Maximum length of zSql in bytes. */
3371 ** This interface can be used in combination [sqlite3_next_stmt()]
3373 ** connection that are in need of being reset. This can be used,
3374 ** for example, in diagnostic routines to search for prepared
3384 ** that can be stored in a database table. SQLite uses dynamic typing
3385 ** for the values it stores. ^Values stored in sqlite3_value objects
3399 ** or if SQLite is run in one of reduced mutex modes
3421 ** The context in which an SQL function executes is stored in an
3437 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3449 ** In the templates above, NNN represents an integer literal,
3473 ** ^(In those routines that have a fourth argument, its value is the
3474 ** number of bytes in the parameter. To be clear: the value is the
3475 ** number of <u>bytes</u> in the value, not the number of characters.)^
3496 ** information is in static, unmanaged space and does not need to be freed.
3507 ** ^A negative value for the zeroblob results in a zero-length BLOB.
3541 ** in a [prepared statement]. SQL parameters are tokens of the
3549 ** there may be gaps in the list.)^
3561 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
3565 ** In other words, the initial ":" or "$" or "@" or "?"
3574 ** always in UTF-8 encoding even if the named parameter was
3575 ** originally specified as UTF-16 in [sqlite3_prepare16()] or
3591 ** name must be given in UTF-8 even if the original statement
3610 ** CAPI3REF: Number Of Columns In A Result Set
3612 ** ^Return the number of columns in the result set returned by the
3621 ** CAPI3REF: Column Names In A Result Set
3624 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
3650 ** CAPI3REF: Source Of Data In A Query Result
3653 ** table column that is the origin of a particular result column in
3663 ** again in a different encoding.
3725 ** data stored in that column is of the declared type. SQLite is
3748 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
3776 ** [prepared statement]. ^In the "v2" interface,
3784 ** more threads at the same moment in time.
3790 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
3792 ** calling [sqlite3_reset()] automatically in this circumstance rather
3798 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
3801 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
3813 ** CAPI3REF: Number of columns in a result set
3815 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3824 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
3836 ** ^(Every value in SQLite has one of five fundamental datatypes:
3848 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
3871 ** result row of a query. ^In every case the first argument is a pointer
3876 ** ^The number of columns in the result can be determined using
3902 ** routine returns the number of bytes in that BLOB or string.
3907 ** the number of bytes in that string.
3911 ** routine returns the number of bytes in that BLOB or string.
3916 ** the number of bytes in that string.
3923 ** bytes in the string, not the number of characters.
3933 ** [sqlite3_column_value()] is used in any other way, including calls
3969 ** used in
3976 ** in the following cases:
3990 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
3993 ** of conversion are done in place when it is possible, but sometimes they
3994 ** are not possible and in those cases prior pointers are invalidated.
3997 ** in one of the following ways:
4005 ** In other words, you should call sqlite3_column_text(),
4056 ** The application must finalize every [prepared statement] in order to avoid
4059 ** statement after it has been finalized can result in undefined and
4110 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
4112 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
4114 ** will result in [SQLITE_MISUSE] being returned.
4140 ** deterministic. The built-in [random()] SQL function is an example of a
4170 ** the implementation that most closely matches the way in which the
4180 ** ^Built-in functions may be overloaded by new application-defined functions.
4185 ** statement in which the function is running.
4246 ** These functions are [deprecated]. In order to maintain
4279 ** object results in undefined behavior.
4286 ** in the native byte-order of the host machine. ^The
4293 ** such a conversion is possible without loss of information (in other
4336 ** In those cases, sqlite3_aggregate_context() might be called for the
4345 ** value of N in subsequent call to sqlite3_aggregate_context() within
4348 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
4359 ** This routine must be called from the same thread in which
4373 ** This routine must be called from the same thread in which
4396 ** of where this might be useful is in a regular-expression matching
4425 ** Note the last bullet in particular. The destructor X in
4432 ** ^(In practice, metadata is preserved between function calls for
4436 ** These routines must be called from the same thread in which
4446 ** These are special values for the destructor that is passed in as the
4450 ** SQLITE_TRANSIENT value means that the content will likely change in
4454 ** The typedef is necessary to work around problems in certain
4470 ** functions used to bind values to host parameters in prepared statements.
4480 ** bytes and N bytes in size, where N is the value of the 2nd parameter.
4492 ** interprets the string from sqlite3_result_error16() as UTF-16 in native
4504 ** returned by SQLite as a result of an error in a function. ^By default,
4516 ** value given in the 2nd argument.
4519 ** value given in the 2nd argument.
4540 ** in the string at a byte offset that is less than the value of the 3rd
4549 ** assumes that the text or BLOB result is in constant space and does not
4561 ** so that the [sqlite3_value] specified in the parameter may change or
4596 ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
4627 ** application data pointer and with two strings in the encoding specified
4700 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
4701 ** the names are passed as UTF-16 in machine native byte order.
4732 ** The code to implement this API is not available in the public release
4750 ** The code to implement this API is not available in the public release
4786 ** for at least a number of milliseconds specified in its parameter.
4797 ** in the previous paragraphs.
4806 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
4807 ** will be placed in that directory.)^ ^If this variable
4816 ** be avoided in new projects.
4818 ** It is not safe to read or modify this variable in more than one
4820 ** if a [database connection] is being used at the same time in a separate
4830 ** that this variable points to is held in memory obtained from
4865 ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
4873 ** open can result in a corrupt database.
4875 ** It is not safe to read or modify this variable in more than one
4877 ** if a [database connection] is being used at the same time in a separate
4887 ** that this variable points to is held in memory obtained from
4901 ** zero if the given database connection is or is not in autocommit mode,
4927 ** create the statement in the first place.
4937 ** connection D, or if database N is a temporary or in-memory database, then
4941 ** xFullPathname method of the [VFS]. ^In other words, the filename
4965 ** The [database connection] pointer D in a call to
4967 ** connection and in particular must not be a NULL pointer.
4996 ** or rollback hook in the first place.
4999 ** the database connections for the meaning of "modify" in this paragraph.
5025 ** to be invoked whenever a row is updated, inserted or deleted in
5031 ** row is updated, inserted or deleted in a rowid table.
5040 ** ^In the case of an update, this is the [rowid] after the update takes place.
5046 ** ^In the current implementation, the update hook
5050 ** The exceptions defined in this paragraph might change in a future
5058 ** database connections for the meaning of "modify" in this paragraph.
5083 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
5089 ** that was in effect at the time they were opened.)^
5094 ** ^Shared cache is disabled by default. But this might change in
5126 ** [sqlite3_release_memory()] interface, this interface is in effect even
5140 ** limit by reducing the number of pages held in the page cache
5144 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
5148 ** the soft heap limit prior to the call, or negative in the case of an
5156 ** ^(The soft heap limit is not enforced in the current implementation
5177 ** the page cache is the predominate memory user in SQLite, most
5182 ** changes in future releases of SQLite.
5218 ** NULL, in which case the corresponding element of metadata is omitted.
5255 ** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
5278 ** [SQLite extension] library contained in the file zFile. If
5286 ** ^(zProc may be 0, in which case SQLite will try to come up with an
5290 ** characters in the filename from the last "/" to the first following
5296 ** fill *pzErrMsg with error message text stored in memory
5316 ** ^So as not to open security holes in older applications that are
5388 ** to be experimental. The interface might change in incompatible ways.
5411 ** ^A virtual table module is created by filling in a persistent
5447 /* The methods above are in version 1 of the sqlite_module object. Those
5470 ** stored in aConstraint[].op using one of the
5472 ** ^(The index of the column is stored in
5478 ** and makes other simplifications to the WHERE clause in an attempt to
5483 ** ^Information about the ORDER BY clause is stored in aOrderBy[].
5489 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
5498 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5521 int nConstraint; /* Number of entries in aConstraint */
5528 int nOrderBy; /* Number of terms in the ORDER BY clause */
5543 /* Fields below are only available in SQLite 3.8.2 and later */
5552 ** an operator that is part of a constraint term in the wHERE clause of
5640 ** This superclass exists in order to define fields of the cursor that
5664 ** must exist in order to be overloaded.)^
5679 ** to be experimental. The interface might change in incompatible ways.
5696 ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
5704 ** in row iRow, column zColumn, table zTable in database zDb;
5705 ** in other words, the same BLOB that would be selected by:
5728 ** functions. ^Note that the *ppBlob variable is always initialized in a
5752 ** and the built-in [zeroblob] SQL function can be used, if desired,
5753 ** to create an empty, zero-filled blob in which to read or write using
5780 ** it must exist and there must be either a blob or text value stored in
5781 ** the nominated column.)^ ^If the new row is not present in the table, or if
5800 ** database connection is in [autocommit mode].
5801 ** ^If any writes were made to the BLOB, they might be held in cache
5820 ** ^Returns the size in bytes of the BLOB accessible via the
5821 ** successfully opened [BLOB handle] in its only argument. ^The
5827 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5828 ** to this routine results in undefined and probably undesirable behavior.
5853 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5854 ** to this routine results in undefined and probably undesirable behavior.
5891 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5892 ** to this routine results in undefined and probably undesirable behavior.
5942 ** implementations are available in the SQLite core:
5951 ** that does no real locking and is appropriate for use in
5958 ** implementation is included with the library. In this case the
5989 ** not want to. ^SQLite will only request a recursive mutex in
5992 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
6011 ** dynamic mutex that it allocates. The dynamic mutexes must not be in
6013 ** mutex results in undefined behavior. ^SQLite never deallocates
6022 ** In such cases the,
6027 ** such behavior in its own use of mutexes.)^
6061 ** does not provide a suitable implementation. In this case, the user
6114 ** If xMutexInit fails in any way, it is expected to clean up after itself
6142 ** ^These routines should return true if the mutex in their argument
6171 ** next. Applications that override the built-in mutex logic must be
6192 ** serializes access to the [database connection] given in the argument
6208 ** ^A NULL pointer can be used in place of "main" to refer to the
6294 ** ^The highest recorded value is returned in *pHighwater. ^If the
6307 ** interfaces. However the values returned in *pCurrent and
6308 ** *pHighwater reflect the status of SQLite at different points in time
6310 ** in between the times when *pCurrent and *pHighwater are written.
6331 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
6333 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
6338 ** internal equivalents). Only the value returned in the
6350 ** value returned is in pages, not in bytes.</dd>)^
6360 ** no space was left in the page cache.</dd>)^
6364 ** handed to [pagecache memory allocator]. Only the value returned in the
6371 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
6372 ** in bytes. Since a single thread may only have one scratch allocation
6388 ** handed to [scratch memory allocator]. Only the value returned in the
6420 ** to grow in future releases of SQLite.
6441 ** New verbs may be added in future releases of SQLite. Existing verbs
6469 ** memory already being in use.
6509 ** wal file in wal mode databases, or the number of pages written to the
6510 ** database file in rollback mode databases. Any pages written as part of
6573 ** <dd>^This is the number of times that SQLite has stepped forward in
6580 ** A non-zero value in this counter may indicate an opportunity to
6585 ** were created automatically in order to help joins run faster.
6586 ** A non-zero value in this counter may indicate an opportunity to
6621 ** The sqlite3_pcache_page object represents a single page in the
6639 ** register an alternative page cache implementation by passing in an
6641 ** In many applications, most of the heap memory allocated by
6645 ** the amount of memory consumed by SQLite, the way in which
6652 ** The built-in page cache is recommended for most uses.
6667 ** built-in default page cache is used instead of the application defined
6680 ** in multithreaded applications.
6689 ** first parameter, szPage, is the size in bytes of the pages that must
6699 ** false if it is used for an in-memory database. The cache implementation
6703 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
6718 ** stored in the cache, both pinned and unpinned.
6721 ** The xFetch() method locates a page in the cache and returns a pointer to
6727 ** for each entry in the page cache.
6733 ** If the requested page is already in the page cache, then the page cache
6735 ** intact. If the requested page is not already in the cache, then the
6740 ** <tr><th> createFlag <th> Behavior when page is not already in cache
6750 ** failed.)^ In between the to xFetch() calls, SQLite may
6814 ** retained in the header file for backwards compatibility only.
6849 ** for copying in-memory databases to or from persistent files.
6879 ** temporary database, or the name specified after the AS keyword in
6889 ** returned and an error code and error message are stored in the
6920 ** <li> the destination database is an in-memory database and the
6928 ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
6932 ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
6936 ** there is no point in retrying the call to sqlite3_backup_step(). These
6985 ** up and the total number of pages in the source database file.
7010 ** backup is in progress might also also cause a mutex deadlock.
7012 ** If running in [shared cache mode], the application must
7014 ** is not accessed while the backup is running. In practice this means
7040 ** ^When running in shared-cache mode, a database operation may fail with
7065 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
7099 ** and the second is the number of entries in the array.
7122 ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
7123 ** unlock-notify callback is registered. The system is said to be in
7140 ** returned. In this case there is no "blocking connection", so invoking
7141 ** sqlite3_unlock_notify() results in the unlock-notify callback being
7147 ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
7163 ** strings in a case-independent fashion, using the same definition of "case
7174 ** the glob pattern P. ^The definition of glob pattern matching used in
7175 ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
7200 ** will not use dynamically allocated memory. The log message is stored in
7212 ** [write-ahead log] (i.e. whenever a transaction is committed in
7224 ** is the number of pages currently in the write-ahead log file,
7255 ** more frames in the [write-ahead log] file. ^Passing zero or
7284 ** connection D. ^If the database connection D is not in
7310 ** readers or writers to finish. Sync the db file if all frames in the log
7319 ** snapshot. It then checkpoints all frames in the log file and syncs the
7333 ** If pnLog is not NULL, then *pnLog is set to the total number of frames in
7344 ** busy-handler configured, it will not be invoked in this case.
7353 ** checkpoint operation proceeds from that point in the same way as
7355 ** without blocking any further. SQLITE_BUSY is returned in this case.
7358 ** specified operation is attempted on all WAL databases. In this case the
7368 ** If database zDb is the name of an attached database that is not in WAL
7377 int *pnLog, /* OUT: Size of WAL log in frames */
7405 ** may be added in the future.
7422 ** support constraints. In this configuration (which is the default) if
7444 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
7498 ** The author disclaims copyright to this source code. In place of
7585 unsigned int *anQueue; /* Number of pending entries in the queue */
7588 int mxLevel; /* The largest iLevel value in the tree */
7612 /************** Continuing where we left off in sqliteInt.h ******************/
7622 /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
7627 ** The author disclaims copyright to this source code. In place of
7640 ** The maximum length of a TEXT or BLOB in bytes. This also
7641 ** limits the size of a row in a table or index.
7653 ** * Columns in a table
7654 ** * Columns in an index
7655 ** * Columns in a view
7656 ** * Terms in the SET clause of an UPDATE statement
7657 ** * Terms in the result set of a SELECT statement
7658 ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
7659 ** * Terms in the VALUES clause of an INSERT statement
7662 ** tell you that in a well-normalized database, you usually should
7663 ** not have more than a dozen or so columns in any table. And if
7664 ** that is the case, there is no point in having more than a few
7665 ** dozen values in any of the other situations described above.
7672 ** The maximum length of a single SQL statement in bytes.
7697 ** The maximum number of terms in a compound SELECT statement.
7700 ** if the number of terms is too large. In practice, most SQL
7702 ** any limit on the number of terms in a compount SELECT.
7709 ** The maximum number of opcodes in a VDBE program.
7724 ** The maximum number of in-memory pages to use for the main database
7735 ** The default number of frames to accumulate in the log file before
7736 ** checkpointing the database in WAL mode.
7804 ** Maximum number of pages in one database file.
7815 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
7834 /************** Continuing where we left off in sqliteInt.h ******************/
7877 ** So we have to define the macros in different ways depending on the
7932 ** Exactly one of the following macros must be defined in order to
7973 ** We need to define _XOPEN_SOURCE as follows in order to enable
7988 ** assert() statements in the code. So we want the default action
7990 ** is set. Thus NDEBUG becomes an opt-in rather than an opt-out
8008 ** The testcase() macro is used to aid in coverage testing. When
8010 ** testcase() must be evaluated both true and false in order to
8012 ** to help ensure adequate test coverage in places where simple
8044 ** "Verification, Validation, and Accreditation". In other words, the
8057 ** are included in a few cases in order to enhance the resilience
8062 ** In other words, ALWAYS and NEVER are added for defensive code.
8081 ** to fit in 32-bits. This macro is used inside of various testcase()
8090 ** in theory, be used by the compiler to generate better code, but
8096 /************** Include hash.h in the middle of sqliteInt.h ******************/
8101 ** The author disclaims copyright to this source code. In place of
8110 ** used in SQLite.
8130 ** There are Hash.htsize buckets. Each bucket points to a spot in
8132 ** element pointed to plus the next _ht.count-1 elements in the list.
8134 ** Hash.htsize and Hash.ht may be zero. In that case lookup is done
8137 ** in the table, it is faster to do a linear search than to manage
8141 unsigned int htsize; /* Number of buckets in the hash table */
8142 unsigned int count; /* Number of entries in this table */
8150 /* Each element in the hash table is an instance of the following
8157 HashElem *next, *prev; /* Next and previous elements in the table */
8189 ** Number of entries in a hash table
8196 /************** Continuing where we left off in sqliteInt.h ******************/
8197 /************** Include parse.h in the middle of sqliteInt.h *****************/
8360 /************** Continuing where we left off in sqliteInt.h ******************/
8418 ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
8505 ** that can be stored in a u32 without loss of data. The value
8507 ** have to specify the value in the less intuitive manner shown:
8512 ** The datatype used to store estimates of the number of rows in a
8611 ** pointers. In that case, only verify 4-byte alignment.
8628 ** Default maximum size of memory used by memory-mapped I/O in the VFS
8712 ** A convenience macro that returns the number of elements in
8743 ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
8771 ** For example those parameters only used in assert() statements. In these
8830 /************** Include btree.h in the middle of sqliteInt.h *****************/
8835 ** The author disclaims copyright to this source code. In place of
8844 ** subsystem. See comments in the source code for a detailed description
8887 ** NOTE: These values must match the corresponding PAGER_ values in
8891 #define BTREE_MEMORY 2 /* This is an in-memory DB */
8939 ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
8960 ** to constants so that the offset of the corresponding field in an
9089 /************** Continuing where we left off in sqliteInt.h ******************/
9090 /************** Include vdbe.h in the middle of sqliteInt.h ******************/
9095 ** The author disclaims copyright to this source code. In place of
9115 ** in the source file sqliteVdbe.c are allowed to see the insides
9121 ** The names of the following types declared in vdbeInt.h are required
9135 u8 opflags; /* Mask of the OPFLG_* flags in opcodes.h */
9174 int nOp; /* Elements in aOp[] */
9240 ** The following macro converts a relative address in the p2 field
9251 /************** Include opcodes.h in the middle of vdbe.h ********************/
9312 #define OP_OpenPseudo 58 /* synopsis: P3 columns in r[P2] */
9382 #define OP_RowSetTest 128 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9415 /* Properties such as "out2" or "jump" that are specified in
9416 ** comments following the "case" for each opcode in the vdbe.c
9449 /************** Continuing where we left off in vdbe.h ***********************/
9518 ** comments in VDBE programs that show key decision points in the code
9540 ** numbers in the sqlite3.c source file. VDBE branch coverage testing
9556 ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
9557 ** routine in vdbe.c, alerting the developer to the missed tag.
9577 /************** Continuing where we left off in sqliteInt.h ******************/
9578 /************** Include pager.h in the middle of sqliteInt.h *****************/
9583 ** The author disclaims copyright to this source code. In place of
9609 ** The type used to represent a page number. The first page in a file
9625 ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
9627 ** used in the journal to signify that the remainder of the journal file
9629 ** roll back. See comments for function writeMasterJournal() in pager.c
9637 ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
9640 #define PAGER_MEMORY 0x0002 /* In-memory database */
9657 #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
9792 /************** Continuing where we left off in sqliteInt.h ******************/
9793 /************** Include pcache.h in the middle of sqliteInt.h ****************/
9798 ** The author disclaims copyright to this source code. In place of
9816 ** Every page in the cache is controlled by an instance of the following
9838 PgHdr *pDirtyNext; /* Next element in list of dirty pages */
9839 PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
9877 /* Return the size in bytes of a PCache object. Used to preallocate
9899 /* Get a list of all dirty pages in the cache, sorted by page number */
9919 /* Return the total number of pages stored in the cache */
9923 /* Iterate through all dirty pages currently stored in the cache. This
9958 /************** Continuing where we left off in sqliteInt.h ******************/
9960 /************** Include os.h in the middle of sqliteInt.h ********************/
9965 ** The author disclaims copyright to this source code. In place of
9988 /************** Include os_setup.h in the middle of os.h *********************/
9993 ** The author disclaims copyright to this source code. In place of
10049 /************** Continuing where we left off in os.h *************************/
10067 ** alphanumeric characters, and no file extension. They are stored in the
10069 ** If sqlite is being embedded in another program, you may wish to change the
10075 ** Mcafee started using SQLite in their anti-virus product and it
10076 ** started putting files with the "sqlite" name in the c:/temp folder.
10125 ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
10134 ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
10140 ** SHARED_SIZE is the number of bytes available in the pool from which
10152 ** Locking in windows is manditory. For this reason, we cannot store
10153 ** actual data in the bytes used for locking. The pager never allocates
10154 ** the pages involved in locking therefore. SHARED_SIZE is selected so
10161 ** Changing the value of PENDING_BYTE results in a subtly incompatible
10234 /************** Continuing where we left off in sqliteInt.h ******************/
10235 /************** Include mutex.h in the middle of sqliteInt.h *****************/
10240 ** The author disclaims copyright to this source code. In place of
10251 ** to all source files. We break it out in an effort to keep the code
10309 /************** Continuing where we left off in sqliteInt.h ******************/
10315 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
10331 ** In shared cache mode, a single Schema object can be shared by multiple
10338 ** A thread must be holding a mutex on the corresponding Btree in order
10354 int cache_size; /* Number of pages to use in the cache */
10358 ** These macros can be used to test, set, or clear bits in the
10395 ** lookaside malloc subsystem. Each available memory allocation in
10401 ** be stored in lookaside because in shared cache mode the schema information
10407 u16 sz; /* Size of each buffer in bytes */
10418 LookasideSlot *pNext; /* Next buffer in the list of free buffers */
10440 int nDb; /* Number of backends currently in use */
10511 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
10518 int busyTimeout; /* Busy handler timeout, in msec */
10523 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
10527 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
10540 sqlite3 *pNextBlocked; /* Next in list of all blocked connections */
10570 #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */
10576 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
10599 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10629 #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */
10635 ** structure. A pointer to this structure is stored in the sqlite.aFunc
10675 ** are assert() statements in the code to verify this.
10682 #define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
10683 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10684 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10685 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10686 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
10706 ** are interpreted in the same way as the first 4 parameters to
10737 ** All current savepoints are stored in a linked list starting at
10738 ** sqlite3.pSavepoint. The first element in the list is the most recently
10760 ** instance of the following structure, stored in the sqlite3.aModule
10771 ** information about each column of an SQL table is held in an instance
10789 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
10811 #define SQLITE_SO_ASC 0 /* Sort in ascending order */
10812 #define SQLITE_SO_DESC 1 /* Sort in ascending order */
10852 #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
10857 ** An object of this type is created for each virtual table present in
10865 ** database connections, even when the rest of the in-memory database
10874 ** All VTable objects that correspond to a single table in a shared
10875 ** database schema are initially stored in a linked-list pointed to by
10880 ** sqlite3_vtab* handle in the compiled query.
10882 ** When an in-memory Table object is deleted (for example when the
10895 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
10905 VTable *pNext; /* Next in linked list (see above) */
10909 ** Each SQL table is represented in memory by an instance of the
10916 ** Table.nCol is the number of columns in this table. Table.aCol is a
10927 ** Table.tnum is the page number for the root BTree page of the table in the
10929 ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
10931 ** then the table is stored in a file that is automatically deleted
10932 ** when the VDBE cursor to the table is closed. In this case Table.tnum
10935 ** sub-query that appears instead of a real table name in the FROM clause
10943 FKey *pFKey; /* Linked list of all foreign keys in this table */
10948 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
10951 i16 nCol; /* Number of columns in this table */
10953 LogEst szTabRow; /* Estimated size of each table row in bytes */
10958 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
10960 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
10967 Trigger *pTrigger; /* List of triggers stored in pSchema */
11004 ** key. The "to" table is the table that is named in the REFERENCES clause.
11025 ** is held in Schema.fkeyHash with a hash key of Z.
11029 FKey *pNextFrom; /* Next FKey with the same in
11033 int nCol; /* Number of columns in this key */
11038 struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
11039 int iFrom; /* Index of column in pFrom */
11040 char *zCol; /* Name of column in zTo. If NULL use PRIMARY KEY */
11047 ** causes the operation in process to fail and for the current transaction
11048 ** to be rolled back. ABORT processing means the operation in process
11051 ** the operation in progress stops and returns an error code. But prior
11096 u16 nField; /* Number of key columns in the index */
11122 u16 nField; /* Number of entries in apMem[] */
11132 ** Each SQL index is represented in memory by an
11142 ** In the Table structure describing Ex1, nCol==3 because there are
11143 ** three columns in the table. In the Index structure describing
11146 ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
11147 ** The second column to be indexed (c1) has an index of 0 in
11170 LogEst szIdxRow; /* Estimated average row size in bytes */
11172 u16 nColumn; /* Number of columns stored in the index */
11175 unsigned bUnordered:1; /* Use this index for == or IN queries only */
11180 int nSample; /* Number of elements in aSample[] */
11182 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11201 ** Each sample stored in the sqlite_stat3 table is represented in memory
11207 int n; /* Size of record in bytes */
11223 unsigned int n; /* Number of characters in this token */
11231 ** pointer to this structure. The Expr.iColumn field is the index in
11242 u8 useSortingIdx; /* In direct mode, reference the sorting index rather
11246 int nSortingColumn; /* Number of columns in the sorting index */
11249 struct AggInfo_col { /* For each column used in source tables */
11253 int iSorterColumn; /* Column number in the sorting index */
11257 int nColumn; /* Number of used entries in aCol[] */
11267 int nFunc; /* Number of entries in aFunc[] */
11274 ** it uses less memory in the Expr object, which is a big memory user
11275 ** in systems with lots of prepared statements. And few applications
11287 ** Each node of an expression in the parse tree is an instance
11293 ** to represent the greater-than-or-equal-to operator in the expression
11306 ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)".
11308 ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the
11312 ** An expression of the form ID or ID.ID refers to a column in a table.
11316 ** expression is used as a result in an aggregate SELECT, then the
11317 ** value is also stored in the Expr.iAgg column in the aggregate so that
11321 ** character '?' in the original SQL) then the Expr.iTable holds the index
11336 ** Expr objects can use a lot of memory space in database schema. To
11339 ** two or more Expr objects will be stored in a single memory allocation,
11344 ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
11346 ** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately
11358 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no
11360 ** access them will result in a segfault or malfunction.
11366 ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */
11367 Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */
11370 /* If the EP_Reduced flag is set in the Expr.flags mask, then no
11372 ** access them will result in a segfault or malfunction.
11384 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
11394 ** The following are the meanings of bits in the Expr.flags field.
11396 #define EP_FromJoin 0x000001 /* Originated in ON or USING clause of a join */
11402 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
11406 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
11411 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11418 ** These macros can be used to test, set, or clear bits in the
11438 ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
11453 ** name. An expr/name combination can be used in several ways, such
11454 ** as the list of "expr AS ID" fields following a "SELECT" or in the
11455 ** list of "ID = expr" items in an UPDATE. A list of expressions can
11456 ** also be used as the argument to a function, in which case the a.zName
11460 ** the expression that is used in the generation of error messages and
11461 ** column labels. In this case, Expr.zSpan is typically the text of a
11462 ** column expression as it exists in a SELECT statement. However, if
11464 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
11469 struct ExprList_item { /* For each expression in the list */
11479 u16 iOrderByCol; /* For ORDER BY, column number in result set */
11482 int iConstExprReg; /* Register in which Expr value is cached */
11500 ** such as the list "a,b,c" in the following statements:
11507 ** column names after a table name in an INSERT statement. In the statement
11516 int idx; /* Index in some Table.aCol[] of a column named zName */
11525 ** tables in a join to 32 instead of 64. But it also reduces the size
11531 ** The number of bits in a Bitmask. "BMS" means "BitMask Size".
11536 ** A bit in a Bitmask
11543 ** Each table or subquery in the FROM clause is a separate element of
11548 ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
11549 ** such a table must be a simple name: ID. But in SQLite, the table can
11557 ** In the colUsed field, the high-order bit (bit 63) is set if the table
11561 int nSrc; /* Number of tables or subqueries in the FROM clause */
11562 u32 nAlloc; /* Number of entries allocated in a[] below */
11569 Select *pSelect; /* A SELECT statement used in place of a table name */
11577 unsigned isRecursive :1; /* True for recursive reference in WITH */
11579 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
11613 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11629 ** A NameContext defines a context in which to resolve table and column
11645 ** NameContext in the parent query. Thus the process of scanning the
11665 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11677 ** in the VDBE that record the limit and offset counters.
11680 ** These addresses must be stored so that we can go back and fill in
11682 ** the number of columns in P2 can be computed at the same time
11701 Select *pPrior; /* Prior select in a compound select statement */
11702 Select *pNext; /* Next select to the left in a compound */
11728 ** The results of a SELECT can be distributed in several ways, as defined
11732 ** SRT_Union Store results as a key in a temporary index
11737 ** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result
11748 ** opcode) for each row in the result set.
11752 ** in register pDest->iSDParm then abandon the rest
11756 ** row of result as the key in table pDest->iSDParm.
11758 ** results. Used to implement "IN (SELECT ...)".
11768 ** of the co-routine is stored in register pDest->iSDParm
11769 ** and the result row is stored in pDest->nDest registers
11772 ** SRT_Table Store results in temporary table pDest->iSDParm.
11778 ** SRT_DistFifo Store results in a temporary table pDest->iSDParm.
11783 ** SRT_Queue Store results in priority queue pDest->iSDParm (really
11787 ** SRT_DistQueue Store results in priority queue pDest->iSDParm only if
11791 #define SRT_Union 1 /* Store result as keys in an index */
11797 #define SRT_Queue 7 /* Store result in an queue */
11804 #define SRT_Mem 10 /* Store result in a memory cell */
11805 #define SRT_Set 11 /* Store results as keys in an index */
11828 ** information in case inserts are down within triggers. Triggers do not
11833 AutoincInfo *pNext; /* Next info block in a list of them all */
11835 int iDb; /* Index in sqlite3.aDb[] of database holding pTab */
11849 ** statement. All such objects are stored in the linked list headed at
11855 ** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable.
11866 TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */
11893 ** the parser and down into all the parser action routine in order to
11915 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
11922 int iRangeReg; /* First register in temporary register block */
11953 int nTableLock; /* Number of locks in aTableLock */
11974 ** in the recursive region.
11977 int nVar; /* Number of '?' variables seen in the SQL so far */
11978 int nzVar; /* Number of available slots in azVar[] */
12028 ** Bitfield flags for P5 value in various opcodes.
12034 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
12035 #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */
12043 * Each trigger present in the database schema is stored as an instance of
12046 * Pointers to instances of struct Trigger are stored in two ways.
12047 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
12076 ** In that cases, the constants below can be ORed together.
12085 * Instances of struct TriggerStep are stored in a singly linked list (linked
12128 TriggerStep *pNext; /* Next in the link-list */
12129 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */
12142 const char *zDb; /* Make sure all objects are contained in this database */
12149 ** do not necessarily know how big the string will be in the end.
12156 int nAlloc; /* Amount of space allocated in zText */
12202 int szPage; /* Size of each page in pPage[] */
12203 int nPage; /* Number of pages in pPage[] */
12209 int inProgress; /* True while initialization in progress */
12289 int nCte; /* Number of CTEs in the WITH clause */
12291 struct Cte { /* For each CTE in the WITH clause.... */
12335 ** needed by FTS3 when FTS3 is included in the amalgamation.
12771 ** be defined locally, but now we use the varint routines in the util.c
12786 ** and decode of the integers in a record header. It is faster for the common
13019 /* Declarations for functions in fkey.c. All of these are replaced by
13020 In this case no foreign
13022 ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
13056 ** The interface to the code in fault.c used for identifying "benign"
13080 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
13081 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
13148 ** sqlite3MemdebugHasType() returns true if any of the bits in its second
13152 ** sqlite3MemdebugNoType() returns true if none of the bits in its second
13189 ** The author disclaims copyright to this source code. In place of
13247 ** The following 256 byte lookup table is used to support SQLites built-in
13268 ** Bit 0x40 is set if the character non-alphanumeric and can be used in an
13274 ** locale of "C". They are implemented as macros in sqliteInt.h.
13396 ** 1-gibabyte boundary) in a compatible database. SQLite never uses
13402 ** a different position in the file. This allows code that has to
13408 ** 0x40000000 results in an incompatible database file format!
13409 ** Changing the pending byte during operating results in undefined
13419 ** from the comments following the "case OP_xxxx:" statements in
13429 ** The author disclaims copyright to this source code. In place of
13449 ** This array looks large, but in a typical installation actually uses
13456 ** for those options in which the value is meaningful. */
13815 /* Since ArraySize(azCompileOpt) is normally in single digits, a
13845 ** The author disclaims copyright to this source code. In place of
13857 /************** Include vdbeInt.h in the middle of status.c ******************/
13862 ** The author disclaims copyright to this source code. In place of
13899 /* Opaque type used by code in vdbesort.c */
13927 i16 nField; /* Number of fields in the header */
13932 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
13957 u32 payloadSize; /* Total number of bytes in the record */
13958 u32 szRow; /* Byte available in aRow */
13961 u32 aType[1]; /* Type values for all entries in the record */
13963 ** static element declared in the structure. nField total array slots for
13972 ** values stored in the Vdbe struct. When the sub-program is finished,
13978 ** cell in the parent (calling) frame. When the memory cell is deleted or
13981 ** list is deleted when the VM is reset in VdbeHalt(). The reason for doing
13986 ** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
13999 int nCursor; /* Number of entries in apCsr */
14000 int pc; /* Program Counter in parent (calling) frame */
14002 int nMem; /* Number of entries in aMem */
14003 int nOnceFlag; /* Number of entries in aOnceFlag */
14026 i64 i; /* Integer value used when MEM_Int is set in flags */
14027 int nZero; /* Used when bit MEM_Zero is set in flags */
14032 int n; /* Number of characters in string value, excluding '\0' */
14044 ** representations of the value stored in the Mem struct.
14047 ** No other flags may be set in this case.
14050 ** Usually this is encoded in the same unicode encoding as the main
14100 ** implementation calling sqlite3_set_auxdata() is stored in an instance
14102 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
14110 AuxData *pNext; /* Next element in list */
14118 ** There is a typedef for this structure in sqlite.h. So all routines,
14140 ** in describing recursive data structures.
14145 int nIndent; /* Number of elements in aIndent */
14179 int nOp; /* Number of instructions in the program */
14180 int nCursor; /* Number of slots in apCsr[] */
14187 ynVar nVar; /* Number of entries in aVar[] */
14188 ynVar nzVar; /* Number of entries in azVar[] */
14192 u16 nResColumn; /* Number of columns in one row of the result set */
14193 u8 errorAction; /* Recovery action to do in case of an error */
14225 int nFrame; /* Number of frames in pFrame list */
14347 /************** Continuing where we left off in status.c *********************/
14350 ** Variables in which to record status information.
14361 ** we have to locate the state vector at run-time. In the more common
14599 ** The author disclaims copyright to this source code. In place of
14610 ** There is only one exported symbol in this file - the function
14616 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
14633 ** in the following text:
14656 int tz; /* Timezone offset in minutes */
14667 ** come in groups of 5 as follows:
14669 ** N number of digits in the integer
14725 ** of change in p->tz and return 0. If a parser error occurs,
14910 ** In the first form, the +/-HH:MM is always optional. The fractional
15024 ** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
15025 ** library function localtime_r() is used to assist in the calculation of
15061 ** Compute the difference (in milliseconds) between localtime and UTC
15062 ** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
15066 ** is undefined in this case.
15143 ** is in a system call (i.e. localtime()), then an error message is written
15391 ** Return the julian day number of the date specified in the arguments
15704 ** functions. This should be the only routine in this file with
15738 ** The author disclaims copyright to this source code. In place of
16026 ** error in sqlite3_os_init() by the upper layers can be tested.
16130 ** The author disclaims copyright to this source code. In place of
16167 ** we have to locate the state vector at run-time. In the more common
16219 ** The author disclaims copyright to this source code. In place of
16254 ** This routine is the only routine in this file with external linkage.
16256 ** Populate the low-level memory allocation function pointers in
16257 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
16280 ** The author disclaims copyright to this source code. In place of
16294 ** routines specified in the sqlite3_mem_methods object. The content of
16298 ** default configuration is to use memory allocation routines in this
16551 ** This routine is the only routine in this file with external linkage.
16553 ** Populate the low-level memory allocation function pointers in
16554 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
16577 ** The author disclaims copyright to this source code. In place of
16589 ** information to each allocation in order to help detect and fix memory
16593 ** routines specified in the sqlite3_mem_methods object.
16652 ** when this module is combined with other in the amalgamation.
16668 ** The number of levels of backtrace to save in new allocations.
16674 ** Title text to insert in front of each block
16910 ** allocation into a new place in memory. In this way, if the
16933 ** Populate the low-level memory allocation function pointers in
16934 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
16963 ** Return TRUE if the mask of type in eType matches the type of the
16985 ** Return TRUE if the mask of type in eType matches no bits of the type of the
17107 ** The author disclaims copyright to this source code. In place of
17127 ** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
17140 ** Maximum size (in Mem3Blocks) of a "small" chunk.
17157 ** size of the allocation in blocks if the allocation is free.
17162 ** the previous chunk in blocks if the previous chunk is on the
17167 ** We often identify a chunk by its index in mem3.aPool[]. When
17169 ** the chunk. In this way, the first chunk has an index of 1.
17175 ** Pointers to the head of the list are stored in mem3.aiSmall[]
17186 u32 prevSize; /* Size of previous chunk in Mem3Block elements */
17187 u32 size4x; /* 4x the size of current chunk in Mem3Block elements */
17190 u32 next; /* Index in mem3.aPool[] of next free chunk */
17191 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
17200 ** when this module is combined with other in the amalgamation.
17205 ** (in Mem3Blocks) pointed to by aPool less 2.
17227 ** occur off of this chunk. szMaster is the size (in Mem3Blocks)
17229 ** The master chunk is not in either the aiHash[] or aiSmall[].
17321 ** will already be held (obtained by code in malloc.c) if
17403 ** or same size hash. In other words, *pRoot is an entry in either
17410 ** the current mem3.iMaster with the new larger chunk. In order for
17450 ** Return a block of memory of at least nBytes in size.
17471 ** Look for an entry of the correct size in either the small
17472 ** chunk table or in the large chunk hash table. This is
17575 ** Return the size of an outstanding allocation, in bytes. The
17660 /* Store a pointer to the memory block in global structure mem3. */
17765 ** This routine is the only routine in this file with external
17768 ** Populate the low-level memory allocation function pointers in
17769 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
17796 ** The author disclaims copyright to this source code. In place of
17816 ** in the build only if SQLITE_ENABLE_MEMSYS5 is defined.
17827 ** This algorithm is described in: J. M. Robson. "Bounds for Some Functions
17856 ** verified in memsys5Init().
17881 ** when this module is combined with other in the amalgamation.
17887 int szAtom; /* Smallest possible allocation in bytes */
17888 int nBlock; /* Number of szAtom sized blocks in zPool */
17978 ** will already be held (obtained by code in malloc.c) if
17989 ** Return the size of an outstanding allocation, in bytes. The
18004 ** Return a block of memory of at least nBytes in size.
18011 ** threads can be in this routine at the same time.
18040 ** two in order to create a new free block of size iLogsize.
18086 /* Set iBlock to the index of the block pointed to by pOld in
18245 int nMinLog; /* Log base 2 of minimum allocation size in bytes */
18262 /* boundaries on sqlite3GlobalConfig.mnReq are enforced in sqlite3_config() */
18349 ** This routine is the only routine in this file with external
18374 ** The author disclaims copyright to this source code. In place of
18529 ** The author disclaims copyright to this source code. In place of
18539 ** This implementation in this file does not provide any mutual
18540 ** exclusion and is thus suitable for use only in applications
18541 ** that use SQLite in a single thread. The routines defined
18596 ** In this implementation, error checking is provided for testing
18673 ** be entered multiple times by the same thread. In such cases the,
18737 ** The author disclaims copyright to this source code. In place of
18749 ** The code in this file is only used if we are compiling threadsafe
18792 ** deliver incorrect results. In particular, if pthread_equal() is
18845 ** not want to. But SQLite will only request a recursive mutex in
18848 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
18941 ** be entered multiple times by the same thread. In such cases the,
18972 /* Use the built-in recursive mutexes if they are available.
19018 /* Use the built-in recursive mutexes if they are available.
19096 ** The author disclaims copyright to this source code. In place of
19111 /************** Include os_common.h in the middle of mutex_w32.c *************/
19116 ** The author disclaims copyright to this source code. In place of
19136 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
19164 /************** Include hwtime.h in the middle of os_common.h ****************/
19169 ** The author disclaims copyright to this source code. In place of
19253 /************** Continuing where we left off in os_common.h ******************/
19319 /************** Continuing where we left off in mutex_w32.c ******************/
19324 /************** Include os_win.h in the middle of mutex_w32.c ****************/
19329 ** The author disclaims copyright to this source code. In place of
19395 /************** Continuing where we left off in mutex_w32.c ******************/
19399 ** The code in this file is only used if we are compiling multithreaded
19490 /* Another thread is (in the process of) initializing the static
19540 ** not want to. But SQLite will only request a recursive mutex in
19543 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
19621 ** be entered multiple times by the same thread. In such cases the,
19748 ** The author disclaims copyright to this source code. In place of
19764 ** cache database pages that are not currently in use.
19940 ** Return true if the heap is currently under memory pressure - in other
19965 res = (sqlite3_int64)n; /* Work around bug in Borland C. Ticket #3216 */
19978 res = (sqlite3_int64)mx; /* Work around bug in Borland C. Ticket #3216 */
20076 ** xScratchMalloc(). We verify this constraint in the single-threaded
20087 ** This routine is similar to alloca() in that it is not intended
20122 ** are outstanding at one time. (This is only checked in the
20123 ** single-threaded case since checking in the multi-threaded case
20136 ** is outstanding at one time. (This is only checked in the
20137 ** single-threaded case since checking in the multi-threaded case
20240 /* Trash all content in the buffer being freed */
20270 /* The 0x7ffff00 limit term is explained in comments on sqlite3Malloc() */
20332 ** the mallocFailed flag in the connection pointer.
20344 ** the mallocFailed flag in the connection pointer.
20350 ** This is an important assumption. There are many places in the
20357 ** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
20402 ** resize fails, set the mallocFailed flag in the connection object.
20439 ** and set the mallocFailed flag in the database connection.
20451 ** Make a copy of a string in memory obtained from sqliteMalloc(). These
20454 ** called via macros that record the current file and line number in the
20487 ** Store the string in memory obtained from sqliteMalloc() and make *pz
20532 ** The "printf" code that follows dates from the 1980's. It is in
20559 /* The rest are extensions, not normally found in printf() */
20561 #define etSQLESCAPE2 11 /* Strings with '\'' doubled and enclosed in '',
20578 ** Each builtin conversion character (ex: the 'd' in "%d") is described
20650 ** 16 (the number of significant digits in a 64-bit float) '0' is
20709 int c; /* Next character in the format string */
21044 /* The sign in front of the number */
21099 /* The converted number is in buf[] and zero terminated. Output it.
21100 ** Note that the number is in the usual order, not reversed as with
21205 /* The precision in %q and %Q means how many input characters to
21489 ** are not able to use a "," as the decimal point in place of "." as
21518 ** We house it in a separate routine from sqlite3_log() to avoid using
21584 ** The author disclaims copyright to this source code. In place of
21595 ** Random numbers are used by some of the database backends in order
21618 ** we have to locate the state vector at run-time. In the more common
21645 ** Nothing in this file or anywhere else in SQLite does any kind of
21712 ** The author disclaims copyright to this source code. In place of
21852 ** * Bytes in the range of 0x80 through 0xbf which occur as the first
21909 int len; /* Maximum length of output string in bytes */
21954 /* Set len to the maximum number of bytes required in the output buffer. */
21966 ** character. Two bytes are required in the output buffer for the
22043 ** UTF-16 string stored in *pMem. If one is present, it is removed and
22083 ** return the number of unicode characters in pZ up to (but not including)
22085 ** number of unicode characters in the first nByte of pZ (or up to
22106 ** Hence it is only available in debug builds.
22115 ** The translation is done in-place and aborted if the output
22136 ** Convert a UTF-16 string in the native encoding into a UTF-8 string.
22160 ** Return the number of bytes in the first nChar unicode characters
22161 ** in pZ. nChar must be non-negative.
22186 ** characters in each encoding are inverses of each other.
22242 ** The author disclaims copyright to this source code. In place of
22273 ** in places where it is difficult or expensive to do so purely by means
22310 ** -O option since it can result in incorrect output for programs
22337 ** Compute a string length that is limited to what can be stored in
22356 ** error string in the style of the printf functions: The following
22366 ** encoded in UTF-8.
22423 ** the quote characters. The conversion is done in-place. If the
22476 ** the contents of two buffers containing UTF-8 strings in a
22499 ** The string z[] is length bytes in length (bytes, not characters) and
22504 ** are in one of these formats:
22533 *pResult = 0.0; /* Default return value, in case of an error */
22624 /* In the IEEE 754 standard, zero is signed.
22639 ** and store in result. */
22691 ** in the values of the last digit if the only difference is in the
22730 ** length is the number of bytes in the string (bytes, not characters).
22783 /* Less than 19 digits, so we know that it fits in 64 bits */
22806 ** Transform a UTF-8 integer literal, in either decimal or hexadecimal,
22812 ** 0 Successful transformation. Fits in a 64-bit signed integer.
22838 ** If zNum represents an integer that will fit in 32-bits, then set
22990 ** inline in order to work around bugs in the RVT compiler.
23002 ** Return the number of bytes read. The value is stored in *v.
23077 /* we can skip these cause they were (effectively) done above in calc'ing s */
23098 /* we can skip this cause it was (effectively) done above in calc'ing s */
23165 ** Return the number of bytes read. The value is stored in *v.
23167 ** If the varint stored in p[0] is larger than can fit in a 32-bit unsigned
23218 /* A 32-bit varint is used to store size information in btrees.
23277 ** file. In that case we are not in any hurry. Use the (relatively
23377 ** misuse of the interface such as passing in db pointers that are
23421 ** the other 64-bit signed integer at *pA and store the result in *pA.
23422 ** Return 0 on success. Or if the operation would have resulted in an
23498 ** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
23499 ** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
23556 ** Convert an integer into a LogEst. In other words, compute an
23575 ** In other words, compute an approximation for 10*log2(x).
23610 ** The author disclaims copyright to this source code. In place of
23619 ** used in SQLite.
23679 HashElem *pHead; /* First element already in pEntry */
23744 /* This function (for internal use only) locates an element in an
23751 int nKey, /* Bytes in key (not counting zero terminator) */
23836 ** The key is not copied in this instance. If a malloc fails, then
23957 /* 58 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
24027 /* 128 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
24068 ** The author disclaims copyright to this source code. In place of
24080 ** There are actually several different VFS implementations in this file.
24081 ** The differences are in the way that file locking is done. The default
24089 ** in the correct division and should be clearly labeled.
24229 ** cannot be closed immediately. In these cases, instances of the following
24279 ** transaction counter in bytes 24-27 of database files are updated
24287 unsigned char inNormalWrite; /* True if in a normal write operation */
24292 /* In test mode, increase the size of this structure a bit so that
24293 ** it is larger than the struct CrashFile defined in test6.c.
24325 /************** Include os_common.h in the middle of os_unix.c ***************/
24330 ** The author disclaims copyright to this source code. In place of
24350 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
24378 /************** Include hwtime.h in the middle of os_common.h ****************/
24383 ** The author disclaims copyright to this source code. In place of
24467 /************** Continuing where we left off in os_common.h ******************/
24533 /************** Continuing where we left off in os_unix.c ********************/
24574 ** Different Unix systems declare open() in different ways. Same use
24586 ** On some systems, calls to fchown() will trigger a message in a security
24813 ** Do not accept any file descriptor less than this value, in order to avoid
24833 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
25002 /* At one point this code was not commented out. In theory, this branch
25023 * introspection, in which it actually means what it says */
25041 * introspection, in which it actually means what it says */
25045 /* invalid fd, unless during file system support introspection, in which
25075 ** unique file ID in VxWorks. Each instance of this structure contains
25085 struct vxworksFileId *pNext; /* Next in a list of them all */
25106 ** Changes are made in-place. Return the new name length.
25108 ** The original filename is in z[0..n-1]. Return the number of
25109 ** characters in the simplified name.
25229 ** to synchronize access for threads in separate processes, but not
25235 ** st_dev and st_ino fields of the stat structure that fstat() fills in)
25243 ** canonical filename and implemented in the previous division.)
25282 ** in thread B. But there is no way to know at compile-time which
25291 ** per database file in the same process and (2) database connections
25347 ** It is invoked after an error occurs in an OS function and errno has been
25414 ** We assume that close() almost always works, since it is only in a
25432 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
25487 unixFile *pFile, /* Unix file with file desc used in the key */
25514 ** around this problem (we consider it a bug in OS X, not SQLite)
25518 ** in the header of every SQLite database. In this way, if there
25637 /* Check if a thread in this process holds such a lock */
25675 ** in order to coordinate access between separate database connections
25676 ** within this process, but all of that is handled in memory and the
25684 ** to fcntl() fails. In this case, errno is set appropriately (by fcntl()).
25724 ** are inserted in between. The locking might fail on one of the later
25740 ** lock transitions in terms of the POSIX advisory shared and exclusive
25743 ** slightly in order to be compatible with windows systems simultaneously
25744 ** accessing the same database file, in case that is ever required.
25746 ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved
25897 /* We are trying for an exclusive lock but another thread in this
25982 ** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
26020 ** the lock in 2 blocks, so that part of the range will be covered by a
26082 /* In theory, the call to unixFileLock() cannot fail because another
26086 ** SQLITE_BUSY would confuse the upper layer (in practice it causes
26108 ** OS call only when all threads in this same process have released
26247 ** corruption if this locking mode is used in situations where multiple
26292 ** Dotfile locking works by creating a subdirectory in the same directory as
26299 ** The file suffix added to the data base filename in order to create the
26310 ** In dotfile locking, either a lock exists or it does not. So in this
26323 /* Check if a thread in this process holds such a lock */
26325 /* Either this connection or some other connection in the same process
26348 ** are inserted in between. The locking might fail on one of the later
26478 ** flock() locking is like dot-file locking in that the various
26480 ** a single exclusive lock. In other words, SHARED, RESERVED, and
26519 /* Check if a thread in this process holds such a lock */
26573 ** are inserted in between. The locking might fail on one of the later
26585 ** lock states in the sqlite3_file structure, but all locks SHARED or
26689 ** Semaphore locking is like dot-lock and flock in that it really only
26711 /* Check if a thread in this process holds such a lock */
26726 /* someone else has the lock when we are in NO_LOCK */
26750 ** are inserted in between. The locking might fail on one of the later
26762 ** lock states in the sqlite3_file structure, but all locks SHARED or
26914 OSTRACE(("AFPSETLOCK [%s] for %d%s in range %llx:%llx\n",
26960 /* Check if a thread in this process holds such a lock */
26971 /* if we succeeded in taking the reserved lock, unlock it to restore
27000 ** are inserted in between. The locking might fail on one of the later
27127 /* We are trying for an exclusive lock but another thread in this
27265 ** OS call only when all threads in this same process have released
27360 ** methods were defined in divisions above (one locking method per
27445 ** file), the bytes in the locking range should never be read or written. */
27495 int nBuf, /* Size of buffer pBuf in bytes */
27531 ** Seek to the offset in id->offset then read cnt bytes into pBuf.
27558 ** file), the bytes in the locking range should never be read or written. */
27762 ** The ability to override this routine was added in support of the
27902 ** Determine the current size of a file in bytes
27917 ** writes a single byte into that file in order to work around a bug
27918 ** in the OS-X msdos filesystem. In order to avoid problems with upper
27930 ** Handler for proxy-locking file-control verbs. Defined below in the
27938 ** file-control operation. Enlarge the database to nBytes in size
27964 ** the last byte in each block within the extended region. This
28111 ** Return the sector size in bytes of the underlying block device for
28116 ** if two files are created in the same file-system directory (i.e.
28212 ** file system does not always provide powersafe overwrites. (In other
28215 ** very rare. And asserting PSOW makes a large reduction in the amount
28238 ** This function should not be called directly by other code in this file.
28258 ** of this unixShmNode object. In other words, each wal-index is opened
28263 ** every open file that does not use shared memory (in other words, most
28280 ** in this structure.
28408 ** to use 64KB pages - in this case each mapping must cover at least two
28454 ** The file used to implement shared-memory is in the same directory
28460 ** Another approach to is to use files in /dev/shm or /dev/tmp or an
28461 ** some other tmpfs mount. But if a file in a different directory
28466 ** in database corruption. Nevertheless, this tmpfs file usage
28469 ** option results in an incompatible build of SQLite; builds of SQLite
28473 ** "unsupported" and may go away in a future SQLite release.
28476 ** file are currently open, in this process or in other processes, then
28481 ** that no other processes are able to read or write the database. In
28491 int nShmFilename; /* Size of the SHM filename in bytes */
28614 ** bytes in size.
28619 ** region has not been allocated (by any client, including one running in a
28688 ** last page in order to extend the file. But writing to all new
28762 ** different here than in posix. In xShmLock(), one can go from unlocked
28968 ** the three variables above are zeroed. In this case SQLite should
28979 i64 nOrig = pFd->mmapSizeActual; /* Size of pOrig region in bytes */
29039 ** in this case. */
29097 ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
29100 ** value of *pp is undefined in this case.
29202 ** to the METHOD object in the previous bullet.
29303 ** The proxy locking method is a "super-method" in the sense that it
29307 ** proxy locking is located much further down in the file. But we need
29474 ** exception is when opening the proxy "conch" file in builds that
29484 /* No locking occurs in temporary files */
29516 /* Cache zFilename in the locking context (AFP and dotlock override) for
29531 /* If an error occurred in findInodeInfo(), close the file descriptor
29533 ** in two scenarios:
29546 ** implicit assumption here is that if fstat() fails, things are in
29557 /* AFP locking uses the file path so it needs to be included in
29584 /* Dotfile locking uses the file path so it needs to be included in
29603 ** included in the semLockingContext
29644 ** Return the name of a directory in which to put temporary files.
29675 ** Create a temporary file name in zBuf. zBuf must be allocated
29719 ** Implementation in the proxy-lock division, but used by unixOpen()
29734 ** Refer to comments in the unixClose() function and the lengthy comment
29754 ** For this reason, if an error occurs in the stat() call here, it is
29790 ** In most cases cases, this routine sets *pMode to 0, which will become
29817 int nDb; /* Number of valid bytes in zDb */
29862 ** Previously, the SQLite OS layer used three functions in place of this
29884 sqlite3_file *pFile, /* The file descriptor to be filled in */
29919 ** a temporary file. Use this buffer to store the file name in.
30102 /* In theory, the close(fd) call is sub-optimal. If the file opened
30105 ** then the call to close() will cancel those locks. In practice,
30121 /* Use unixClose to clean up the resources added in fillInUnixFile
30236 ** is stored as a nul-terminated string in the buffer pointed to by
30240 ** (in this case, MAX_PATHNAME bytes). The full-path is written to
30246 int nOut, /* Size of output buffer in bytes */
30347 ** uninitialized space in zBuf - but valgrind errors tend to worry
30350 ** in the random seed.
30414 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
30418 ** Find the current time (in Universal Coordinated Time). Write into *piNow
30419 In
30421 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
30457 ** Find the current time (in Universal Coordinated Time). Write the
30474 ** in the core. So this routine is never called. For now, it is merely
30492 ** Proxy locking is a "uber-locking-method" in this sense: It uses the
30496 ** until late in the file (here) after all of the other I/O methods have
30502 ** The default locking schemes in SQLite use byte-range locks on the
30510 ** address in the shared range is taken for a SHARED lock, the entire
30518 ** slowdown in read performance on AFP because the AFP client disables
30550 ** host ID in it, the proxy path in the conch file will be used, otherwise
30579 ** proxy path against the values stored in the conch. The conch file is
30580 ** stored in the same directory as the database file and the file name
30645 ** and local proxy files in it
30703 ** Creates the lock file and any missing directories in lockPath
30739 ** Create a new VFS file descriptor (stored in memory obtained from
30740 ** sqlite3_malloc) and open the file named "path" in the file descriptor.
30834 /* Not always defined in the headers as it ought to be */
31015 ** lockPath means that the lockPath in the conch file will be used if the
31064 /* if the host id matches and the lock path already exists in the conch
31068 do { /* in case we need to try again for an :auto: named lock file */
31076 ** use the local lock file path that's already in there
31120 /* We are trying for an exclusive lock but another thread in this
31231 } while (1); /* in case we need to retry the :auto: lock file -
31260 ** Store the conch filename in memory obtained from sqlite3_malloc().
31272 char *conchPath; /* buffer in which to construct conch name */
31337 ** is a string buffer at least MAXPATHLEN+1 characters in size.
31345 /* afp style keeps a reference to the db path in the filePath field
31365 ** Takes an already filled in unix file and alters it so all file locking
31367 ** are preserved in the locking context so that they can be restored and
31554 ** are inserted in between. The locking might fail on one of the later
31665 ** should be the only routines in this file that are visible from other
31720 ** All default VFSes for unix are contained in the following array.
31756 /* Register all VFSes defined in the aVfs[] array */
31766 ** Some operating systems might need to do some cleanup in this routine,
31781 ** The author disclaims copyright to this source code. In place of
31797 /************** Include os_common.h in the middle of os_win.c ****************/
31802 ** The author disclaims copyright to this source code. In place of
31822 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
31850 /************** Include hwtime.h in the middle of os_common.h ****************/
31855 ** The author disclaims copyright to this source code. In place of
31939 /************** Continuing where we left off in os_common.h ******************/
32005 /************** Continuing where we left off in os_win.c *********************/
32013 ** available in Windows platforms based on the NT kernel.
32059 ** target system. GetVersionEx was first deprecated in Win8.1.
32070 ** This constant should already be defined (in the "WinDef.h" SDK file).
32077 ** Maximum pathname length (in chars) for Win32. This should normally be
32085 ** This constant should already be defined (in the "WinNT.h" SDK file).
32092 ** Maximum pathname length (in chars) for WinNT. This should normally be
32100 ** Maximum pathname length (in bytes) for Win32. The MAX_PATH macro is in
32109 ** Maximum pathname length (in bytes) for WinNT. This should normally be
32118 ** Maximum error message length (in chars) for WinRT.
32149 ** mode (e.g. these APIs are available in the Windows CE SDK; however, they
32150 ** are not present in the header file)?
32298 * data will almost certainly result in an immediate access violation.
32321 * The extra flags to use in calls to the Win32 heap APIs. This value may be
32392 ** In order to facilitate testing on a WinNT system, the test fixture
33136 ** largest committed free block in the heap, in bytes.
33208 ** The Win32 native heap cannot be modified because it may be in use.
33401 ** Return the size of an outstanding allocation, in bytes.
33507 ** Populate the low-level memory allocation function pointers in
33508 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
33679 ** the provided arguments. The type argument must be 1 in order to set the
33680 ** data directory or 2 in order to set the temporary directory. The zValue
33716 ** is zero if the error message fits in the buffer, or non-zero
33799 ** This routine is invoked after an error occurs in an OS function.
33853 ** non-zero if the error code is transient in nature and the operation
33860 ** may be used to include additional error codes in the set that should
33861 ** result in the failing I/O operation being retried by the caller. If
33968 ** Create the mutex and shared memory used for locking in the file
34024 /* If we succeeded in making the shared memory handle, map it. */
34070 /* The following blocks should probably assert in debug mode, but they
34071 are to cleanup in case any locks remained open */
34730 ** Determine the current size of a file in bytes
34876 ** are inserted in between. The locking might fail on one of the later
35008 /* Update the state of the lock has held in the file descriptor then
35235 ** Return the sector size in bytes of the underlying block device for
35240 ** if two files are created in the same file-system directory (i.e.
35297 ** point to a single instance of this object. In other words, each
35313 ** in this structure.
35331 winShmNode *pNext; /* Next in list of all winShmNode objects */
35474 ** file are currently open, in this process or in other processes, then
35482 int nName; /* Size of zName in bytes */
35751 ** bytes in size.
35756 ** region has not been allocated (by any client, including one running in a
36045 ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
36048 ** value of *pp is undefined in this case.
36189 ** operating system wants filenames in. Space to hold the result
36230 ** The pointer returned in pzBuf must be freed via sqlite3_free().
36427 ** name in the following format:
36431 ** If not, return SQLITE_ERROR. The number 17 is used here in order to
36507 void *zConverted; /* Filename in OS encoding */
36508 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
36512 ** a temporary file. Use this buffer to store the file name in.
36774 ** will open a journal file shortly after it is created in order to do
36984 ** a legal UNC name, a volume relative path, or an absolute path name in the
37013 ** bytes in size.
37018 int nFull, /* Size of output buffer in bytes */
37324 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
37328 ** Find the current time (in Universal Coordinated Time). Write into *piNow
37329 ** the current time and date as a Julian Day number times 86_400_000. In
37331 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
37346 /* 2^32 - to avoid use of LL and warnings in gcc */
37376 ** Find the current time (in Universal Coordinated Time). Write the
37402 ** is zero if the error message fits in
37405 ** in the output buffer.
37520 ** The author disclaims copyright to this source code. In place of
37536 ** or all of the pages in a database can get journalled. In those cases,
37549 ** Bitvec object is the number of pages in the database file at the
37554 /* Size of the Bitvec structure in bytes. */
37566 /* Size, in bits, of the bitmap element. */
37568 /* Number of elements in a bitmap array. */
37570 /* Number of bits in the bitmap array. */
37573 /* Number of u32 values in hash table. */
37575 /* Maximum number of entries in hash table before
37580 ** (an arbitrary prime)in the hash function provided
37711 /* in hash, if not, try to find a spot for it */
37717 /* we didn't find it in the hash. h points to the first */
37834 ** 5 N S X Set N bits from S increment X in array only, not in bitvec
37839 ** Opcode 5 is used to deliberately induce a fault in order to
37929 ** The author disclaims copyright to this source code. In place of
37944 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
37945 PgHdr *pSynced; /* Last synced page in dirty page list */
37948 int szPage; /* Size of every page in this cache */
37959 ** Some of the assert() macros in this code are too expensive to run
37976 ** non-zero. This is only used in debugging builds, as follows:
38058 ** being used for an in-memory database, this function is a no-op.
38078 ** built-in default page cache is used instead of the application defined
38092 ** Return the size in bytes of a PCache object.
38098 ** has already been allocated and is passed in as the p pointer.
38330 ** Make every page in the cache clean.
38415 ** Merge two lists of pages connected by pDirty and in pgno order.
38443 ** Sort the list of pages in accending order by pgno. Pages are
38447 ** Since there cannot be more than 2^31 distinct pages in a database,
38449 ** One extra bucket is added to catch overflow in case something
38471 /* To get here, there need to be 2^(N_SORT_BUCKET) elements in
38485 ** Return a list of all dirty pages in the cache, sorted by page number.
38510 ** Return the total number of pages in the cache.
38551 ** For all dirty pages currently in the cache, invoke the specified
38568 ** The author disclaims copyright to this source code. In place of
38595 ** This page cache implementation works in one of two modes:
38605 ** and is therefore often faster. Mode 2 requires a mutex in order to be
38622 ** open database file (including each in-memory database and each
38636 int szPage; /* Size of allocated pages in bytes */
38637 int szExtra; /* Size of extra space in bytes */
38647 unsigned int nRecyclable; /* Number of pages in the LRU list */
38648 unsigned int nPage; /* Total number of pages in apHash */
38649 unsigned int nHash; /* Number of slots in apHash[] */
38657 ** in memory.
38662 u8 isPinned; /* Page in use, not on the LRU list */
38663 PgHdr1 *pNext; /* Next in hash table chain */
38665 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
38666 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
38670 ** Free slots in the allocator used to divide up the buffer provided using
38705 ** All code in this file should access the global structure above via the
38752 ** such buffer exists or there is no space left in it, this function falls
38756 ** in pcache1 need to be protected via mutex.
38775 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
38929 ** allocating a new page cache entry in order to avoid stressing
39022 ** (PCache1.apHash structure) that it is currently stored in.
39108 ** Note that the static mutex allocated in xInit does
39129 ** PGroup. In other words, separateCache is true for mode (1) where no
39134 ** * Always use a unified cache in single-threaded applications
39232 ** For a non-purgeable cache (a cache used as the storage for an in-memory
39243 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
39246 ** 3. If createFlag is 1, and the page is not already in the cache, then
39479 ** Discard all unpinned pages in the cache with a page number equal to
39542 ** held by the pager system. Memory in use by any SQLite pager allocated
39601 ** The author disclaims copyright to this source code. In place of
39613 ** are inserted into the RowSet in an arbitrary order. Inserts
39618 ** elements of the RowSet in sorted order. Once this extraction
39631 ** TEST checks to see if an element is already in the RowSet. SMALLEST
39635 ** allocated in chunks so most INSERTs do no allocation. There is an
39641 ** in the batch number. In other words, if an INSERT occurs between
39652 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
39674 ** Each entry in a RowSet is an instance of the following object.
39677 ** objects. In that alternative use, pRight points to the next entry
39678 ** in the list, pLeft points to the tree, and v is unused. The
39688 ** RowSetEntry objects are allocated in large chunks (instances of the
39699 ** A RowSet in an instance of the following structure.
39701 ** A typedef of this structure if found in sqliteInt.h.
39773 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
39826 ** assumed to each already be in sorted order.
39956 ** as deep as it needs to be in order to contain the entire list.
39978 ** Take all the entries on p->pEntry and on the trees in p->pForest and
39981 ** This routine should only be called once in the life of a RowSet.
40088 /* Test to see if the iRowid value appears anywhere in the forest.
40111 ** The author disclaims copyright to this source code. In place of
40129 /************** Include wal.h in the middle of pager.c ***********************/
40134 ** The author disclaims copyright to this source code. In place of
40144 ** the implementation of each function in log.c for further details.
40194 ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
40217 ** position in the WAL */
40220 /* Move the write position of the WAL back to iFrame. Called in
40236 int *pnLog, /* OUT: Number of frames in WAL */
40237 int *pnCkpt /* OUT: Number of backfilled frames in WAL */
40241 ** number of frames in the WAL at the point of the last commit since
40260 ** stored in each frame (i.e. the db page-size when the WAL was created).
40269 /************** Continuing where we left off in pager.c **********************/
40292 ** (c) The page number is greater than the largest page that existed in
40305 ** both the content in the database when the rollback journal was written
40306 ** and the content in the database at the beginning of the current
40310 ** in length and are aligned on a page boundary.
40313 ** an integer multiple of the page size in length or are taken from the
40324 ** all queries. Note in particular the content of freelist leaf
40335 ** the beginning of the transaction. (In some VFSes, the xTruncate
40339 ** (9) Whenever the database file is modified, at least one bit in the range
40344 ** (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
40382 ** pager may be in any one of the seven states shown in the following
40420 ** The pager starts up in this state. Nothing is guaranteed in this
40430 ** In this state all the requirements for reading the database in
40432 ** was) in exclusive-locking mode, a user-level read transaction is
40433 ** open. The database size is known in this state.
40438 ** running in locking_mode=exclusive (including temp databases) remains in
40450 ** there is no hot-journal in the file-system.
40455 ** is first opened on the database. In WRITER_LOCKED state, all locks
40459 ** In rollback mode, a RESERVED or (if the transaction was opened with
40462 ** to in this state. If the transaction is committed or rolled back while
40463 ** in WRITER_LOCKED state, all that is required is to unlock the database
40466 ** IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
40471 ** * If the connection is open in rollback-mode, a RESERVED or greater
40473 ** * If the connection is open in WAL-mode, a WAL write transaction
40484 ** first modified by the upper layer. In rollback mode the journal file
40514 ** database file. In this state the transaction may be committed simply
40515 ** by finalizing the journal file. Once in WRITER_FINISHED state, it is
40529 ** SQLITE_IOERR_NOMEM) occurs at a point in the code that makes it
40530 ** difficult to be sure that the in-memory pager state (cache contents,
40533 ** Temporary pager files may enter the ERROR state, but in-memory pagers
40537 ** the contents of the page-cache may be left in an inconsistent state.
40549 ** page-cache and any other in-memory state at the same time. Everything
40557 ** 1. An error occurs while attempting a rollback. This happens in
40561 ** following a commit in function sqlite3PagerCommitPhaseTwo().
40564 ** database file in function pagerStress() in order to free up
40567 ** In other cases, the error is returned to the b-tree layer. The b-tree
40572 ** statement executed within a transaction. In this case, if the error
40574 ** automatically attempt a rollback, as it assumes that an error in a
40575 ** read-only statement cannot leave the pager in an internally inconsistent
40581 ** * The pager is not an in-memory pager.
40586 ** * A pager is never in WRITER_DBMOD or WRITER_FINISHED state if the
40587 ** connection is open in WAL mode. A WAL connection is always in one
40590 ** * Normally, a connection open in exclusive mode is never in PAGER_OPEN
40614 ** the operation was successful. In these circumstances pagerLockDb() and
40627 ** in the file-system that needs to be rolled back (as part of a OPEN->SHARED
40636 ** doesn't know it because of a previous error in xUnlock). If this happens
40638 ** transaction in another process, causing SQLite to read from the database
40642 ** database in the ERROR state, Pager.eLock is set to UNKNOWN_LOCK. It
40650 ** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in
40679 ** savepoint and statement transaction in the system. All such structures
40680 ** are stored in the Pager.aSavepoint[] array, which is allocated and
40692 i64 iOffset; /* Starting offset in main journal */
40694 Bitvec *pInSavepoint; /* Set of pages in this savepoint */
40695 Pgno nOrig; /* Original number of pages in file */
40696 Pgno iSubRec; /* Index of first record in sub-journal */
40723 ** For a temporary or in-memory database (neither of which require any
40729 ** In some (obscure) circumstances, this variable may also be set to
40746 ** This mechanism means that when running in exclusive mode, a connection
40757 ** the way in which the journal file is finalized after the transaction is
40758 ** committed or rolled back when running in "journal_mode=PERSIST" mode.
40763 ** running in "journal_mode=truncate" mode.
40779 ** to the file-system in order to free up memory).
40783 ** The SPILLFLAG_ROLLBACK case is done in a very obscure case that
40786 ** while it is being traversed by code in pager_playback(). The SPILLFLAG_OFF
40792 ** the database page-size in order to prevent a journal sync from happening
40793 ** in between the journalling of two pages on the same sector.
40798 ** is opened as an in-memory journal file. If false, then in-memory
40799 ** sub-journals are only used for in-memory pager files.
40806 ** Variable dbSize is set to the number of pages in the database file.
40807 ** It is valid in PAGER_READER and higher states (all states except for
40813 ** is not an integer multiple of the page-size, the value stored in
40815 ** Except, any file that is greater than 0 bytes in size is considered
40820 ** dbSize are modified in the cache, dbSize is updated accordingly.
40824 ** Variables dbOrigSize and dbFileSize are valid in states
40831 ** the file on disk in pages. It is set to a copy of dbSize when the
40841 ** dbFileSize is not used when rolling back a transaction. In this case
40843 ** a call to xFilesize() that is not strictly required). In either case,
40860 ** The Pager.errCode variable is only ever used in PAGER_ERROR state. It
40861 ** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
40876 u8 noLock; /* Do not lock (except in WAL mode) */
40882 ** routine opertion. Class members not in this block are either fixed
40894 u8 subjInMemory; /* True to use in-memory sub-journals */
40895 Pgno dbSize; /* Number of pages in the database */
40897 Pgno dbFileSize; /* Number of pages in the database file */
40903 Bitvec *pInJournal; /* One bit for each page in the database file */
40907 i64 journalOff; /* Current write offset in the journal file */
40911 int nSavepoint; /* Number of elements in aSavepoint[] */
40922 u16 nExtra; /* Add this many bytes to each in-memory page */
40926 int pageSize; /* Number of bytes in a page */
40963 ** testing purposes only. These variables do not exist in
40983 ** written, semi-random garbage data might appear in the journal
40986 ** sanity checking data is an attempt to discover the garbage in the
40992 ** This cksum is initialized to a 32-bit random value that appears in the
40995 ** data that was once in other files that have now been deleted. If the
41005 ** The size of the of each page record in the journal is given by
41017 ** The macro MEMDB is true if we are dealing with an in-memory database.
41079 ** This function runs many asserts to try to find inconsistencies in
41108 /* Check that MEMDB implies noSync. And an in-memory journal. Since
41109 ** this means an in-memory pager performs no IO at all, it cannot encounter
41111 ** a journal file. (although the in-memory journal implementation may
41113 ** is therefore not possible for an in-memory pager to enter the ERROR
41199 ** in ERROR state. Otherwise the pager should have already dropped
41213 ** Return a pointer to a human readable string in a static buffer
41216 ** to "print *pPager" in gdb:
41268 ** * The bit corresponding to the page-number is not set in
41286 ** Return true if the page is already in the journal file.
41294 ** that is read in *pRes. Return SQLITE_OK if everything worked, or an
41309 ** Write a 32-bit integer into a string buffer in big-endian byte order.
41384 ** an error to call this function if pPager is opened on an in-memory
41468 ** name in the journal is longer than nMaster bytes (including a
41470 ** were present in the journal.
41485 u32 len; /* Length in bytes of master journal name */
41486 i64 szJ; /* Total size in bytes of journal file pJrnl */
41524 ** following the value in pPager->journalOff, assuming a sector
41556 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
41557 ** zero the 28-byte header at the start of the journal file. In either case,
41558 ** if the pager is not in no-sync mode, sync the journal file immediately
41563 ** journal file in bytes is larger than this value, then truncate the
41611 ** - 4 bytes: Number of records in journal, or -1 no-sync mode is on.
41648 ** if in full-sync mode), the zero is overwritten with the true number
41658 ** * When the pager is in no-sync mode. Corruption can follow a
41659 ** power failure in this case anyway.
41693 /* In theory, it is only necessary to write the 28 bytes that the
41696 ** record is written to the following sector (leaving a gap in the file
41697 ** that will be implicitly filled in by the OS).
41705 ** The loop is required here in case the sector-size is larger than the
41707 ** bytes in size, more than one call to sqlite3OsWrite() may be required
41722 ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
41723 ** file. The current location in the journal file is given by
41729 ** database before the transaction began, in pages. Also, pPager->cksumInit
41731 ** in this case.
41740 i64 journalSize, /* Size of the open journal file in bytes */
41760 /* Read in the first 8 bytes of the journal header. If they do not match
41798 ** journal header to zero. In this case, assume that the Pager.pageSize
41806 ** are within range. To be 'in range', both values need to be a power
41814 /* If the either the page-size or sector-size in the journal-header is
41816 ** crashed before the header was synced. In this case stop reading
41846 ** thing written to a journal file. If the pager is in full-sync mode, the
41851 ** + N bytes: Master journal filename in utf-8.
41852 ** + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
41856 ** The master journal page checksum is the sum of the bytes in the master
41865 i64 iHdrOff; /* Offset of header in journal file */
41881 /* Calculate the length in bytes and the checksum of zMaster */
41886 /* If in full-sync mode, advance to the next disk sector before writing
41887 ** the master journal name. This is in case the previous page written to
41908 /* If the pager is in peristent-journal mode, then the physical
41915 ** Easiest thing to do in this scenario is to truncate the journal
41927 ** Find a page in the hash table given its page number. Return
41929 ** already in memory.
41942 ** Discard the entire contents of the in-memory page-cache.
41950 ** Free all structures in the Pager.aSavepoint[] array and set both
41952 ** if it is open and the pager is not in exclusive mode.
41969 ** Set the bit number pgno in the PagerSavepoint.pInSavepoint
41989 ** This function is a no-op if the pager is in exclusive mode and not
41990 ** in the ERROR state. Otherwise, it switches the pager to PAGER_OPEN
41993 ** If the pager is not in exclusive-access mode, the database file is
41998 ** If the pager is in ERROR state when this function is called, the
42000 ** the OPEN state. Regardless of whether the pager is in exclusive-mode
42001 ** or not, any journal file left in the file-system will be treated
42041 /* If the pager is in the ERROR state and the call to unlock the database
42053 ** code is cleared and the cache reset in the block below.
42062 ** it can safely move back to PAGER_OPEN state. This happens in both
42088 ** is stored in Pager.errCode. While the pager remains in the ERROR state,
42122 ** This routine is never called in PAGER_ERROR state. If it is called
42123 ** in PAGER_NONE or PAGER_SHARED state and the lock held is less
42132 ** depends on whether or not the pager is running in exclusive mode and
42137 ** in-memory journal.
42140 ** Journal file is truncated to zero bytes in size.
42144 ** the first journal header in the file, and hence the entire journal
42150 ** If the pager is running in exclusive mode, this method of finalizing
42152 ** DELETE and the pager is in exclusive mode, the method described under
42156 ** If running in non-exclusive rollback mode, the lock on the file is
42163 ** tries to unlock the database file if not in exclusive mode. If the
42214 ** a hot-journal was just rolled back. In this case the journal
42216 ** the database file, it will do so using an in-memory journal.
42248 /* Drop the WAL write-lock, if any. Also, if the connection was in
42255 /* This branch is taken when committing a transaction in rollback-journal
42288 ** call to pager_unlock() will discard all in-memory pages, unlock
42290 ** means that there is a hot-journal left in the file-system, the next
42324 ** Changing the formula used to compute this checksum results in an
42362 ** value is increased to the start of the next page in the journal.
42382 ** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
42403 PgHdr *pPg; /* An existing page in the cache */
42404 Pgno pgno; /* The page number of a page in journal */
42422 ** is in state OPEN and holds an EXCLUSIVE lock. Hot-journal rollback
42474 /* If the pager is in CACHEMOD state, then there must be a copy of this
42475 ** page in the pager cache. In this case just update the pager cache,
42476 ** not the database file. The page is left marked dirty in this case.
42478 ** An exception to the above rule: If the database is in no-sync mode
42480 ** not be in the pager cache. Later: if a malloc() or IO error occurs
42481 ** during a Movepage() call, then the page may not be in the cache
42482 ** either. So the condition described in the above paragraph is not
42485 ** If in WRITER_DBMOD, WRITER_FINISHED or OPEN state, then we update the
42487 ** not dirty. Since this code is only executed in PAGER_OPEN state for
42489 ** if the pager is in OPEN state.
42497 ** journal. Otherwise, a power loss might leave modified data in the
42498 ** database file without an entry in the rollback journal that can
42502 ** in the main journal either because the page is not in cache or else
42543 ** the database and the page is not in-memory, there is a potential
42549 ** obscure. When running in synchronous mode, this can only happen
42553 ** The solution is to add an in-memory page to the cache containing
42569 /* No page should ever be explicitly rolled back that is in use, except
42570 ** for page 1 which is held in use in order to keep the lock on the
42572 ** of an internal error resulting in an automatic call to
42582 ** transaction was first opened. In this case we can mark the page
42591 ** already in the journal file (recorded in Pager.pInJournal) and
42686 ** sufficient space (in zMasterPtr) to hold the names of master
42752 ** file in the file-system. This only happens when committing a transaction,
42755 ** If the main database file is not open, or the pager is not in either
42834 ** might change if a crash occurs while writing to a single byte in
42848 ** may not have been opened yet, in which case the OsSectorSize()
42858 ** the state it was in before we started making changes.
42864 ** in the journal. If this value is 0xffffffff, then compute the
42871 ** is this many bytes in size.
42880 ** Each entry in the journal is an instance of the 8th item.
42883 ** valid page entries in the journal. In most cases, you can compute the
42887 ** the extra entries had not yet made it safely to disk. In such a case,
42889 ** that reason, we always use the nRec value in the header.
42894 ** in this case. But for things like temporary table (which will be
42915 i64 szJ; /* Size of the journal file in bytes */
42916 u32 nRec; /* Number of Records in the journal */
42918 Pgno mxPg = 0; /* Size of the original file in pages */
42925 /* Figure out how many records are in the journal. Abort early if
42963 ** not enough bytes left in the journal file for a complete header, or
42976 ** working in no-sync mode. This means that the rest of the journal
42986 ** process and if this is the final header in the journal, then it means
42994 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
43033 ** not completely written and synced prior to a crash. In that
43034 ** case, the database should have never been written in the
43053 /* Following a rollback, the database file should be back in its original
43067 ** modification may just have been reverted. If this happens in exclusive
43070 ** problems for other processes at some point in the future. So, just
43071 ** in case this has happened, clear the changeCountDone flag now.
43149 ** zero or the size of the database in page. Bytes 32..35 and 35..39
43176 ** Update the value of the change-counter at offsets 24 and 92 in
43190 /* Also store the SQLite version number in bytes 96..99 and in
43204 ** If page iPg is present in the cache, and has no outstanding references,
43253 /* For all pages in the cache that are currently dirty or have already
43288 int nList; /* Number of pages in pList */
43296 /* Verify that the page list is in accending order */
43304 /* If a WAL transaction is being committed, there is no point in writing
43348 ** makes a snapshot of the database at the current point in time and preserves
43349 ** that snapshot for use by the reader in spite of concurrently changes by
43360 ** transaction in locking_mode=EXCLUSIVE. So call it now. If we
43361 ** are in locking_mode=NORMAL and EndRead() was previously called,
43379 ** in pages (assuming the page size currently stored in Pager.pageSize).
43382 ** in pages is stored in *pnPage. Otherwise, an error code (perhaps
43402 ** bytes in size is considered to contain at least one page.
43405 i64 n = 0; /* Size of db file in bytes */
43416 /* If the current number of pages in the file is greater than the
43435 ** in WAL mode. If the database is empty or if no *-wal file exists and
43488 ** performed in the order specified:
43504 ** corresponding bit is set in a bitvec structure (variable pDone in the
43506 ** rolled back the first time it is encountered in either journal.
43509 ** journal file. There is no need for a bitvec in this case.
43511 ** In either case, before playback commences the Pager.dbSize variable
43544 ** journal. The actual file might be larger than this in
43553 ** There might be records in the main journal that have a page number
43583 ** test is related to ticket #2565. See the discussion in the
43599 ** previously rolled back out of the main journal (and are hence in pDone)
43625 ** Change the maximum number of in-memory pages that are allowed.
43662 ** Adjust settings of the pager to those specified in the pgFlags parameter.
43664 ** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness
43676 ** in a state which would cause damage to the database
43681 ** of the journal header - being written in between the two
43692 ** an ordinary commit in NORMAL mode with WAL. FULL means that the WAL
43693 ** file is synced following each commit operation, in addition to the
43822 ** is passed in *pPageSize.
43824 ** If the pager is in the error state when this function is called, it
43835 ** * the database is either not an in-memory database or it is
43836 ** an in-memory database that currently consists of zero pages.
43843 ** In all other cases, SQLITE_OK is returned.
43846 ** conditions above is not true, the pager was in error state when this
43857 ** At one point this function returned an error if the pager was in
43932 ** errors in places where we do not care about errors.
43958 ** opened on a file less than N bytes in size, the output buffer is
43990 ** the pager. It returns the total number of pages in the database.
43992 ** However, if the file is between 1 and <page-size> bytes in size, then
44037 ** following is true for all dirty pages currently in the page-cache:
44040 ** current database image, in pages, OR
44051 ** content of the page. However, since this content is not present in either
44070 ** Truncate the in-memory database file image to nPage pages. This
44087 ** if one or more savepoints are open, present in the savepoint
44185 ** Free all PgHdr objects stored in the Pager.pMmapFreelist list.
44200 ** If a transaction was in progress when this routine is called, that
44204 ** result in a coredump.
44208 ** a hot journal may be left in the filesystem but no error is returned
44281 ** Sync the journal. In other words, make sure all the pages that have
44283 ** disk and can be restored in the event of a hot-journal rollback.
44289 ** * If the journal file is an in-memory journal file, no action need
44295 ** been written following it. If the pager is operating in full-sync
44301 ** Or, in pseudo-code:
44303 ** if( NOT <in-memory journal> ){
44312 ** page currently held in memory before returning SQLITE_OK. If an IO
44335 ** that wrote to this database was operating in persistent-journal
44337 ** than Pager.journalOff bytes. If the next thing in the journal
44373 /* Write the nRec value into the journal file header. If in
44379 ** SAFE_APPEND property. Because in this case it is not possible
44416 /* Unless the pager is in noSync mode, the journal file was just
44427 ** The argument is the first in a linked list of dirty pages connected
44429 ** in-memory pages in the list to the database file. The argument may
44430 ** be NULL, representing an empty list. In this case this function is
44443 ** the pages are written out to the database file in list order. Writing
44451 ** in Pager.dbFileVers[] is updated to match the new value stored in
44461 /* This function is only called for rollback pagers in WRITER_DBMOD state. */
44491 /* If there are dirty pages in the page cache with page numbers greater
44513 ** the value now stored in the database file. If writing this
44566 ** If successful, set the bit corresponding to pPg->pgno in the bitvecs
44571 ** SQLITE_NOMEM if a malloc fails while setting a bit in a savepoint
44615 ** (cast as a void*). The pager is always 'purgeable' (not an in-memory
44647 ** Spilling is also prohibited when in an error state since that could
44648 ** lead to database corruption. In the current implementaton it
44650 ** while in the error state, hence it is impossible for this routine to
44651 ** be called in the error state. Nevertheless, we include a NEVER()
44686 ** actually write data to the file in this case.
44735 ** in *ppPager. The pager should eventually be freed by passing it
44742 ** all information is held in cache. It is never written to disk.
44743 ** This can be used to implement an in-memory database.
44767 int nExtra, /* Extra bytes append to each in-memory page */
44775 int tempFile = 0; /* True for temp files (incl. in-memory files) */
44776 int memDb = 0; /* True if this is an in-memory file */
44780 int nPathname = 0; /* Number of bytes in zPathname */
44789 ** is the maximum space required for an in-memory journal file handle
44792 ** file in memory to implement the atomic-write optimization (see
44801 /* Set the output variable to NULL in case an error occurs. */
44816 /* Compute and store the full pathname in an allocated buffer pointed
44840 ** bytes in length. This means the database cannot be opened,
44854 ** file name. The layout in memory is as follows:
44888 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
44917 ** choose a default page size in case we have to create the
44959 ** In this case we accept the default page size and delay actually
44962 ** This branch is also run for an in-memory database. An in-memory
44964 ** disk and uses an in-memory rollback journal.
44971 pPager->eLock = EXCLUSIVE_LOCK; /* Pretend we are in EXCLUSIVE locking mode */
44985 /* If an error occurred in either of the blocks above, free the
45085 ** PAGER_SHARED state. It tests if there is a hot journal present in
45090 ** * The journal file exists in the file system, and
45092 ** * The database file itself is greater than 0 bytes in size, and
45097 ** database with the same name. In this case the journal file is
45103 ** does not exist, then the journal file is not really hot. In this
45140 ** in fact there is none. This results in a false-positive which will
45145 Pgno nPage; /* Number of pages in database file */
45149 /* If the database is zero pages in size, that means that either (1) the
45153 ** In either case, the journal file can be deleted. However, take care
45186 /* If we cannot open the rollback journal file in order to see if
45188 ** it might be due to the race condition described above and in
45214 ** 1) If the pager is currently in PAGER_OPEN state (no lock held
45223 ** 2) If the pager is running in exclusive-mode, and there are currently
45224 ** no outstanding references to any pages, and is in the error state,
45238 ** be OPEN or READER. READER is only possible if the pager is or was in
45281 ** this point in the code and fail to obtain its own EXCLUSIVE lock
45284 ** Unless the pager is in locking_mode=exclusive mode, the lock is
45294 ** in exclusive-access mode the file descriptor will be kept open
45296 ** is usually required to finalize the journal in journal_mode=persist
45300 ** other connection managed to get in and roll it back before
45302 ** may mean that the pager was in the error-state when this
45350 ** In order to get pager_unlock() to do this, set Pager.eState to
45352 ** to ERROR state in the state diagram at the top of this file,
45356 ** to be in ERROR state when there are zero outstanding page
45375 ** and there are already pages in the cache (from a previous
45384 ** a codec is in use.
45412 ** In this case there may exist a Pager.pMap mapping that appears
45421 /* If there is a WAL file in the file-system, open this database in WAL
45454 ** Except, in locking_mode=EXCLUSIVE when there is nothing to in
45465 ** Acquire a reference to page number pgno in pager pPager (a page
45469 ** If the requested page is already in the cache, it is returned.
45471 ** read from the database file. In some cases, the pcache module may
45477 ** already in the cache when this function is called, then the extra
45482 ** requested page is not already stored in the cache, then no
45483 ** actual disk read occurs. In this case the memory image of the
45487 ** of the page. This occurs in two scenarios:
45497 ** to pgno in Pager.pInJournal (bitvec of pages already written to the
45500 ** point in the future, using a call to sqlite3PagerWrite(), its contents
45503 ** The acquisition might fail for several reasons. In all cases,
45507 ** to find a page in the in-memory cache first. If the page is not already
45508 ** in memory, this routine goes to disk to read it in whereas Lookup()
45528 ** temporary or in-memory database. */
45544 /* If the pager is in the error state, return an error immediately.
45587 ** pager was already in the error-state when this function was called.
45596 /* In this case the pcache already contains an initialized copy of
45622 /* Failure to set the bits in the InJournal bit-vectors is benign.
45626 ** a bit in a bit vector.
45668 ** Acquire a page if it is already in the in-memory cache. Do
45670 ** or 0 if the page is not in cache.
45674 ** in the page if the page is not already in cache. This routine
45675 ** returns NULL if the page is not in cache or if a disk I/O error
45722 ** If the journal file is already open (as it may be in exclusive mode),
45741 /* If already in the error state, this function is a no-op. But on
45742 ** the other hand, this routine is never called if we are already in
45815 ** within this transaction will be opened as an in-memory file. This
45817 ** running in exclusive mode) or if the transaction does not require a
45819 ** sub-journal is implemented in-memory if pPager is an in-memory database,
45867 ** This is because in those states the code to roll back savepoint
45869 ** file as well as into the page cache. Which would be incorrect in
45891 ** one of the journals, the corresponding bit is set in the
45902 ** It is never called in the ERROR state.
45920 ** an error might occur and the pager would end up in WRITER_LOCKED state
45921 ** with pages marked as dirty in the cache.
45960 ** page in the block above, set the need-sync flag for the page.
45961 ** Otherwise, when the transaction is rolled back, the logic in
45963 ** in the database file. And if an IO error occurs while doing so,
46003 /* If the statement journal is open and the page is not in it,
46006 ** in that it omits the checksums and the header.
46029 ** fit on a single disk sector. In this case all co-resident pages
46047 Pgno nPageCount; /* Total number of pages in database file */
46128 ** Return TRUE if the page given in the argument was previously passed
46129 ** to sqlite3PagerWrite(). In other words, return TRUE if it is ok
46175 ** page data. In this case the file will be updated when the current
46179 ** with the SQLITE_ENABLE_ATOMIC_WRITE macro defined. In this case,
46193 ** atomic-write optimization is enabled in this build, then isDirect
46199 ** 'isDirect' below, as well as the block enclosed in the
46220 ** operating in direct-mode, make page 1 writable. When not in
46221 ** direct mode, page 1 is always held in cache and hence the PagerGet()
46232 /* If running in direct mode, write the contents of page 1 to the file. */
46261 ** Sync the database file to disk. This is a no-op for in-memory databases
46283 ** This function may only be called while a write-transaction is active in
46284 ** rollback. If the connection is in WAL mode, this call is a no-op.
46289 ** successful, or the connection is in WAL mode, SQLITE_OK is returned.
46330 ** journal file in this case.
46356 /* If this is an in-memory db, or no pages have been written to, or this
46358 ** backup in progress needs to be restarted.
46389 ** * Exactly one page has been modified and store in the journal file.
46393 ** counter in 'indirect-mode'. If the optimization is compiled in but
46396 ** pager_incr_changecounter() to update the change-counter in indirect
46401 ** in 'direct' mode. In this case the journal file will never be
46416 ** following call will modify the in-memory representation of page 1
46446 ** journal requires a sync here. However, in locking_mode=exclusive
46448 ** not the case. In this case it is likely enough that the redundant
46464 ** last page in the db image moved to the free-list. In this case the
46493 ** synced to disk. The journal file still exists in the file-system
46509 ** But if (due to a coding error elsewhere in the system) it does get
46520 ** this transaction, the pager is running in exclusive-mode and is
46527 ** header. Since the pager is in exclusive mode, there is no need
46550 ** If the pager is already in PAGER_ERROR state when this function is called,
46551 ** it returns Pager.errCode immediately. No work is performed in this case.
46553 ** Otherwise, in rollback mode, this function performs two functions:
46556 ** in-memory cache pages to the state they were in when the transaction
46560 ** rollback at any point in the future.
46565 ** In WAL mode, all cache-entries containing data modified within the
46574 /* PagerRollback() is a no-op if called in READER or OPEN state. If
46575 ** the pager is already in the ERROR state, the rollback is not
46617 ** if the database is (in theory) writable.
46695 ** Return true if this is an in-memory pager.
46723 ** if the allocation fails. Otherwise, zero the new portion in case a
46724 ** malloc failure occurs while populating it in the for(...) loop below.
46782 ** In any case, all savepoints with an index greater than iSavepoint
46801 ** operation. Store this value in nNew. Then free resources associated
46811 ** the sub-journal to zero bytes in size. */
46814 /* Only truncate if it is an in-memory sub-journal. */
46824 ** not yet been opened. In this case there have been no changes to
46840 ** Except, if the pager is in-memory only, then return an empty string if
46844 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
46845 ** participate in shared-cache.
46927 ** Move the page pPg to location pgno in the file.
46931 ** in cache. If the page previously located at pgno is not already
46932 ** in the rollback journal, it is not put there by by this routine.
46935 ** meta-data associated with pPg (i.e. data stored in the nExtra bytes
46945 ** is being committed. In this case, it is guaranteed that the database page
46963 /* In order to be able to rollback, an in-memory database must journal
46976 ** <journal page X, then modify it in memory>
47001 ** be written to, store pPg->pgno in local variable needSyncPgno.
47025 /* Do not discard pages from an in-memory database since we might
47037 /* For an in-memory database, make sure the original page continues
47038 ** to exist, in case the transaction needs to roll back. Use pPgOld
47050 ** Currently, no such page exists in the page-cache and the
47056 ** to a malloc() or IO failure), clear the bit in the pInJournal[]
47057 ** array. Otherwise, if the page is loaded and written again in
47059 ** it is synced into the journal file. This way, it may end up in
47132 ** * An in-memory database can only have its journal_mode set to _OFF
47163 /* Do allow the journalmode of an in-memory database to be set to
47180 ** mode except WAL, unless the pager is in locking_mode=exclusive mode,
47193 /* In this case we would like to delete the journal file. If it is
47199 ** while it is in use by some other client.
47240 ** Return TRUE if the pager is in a state where it is OK to change the
47267 ** in backup.c maintains the content of this variable. This module
47277 ** Unless this is an in-memory or temporary database, clear the pager cache.
47336 ** Call sqlite3WalOpen() to open the WAL handle. If the pager is in
47339 ** in. Otherwise, use the normal shared-memory.
47347 /* If the pager is already in exclusive-mode, the WAL module will use
47376 ** file (not a temp file or an in-memory database), and the WAL file
47380 ** not modified in either case.
47382 ** If the pager is open on a temp-file (or in-memory database), or if
47430 /* If the log file is not already open, but does exist in the file-system,
47467 ** the pager is in WAL mode and the WAL file currently contains one or more
47468 ** frames, return the size in bytes of the page images stored within the
47485 ** The author disclaims copyright to this source code. In place of
47494 ** This file contains the implementation of a write-ahead log (WAL) used in
47505 ** transferred back into the database file in an operation called a
47508 ** A single WAL file can be used multiple times. In other words, the
47515 ** The WAL header is 32 bytes in size and consists of the following eight
47533 ** 4: For commit records, the size of the database image in pages
47543 ** (1) The salt-1 and salt-2 values in the frame-header match
47544 ** salt values in the wal-header
47546 ** (2) The checksum values in the final 8 bytes of the frame-header
47552 ** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
47554 ** The checksum values are always stored in the frame header in a
47566 ** in reverse order (the largest fibonacci weight occurs on the first element
47577 ** value is randomized. This prevents old and new frames in the WAL from
47592 ** valid frame in the WAL. The reader uses this recorded "mxFrame" value
47596 ** of the database from a single point in time. This technique allows
47600 ** The reader algorithm in the previous paragraphs works correctly, but
47617 ** be) reconstructed from the original WAL file. In fact, the VFS is required
47622 ** as big endian, the wal-index can store multi-byte values in the native
47627 ** last frame in the wal before frame M for page P in the WAL, or return
47628 ** NULL if there are no frames for page P in the WAL prior to M.
47634 ** in the mxFrame field.
47640 ** first index block are the same size as all other index blocks in the
47647 ** for the first index block) 32-bit page numbers. The first entry in the
47649 ** first frame in the WAL file. The first entry in the second index block
47650 ** in the WAL file corresponds to the (HASHTABLE_NPAGE_ONE+1)th frame in
47653 ** The last index block in a wal-index usually contains less than the full
47667 ** HASHTABLE_NSLOT = 2*HASHTABLE_NPAGE, and there is one entry in the
47668 ** hash table for each page number in the mapping section, so the hash
47671 ** 1-based index of an entry in the mapping section of the same
47672 ** index block. Let K be the 1-based index of the largest entry in
47678 ** To look for page P in the hash table, first compute a hash iKey on
47691 ** no hash slot such that aHash[i]==p) then page P is not in the
47698 ** average, only two or three slots in each index block need to be
47699 ** examined in order to either find the last entry for page P, or to
47700 ** establish that no such entry exists in the block. Each index block
47703 ** comparisons (on average) suffice to either locate a frame in the
47704 ** WAL or to establish that the frame does not exist in the WAL. This
47707 ** Note that entries are added in order of increasing K. Hence, one
47712 ** the correct result. There may be entries in the hash table with
47714 ** slots in the hash table and so the first reader will get an answer as
47716 ** in the first place - which is what reader one wants. Meanwhile, the
47742 ** values in the wal-header are correct and (b) the version field is not
47774 ** The actual header in the wal-index consists of two copies of this
47779 ** added in 3.7.1 when support for 64K pages was added.
47786 u8 bigEndCksum; /* True if checksums in WAL are big-endian */
47787 u16 szPage; /* Database page size in bytes. 1==64K */
47788 u32 mxFrame; /* Index of last valid frame in the WAL */
47789 u32 nPage; /* Size of database in pages */
47790 u32 aFrameCksum[2]; /* Checksum of last frame in log */
47796 ** A copy of the following object occurs in the wal-index immediately
47800 ** nBackfill is the number of frames in the WAL that have been written
47808 ** There is one entry in aReadMark[] for each reader lock. If a reader
47809 ** holds read-lock K, then the value in aReadMark[K] is no greater than
47824 ** in use (that is, every aReadMark[j] for which there is a corresponding
47829 ** in the WAL has been backfilled into the database) then new readers
47837 ** (in other words, if there are no WAL_READ_LOCK(i) where i>0) then
47841 ** We assume that 32-bit loads are atomic and so no locks are needed in
47860 /* Size of header before each frame in wal */
47868 ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
47869 ** big-endian format in the first 4 bytes of a WAL file.
47879 ** Return the offset of frame iFrame in the write-ahead log file,
47899 volatile u32 **apWiData; /* Pointer to wal-index content in memory */
47903 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
47904 u8 writeLock; /* True if in a write transaction */
47912 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
47940 ** all frames in the WAL in database page order. Where two or more frames
47942 ** frame most recently written to the WAL (in other words, the frame with
47955 int nSegment; /* Number of entries in aSegment[] */
47957 int iNext; /* Next slot in aIndex[] not yet returned */
47958 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
47960 int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
47962 } aSegment[1]; /* One for every 32KB page in the wal-index */
47966 ** Define the parameters of the hash tables in the wal-index file. There
47967 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
47978 ** The block of page numbers associated with the first hash-table in a
48038 ** Return a pointer to the WalCkptInfo structure in the wal-index.
48046 ** Return a pointer to the WalIndexHdr structure in the wal-index.
48066 ** Generate or extend an 8 byte checksum based on the data in
48077 int nByte, /* Bytes of content in a[]. Must be a multiple of 8. */
48119 ** Write the header information in pWal->hdr into the wal-index.
48142 ** 4: For commit records, the size of the database image in pages
48172 ** Check to see if the frame with header in aFrame[] and content
48173 ** in aData[] is valid. If it is a valid frame, fill *piPage and
48188 /* A frame is only valid if the salt values in the frame-header
48189 ** match the salt values in the wal-header.
48204 ** and the frame-data matches the checksum in the last 8
48253 ** In locking_mode=EXCLUSIVE, all of these routines become no-ops.
48292 ** the hash to the next value in the event of a collision.
48309 ** in the wal-index file. Set *piZero to one less than the frame
48311 ** slot in the hash table is set to N, it refers to frame number
48312 ** (*piZero+N) in the log.
48367 ** Return the page number associated with frame iFrame in this WAL.
48394 int nByte; /* Number of bytes to zero in aPgno[] */
48423 /* Zero the entries in the aPgno array that correspond to frames with
48430 /* Verify that the every entry in the mapping region is still reachable
48448 ** Set an entry in the wal-index that will map database page number
48478 /* If the entry in aPgno[] is already set, then the previous writer
48479 ** must have exited unexpectedly in the middle of a transaction (after
48498 /* Verify that the number of entries in the hash table exactly equals
48499 ** the number of entries in the mapping region.
48503 int nEntry = 0; /* Number of entries in the hash table */
48508 /* Verify that the every entry in the mapping region is reachable
48547 /* Obtain an exclusive lock on all byte in the locking range not already
48575 int szFrame; /* Number of bytes in buffer aFrame[] */
48584 /* Read in the WAL header. */
48737 int bNoShm, /* True to run in heap-memory mode */
48748 /* In the amalgamation, the os_unix.c and os_win.c source files come before
48750 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
48808 ** Find the smallest page number out of all pages held in the WAL that
48814 in the WAL with a page
48858 ** of indices such that the aRight[] contains every index that appears in
48871 const u32 *aContent, /* Pages in wal - keys for the sort */
48872 ht_slot *aLeft, /* IN: Left hand input list */
48873 int nLeft, /* IN: Elements in array *paLeft */
48874 ht_slot **paRight, /* IN/OUT: Right hand input list */
48875 int *pnRight, /* IN/OUT: Elements in *paRight */
48878 int iLeft = 0; /* Current index in aLeft */
48879 int iRight = 0; /* Current index in aRight */
48880 int iOut = 0; /* Current index in output buffer */
48911 ** Sort the elements in list aList using aContent[] as the sort key.
48915 ** The aList[] entries are indices into aContent[]. The values in
48928 const u32 *aContent, /* Pages in wal */
48930 ht_slot *aList, /* IN/OUT: List to sort */
48931 int *pnList /* IN/OUT: Number of elements in aList[] */
48934 int nList; /* Number of elements in aList */
48939 int nMerge = 0; /* Number of elements in list aMerge */
48992 ** pages in the WAL in ascending order. The caller must hold the checkpoint
49005 u32 iLast; /* Last frame in log */
49012 ** it only runs if there is actually content in the log (mxFrame>0).
49047 int nEntry; /* Number of entries in this segment */
49100 ** Return the page-size in bytes used by the database.
49108 ** in response to an sqlite3_wal_checkpoint() request or the equivalent.
49114 ** All I/O barrier operations (a.k.a fsyncs) occur in this routine when
49115 ** SQLite is in WAL-mode in synchronous=NORMAL. That means that if
49121 ** in the WAL and can be recovered following a power-loss or hard reset.
49125 ** it safe to delete the WAL since the new content will persist in the
49134 ** checkpoint is running (in any other thread or process) at the same
49171 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
49173 ** overwrite database pages that are in use by active readers and thus
49282 ** If the WAL file is currently larger than nMax bytes in size, truncate
49315 ** the database. In this case checkpoint the database and unlink both
49335 ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
49340 ** completed and fsynced (rc==SQLITE_OK) and we are in persistent
49368 ** The wal-index is in shared memory. Another thread or process might
49370 ** read it, which might result in inconsistency. A dirty read is detected
49384 WalIndexHdr volatile *aHdr; /* Header in shared memory */
49390 ** same area of shared memory on a different CPU in a SMP,
49395 ** When reading, read [0] first then [1]. Writes are in the reverse order.
49432 ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
49537 ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1)
49552 ** update values of the aReadMark[] array in the header, but if it does
49557 volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */
49572 ** during the few nanoseconds that it is holding the lock. In that case,
49583 int nDelay = 1; /* Pause time in microseconds */
49595 /* If there is not a recovery running in another thread or process
49607 ** modules may return SQLITE_BUSY due to a race condition in the
49644 ** it finished. Leaving a corrupt image in the database file.
49698 ** value in the aReadMark[] array or the contents of the wal-index
49705 ** that occur later in the log than pWal->hdr.mxFrame may have been
49736 ** instant in time. The current thread will continue to use this snapshot.
49773 ** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
49785 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
49793 ** in this case as an optimization. Likewise, if pWal->readLock==0,
49806 ** This code might run concurrently to the code in walIndexAppend()
49816 ** For the reasons above, the if(...) condition featured in the inner
49875 ** (which is nOut bytes in size). Return SQLITE_OK if successful, or an
49881 int nOut, /* Size of buffer pOut in bytes */
49896 ** Return the size of the database in pages (or zero, if unknown).
49915 ** returns SQLITE_BUSY in that case and no write transaction is started.
49984 ** was in before the client began writing to the database.
49993 ** is passed as the second argument is (a) in the cache and
50016 ** point in the event of a savepoint rollback (via WalSavepointUndo()).
50028 ** the values in the aWalData[] array. aWalData must point to an array
50082 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
50087 ** In theory it would be Ok to update the cache of the header only
50141 ** In other words, if iSyncPoint is in between iOffset and iOffset+iAmt,
50178 u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-header in */
50198 int szPage, /* Database page-size in bytes */
50207 PgHdr *pLast = 0; /* Last frame in list */
50210 i64 iOffset; /* Next byte to write in WAL file */
50240 u8 aWalHdr[WAL_HDRSIZE]; /* Buffer to assemble wal-header in */
50267 ** an out-of-order write following a WAL restart could result in
50329 /* If this frame set completes the first transaction in the WAL and
50345 ** be in use by existing readers is being overwritten.
50387 ** callback. In this case this function runs a blocking checkpoint.
50397 int *pnLog, /* OUT: Number of frames in WAL */
50398 int *pnCkpt /* OUT: Number of backfilled frames in WAL */
50424 ** there is no point in blocking waiting for any readers. Assuming no
50479 ** number of frames in the WAL at the point of the last commit since
50498 ** on the pWal->readLock byte. If the WAL is already in locking_mode=NORMAL
50507 ** WAL is already in exclusive-locking mode - meaning that this
50523 ** happen if the connection is actually in exclusive mode (as no xShmLock
50524 ** locks are taken in this case). Nor should the pager attempt to
50538 /* Already in locking_mode=NORMAL */
50581 ** The author disclaims copyright to this source code. In place of
50591 ** This code really belongs in btree.c. But btree.c is getting too
50595 /************** Include btreeInt.h in the middle of btmutex.c ****************/
50600 ** The author disclaims copyright to this source code. In place of
50629 ** disk where M is the number of entries in the tree.
50631 ** In this implementation, a single file can hold one or more separate
50655 ** 16 2 Page size in bytes. (1 means 65536)
50665 ** 36 4 Number of freelist pages in the file
50687 ** space in a page that can be consumed by a single cell for standard
50698 ** except that it applies to leaf nodes in a LEAFDATA tree. The maximum
50700 ** not specified in the header.
50735 ** which is stored in the key size entry of the cell header rather than in
50740 ** offsets from the beginning of the page to the cell content in the cell
50741 ** content area. The cell pointers occur in sorted order. The system strives
50749 ** freeblocks. Each freeblock is at least 4 bytes in size. The byte offset
50750 ** to the first freeblock is given in the header. Freeblocks occur in
50751 ** increasing order. Because a freeblock must be at least 4 bytes in size,
50752 ** any group of 3 or fewer unused bytes in the cell content area cannot
50754 ** a fragment. The total number of bytes in all fragments is recorded.
50755 ** in the page header at offset 7.
50759 ** 2 Bytes in this freeblock
50761 ** Cells are of variable length. Cells are stored in the cell content area at
50762 ** the end of the page. Pointers to the cells are in the cell pointer array
50764 ** contiguous or in order, but cell pointers are contiguous and in order.
50772 ** allows a 64-bit integer to be encoded in 9 bytes.
50783 ** bytes of key and data in a btree cell.
50802 ** Freelist pages come in two subtypes: trunk pages and leaf pages. The
50803 ** file header points to the first in a linked list of trunk page. Each trunk
50821 ** plus 2 bytes for the index to the cell in the page header). Such
50832 ** SQLite database in order to identify the file as a real database.
50866 ** stored in MemPage.pBt->mutex.
50870 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
50879 u16 cellOffset; /* Index in aData of first cell pointer */
50895 ** The in-memory image of a disk page has the auxiliary information appended
50912 BtLock *pNext; /* Next in BtShared.pLock list */
50928 ** shared between multiple connections. In that case, each connection
50934 ** All fields in this structure are accessed under sqlite3.mutex.
50936 ** in the referenced BtShared that point back to this Btree since those
50969 ** A single database file can be in use at the same time by two
50976 ** Fields in this structure are accessed under the BtShared.mutex
50996 ** while in the 'pending-lock' state, no connection may start a new
51015 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
51016 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
51017 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
51018 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
51022 u32 nPage; /* Number of pages in the database */
51049 ** about a cell. The parseCellPtr() function fills in this structure
51054 i64 nKey; /* The key for INTKEY tables, or number of bytes in key */
51058 u16 nHeader; /* Size of the cell content header in bytes */
51079 ** The entry is identified by its MemPage and the index in
51086 ** Fields in this structure are accessed under the BtShared.mutex
51104 i16 iPage; /* Index of current page in apPage */
51105 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
51137 ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
51144 ** cursor. The error has left the cache in an inconsistent state.
51146 ** should return the error code stored in BtCursor.skip
51163 ** page number to look up in the pointer map.
51180 ** each child page in the database file. The parent page is the page that
51181 ** contains a pointer to the child. Every page in the database contains
51182 ** 0 or 1 parent pages. (In this context 'database page' refers
51188 ** position in the file to another as part of autovacuum. When a page
51189 ** is moved, the pointer in its parent must be updated to point to the
51193 ** used in this case.
51196 ** is not used in this case.
51198 ** PTRMAP_OVERFLOW1: The database page is the first page in a list of
51202 ** PTRMAP_OVERFLOW2: The database page is the second or later page in a list of
51204 ** page in the overflow page list.
51207 ** identifies the parent page in the btree.
51239 ** in order to keep track of some global state information.
51241 ** The aRef[] array is allocated so that there is 1 bit for each page in
51242 ** the database. As the integrity-check proceeds, for each page used in
51251 u8 *aPgRef; /* 1 bit per page in the db (see above) */
51252 Pgno nPage; /* Number of pages in the database */
51268 /************** Continuing where we left off in btmutex.c ********************/
51307 ** But we keep a reference count in Btree.wantToLock so the behavior
51310 ** To avoid deadlocks, multiple Btrees are locked in the same order
51322 ** connected by pNext and pPrev should be in sorted order by
51346 /* In most cases, we should be able to acquire the lock we
51358 ** the other BtShared locks that we used to hold in ascending
51432 ** Enter the mutexes in accending order by BtShared pointer address
51434 ** two or more btrees in common both try to lock all their btrees
51516 ** in single threaded applications that use shared cache. Except for
51517 ** these two routines, all mutex operations are no-ops in that case and
51518 ** are null #defines in btree.h.
51521 ** the ones below, are no-ops and are null #defines in btree.h.
51544 ** The author disclaims copyright to this source code. In place of
51607 ** in shared cache. This variable has file scope during normal builds,
51640 ** manipulate entries in the BtShared.pLock linked list used to store
51668 ** When writing to an index that resides in a sharable database, the
51810 /* The condition (pIter->eLock!=eLock) in the following if(...)
51816 ** may hold a WRITE_LOCK on any table in this file (since there can
51863 ** by a connection in read-uncommitted mode is on the sqlite_master
51864 ** table, and that lock is obtained in BtreeBeginTrans(). */
51947 ** than the writer must be about to drop to zero. In this case
51951 ** be zero already. So this next line is harmless in that case.
52013 ** table is about to be deleted. In this case invalidate all incrblob
52017 ** rowid iRow is being replaced or deleted. In this case invalidate
52065 ** may be lost. In the event of a rollback, it may not be possible
52070 ** set in the bitvec. Whenever a leaf page is extracted from the free-list,
52072 ** set in BtShared.pHasContent. The contents of the bitvec are cleared
52125 ** Save the current cursor position in the variables BtCursor.nKey
52142 ** stores the integer key in pCur->nKey. In this case this value is
52207 ** In this version of BtreeMoveto, pKey is a packed index record
52245 ** Restore the cursor to the position it was in (or as close to as possible)
52350 int offset; /* Offset in pointer map page */
52402 int offset; /* Offset of entry in pointer map */
52468 ** Parse a cell content block and fill in the CellInfo structure. There
52479 CellInfo *pInfo /* Fill in this structure */
52481 u16 n; /* Number bytes in cell content header */
52520 ** in between minLocal and maxLocal.
52522 ** Warning: changing the way overflow payload is distributed in any
52523 ** way will result in an incompatible file format.
52548 CellInfo *pInfo /* Fill in this structure */
52554 ** Compute the total number of bytes that a Cell needs in the cell
52643 ** big FreeBlk that occurs in between the header and cell
52685 /* These conditions have already been verified in btreeInitPage()
52730 ** allocation. This routine might need to defragment in order to bring
52733 ** allocation is being made in order to insert a new cell, so we will
52770 ** the request. The allocation is made from the first free slot in
52802 /* Check to make sure there is enough space in the gap to satisfy
52814 /* Allocate memory from the gap in between the cell pointer array
52832 ** Most of the effort here is involved in coalesing adjacent
52857 ** cell content area exceeds the value in the page header. If these
53047 /* Free blocks must be in ascending order. And the last byte of
53127 ** to fetch the content. Just fill in the content with zeros for now.
53128 ** If in the future we call sqlite3PagerWrite() on this page, that
53135 MemPage **ppPage, /* Return the page in this parameter */
53151 ** already in the pager cache return NULL. Initialize the MemPage.pBt and
53165 ** Return the size of the database file in pages. If there is any kind of
53245 ** or ptrmap page or a free page. In those cases, the following
53249 ** the call for every page that comes in for re-initing. */
53270 ** be exclusively in memory, or it might use a disk-based memory cache.
53274 in-memory database is created
53280 ** If the database is already opened in the same database connection
53281 ** and we are in shared cache mode, then the open will fail with an
53283 ** objects in the same database connection since doing so will lead
53304 /* Set the variable isMemdb to true for an in-memory database, or
53318 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
53400 /* In debug mode, we mark all persistent databases as sharable
53452 /* If the magic name ":memory:" will create an in-memory database, then
53456 ** regular file-name. In this case the auto-vacuum applies as per normal.
53503 ** The list is kept in ascending order by pBt address.
53607 ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
53686 ** Change the limit on the number of pages allowed in the cache.
53696 ** could be left in an inconsistent and unrecoverable state.
53725 ** Change the way data is synced to disk in order to increase or decrease
53747 ** Return TRUE if the given btree is set to safety level 1. In other
53821 ** This is useful in one special case in the backup API code where it is
53823 ** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
53938 int nPage; /* Number of pages in the database */
53939 int nPageFile = 0; /* Number of pages in the database file */
53940 int nPageHeader; /* Number of pages in the database according to hdr */
53982 ** in WAL mode. If the log is not already open, open it now. Then
53985 ** required as the version of page 1 currently in the page1 buffer
53986 ** may not be the latest version - there may be a newer one in the log
54085 ** in assert() expressions, so it is only compiled if NDEBUG is not
54107 ** If there are no outstanding cursors and we are not in the middle
54112 ** If there is a transaction in progress, this routine is a no-op.
54209 ** returned when there is already a read-lock in order to avoid a deadlock.
54227 /* If the btree is already in a write-transaction, or it
54228 ** is already in a read-transaction and a read-transaction
54280 ** file is not pBt->pageSize. In this case lockBtree() will update
54366 int nCell; /* Number of cells in page pPage */
54412 ** overflow page in the list.
54418 /* The pointer is always the first 4 bytes of the page in this case. */
54466 ** Move the open database page pDbPage to location iFreePage in the
54552 ** SQLITE_OK. If there is no work to do (and therefore no point in
54557 ** that the last page of the file currently in use is no longer in use.
54594 ** if bCommit is non-zero. In that case, the free-list will be
54660 ** nOrig pages in size containing nFree free pages. Return the expected
54661 ** size of the database in pages following an auto-vacuum operation.
54729 ** pages are in use.
54740 Pgno nFin; /* Number of pages in database after autovacuuming */
54874 ** Commit the transaction currently in progress.
54881 ** routine has to do is delete or truncate or zero the header in the
54889 ** transaction. In this case, the transaction has already been committed
54891 ** functions return code. So, even if an error occurs in the pager layer,
54976 ** Rollback the transaction in progress. All cursors will be
54979 ** in an error.
55074 ** SAVEPOINT_ROLLBACK, then iSavepoint may also be -1. In this case the
55114 ** are the conditions that must be met in order for writing to
55120 ** but which are not in the READ_UNCOMMITTED state may not have
55123 ** the read cursors in the other database connection.
55168 /* Now that no other errors can occur, finish filling in the BtCursor
55200 ** Return the size of a BtCursor object in bytes.
55254 ** Make sure the BtCursor* given in the argument has a valid
55256 ** btreeParseCell() to fill it in.
55258 ** BtCursor.info is a cache of the information in the current cell.
55261 ** 2007-06-25: There is a bug in some versions of MSVC that cause the
55280 /* Use a real function in MSVC to work around bugs in that compiler. */
55291 /* Use a macro in all other compilers so that the function is inlined */
55305 ** that is currently pointing to a row in a (non-empty) table.
55319 ** itself, not the number of bytes in the key.
55338 ** Set *pSize to the number of bytes of data in the entry the
55342 ** valid entry. In other words, the calling procedure must guarantee
55358 ** Given the page number of an overflow page in the database (parameter
55359 ** ovfl), this function finds the page number of the next page in the
55365 ** The page number of the next overflow page in the linked list is
55366 ** written to *pPgnoNext. If page ovfl is the last page in its linked
55372 ** on *ppPage to free the reference. In no reference was obtained (because
55390 /* Try to find the next page in the overflow list using the
55391 ** autovacuum pointer-map pages. Guess that the next page in
55488 ** the cursor is moved to a different row. Additionally, in auto-vacuum
55492 ** * A commit in auto_vacuum="full" mode,
55556 ** in the overflow chain. The page number of the first overflow page is
55557 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
55599 ** number for the next page in the overflow chain. The page
55688 ** in the table.
55777 ** in the common case where no overflow pages are used.
55828 ** cell in page pParent. Or, if iIdx is equal to the total number of
55829 ** cells in pParent, that page number iChild is the right-child of
55862 ** into more than one b-tree structure in a corrupt database. */
55940 ** in such a way that page pRoot is linked into a second b-tree table
55970 ** in ascending order.
55995 ** key in ascending order.
56017 /* Move the cursor to the first entry in the table. Return SQLITE_OK
56040 /* Move the cursor to the last entry in the table. Return SQLITE_OK
56054 ** to the last entry in the b-tree. */
56171 u8 *pCell; /* Pointer to current cell in pPage */
56247 /* The record flows over onto one or more overflow pages. In
56317 ** past the last entry in the table or sqlite3BtreePrev() moves past
56321 /* TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
56329 ** Advance the cursor to the next entry in the database. If
56331 ** was already pointing to the last entry in the database before
56382 ** only happen if the database is corrupt in such a way as to link the
56426 ** Step the cursor to the back to the previous entry in the database. If
56428 ** was already pointing to the first entry in the database before
56510 ** The new page is marked as dirty. (In other words, sqlite3PagerWrite()
56516 ** an error. *ppPage and *pPgno are undefined in the event of an error.
56520 ** locate a page close to the page number "nearby". This can be used in an
56521 ** attempt to keep related pages close to each other in the database file,
56522 ** which in turn can make database access faster.
56658 ** page in this case.
56769 ** that is required in the event of a rollback. In this case, do
56886 /* If the database supports auto-vacuum, write an entry in the pointer-map
56896 ** trunk page in the free-list is full, then this page will become a
56898 ** first trunk page in the current free-list. This block tests if it
56917 /* In this case there is room on the trunk page to insert the page
56922 ** coded. But due to a coding error in versions of SQLite prior to
56924 ** usableSize/4 - 8 entries will be reported as corrupt. In order
56927 ** for now. At some point in the future (once everyone has upgraded
56946 ** the page being freed as a leaf page of the first trunk in the free-list.
56948 ** first trunk in the free-list is full. Either way, the page being freed
56949 ** will become the new first trunk page in the free-list.
57025 ** caller is iterating through or using in some other way, this
57045 ** allocated and filled in as necessary. The calling procedure
57051 ** be constructed in this temporary area then copied into pPage->aData
57082 /* Fill in the header. */
57098 /* Fill in the payload */
57137 ** then the optimistic overflow chain processing in clearCell()
57210 ** "sz" must be the number of bytes in the cell.
57253 ** in pPage->apOvfl[] and make it point to the cell content (either
57254 ** in pTemp or the original pCell) and also record its index.
57255 ** Allocating a new entry in pPage->aCell[] implies that
57267 int sz, /* Bytes of content in pCell */
57272 int idx = 0; /* Where to write new cell content in data[] */
57274 int end; /* First byte past the last cell pointer in data[] */
57275 int ins; /* Index in data[] where new cell pointer is inserted */
57276 int cellOffset; /* Address of first cell pointer in data[] */
57292 ** the term after the || in the following assert(). */
57387 ** in a balancing operation. NN is the number of neighbors on either side
57388 ** of the page that participate in the balancing operation. NB is the
57393 ** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
57394 ** in exchange for a larger degradation in INSERT and UPDATE performance.
57398 #define NB (NN*2+1) /* Total pages involved in the balance */
57405 ** tree, in other words, when the new entry will become the largest
57406 ** entry in the tree.
57409 ** a new page to the right-hand side and put the one new entry in
57415 ** pPage is the leaf page which is the right-most page in the tree.
57421 ** byte page number followed by a variable length integer. In other
57423 ** least 13 bytes in size.
57479 ** record-length (a variable length integer at most 32-bits in size)
57552 ** parent page stored in the pointer map is page pTo. If pFrom contained
57556 ** If pFrom is currently carrying any overflow cells (entries in the
57610 ** page are used in the balancing, though both siblings might come from one
57614 ** participate in the balancing.
57617 ** one or two in an effort to keep pages nearly full but not over full.
57620 ** might not actually be stored in MemPage.aData[]. This can happen
57624 ** In the course of balancing the page and its siblings, cells may be
57631 ** in a corrupted state. So if this routine fails, the database should
57651 int iParentIdx, /* Index of "the page" in pParent */
57657 int nCell = 0; /* Number of cells in apCell[] */
57659 int nNew = 0; /* Number of pages in apNew[] */
57660 int nOld; /* Number of pages in apOld[] */
57662 int nxDiv; /* Next divider slot in pParent->aCell[] */
57666 int usableSpace; /* Bytes in pPage beyond the header */
57668 int subtotal; /* Subtotal of bytes in cells on one page */
57675 u8 *pRight; /* Location in parent of right-sibling pointer */
57676 u8 *apDiv[NB-1]; /* Divider cells in pParent */
57677 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
57680 u16 *szCell; /* Local size of all cells in apCell[] */
57682 Pgno pgno; /* Temp var to store a page number in */
57704 /* Find the sibling pages to balance. Also locate the cells in pParent
57712 ** overflow cells in the parent page, since if any existed they will
57763 ** But not if we are in secure-delete mode. In secure-delete mode,
57765 ** In this case, temporarily copy the cell into the aOvflSpace[]
57785 /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
57815 ** into aSpace1[]. In this way, all cells in apCell[] are without
57816 ** child pointers. If siblings are not leaves, then all cell in
57817 ** apCell[] include child pointers. Either way, all cells in apCell[]
57830 ** that the original pages since the original pages will be in the
57888 ** Store this number in "k". Also compute szNew[] which is the total
57890 ** in apCell[] of the cell that divides page i from page i+1.
57897 ** cntNew[i]: Index in apCell[] and szCell[] for the first cell to
57932 int r; /* Index of right-most cell in left sibling */
57958 ** in this procedure so there is no need to act upon it now.
58014 ** Put the new pages in accending order. This helps to
58015 ** keep entries in the disk file in order so that a scan
58017 ** in turn helps the operating system to deliver pages
58054 ** Evenly distribute the data in apCell[] across the new pages.
58086 ** then there is no divider cell in apCell[]. Instead, the divider
58105 ** Note that this can never happen in an SQLite data file, as all
58106 ** cells are at least 4 bytes. It only happens in b-trees used
58107 ** to evaluate "IN (SELECT ...)" and similar clauses.
58138 ** sub-algorithm in some documentation.
58167 ** page in any overflow chains used by new divider cells. These
58299 ** page and SQLITE_OK is returned. In this case the caller is required
58351 ** The page that pCur currently points to has just been modified in
58375 /* The root page of the b-tree is overfull. In this case call the
58411 ** happens, the overflow cell is stored in the aBalanceQuickSpace[]
58417 ** of the aBalanceQuickSpace[] might sneak in.
58424 /* In this case, call balance_nonroot() to redistribute cells
58431 ** are stored in the pSpace buffer allocated immediately below.
58532 ** In some cases, the call to btreeMoveto() below is a no-op. For
58536 ** data into the intkey B-Tree. In this case btreeMoveto() recognizes
58617 ** is advantageous to leave the cursor pointing to the last entry in
58619 ** entry in the table, and the next row inserted has an integer key
58673 ** the cursor to the largest entry in the tree that is smaller than
58706 ** is currently pointing to the largest entry in the sub-tree headed
58730 ** then the cursor still points to that page. In this case the first
58738 ** be either under or overfull. In this case run the balancing algorithm
58740 ** tree that we can be sure that any problem in the internal node has
58763 ** following values of flags are currently in use. Other values for
58791 ** to make room for the new tables root page. In case this page turns
58832 /* Save the positions of any open cursors. This is required in
58883 /* When the new root page was allocated, page 1 was made writable in
58971 ** Delete all information from a single table in the database. iTable is
58981 ** entries in the table.
59012 ** Erase all information in a table and add the root of the table to
59020 ** root page in the database file, then the last root page
59021 ** in the database file is moved into the slot formerly occupied by
59023 ** is added to the freelist instead of iTable. In this say, all
59026 ** page number that used to be the last root page in the file before
59028 ** The last root page is recorded in meta[3] and the value of
59040 ** database. This is because in auto-vacuum mode the backend may
59073 ** number in the database, put the root page on the free list.
59082 ** number in the database. So move the page that does into the
59106 /* Set the new 'max-root-page' value in the database header. This
59126 ** This really never should happen except in a corrupt
59148 ** is the number of free pages currently in the database. Meta[1]
59167 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
59209 ** number of entries in the b-tree and write the result to *pnEntry.
59216 i64 nEntry = 0; /* Value to return in *pnEntry */
59226 ** page in the B-Tree structure (not including overflow pages).
59229 int iIdx; /* Index of child node in parent */
59243 ** the next page in the tree that has not yet been visited. The
59245 ** of the page, or to the number of cells in the page if the next page
59248 ** If all pages in the tree have been visited, return SQLITE_OK to the
59321 ** Return non-zero if the bit in the IntegrityCk.aPgRef[] array that
59330 ** Set the bit in the IntegrityCk.aPgRef[] array that corresponds to page iPg.
59344 ** Also check that the page number is in bounds.
59362 ** Check that the entry in the pointer-map for page iChild maps to
59399 int iPage, /* Page number for first page in the list */
59400 int N, /* Expected number of pages in the list */
59448 ** page in this overflow list, check that the pointer-map entry for
59473 ** NO 2. Make sure cell keys are in order.
59515 /* Clear MemPage.isInit to make sure the corruption detection code in
59542 /* For intKey pages, check that the keys are in order.
59595 /* For intKey leaf pages, check that the min/max keys are in order
59654 "Corruption detected in cell %d on page %d",i,iPage);
59696 ** a table. nRoot is the number of entries in aRoot.
59701 ** Write the number of error seen in *pnErr. Except for some memory
59702 ** allocation errors, an error message held in memory obtained from
59709 int nRoot, /* Number of entries in aRoot[] */
59762 /* Make sure every page in the file is referenced
59812 ** an empty string if the database is in-memory or a TEMP database.
59982 ** required in case any of them are holding references to an xFetch
60021 ** "write version" (single byte at byte offset 19) fields in the database
60076 ** The author disclaims copyright to this source code. In place of
60094 u32 iDestSchema; /* Original schema cookie in destination */
60122 ** structure, in that order.
60125 ** invoked by the pager layer to report various state changes in
60139 ** Non-sharable Btrees (in-memory databases for example), do not have
60145 ** in connection handle pDb. If such a database cannot be found, return
60197 ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
60201 ** stored in database handle pDestDb.
60212 ** handle is not locked in this routine, but it is locked in
60216 ** database connection while a backup is in progress may cause
60307 /* Catch the case where the destination is an in-memory database and the
60316 ** and a codec is in use.
60418 int nSrcPage = -1; /* Size of source db in pages */
60421 /* If the source pager is currently in a write-transaction, return
60447 /* Do not allow backup if the destination database is in WAL mode
60457 ** source pager for the number of pages in the database.
60484 /* Update the schema version field in the destination database. This
60485 ** is to make sure that the schema-version really does change in
60507 /* Set nDestTruncate to the final number of pages in the destination
60512 ** round up. In this case the call to sqlite3OsTruncate() below will
60514 ** sqlite3PagerTruncateImage() here so that any pages in the
60539 ** pending-byte page in the source database may need to be
60557 ** database has been stored in the journal for pDestPager and the
60559 ** the database file in any way, knowing that if a power failure
60700 ** Return the total number of pages in the source database as of the most
60744 ** connection. In this case there is no way of knowing which of the
60796 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
60825 ** The author disclaims copyright to this source code. In place of
60835 ** stores a single value in the VDBE. Mem is an opaque structure visible
60857 ** (1) Memory in Mem.zMalloc and managed by the Mem object
60922 ** in pMem->z is discarded.
60965 ** Make the given Mem object MEM_Dyn. In other words, make it so
60966 ** that any TEXT or BLOB content is stored in memory obtained from
60967 ** malloc(). In this way, we know that the memory is safe to be
60995 ** blob stored in dynamically allocated space.
61050 ** keys are strings. In the former case a NULL pointer is returned the
61141 ** Release any memory held by the Mem. This may leave the Mem in an
61231 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
61236 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
61259 ** The second and third terms in the following conditional enforces
61323 ** Delete any previous value and set the value stored in *pMem to NULL.
61362 ** Delete any previous value and set the value stored in *pMem to val,
61373 ** Delete any previous value and set the value stored in *pMem to val,
61493 ** Transfer the contents of pFrom to pTo. Any existing value in pTo is
61522 ** is required to store the string, then value of pMem is unchanged. In
61528 int n, /* Bytes in string, or negative */
61562 ** also sets a flag in local variable "flags" to indicate the memory
61616 ** to read from the disk) then the pMem is left in an inconsistent state.
61623 Mem *pMem /* OUT: Return data in this Mem structure. */
61666 ** external API. It works in a similar way to sqlite3_value_text(),
61667 ** except the data returned is in the encoding specified by the second
61787 ** Extract a value from the supplied expression in the manner described
61794 ** in all cases.
61818 /* Handle negative integers in a single step. This is needed in the
61924 ** This is used to convert the value stored in the 'sample' column of the
61960 ** Register built-in functions used to help read ANALYZE data.
61981 ** A value is extracted in the following cases:
61983 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
62039 ** in the sqlite_stat4 table.
62045 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
62069 UnpackedRecord **ppRec, /* IN/OUT: Probe record */
62098 ** is undefined in this case.
62110 ** Extract the iCol-th column from the nRec-byte record in pRec. Write
62120 int nRec, /* Size of buffer pRec in bytes */
62125 int nHdr; /* Size of the header in the record */
62200 ** Return the number of bytes in the sqlite3_value object assuming
62220 ** The author disclaims copyright to this source code. In place of
62306 ** SQLITE_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain
62350 ** Add a new instruction to the list of instructions current in the
62527 ** in a Vdbe main program and each of the sub-programs (triggers) it may
62545 int nSub; /* Number of entries in apSub */
62594 ** Check if the program stored in the VM associated with pParse may
62609 ** part of an assert statement in the compiler. Similar to:
62638 ** true for this case to prevent the assert() in the callers frame
62750 ** Before returning, *pnOp is set to the number of entries in the returned
62752 ** the number of entries in the Vdbe.apArg[] array required to execute the
62995 ** the Vdbe. In these cases we can just copy the pointer.
63065 ** in a production build.
63149 ** The Synopsis: field in comments in the vdbe.c source file gets converted
63150 ** to an extra string that is appended to the sqlite3OpcodeName(). In the
63163 int nTemp /* Space available in zTemp[] */
63337 ** The prepared statements need to know in advance the complete set of
63339 ** is maintained in p->btreeMask. The p->lockMask value is the subset of
63355 ** that may be accessed by the VM passed as an argument. In doing so it also
63368 ** statement p will ever use. Let N be the number of bits in p->btreeMask
63487 ** allocated by the OP_Program opcode in sqlite3VdbeExec().
63502 ** Give a listing of the program in the virtual machine.
63510 ** are shown in a different format. p->explain==2 is used to implement
63548 ** nRow is the sum of the number of rows in the main program, plus
63549 ** the sum of the number of rows in all trigger subprograms encountered
63586 /* The output line number is small enough that we are still in the
63613 ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
63758 ** to allocate. If there is insufficient space in *ppFrom to satisfy the
63764 u8 **ppFrom, /* IN/OUT: Allocate from *ppFrom */
63781 ** Rewind the VDBE back to the beginning in preparation for
63846 int nArg; /* Number of arguments in subprograms */
63865 if( nOnce==0 ) nOnce = 1; /* Ensure at least one byte in p->aOnceFlag[] */
63871 ** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
63879 ** an array to marshal SQL function arguments in.
63894 /* Memory for registers, parameters, cursor, etc, is allocated in two
63898 ** pass will fill in the rest using a fresh allocation.
63974 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
63996 ** Also release any dynamic memory held by the VM in the Vdbe.aMem memory
63998 ** pointers to VdbeFrame objects, which may in turn contain pointers to
64039 ** variables in the aVar[] array.
64135 ** virtual module tables written in this transaction. This has to
64175 ** string, it means the main database is :memory: or a temp file. In
64192 ** but could happen. In this case abandon processing and return the error.
64258 /* Write the name of each database file in the transaction into the new
64299 /* Sync all the db files involved in the transaction. The same call
64300 ** sets the master journal pointer in each individual journal. If
64306 ** in case the master journal file name was written into the journal
64360 ** matches the number of vdbe's in the list sqlite3.pVdbe that are
64407 ** In this case (db->nStatement==0), and there is nothing to do.
64482 ** has made changes and is in autocommit mode, then commit those
64487 ** call this on a VM that is in the SQLITE_MAGIC_HALT state.
64508 ** Then the internal cache might have been left in an inconsistent
64547 ** pagerStress() in pager.c), the rollback is required to restore
64688 ** in p->rc. This routine sets that result back to SQLITE_OK.
64775 ** called), set the database error in this case as well.
64854 ** * the corresponding bit in argument mask is clear (where the first
64981 ** encapsulate the code that serializes values for storage in SQLite
64986 ** In an SQLite index record, the serial type is stored directly before
64987 ** the blob of data that it corresponds to. In a table record, all serial
65010 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
65015 ** Return the serial-type for the value stored in pMem.
65079 ** float in the wrong order. And that error has been propagated
65104 static u64 floatSwap(u64 in){
65111 u.r = in;
65123 ** Write the serialized data blob for the value stored in pMem into
65127 ** nBuf is the amount of space left in buf[]. The caller is responsible
65132 ** of bytes in the zero-filled tail is included in the return value only
65133 ** if those bytes were zeroed in buf[].
65180 ** and store the result in pMem. Return the number of bytes read.
65292 int szSpace, /* Size of pSpace[] in bytes */
65322 ** Given the nKey-byte encoding of a record in pKey[], populate the
65334 u32 idx; /* Offset in aKey[] to read from */
65362 ** This function compares two index or table record keys in the same way
65366 ** in assert() statements to ensure that the optimized code in
65375 u32 szHdr1; /* Number of bytes in header */
65390 ** But in fact, mem1.u.i will never actually be used uninitialized, and doing
65406 /* Read the serial types for the next element in each key. */
65413 ** sqlite3VdbeSerialTypeLen() in the common case.
65455 ** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
65463 /* The strings are already in the correct encoding. Call the
65634 ** fields that appear in both keys are equal, then pPKey2->default_rc is
65647 u32 szHdr1; /* Size of record header in bytes */
65648 u32 idx1; /* Offset of first type in header */
65656 ** two elements in the keys are equal. Fix the various stack variables so
65828 ** size-of-header varint at the start of (pKey1/nKey1) fits in a single
65914 ** fields. Return pPKey2->default_rc in this case. */
65930 ** at the start of (pKey1/nKey1) fits in a single byte.
65999 ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
66004 ** limit the size of the header to 64 bytes in cases where the first field
66036 ** Read the rowid (the last field in the record) and store it in *rowid.
66054 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
66062 /* Read in the complete content of the index entry */
66113 ** the key string in pUnpacked. Write into *pRes a number
66162 ** Set a flag in the vdbe to update the change counter when it is finalised
66220 ** in a better query plan.
66234 ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
66235 ** in memory obtained from sqlite3DbMalloc).
66251 ** The author disclaims copyright to this source code. In place of
66268 ** execution environment changes in a way that would alter the program
66353 ** Set all the parameters in the compiled SQL statement to NULL.
66467 int n, /* Bytes in string, or negative */
66633 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
66724 ** be one of the values in the first assert() below. Variable p->rc
66734 ** error has occurred, then return the error code in p->rc to the
66735 ** caller. Set the error code in the database handle to the same value.
66832 ** fails with an error message stating that the function is used in the
66847 "unable to use function %s in the requested context", zName);
66957 ** Return the number of columns in the result set for the statement pStmt.
67025 ** column value (i.e. a value returned by evaluating an SQL expression in the
67057 ** in the result set.
67261 ** Routines used to attach values to wildcards in a compiled SQL statement.
67264 ** Unbind the value bound to variable i in virtual machine p. This is the
67271 ** The error code stored in database p->db is overwritten with the return
67272 ** value in any case.
67298 /* If the bit corresponding to this variable in Vdbe.expmask is set, then
67302 ** parameter in the WHERE clause might influence the choice of query plan
67550 ** in the argument belongs. This is the same database handle that was
67552 ** the statement in the first place.
67567 ** Return true if the prepared statement is in need of being reset.
67607 ** The author disclaims copyright to this source code. In place of
67626 ** bytes in this text up to but excluding the first character in
67628 ** the total number of bytes in the text.
67650 ** This function returns a pointer to a nul-terminated string in memory
67665 ** ALGORITHM: Scan the input string looking for host parameters in any of
67670 ** parameter index is known, locate the value in p->aVar[]. Then render
67671 ** the value as a literal in place of the host parameter name.
67733 int nOut; /* Number of bytes of the string text to include in output */
67764 int nOut; /* Number of bytes of the blob to include in output */
67908 ** The author disclaims copyright to this source code. In place of
67916 ** The code in this file implements the function that runs the
67919 ** Various scripts scan this source file in order to generate HTML
67921 ** of the code in this file is, therefore, important. See other comments
67922 ** in this file for details. If in doubt, do not deviate from existing
67931 ** is changed while the copy is still in use, the string or blob might
67954 ** each instruction in the VDBE. When it reaches zero, the u1.isInterrupted
67955 ** field of the sqlite3 structure is set in order to simulate an interrupt.
67958 ** in an ordinary build.
68024 ** source code is in a single file (the amalgamation). Special values 1
68062 ** string that the register itself controls. In other words, it
68079 int nField, /* Number of fields in the table or index */
68089 ** purposes in a vdbe program. The different uses might require
68130 ** do so without loss of information. In other words, if the string
68372 /************** Include hwtime.h in the middle of vdbe.c *********************/
68377 ** The author disclaims copyright to this source code. In place of
68461 /************** Continuing where we left off in vdbe.c ***********************/
68469 ** the number of non-transaction savepoints currently in the
68603 ** an undefined integer. Opcodes will either fill in the integer
68655 ** separate instruction in the virtual machine. If we follow the usual
68659 ** big comment (similar to this one) will mark the point in the code where
68671 ** Other keywords in the comment that follows each case are used to
68678 ** comment lines are used in the generation of the opcode.html documentation
68684 ** Do not deviate from the formatting style currently in use.
68754 ** Jump to the next instruction after the address in register P1. After
68790 ** The instruction at the address in register P1 is a Yield.
68811 ** Swap the program counter with the value in register P1. This
68837 ** Check the value in register P3. If it is NULL then Halt using
68839 ** value in register P3 is not NULL, then this routine is a no-op.
68894 ** an IGNORE exception. In this case jump to the address specified
68919 zLogFmt = "abort at %d in [%s]: %s";
69018 ** The string value P4 of length P1 (bytes) is stored in register P2.
69034 ** NULL into register P3 and every register in between P2 and P3. If P3
69077 ** blob in register P2.
69092 ** If the parameter is named, then its name appears in P4.
69112 ** Move the P3 values in register P1..P1+P3-1 over into
69245 /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
69250 ** In case this is such a statement, close any statement transaction
69294 ** Add the text in register P1 onto the end of the text in
69295 ** register P2 and store the result in register P3.
69296 ** If either the P1 or P2 text are NULL then store NULL in P3.
69342 ** Add the value in register P1 to the value in register P2
69343 ** and store the result in register P3.
69350 ** Multiply the value in register P1 by the value in register P2
69351 ** and store the result in register P3.
69357 ** Subtract the value in register P1 from the value in register P2
69358 ** and store the result in register P3.
69364 ** Divide the value in register P1 by the value in register P2
69365 ** and store the result in register P3 (P3=P2/P1). If the value in
69373 ** register P1 and store the result in register P3.
69374 ** If the value in register P1 is zero the result is NULL.
69431 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
69470 ** be returned. This is used by the built-in min(), max() and nullif()
69479 ** publicly, only to user functions defined in func.c.
69494 ** successors. The result of the function is stored in register P3.
69536 ** the pointer to ctx.s so in case the user-function can use
69599 ** Take the bit-wise AND of the values in register P1 and P2 and
69600 ** store the result in register P3.
69606 ** Take the bit-wise OR of the values in register P1 and P2 and
69607 ** store the result in register P3.
69613 ** Shift the integer value in register P2 to the left by the
69614 ** number of bits specified by the integer in register P1.
69615 ** Store the result in register P3.
69621 ** Shift the integer value in register P2 to the right by the
69622 ** number of bits specified by the integer in register P1.
69623 ** Store the result in register P3.
69652 /* If shifting by a negative amount, shift in the other direction */
69681 ** Add the constant P2 to the value in register P1.
69696 ** Force the value in register P1 to be an integer. If the value
69697 ** in P1 is not an integer and cannot be converted into an integer
69742 ** Force the value in register P1 to be text.
69765 ** Force the value in register P1 to be a BLOB.
69788 ** Force the value in register P1 to be numeric (either an
69805 ** Force the value in register P1 to be an integer. If
69823 ** Force the value in register P1 to be a floating point number.
69843 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
69861 ** are text, then the appropriate collating function specified in
69869 ** store a boolean result (either 0, or 1, or NULL) in register P2.
69871 ** If the SQLITE_NULLEQ bit is set in P5, then NULL values are considered
69879 ** the operands in registers P1 and P3 are not equal. See the Lt opcode for
69882 ** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
69892 ** the operands in registers P1 and P3 are equal.
69895 ** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
70016 ** of integers in P4.
70019 ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should
70032 ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
70033 ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
70038 ** OPFLAG_PERMUTE bit is clear, then register are compared in sequential
70099 ** in the most recent OP_Compare instruction the P1 vector was less than
70116 ** Take the logical AND of the values in registers P1 and P2 and
70126 ** Take the logical OR of the values in register P1 and P2 and
70127 ** store the answer in register P3.
70170 ** Interpret the value in register P1 as a boolean value. Store the
70171 ** boolean complement in register P2. If the value in register P1 is
70172 ** NULL, then a NULL is stored in P2.
70190 ** a NULL then store a NULL in P2.
70207 ** In other words, this opcode causes all following opcodes up through P2
70227 ** Jump to P2 if the value in register P1 is true. The value
70229 ** in P1 is NULL then take the jump if and only if P3 is non-zero.
70233 ** Jump to P2 if the value in register P1 is False. The value
70235 ** in P1 is NULL then take the jump if and only if P3 is non-zero.
70261 ** Jump to P2 if the value in register P1 is NULL.
70275 ** Jump to P2 if the value in register P1 is not NULL.
70293 ** values in the record, extract a NULL.
70295 ** The value extracted is stored in register P3.
70312 i64 payloadSize64; /* Number of bytes in the record */
70326 u32 szField; /* Number of bytes in the content of a field */
70421 ** parsed and valid information is in aOffset[] and aType[].
70424 /* If there is more header available for parsing in the record, try
70441 /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
70471 /* If we have read more header data than was contained in the header,
70522 ** for text and blob and whatever is in
70538 /* If we dynamically allocated space to hold the data (in the
70569 ** memory cell in the range.
70592 ** use as a data record in a database table or as a key
70593 ** in an index. The OP_Column opcode can decode the record later.
70600 ** macros defined in sqliteInt.h.
70611 int nVarint; /* Number of bytes in a varint */
70615 int nField; /* Number of fields in the record */
70618 int i; /* Space used in zNewRecord[] header */
70619 int j; /* Space used in zNewRecord[] content */
70734 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
70743 ** Store the number of entries (an integer value) in the table or index
70744 ** opened by cursor P1 in register P2
70794 "SQL statements in progress");
70852 "cannot release savepoint - SQL statements in progress"
70906 ** constraint violations present in the database to the value stored
70959 "SQL statements in progress");
70968 "SQL statements in progress");
71022 ** connection is currently not in autocommit mode, or if there are other
71033 ** cookie in P3 differs from the schema cookie in the database header or
71034 ** if the schema generation counter in P4 differs from the current
71098 ** stored with the in-memory representation of the schema, do
71101 ** If virtual-tables are in use, this is not just an optimization.
71102 ** Often, v-tables store their data in other SQLite tables, which
71177 /* Record changes in the file format */
71193 ** P2 in a database file. The database file is determined by P3.
71216 ** value, it is set to the number of columns in the table.
71225 ** number of P2 and if it is this opcode becomes a no-op. In other words,
71245 ** value, it is set to the number of columns in the table, or to the
71249 ** in read/write mode. For a given table, there can be one or more read-only
71365 ** P2 is the number of columns in the ephemeral table.
71368 ** that defines the format of keys in the index.
71371 ** in btree.h. These flags control aspects of the operation of
71381 ** indices in joins.
71453 ** Synopsis: P3 columns in r[P2]
71457 ** register P2. In other words, cursor P1 becomes an alias for the
71458 ** MEM_Blob content contained in register P2.
71465 ** P3 is the number of fields in the records that will be stored by
71498 ** use the value in register P3 as the key. If cursor P1 refers
71499 ** to an SQL index, then P3 is the first in an array of P4 registers
71506 ** This opcode leaves the cursor configured to move in forward order,
71507 ** from the beginning toward the end. In other words, the cursor is
71516 ** use the value in register P3 as a key. If cursor P1 refers
71517 ** to an SQL index, then P3 is the first in an array of P4 registers
71524 ** This opcode leaves the cursor configured to move in forward order,
71525 ** from the beginning toward the end. In other words, the cursor is
71534 ** use the value in register P3 as a key. If cursor P1 refers
71535 ** to an SQL index, then P3 is the first in an array of P4 registers
71542 ** This opcode leaves the cursor configured to move in reverse order,
71543 ** from the end toward the beginning. In other words, the cursor is
71552 ** use the value in register P3 as a key. If cursor P1 refers
71553 ** to an SQL index, then P3 is the first in an array of P4 registers
71560 ** This opcode leaves the cursor configured to move in reverse order,
71561 ** from the end toward the beginning. In other words, the cursor is
71593 /* The input value in P3 might be of any type: integer, real, string,
71744 ** is a prefix of any entry in P1 then a jump is made to P2 and
71747 ** This operation leaves the cursor in a state where it can be
71748 ** advanced in the forward direction. The Next instruction will work,
71761 ** is not the prefix of any entry in P1 then a jump is made to P2. If P1
71766 ** This operation leaves the cursor in a state where it cannot be
71767 ** advanced in either direction. In other words, the Next and Prev
71781 ** record are not-NULL then a check is done to determine if any row in the
71789 ** This operation leaves the cursor in a state where it cannot be
71790 ** advanced in either direction. In other words, the Next and Prev
71889 ** This opcode leaves the cursor in a state where it cannot be advanced
71890 ** in either direction. In other words, the Next and Prev opcodes will
71950 ** The record number is not previously used as a key in the database
71954 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds
71978 ** thing) is obtained in a two-step algorithm.
71986 ** it already exists in the table. If it does not exist, we have
72056 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
72096 ** entry is overwritten. The data is the value MEM_Blob stored in register
72097 ** number P2. The key is stored in register P3. The key must
72135 ** integer value P3, not the value of the integer stored in register P3.
72209 ** record in the table. If it is left pointing at the next record, then
72274 ** record blob in register P3 against a prefix of the entry that
72278 ** If either P3 or the sorter contains a NULL in one of their significant
72325 ** it is found in the database file.
72336 ** it is found in the database file.
72367 ** a no-op and can never fail. But we leave it in place as a safety.
72398 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
72407 ** Store in register P2 an integer which is the key of the table entry that
72476 ** will refer to the last entry in the database table or index.
72481 ** This opcode leaves the cursor configured to move in reverse order,
72482 ** from the end toward the beginning. In other words, the cursor is
72536 ** will refer to the first entry in the database table or index.
72541 ** This opcode leaves the cursor configured to move in forward order,
72542 ** from the beginning toward the end. In other words, the cursor is
72579 ** Advance cursor P1 so that it points to the next key/data pair in its
72600 ** number P5-1 in the prepared statement is incremented.
72611 ** Back up cursor P1 so that it points to the previous key/data pair in its
72633 ** number P5-1 in the prepared statement is incremented.
72791 ** Write into register P2 an integer which is the last entry in the record at
72916 ** Delete an entire database table or index whose root page in the database
72919 ** The table being destroyed is in the main database file if P3==0. If
72920 ** P3==1 then the table to be clear is in the auxiliary database file
72924 ** might be moved into the newly deleted root page in order to keep all
72927 ** is stored in register P2. If no page
72929 ** the last one in the database) then a zero is stored in register P2.
72930 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
72980 ** in the database file is given by P1. But, unlike Destroy, do not
72983 ** The table being clear is in the main database file if P2==0. If
72984 ** P2==1 then the table to be clear is in the auxiliary database file
72988 ** intkey table (an SQL table, not an index). In this case the row change
72989 ** count is incremented by the number of rows in the table being cleared.
72990 ** If P3 is greater than zero, then the value stored in register P3 is
72991 ** also incremented by the number of rows in the table being cleared.
73041 ** Allocate a new table in the main database file if P1==0 or in the
73042 ** auxiliary database file if P1==1 or in an attached database if
73055 ** Allocate a new index in the main database file if P1==0 or in the
73056 ** auxiliary database file if P1==1 or in an attached database if
73156 ** Remove the internal (in-memory) data structures that describe
73157 ** the table named P4 in database P1. This is called after a table
73158 ** is dropped from disk (using the Destroy opcode) in order to keep
73169 ** Remove the internal (in-memory) data structures that describe
73170 ** the index named P4 in database P1. This is called after an index
73172 ** in order to keep the internal representation of the
73182 ** Remove the internal (in-memory) data structures that describe
73183 ** the trigger named P4 in database P1. This is called after a trigger
73184 ** is dropped from disk (using the Destroy opcode) in order to keep
73197 ** Do an analysis of the currently open database. Store in
73199 ** If no problems are found, store a NULL in register P1.
73203 ** In other words, the analysis stops as soon as reg(P1) errors are
73206 ** The root page numbers of all tables in the database are integer
73207 ** stored in reg(P1), reg(P1+1), reg(P1+2), .... There are P2 tables
73261 ** held in register P1.
73304 ** Synopsis: if r[P3] in rowset(P1) goto P2
73308 ** the value held in P3, jump to register P2. Otherwise, insert the
73309 ** integer in P3 into the RowSet and continue on to the
73336 /* If there is anything other than a rowset object in memory cell P1,
73368 ** cell in an array of values used as arguments to the sub-program. P2
73371 ** of a memory cell in this (the parent) VM that is used to allocate the
73383 Mem *pEnd; /* Last memory cell in new array */
73384 VdbeFrame *pFrame; /* New vdbe frame to execute in */
73398 ** disabled. In some cases a single trigger may generate more than one
73421 ** program stored in SubProgram.aOp. As well as these, one memory
73486 ** This opcode is only ever present in sub-programs called via the
73487 ** OP_Program instruction. Copy a value currently stored in a memory
73488 ** cell of the calling (parent) frame to cell P2 in the current frames
73492 ** The address of the cell in the parent frame is determined by adding
73555 ** P1 is a register in the root frame of this VM (the root frame is
73558 ** its current value and the value in register P2.
73603 ** Register P1 must contain an integer. Add literal P3 to the value in
73621 ** value in register P1. If the result is exactly 0, jump to P2.
73730 ** Checkpoint database P1. This is a no-op if P1 is not currently in
73733 ** SQLITE_BUSY or not, respectively. Write the number of pages in the
73735 ** in the WAL that have been checkpointed after the checkpoint
73806 ** in temporary storage or if the VFS does not support shared memory
73933 ** P1 is the index of the database in sqlite3.aDb[] of the database
73981 ** P4 is the name of a virtual table in database P1. Call the xCreate method
73993 ** P4 is the name of a virtual table in database P1. Call the xDestroy method
74009 ** table and stores that cursor in P1.
74054 ** by P1. The integer query plan parameter to xFilter is stored in register
74145 ** the current contents to sContext.s so in case the user-function
74160 ** dynamic allocation in sContext.s (a Mem struct) is released.
74177 ** Advance virtual table P1 to the next row in its result set and
74224 ** in register P1 is passed as the zName argument to the xRename method.
74257 ** invocation. The value in register (P3+P2-1) corresponds to the
74265 ** rowid for itself. The subsequent elements in the array are
74266 ** the values of columns in the new row.
74276 ** apply in the case of a constraint failure on an insert or update.
74330 ** Write the current number of pages in database P1 to memory cell P2.
74342 ** Try to set the maximum page count for database P1 to the value in P3.
74346 ** Store the maximum page count after the change in register P2.
74371 ** the UTF-8 string contained in P4 is emitted on the trace callback.
74423 ** the same as a no-op. This opcodesnever appears in a real VM program.
74538 ** The author disclaims copyright to this source code. In place of
74559 int nByte; /* Size of open blob, in bytes */
74560 int iOffset; /* Byte offset of blob in cursor data */
74575 ** contain a value of type TEXT or BLOB in the column nominated when the
74649 int iCol; /* Index of zColumn in row-record */
74822 ** we can invoke OP_Column to fill in the vdbe cursors type
74909 ** already been invalidated. Return SQLITE_ABORT in this case.
74979 ** already been invalidated. Return SQLITE_ABORT in this case.
75005 ** The author disclaims copyright to this source code. In place of
75013 ** This file contains code for the VdbeSorter object, used in concert with
75015 ** example, by CREATE INDEX statements on tables too large to fit in main
75028 ** As keys are added to the sorter, they are written to disk in a series
75030 ** the same as the cache-size allowed for temporary databases. In order
75031 ** to allow the caller to extract keys from the sorter in sorted order,
75034 ** merging any number of arrays in a single pass with no redundant comparison
75040 ** N elements in size, where N is the smallest power of 2 greater to or equal
75044 in size. The value of N is stored in
75076 ** be advanced to the next key in its segment. Say the next key is
75090 ** In other words, each time we advance to the next sorter element, log2(N)
75099 int nPMA; /* Number of PMAs stored in pTemp1 */
75100 int mnPmaSize; /* Minimum PMA size, in bytes */
75101 int mxPmaSize; /* Maximum PMA size, in bytes. 0==no limit */
75105 SorterRecord *pRecord; /* Head of in-memory record list */
75110 ** The following type is an iterator for a PMA. It caches the current key in
75117 int nKey; /* Number of bytes in key */
75122 int nBuffer; /* Size of read buffer in bytes */
75128 ** blocks. Doing all I/O in aligned page-sized blocks helps I/O to go
75132 int eFWErr; /* Non-zero if in an error state */
75134 int nBuffer; /* Size of write buffer in bytes */
75137 i64 iWriteOff; /* Offset of start of buffer in file */
75142 ** A structure to store a single record. All in-memory records are connected
75155 /* Maximum number of segments to merge in a single pass. */
75184 int nAvail; /* Bytes of data available in buffer */
75189 ** than p->nBuffer bytes remaining in the PMA, read all remaining data. */
75211 /* The requested data is available in the in-memory buffer. In this
75217 /* The requested data is not all available in the in-memory buffer.
75218 ** In this case, allocate space at p->aAlloc[] to copy the requested
75231 /* Copy as much data as is available in the buffer into the start of
75285 ** Advance iterator pIter to the next key in its PMA. Return SQLITE_OK if
75293 u64 nRec = 0; /* Size of record in bytes */
75311 ** Initialize iterator pIter to scan through the PMA stored in file pFile
75313 ** leaves the iterator pointing to the first key in the PMA (or EOF if the
75319 i64 iStart, /* Start offset in pFile */
75321 i64 *pnByte /* IN/OUT: Increment this value by PMA size */
75355 u64 nByte; /* Size of PMA in bytes */
75377 ** If the bOmitRowid argument is non-zero, assume both keys end in a rowid
75447 assert( pCsr->pSorter->pUnpacked!=0 ); /* allocated in vdbeSorterMerge() */
75717 ** Write the current contents of the in-memory linked-list to a PMA. Return
75723 ** in the PMA (not including the varint itself).
75725 ** * One or more records packed end-to-end in order of ascending keys.
75727 ** key). The varint is the number of bytes in the blob of data.
75800 ** * The total memory allocated for the in-memory list is greater
75803 ** * The total memory allocated for the in-memory list is greater
75829 i64 *pnByte /* Sum of bytes in all opened PMAs */
75834 i64 nByte = 0; /* Total bytes in all opened PMAs */
75856 ** for iterating through its contents in sorted order.
75871 ** from the in-memory list. */
75878 /* Write the current in-memory list to a PMA. */
75902 i64 nWrite; /* Number of bytes in new PMA */
75906 /* If there are SORTER_MAX_MERGE_COUNT or less PMAs in file pTemp1,
75965 ** Advance to the next element in the sorter.
75981 ** advanced (iPrev) and the one next to it in the array. */
75987 /* Compare pIter1 and pIter2. Store the result in variable iRes. */
76000 ** Then set pIter2 to the next iterator to compare to pIter1. In this
76001 ** case there is no cache of pIter2 in pSorter->pUnpacked, so set
76039 int *pnKey /* OUT: Size of current key in bytes */
76073 ** Compare the key in memory cell pVal with the key that the sorter cursor
76079 ** key in pVal is smaller than, equal to or larger than the current sorter
76101 ** The author disclaims copyright to this source code. In place of
76116 ** the caller specifies a buffer size for an in-memory buffer to
76120 ** 1) The in-memory representation grows too large for the allocated
76133 int nBuf; /* Size of zBuf[] in bytes */
76160 ** returning. This way, SQLite uses the in-memory journal data to
76260 ** Query the size of the file in bytes.
76359 ** The author disclaims copyright to this source code. In place of
76368 ** This file contains code use to implement an in-memory rollback journal.
76369 ** The in-memory rollback journal is used to journal transactions for
76378 /* Space to hold the rollback journal is allocated in increments of
76383 ** a power-of-two allocation. This mimimizes wasted space in power-of-two
76392 FileChunk *pNext; /* Next chunk in the journal */
76411 FileChunk *pFirst; /* Head of in-memory chunk-list */
76417 ** Read data from the in-memory journal file. This is the implementation
76475 /* An in-memory journal file should only ever be appended to. Random
76542 ** Syncing an in-memory journal is a no-op. And, in fact, this routine
76543 ** is never called in a working implementation. This implementation
76544 ** exists purely as a contingency, in case some malfunction in some other
76553 ** Query the size of the file in bytes.
76598 ** an in-memory journal
76616 ** The author disclaims copyright to this source code. In place of
76633 ** of the expression, while decending. (In other words, the callback
76670 ** Call sqlite3WalkExpr() for every expression in list p or until
76702 ** Walk the parse trees associated with all subqueries in the
76705 ** and on any subqueries further down in the tree. Return
76725 ** Call sqlite3WalkExpr() for every expression in Select statement p.
76726 ** Invoke sqlite3WalkSelect() for subqueries in the FROM clause and
76772 ** The author disclaims copyright to this source code. In place of
76813 ** result set in pEList.
76826 ** that in a GROUP BY clause, the expression is evaluated twice. Hence:
76834 ** The result of random()%5 in the GROUP BY clause is probably different
76835 ** from the result in the result-set. On the other hand Standard SQL does
76837 ** So this should never come up in well-formed queries.
76857 int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
76907 ** Return TRUE if the name zCol occurs anywhere in the USING clause.
76924 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
76954 ** that name in the set of source tables in pSrcList and make the pExpr
76958 ** pExpr->iDb Set the index in db->aDb[] of the database X
76977 ** in pParse and return WRC_Abort. Return WRC_Prune on success.
76994 NameContext *pTopNC = pNC; /* First namecontext in the list */
77001 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
77009 /* Translate the schema name in zDb into a pointer to the corresponding
77011 ** resulting in an appropriate error message toward the end of this routine
77072 ** is for the right-hand table of a NATURAL JOIN or is in a
77162 ** we are resolving names in the WHERE clause of the following command:
77166 ** In cases like this, replace pExpr with a copy of the expression that
77167 ** forms the result set entry ("a+b" in the example) and return immediately.
77168 ** Note that the expression in the result set should have already been
77171 ** The ability to use an output result-set column in the WHERE, GROUP BY,
77172 ** or HAVING clauses, or as part of a larger expression in the ORDRE BY
77212 ** If X and Y are NULL (in other words if only the column name Z is
77213 ** supplied) and the value of Z is enclosed in double-quotes, then
77214 ** Z is a string literal if it doesn't match any column names. In that
77219 ** fields are not changed in any context.
77245 /* If a column from a table in pSrcList is referenced, then record
77246 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
77248 ** column number is greater than the number of bits in the bitmask
77290 ** from datasource iSrc in SrcList pSrc.
77321 sqlite3ErrorMsg(pParse, "%s prohibited in partial index WHERE clauses",
77336 sqlite3ErrorMsg(pParse,"%s prohibited in CHECK constraints", zMsg);
77361 ** node in the expression tree. Return 0 to continue the search down
77392 ** column in the FROM clause. This is used by the LIMIT and ORDER BY
77448 int nId; /* Number of characters in function name */
77564 ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
77568 ** elements in pEList, corresponding to the matching entry. If there is
77596 ** pE is a pointer to an expression which is a single term in the
77604 ** Attempt to match pE against result set columns in the left-most
77607 ** The left-most column is 1. In other words, the value returned is the
77608 ** same integer value that would be used in the SQL statement to indicate
77628 /* Resolve all names in the ORDER BY term expression
77644 ** in the result set. Return an 1-based index of the matching
77672 ** Analyze the ORDER BY clause in a compound SELECT statement. Modify
77674 ** and N where N is the number of columns in the compound SELECT.
77701 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
77765 "column in the result set", i+1);
77773 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
77796 sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType);
77815 ** pOrderBy is an ORDER BY or GROUP BY clause in SELECT statement pSelect.
77821 ** number of columns in the result set of the SELECT) then the expression
77822 ** in the resolution is a copy of the I-th result-set expression. If
77825 ** result-set expression. Otherwise, the expression is resolved in
77829 ** an appropriate error message might be left in pParse. (OOM errors
77842 int nResult; /* Number of terms in the result set */
77888 ** Resolve names in the SELECT statement p and all of its descendents.
77917 ** this routine in the correct order.
77932 /* Resolve the expressions in the LIMIT and OFFSET clauses. These
77942 /* Recursively resolve names in all subqueries
77952 ** parent contexts. After resolving references to expressions in
77976 /* Resolve names in the result set. */
77986 /* If there are no aggregate functions in the result-set, and no GROUP BY
77987 ** expression, do not allow aggregates in any of the other expressions.
78005 ** other expressions in the SELECT statement. This is so that
78006 ** expressions in the WHERE clause (etc.) can refer to expressions by
78007 ** aliases in the result set.
78016 /* The ORDER BY and GROUP BY clauses may not refer to terms in
78045 sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
78080 ** Y: The name of a table in a FROM clause. Or in a trigger
78083 ** Z: The name of a column in table Y.
78089 ** Expr.iColumn The column index in X.Y. -1 for the rowid.
78095 ** size of an AS clause in the result-set of a SELECT. The Z expression
78098 ** tree. For example, in:
78113 ** An error message is left in pParse if anything is amiss. The number
78117 NameContext *pNC, /* Namespace to resolve expressions in. */
78157 ** Resolve all names in all expressions of a SELECT and in all
78159 ** subqueries in expressions, and subqueries used as FROM clause
78185 ** Resolve names in expressions that can only reference a single table:
78193 ** Any errors cause an error message to be set in pParse.
78231 ** The author disclaims copyright to this source code. In place of
78240 ** for generating VDBE code that evaluates expressions in SQLite.
78251 ** i.e. the WHERE clause expresssions in the following statements all
78278 ** a TK_COLUMN but was previously evaluated and cached in a register */
78292 ** If a memory allocation error occurs, that fact is recorded in pParse->db
78366 ** a TK_COLUMN but was previously evaluated and cached in a register */
78440 ** pExpr is a comparison expression, eg. '=', '<', IN(...) etc.
78443 ** the comparison in pExpr.
78476 ** Argument pRight (but not pLeft) may be a null pointer. In this case,
78526 ** expression depth allowed. If it is not, leave an error message in
78579 ** Set the Expr.nHeight variable in the structure passed as an
78600 ** leave an error in pParse.
78636 ** stored in u.zToken. Instead, the integer values is written
78704 ** In that case, delete the subtrees pLeft and pRight.
78765 ** boolean values in different circumstances (a false positive.)
78829 ** in the original SQL statement.
78948 ** to store a copy of an expression or expression tree. They differ in
79003 ** This function returns the space in bytes required to store the copy
79024 ** space to duplicate all Expr nodes in the tree formed by Expr.pLeft
79100 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
79108 /* Fill in pNew->pLeft and pNew->pRight. */
79172 ** part of the in-memory representation of the database schema.
79405 ** leave an error message in pParse.
79416 sqlite3ErrorMsg(pParse, "too many columns in %s", zObject);
79537 ** to fit in a 32-bit integer, return 1 and put the value of the integer
79538 ** in *pValue. If the expression is not an integer or if it is too big
79539 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
79544 /* If an expression is an integer literal that fits in a signed 32-bit
79580 ** (returning TRUE when in fact the expression can never be NULL) might
79583 ** will likely result in an incorrect answer. So when in doubt, return
79607 ** unchanged by OP_Affinity with the affinity given in the second
79611 ** can be omitted. When in doubt return FALSE. A false negative
79612 ** is harmless. A false positive, however, can result in the wrong
79656 ** Return true if we are able to the IN operator optimization on a
79659 ** x IN (SELECT ...)
79664 ** The Select object passed in has already been preprocessed and no
79672 if( p==0 ) return 0; /* right-hand side of IN is SELECT */
79685 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
79692 if( pEList->nExpr!=1 ) return 0; /* One column in the result set */
79726 ** The argument is an IN operator with a list (not a subquery) on the
79742 ** This function is used by the implementation of the IN (...) operator.
79743 ** The pX parameter is the expression on the RHS of the IN operator, which
79747 ** be used either to test for membership in the RHS set or to iterate through
79750 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
79760 ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be
79768 ** If the RHS of the IN operator is a list or a more complex subquery, then
79777 ** IN index will be used to loop over all values of the RHS of the
79778 ** IN operator.
79792 ** if the RHS of the IN operator is a list (not a subquery) then this
79794 ** testing is too expensive and return IN_INDEX_NOOP. In that case, the
79795 ** calling routine should implement the IN operator using a sequence
79799 ** might need to know whether or not the RHS side of the IN operator
79806 ** If a register is allocated and its location stored in *prRhsHasNull, then
79807 ** the value in that register will be NULL if the b-tree contains one or more
79813 Select *p; /* SELECT to the right of IN operator */
79847 /* This function is only called from two places. In both cases the vdbe
79864 ** be used in place of a temp-table, it must be ordered according
79896 /* If no preexisting index is available for the IN clause
79898 ** and the RHS of the IN operator is a list, not a subquery
79901 ** the IN operator so return IN_INDEX_NOOP.
79938 ** or IN operators. Examples:
79942 ** x IN (4,5,11) -- IN operator with list on right-hand side
79943 ** x IN (SELECT a FROM b) -- IN operator with subquery on the right
79945 ** The pExpr parameter describes the expression that contains the IN
79949 ** to be of the form "<rowid> IN (?, ?, ?)", where <rowid> is a reference
79950 ** to some integer key column of a table B-Tree. In this case, use an
79951 ** intkey B-Tree to store the set of IN(...) values instead of the usual
79954 ** If rMayHaveNull is non-zero, that means that the operation is an IN
79961 ** result. For IN operators or if an error occurs, the return value is 0.
79966 Expr *pExpr, /* The IN, SELECT, or EXISTS operator */
79967 int rHasNullFlag, /* Register that records whether NULLs exist in RHS */
79968 int isRowid /* If true, LHS of IN operator is a rowid */
79976 /* This code must be run in its entirety every time it is encountered
80002 char affinity; /* Affinity of the LHS of the IN */
80004 Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
80009 /* Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)'
80027 /* Case 1: expr IN (SELECT ...)
80043 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
80056 /* Case 2: expr IN (exprlist)
80059 ** store it in the temporary table. If <expr> is a column, then use
80076 /* Loop through each expression in <exprlist>. */
80124 ** value of this select in a memory cell and record the number
80125 ** of the memory cell in iColumn. If this is an EXISTS, write
80127 ** and record that memory cell in iColumn.
80176 ** Generate code for an IN expression.
80178 ** x IN (SELECT ...)
80179 ** x IN (value, value, ...)
80189 ** is contained in the RHS then jump to destIfNull. If the LHS is contained
80194 Expr *pExpr, /* The IN expression */
80195 int destIfFalse, /* Jump here if LHS is not contained in the RHS */
80209 VdbeNoopComment((v, "begin IN expr"));
80220 /* Code the LHS, the <expr> from "<expr> IN (...)".
80227 ** suitable for evaluating the IN operator, then evaluate using a
80287 /* In this case, the RHS is the ROWID of table b-tree
80293 /* In this case, the RHS is an index b-tree.
80298 ** "x IN (...)" expression must be either 0 or NULL. If the set
80307 ** of a "NOT NULL" constraint in the database schema.
80310 ** for this particular IN operator.
80315 /* In this branch, the RHS of the IN might contain a NULL and
80316 ** the presence of a NULL on the RHS makes a difference in the
80321 /* First check to see if the LHS is contained in the RHS. If so,
80322 ** then the answer is TRUE the presence of NULLs in the RHS does
80323 ** not matter. If the LHS is not contained in the RHS, then the
80338 VdbeComment((v, "end IN expr"));
80345 static char *dup8bytes(Vdbe *v, const char *in){
80348 memcpy(out, in, 8);
80431 ** Record in the column cache that a particular column from a
80432 ** particular table is stored in a particular register.
80452 ** that the object will never already be in cache. Verify this guarantee.
80527 ** the previous sqlite3ExprCachePush operation. In other words, restore
80528 ** the cache to the state it was in prior the most recent Push.
80551 ** register might be in the cache in multiple places, so be sure to
80591 ** table pTab and store the column value in a register. An effort
80592 ** is made to store the column value in register iReg, but this is
80595 ** There must be an open cursor to pTab in iTable when this routine
80674 ** Return true if any register in the range iFrom..iTo (inclusive)
80678 ** and does not appear in a normal build.
80703 ** expression. Attempt to store the results in register "target".
80707 ** be stored in target. The result might be stored in some other
80715 int inReg = target; /* Results stored in register inReg */
80975 int nId; /* Length of the function name in bytes */
80998 /* Attempt a direct implementation of the built-in COALESCE() and
81076 ** see if it is a column in a virtual table. This is done because
81080 ** "glob(B,A). We want to use the A in "A glob B" to test
81081 ** for function overloading. But we use the B term in "glob(B,A)".
81130 ** X is stored in pExpr->pLeft.
81131 ** Y is stored in pExpr->pList->a[0].pExpr.
81132 ** Z is stored in pExpr->pList->a[1].pExpr.
81167 ** to a column in the new.* or old.* pseudo-tables available to
81168 ** trigger programs. In this case Expr.iTable is set to 1 for the
81177 ** set to (n+1), where n is the number of columns in each pseudo-table.
81178 ** For a reference to any other column in the new.* pseudo-table, p1
81230 ** X (if it exists) is in pExpr->pLeft.
81231 ** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
81232 ** odd. The Y is also optional. If the number of elements in x.pList
81234 ** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
81267 ** The value in regFree1 might get SCopy-ed into the file result.
81341 int regDest, /* Store the value in this register */
81367 ** code to fill the register in the initialization section of the
81368 ** VDBE program, in order to factor it out of the evaluation loop.
81405 ** results in register target. The results are guaranteed to appear
81406 ** in register target.
81425 ** results in register target. The results are guaranteed to appear
81426 ** in register target. If the expression is constant, then this routine
81439 ** in register target.
81616 sqlite3ExplainPrintf(pOut, "IN(");
81636 ** X is stored in pExpr->pLeft.
81637 ** Y is stored in pExpr->pList->a[0].pExpr.
81638 ** Z is stored in pExpr->pList->a[1].pExpr.
81655 ** to a column in the new.* or old.* pseudo-tables available to
81656 ** trigger programs. In this case Expr.iTable is set to 1 for the
81802 Expr exprAnd; /* The AND operator in x>=y AND x<=z */
81848 ** operation. Special comments in vdbe.c and the mkopcodeh.awk script in
81849 ** the make process cause these values to align. Assert()s in the code
82131 ** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
82141 ** can be sure the expressions are the same. In the places where
82143 ** just might result in some slightly slower code. But returning
82189 ** non-zero if they differ in any way.
82192 ** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
82232 ** When in doubt, return false. Returning true might give a performance
82257 ** to count references to table columns in the arguments of an
82258 ** aggregate function, in order to implement the
82262 SrcList *pSrc; /* One particular FROM clause in a nested query */
82263 int nThis; /* Number of references to columns in pSrcList */
82264 int nOther; /* Number of references to columns in other FROM clauses */
82274 ** sqlite3FunctionUsesThisSrc() is used differently in the future, the
82296 ** references columns but not columns of tables found in pSrcList.
82361 /* Check to see if the column is in one of the tables in the FROM
82370 ** that is in the FROM clause of the aggregate query.
82372 ** Make an entry for the column in pAggInfo->aCol[] if there
82411 /* There is now an entry for pExpr in pAggInfo->aCol[] (either
82431 ** function that is already in the pAggInfo structure
82440 /* pExpr is original. Make a new entry in pAggInfo->aFunc[]
82500 ** Call sqlite3ExprAnalyzeAggregates() for every expression in an
82585 ** The author disclaims copyright to this source code. In place of
82598 ** The code in this file only exists if we are not omitting the
82607 ** CREATE INDEX command. The second is a table name. The table name in
82635 /* The principle used to locate the table name in the CREATE TABLE
82646 /* Store the token that zCsr points to in tname. */
82650 /* Advance zCsr to the next token. Store that token type in 'token',
82651 ** and its length in 'len' (to be used next iteration of this loop).
82733 ** statement. The second is a table name. The table name in the CREATE
82756 /* The principle used to locate the table name in the CREATE TRIGGER
82769 /* Store the token that zCsr points to in tname. */
82773 /* Advance zCsr to the next token. Store that token type in 'token',
82774 ** and its length in 'len' (to be used next iteration of this loop).
82798 ** in the CREATE TRIGGER statement.
82808 ** Register built-in functions used to help implement ALTER TABLE
82842 ** In this case zWhere is passed to sqlite3DbFree() before returning.
82876 ** table pTab has no temporary triggers, or is itself stored in the
82884 /* If the table is not located in the temp-db (in which case NULL is
82887 ** expression being built up in zWhere.
82908 ** Argument zName is the name of the table in the database schema at
82945 /* Now, if the table is not stored in the temp database, reload any temp
82946 ** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.
82958 ** in pParse->zErr (system tables may not be altered) and returns non-zero.
82984 int nTabName; /* Number of UTF-8 characters in zTabName */
83009 ** in database iDb. If so, this is an error.
83079 /* figure out how many UTF-8 characters are in zName */
83124 /* If the sqlite_sequence table exists in this database, then update
83136 ** table. Don't do this if the table being ALTERed is itself located in
83315 ** This function is called by the parser after the table-name in
83364 /* Put a copy of the Table struct in Parse.pNewTable for the
83415 ** The author disclaims copyright to this source code. In place of
83436 ** Additional tables might be added in future releases of SQLite.
83445 ** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is
83455 ** name in the idx column. The tbl column is the name of the table to
83456 ** which the index belongs. In each such row, the stat column will be
83457 ** a string consisting of a list of integers. The first integer in this
83458 ** list is the number of rows in the index. (This is the same as the
83459 ** number of rows in the table, except for partial indices.) The second
83460 ** integer is the average number of rows in the index that have the same
83461 ** value in the first column of the index. The third integer is the average
83462 ** number of rows in the index that have the same value for the first two
83463 ** columns. The N-th integer (for N>1) is the average number of rows in
83465 ** a K-column index, there will be K+1 integers in the stat column. If
83468 ** The list of integers in the stat column can optionally be followed
83476 ** rows in the table identified by sqlite_stat1.tbl.
83485 ** the index belongs. There are usually 10 rows in the sqlite_stat2
83489 ** inclusive are samples of the left-most key value in the index taken at
83491 ** (10 in the standard build) and let C be the number of rows in the index.
83513 ** to aid the query planner in choosing good indices based on the values
83514 ** that indexed columns are compared against in the WHERE clauses of
83523 ** of entries in the index whose left-most column exactly matches
83524 ** the left-most column of the sample. The second integer in nEq
83525 ** is the approximate number of entries in the index where the
83529 ** integer in nLt contains the number of entries in the index where the
83531 ** The K-th integer in the nLt entry is the number of index entries
83534 ** number of distinct entries in the index that are less than the
83548 ** of a blob encoding of the complete index key as is found in
83551 ** integer in the equivalent columns in sqlite_stat4.
83578 ** or it may be a NULL pointer. If it is not NULL, then all entries in
83584 int iDb, /* The database we are looking in */
83627 ** of the new table in register pParse->regRoot. This is important
83683 i64 iRowid; /* Rowid in main table of the key */
83693 tRowcnt nRow; /* Number of rows in the entire table */
83695 int nCol; /* Number of columns in index + pk/rowid */
83701 int iMin; /* Index in a[] of entry with minimum score */
83784 ** N: The number of columns in the index including the rowid/pk (note 1)
83785 ** K: The number of columns in the index excluding the rowid/pk.
83786 ** C: The number of rows in the index (note 2)
83788 ** Note 1: In the special case of the covering index that implements a
83790 ** total number of columns in the table.
83795 ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
83799 ** This routine allocates the Stat4Accum object in heap memory. The return
83809 int nCol; /* Number of columns in index being sampled */
83901 ** In other words, if we assume that the cardinalities of the selected
83969 /* This sample is being added because the prefix that ends in column
83970 ** iCol occurs many times in the table. However, if we have already
84010 ** for the last sample in the p->a[] array. Otherwise, the samples would
84022 /* Zero the first nEqZero entries in the anEq[] array. */
84083 /* Or if it is a non-periodic sample. Add it in this case too. */
84108 ** statistical data and/or samples in
84234 /* Return the value to store in the "stat" column of the sqlite_stat1
84238 ** the index. The first integer in the list is the total number of
84239 ** entries in the index. There is one additional integer in the list
84242 ** a key with the corresponding number of fields. In other words,
84426 int nCol; /* Number of columns in pIdx. "N" */
84494 ** (1) the number of columns in the index including the rowid
84496 ** (2) the number of columns in the key without the rowid/pk
84497 ** (3) the number of rows in the index,
84719 ** Generate code that will do an analysis of a single table in
84721 ** in pTab that should be analyzed.
84750 ** Form 1 causes all indices in all attached databases to be analyzed.
84765 ** and code in pParse and return NULL. */
84831 int nOut, /* Number of slots in aOut[] */
84894 ** Entries for which argv[1]==NULL simply record the number of rows in
84966 ** stored in pIdx->aSample[].
84990 ** occur in the stat4 table for this index before pFinal. Set
85049 Index *pPrevIdx = 0; /* Previous index in the loop */
85050 IndexSample *pSample; /* A slot in pIdx->aSample[] */
85062 int nIdxCol = 1; /* Number of columns in stat4 records */
85077 ** loaded from the stat4 table. In this case ignore stat3 data. */
85120 int nCol = 1; /* Number of columns in index */
85127 ** the sqlite_stat4 table. In this case ignore stat3 data. */
85140 ** This is in case the sample record is corrupted. In that case, the
85193 ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
85194 ** is returned. In this case, even if SQLITE_ENABLE_STAT3/4 was defined
85199 ** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
85200 ** returned. However, in this case, data is read from the sqlite_stat1
85269 ** The author disclaims copyright to this source code. In place of
85367 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
85372 /* Allocate the new entry in the db->aDb[] array and initialize the schema
85703 ** was left unspecified in the original SQL statement. The pFix structure
85707 ** view in one database does not refer to objects in a different database.
85708 ** (Exception: indices, triggers, and views in the TEMP database are
85710 ** to an object in a different database, an error message is added to
85728 "%s %T cannot reference objects in database %s",
85845 ** The author disclaims copyright to this source code. In place of
85860 ** All of the code in this file may be omitted by defining a single
85934 ** table zTab in database zDb. This function assumes that an authorization
85939 ** is treated as SQLITE_DENY. In this case an error is left in pParse.
85967 ** is in pTabList or else it is the NEW or OLD table of a trigger.
85983 int iSrc; /* Index in pTabList->a[] of table being read */
85985 int iCol; /* Index of column in table */
86028 ** is returned, then the error count and error message in pParse are
86096 ** The author disclaims copyright to this source code. In place of
86105 ** when syntax rules are reduced. The routines in this file handle the
86142 ** The table to be locked has root page iTab and is found in database iDb.
86328 ** Run the parser and code generator recursively in order to generate
86366 ** Locate the in-memory structure that describes a particular database
86396 ** Locate the in-memory structure that describes a particular database
86399 ** error message in pParse->zErrMsg.
86402 ** routine leaves an error message in pParse->zErrMsg where
86406 Parse *pParse, /* context in which to report errors */
86414 ** and code in pParse and return NULL. */
86458 ** Locate the in-memory structure that describes
86502 ** For the index called zIdxName which is found in the database iDb,
86535 ** Look through the list of open database files in db->aDb[] and if
86580 ** since TEMP might be holding triggers that reference tables in the
86647 ** contains lookaside memory. (Table objects in the schema do not use
86662 /* Record the number of outstanding lookaside allocations in schema Tables
86749 ** Open the sqlite_master table stored in database number iDb for
86764 ** function returns the index of the named database in db->aDb[], or
86785 ** index of the named database in db->aDb[], or -1 if the named db
86815 Token *pName1, /* The "xxx" in the name "xxx.yyy" or "xxx" */
86816 Token *pName2, /* The "yyy" in the name "xxx.yyy" */
86847 ** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
86882 ** Begin constructing a new table representation in memory. This is
86883 ** the first of several action routines that get called in response
86884 ** to a CREATE TABLE statement. In particular, this routine is called
86886 ** flag is true if the table should be stored in the auxiliary database
86887 ** file instead of in the main database file. This is normally the case
86888 ** when the "TEMP" or "TEMPORARY" keyword occurs in between
86891 ** The new table record is initialized and put in pParse->pNewTable.
86910 int iDb; /* Database number to create the table in */
86928 ** created in.
86975 ** index or table name in the same database. Issue an error message if
86977 ** to an sqlite3_declare_vtab() call. In that case only the column names
87018 ** then record a pointer to this table in the main database structure
87029 ** the SQLITE_MASTER table. Note in particular that we must go ahead
87048 /* If the file format and encoding in the database have not been set,
87065 /* This just creates a place-holder record in the sqlite_master table.
87067 ** by the real entry in code generated at sqlite3EndTable().
87069 ** The rowid for the new entry is left in register pParse->regRowid.
87070 ** The root page number of the new table is left in reg pParse->regRoot.
87100 ** This macro is used to compare two strings in a case-insensitive manner.
87116 ** in a CREATE TABLE statement. sqlite3StartTable() gets called
87165 ** This routine is called by the parser while in the middle of
87182 ** substrings in the following table. If one of the substrings is
87199 ** If none of the substrings in the above table are found,
87265 ** This routine is called by the parser while in the middle of
87267 ** token in the sequence of tokens that describe the type of the
87269 ** in the sequence. Use this information to construct a string
87271 ** in zType.
87292 ** This routine is called by the parser while in the middle of
87470 ** in the database native encoding, the collation factory is invoked to
87472 ** and the sequence is available in another text encoding, then that is
87514 ** 1 chance in 2^32. So we're safe enough.
87547 ** to the specified offset in the buffer and updates *pIdx to refer
87721 ** (3) Set the Index.tnum of the PRIMARY KEY Index object in the
87787 /* Update the in-memory representation of all UNIQUE indices by converting
87840 ** An entry for the table is made in the master table on disk, unless
87844 ** recently changed, so the entry for this table already exists in
87855 Token *pEnd, /* The ')' before options in the CREATE TABLE */
87861 int iDb; /* Database in which the table lives */
87900 /* Resolve names in all CHECK constraint expressions.
87914 ** in the SQLITE_MASTER table of the database.
87948 ** new table is in register pParse->regRoot.
87950 ** Once the SELECT has been coded by sqlite3Select(), it is in a
87994 /* A slot for the record has already been allocated in the
88035 /* Add the table to the in-memory representation of the database.
88068 ** The parser calls this routine in order to create a new VIEW
88089 sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
88143 ** The Table structure pTable is really a VIEW. Fill in the names of
88144 ** the columns of the view in the pTable structure. Return the number
88145 ** of errors. If an error is seen leave an error message in pParse->zErrMsg.
88179 ** in the following:
88193 ** "*" elements in the results set of the view and will assign cursors
88240 ** Clear the column names from every VIEW in database idx.
88263 ** root-page of a table or index in database iDb has changed from iFrom
88275 ** in order to be certain that we got the right one.
88314 /* OP_Destroy stores an in integer r1. If this integer
88319 ** The "#NNN" in the SQL is a special constant that means whatever value
88320 ** is in register NNN. See grammar rules associated with the TK_REGISTER
88333 ** in case a root-page belonging to another table is moved by the btree layer
88347 ** table and index root-pages in order, starting with the numerically
88356 ** and root page 5 happened to be the largest root-page number in the
88391 ** Remove entries from the sqlite_statN tables (for N in (1,2,3))
88448 ** at the btree level, in case the sqlite_sequence table needs to
88449 ** move as a result of the drop (can happen in auto-vacuum mode).
88463 ** created in the temp database that refers to a table in another
88589 ** in the current table point to the foreign key. If pFromCol==0 then
88592 ** of tables in the parent pTo table. flags contains all
88594 ** in the ON DELETE, ON UPDATE and ON INSERT clauses.
88597 ** under construction in the pParse->pNewTable field.
88604 ExprList *pFromCol, /* Columns in this table that point to other table */
88606 ExprList *pToCol, /* Columns in the other table */
88633 "number of columns in foreign key does not match the number of "
88634 "columns in the referenced table");
88671 "unknown column \"%s\" in foreign key definition",
88736 ** content of an index in response to a REINDEX command.
88748 int iSorter; /* Cursor opened by OpenSorter (if in use) */
88828 ** pointer to this extra space in *ppExtra.
88832 i16 nCol, /* Total number of columns in the index */
88890 int nName; /* Number of characters in zName */
88893 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
88899 const Column *pTabCol; /* A column in the table */
89192 ** the constraint occur in different orders, then the constraints are
89193 ** considered distinct and both result in separate indices.
89214 ** constraint specified somewhere in the CREATE TABLE statement.
89234 ** in-memory database structures.
89256 ** the index in the sqlite_master table and populate the index with
89262 ** or UNIQUE index in a CREATE TABLE statement. Since the table
89295 /* Add an entry in sqlite_master for this index
89322 ** processing (in sqlite3GenerateConstraintChecks()) as part of
89356 ** aiRowEst[0] is suppose to contain the number of elements in the index.
89358 ** number of rows in the table that match any particular value of the
89368 ** are based on typical values found in actual indices.
89377 /* Set the first entry (number of rows in the index) to the estimated
89378 ** number of rows in the table. Or 10, if the estimated number of rows
89379 ** in the table is less than that. */
89463 ** pArray is a pointer to an array of objects. Each object in the
89464 ** array is szEntry bytes in size. This routine uses sqlite3DbRealloc()
89468 ** the array (in entries - so the allocation is ((*pnEntry) * szEntry) bytes
89469 ** in total).
89474 ** returned. *pIdx is set to the index of the new array entry in this case.
89482 int szEntry, /* Size of each object in the array */
89483 int *pnEntry, /* Number of objects currently in use */
89545 ** Return the index in pList of the identifier named zId. Return -1
89580 int iStart /* Index in pSrc->a[] of first new slot */
89626 ** need be. A new entry is created in the SrcList even if pTable is NULL.
89641 ** In other words, if call like this:
89651 ** then so is B. In other words, we never have a case where:
89691 ** Assign VdbeCursor index numbers to all tables in a SrcList
89733 ** are the name of the table and database named in the FROM clause term.
89750 Select *pSubquery, /* A subquery used in place of a table name */
89804 ** When building up a FROM clause in the parser, the join operator
89815 ** in p->a[0] and p->a[1], respectively. The parser initially stores the
89911 ** the number of errors. Leave any error messages in the pParse structure.
90003 ** inserting multiple rows in a table, or inserting a row and index entries.)
90014 ** possible to abort a statement prior to completion. In order to
90023 ** makes it more difficult to prove that the code is correct (in
90145 ** Recompute all indices of all tables in all databases where the
90154 HashElem *k; /* For looping over tables in pDb */
90155 Table *pTab; /* A table in the database */
90176 ** Form 1 causes all indices in all attached databases to be rebuilt.
90177 ** Form 2 rebuilds all indices in all databases that use the named
90186 Table *pTab; /* A table in the database */
90193 ** and code in pParse and return NULL. */
90239 ** The KeyInfo structure for an index is cached in the Index object.
90300 ** not, store an error in the Parse structure. */
90358 ** The author disclaims copyright to this source code. In place of
90374 ** in the encoding enc of name zName, length nName.
90400 ** collation function in the best encoding but there may be other versions
90424 ** requested collation sequence is not available in the desired encoding.
90429 ** The return value is either the collation sequence to be used in database
90496 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
90501 ** the collation sequence name. A pointer to this string is stored in
90527 /* If a malloc() failure occurred in sqlite3HashInsert(), it will
90577 ** matches the request for a function with nArg arguments in a system
90582 ** is also -1. In other words, we are searching for a function that
90643 int nFunc /* Number of bytes in zFunc */
90701 int nName, /* Number of characters in the name */
90727 /* If no match is found, search the built-in functions.
90729 ** If the SQLITE_PreferBuiltin flag is set, then search the built-in
90731 ** priority to built-in functions.
90736 ** new function. But the FuncDefs for built-in functions are read-only.
90837 ** The author disclaims copyright to this source code. In place of
90846 ** in order to generate code for DELETE FROM statements.
90850 ** While a SrcList can in general represent multiple tables and subqueries
90851 ** (as in the FROM clause of a SELECT statement) in this case it contains
90852 ** the name of a single table, as one might find in an INSERT, DELETE,
90853 ** or UPDATE statement. Look up that table in the symbol table and
90857 ** The following fields are initialized appropriate in pSrc:
90893 ** In either case leave an error message in pParse and return non-zero.
90917 ** Evaluate a view and store its result in an ephemeral table. The
90919 ** set of rows in the view that are to be added to the ephemeral table.
90967 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
90993 ** DELETE FROM table_a WHERE rowid IN (
91016 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
91066 NameContext sNC; /* Name context to resolve expressions in */
91075 i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
91077 i16 nKey; /* Number of memory cells in the row key */
91098 ** put in an SrcList structure because some of the subroutines we
91172 /* Resolve the column names in the WHERE clause.
91258 ** one, so just keep it in its register(s) and fall through to the
91281 /* Get the rowid of the row to be deleted and remember it in the RowSet */
91307 /* Set up a loop over the rowids/primary-keys that were found in the
91390 ** thely may interfere with compilation of other functions in this file
91391 ** (or in another file, if this file becomes part of the amalgamation). */
91408 ** in the case of a rowid table, or the PRIMARY KEY index in the case
91414 ** 3. The primary key for the row to be deleted must be stored in a
91416 ** that a search record formed from OP_MakeRecord is contained in the
91432 int iOld = 0; /* First register in OLD.* array */
91453 ** use for the old.* references in the triggers. */
91455 u32 mask; /* Mask of OLD.* columns in use */
91503 ** a view (in which case the only effect of the DELETE statement is to
91514 ** handle rows (possibly in other tables) that refer via a foreign key
91580 ** Generate code that will assemble an index key and stores it in register
91586 ** Return a register number which is the first in a block of
91591 ** If *piPartIdxLabel is not NULL, fill it in with a label and jump
91604 ** a column in common, then the register corresponding to that column already
91645 ** might be stored in the table as an integer (using a compact
91676 ** The author disclaims copyright to this source code. In place of
91685 ** functions of SQLite. (Some function, and in particular the date and
91842 ** in haystack and returns the number of previous characters plus 1,
91846 ** the number of bytes in haystack prior to the first occurrence of needle,
91847 ** or 0 if needle never occurs in haystack.
92025 /* If Y==0 and X will fit in a 64-bit int,
92117 ** routines in the function table. The noopFunc macro provides this.
92138 ** in a way that is testable, mask the sign bit off of negative
92139 ** values, resulting in a positive value. Then take the
92234 ** character is exactly one byte in size. Also, all characters are
92235 ** able to participate in upper-case-to-lower-case mappings in EBCDIC
92236 ** whereas only characters less than 0x80 do in ASCII.
92267 ** [^...] Matches one character not in the enclosed list.
92270 ** in the list by making it the first character after '[' or '^'. A
92273 ** it the last character in the list.
92275 ** This routine is usually quick, but can be N**2 in the worst case.
92277 ** Hints: to match '*' or '?', put them in "[]". Like this:
92408 ** the build-in LIKE operator. The first argument to the function is the
92432 ** of deep recursion and N*N behavior in patternCompare().
92586 ** "NULL". Otherwise, the argument is enclosed in single quotes with
92865 int nIn; /* Number of bytes in input */
92868 unsigned char *aLen = 0; /* Length of each character in zCharSet */
92869 unsigned char **azChar = 0; /* Individual characters in zCharSet */
92870 int nChar; /* Number of characters in zCharSet */
93040 ** 0.0 in that case. In addition, TOTAL always returns a float where
93089 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
93231 ** of the built-in functions above are part of the global function set.
93255 ** Register the built-in LIKE and GLOB functions. The caseSensitive
93299 ** the first three statements in the compareInfo structure. The
93311 ** All all of the FuncDef structures in the aBuiltinFunc[] array above
93320 ** defined in this file.
93424 ** The author disclaims copyright to this source code. In place of
93443 ** Foreign keys in SQLite come in two flavours: deferred and immediate.
93478 ** row in the parent table. Decrement the counter for each row
93485 ** deleted row in the child table. If such a row is not found,
93490 ** in the parent table. For each found increment the counter.
93513 ** statement that inserts a single row only (no triggers). In this case,
93564 ** A foreign key constraint requires that the key columns in the parent
93576 ** N is the number of columns in the parent key. The first element of the
93578 ** constraint to the parent table column stored in the left-most column
93596 ** consists of a a different number of columns to the child key in
93604 Parse *pParse, /* Parse context to store any error in */
93608 int **paiCol /* OUT: Map of index columns in pFKey */
93612 int nCol = pFKey->nCol; /* Number of columns in parent key */
93666 ** map to an explicit list of columns in table pParent. Check if this
93671 i16 iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
93677 ** unusable. Bail out early in this case. */
93720 ** row in the parent table that corresponds to the row being inserted into
93723 ** found in the parent table:
93735 ** These operations are identified in the comment at the top of this file
93742 Index *pIdx, /* Unique index on parent key columns in pTab */
93758 ** Check if any of the key columns in the child table row are NULL. If
93760 ** search for a matching row in the parent table. */
93932 ** The code generated by this function scans through the rows in the child
93950 ** These operations are identified in the comment at the top of this file
93993 i16 iCol; /* Index of column in child table */
93994 const char *zCol; /* Name of column in child table */
94014 ** for WITHOUT ROWID tables. In the second form, the primary key is
94041 /* Resolve the references in the WHERE clause. */
94047 /* Create VDBE to loop through the entries in pSrc that match the WHERE
94116 ** constraint violations in the database,
94175 ** actually updated, the corresponding element in the aChange[] array
94202 ** actually updated, the corresponding element in the aChange[] array
94240 ** first register in an array of (pTab->nCol+1) registers containing the
94243 ** zero in this case.
94281 Index *pIdx = 0; /* Index on key columns in pTo */
94296 ** on the parent key columns in the parent table. If either of these
94297 ** schema items cannot be located, set an error in pParse and return
94308 /* If isIgnoreErrors is true, then a table is being dropped. In this
94310 ** before actually dropping it in order to check FK constraints.
94352 ** in the parent table. */
94387 ** foreign key violation. So do nothing in this case. */
94430 ** row contained in table pTab.
94457 ** row contained in table pTab. If the operation is a DELETE, then
94459 ** to an array of size N, where N is the number of columns in table pTab.
94461 ** entry in the aChange[] array is set to -1. If the column is modified,
94478 ** table in question is either the child or parent table for any
94513 ** For example, if pFKey is the foreign key and pTab is table "p" in
94546 int nFrom; /* Length in bytes of zFrom */
94562 Token tFromCol; /* Name of column in child table */
94563 Token tToCol; /* Name of column in parent table */
94564 int iFromCol; /* Idx of column in child table */
94658 in trigger program */
94768 /* EV: R-30323-21917 Each foreign key constraint in SQLite is
94790 ** The author disclaims copyright to this source code. In place of
94799 ** to handle INSERT statements in SQLite.
94814 int iDb, /* The database index in sqlite3.aDb[] */
94839 ** pIdx. A column affinity string has one character for each column in
94851 ** rowid that appears as the last column in every index.
94935 ** Return non-zero if the table pTab in database iDb or any of its indices
94936 ** have been opened at any point in the VDBE program. This is used to see if
94977 ** which is in database iDb. Return the register number for the register
94990 ** (3) Register to hold the rowid in sqlite_sequence of pTab
95016 pToplevel->nMem++; /* Rowid in sqlite_sequence */
95067 ** larger than the maximum rowid in the memId memory cell, then the
95135 ** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted.
95137 ** The pList parameter holds EXPRLIST in the first form of the INSERT
95157 ** in other words if the SELECT pulls all columns from a single table
95167 ** transfer all records in <table2> over to <table>
95183 ** loop over the rows in the SELECT
95197 ** that is also read as part of the SELECT. In the third form,
95204 ** loop over the tables in the SELECT
95235 int nColumn; /* Number of columns in the data */
95243 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
95247 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
95250 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
95357 /* If this is an AUTOINCREMENT table, look up the sequence number in the
95358 ** sqlite_sequence table and store it in memory cell regAutoinc.
95378 ** is named in the IDLIST, then record in the ipkColumn variable
95380 ** the index of the primary key as it appears in IDLIST, not as
95381 ** is appears in the original table. (The index of the INTEGER
95382 ** PRIMARY KEY in the original table is pTab->iPKey.)
95446 ** temp table in the case of row triggers.
95499 ** column index in the original table definition.
95505 /* Make sure the number of columns in the source data matches the number
95698 ** in its place. Hence, fill this column with a NULL to avoid
95815 ** thely may interfere with compilation of other functions in this file
95816 ** (or in another file, if this file becomes part of the amalgamation). */
95831 ** The regNewData parameter is the first register in a range that contains
95833 ** pTab->nCol+1 registers in this range. The first register (the one
95834 ** that regNewData points to) will contain the new rowid, or NULL in the
95835 ** case of a WITHOUT ROWID table. The second register in the range will
95858 ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
95867 ** for the first index in the pTab->pIndex list. Cursors for other indices
95891 ** any IGNORE The attempt in insert or update the current
95903 ** CHECK REPLACE Illegal. The results in an exception.
95916 int regNewData, /* First register in a range holding values to insert */
95933 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
95948 ** normal rowid tables. nPkField is the number of key fields in the
95949 ** pPk index or 1 for a rowid table. In other words, nPkField is the
95950 ** number of fields in the true primary key of the table. */
96036 ** exist in the table.
96041 /* Figure out what action to take in case of a rowid collision */
96072 /* Check to see if the new rowid already exists in the table. Skip
96171 ** the insert or update. Store that record in the aRegIdx[ix] register
96178 if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
96191 /* In an UPDATE operation, if this index is the PRIMARY KEY index
96200 /* Find out what action to take in case there is a uniqueness conflict */
96232 ** store it in registers regR..regR+nPk-1 */
96388 ** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
96389 ** ROWID table) is returned in *piDataCur. The first index cursor is
96390 ** returned in *piIdxCur. The number of indices is returned.
96397 in the range
96480 ** for index pDest in an insert transfer optimization. The rules
96525 ** performance. Raw index records are transferred in the same way.
96529 ** embedded in the code for details.
96533 ** is empty - a factor that can only be determined at run-time. In that
96536 ** xfer optimization code if the test fails. In that case, this routine
96551 Table *pSrc; /* The table in the FROM clause of SELECT */
96625 ** correct syntactic form to participate in this optimization. Now
96648 return 0; /* Number of columns must be the same in tab1 and tab2 */
96681 return 0; /* pDestIdx has no corresponding index in pSrc */
96726 /* In some circumstances, we are able to run the xfer optimization
96810 ** The author disclaims copyright to this source code. In place of
96818 ** Main file for the SQLite library. The routines in this file
96819 ** implement the programmer interface to the library. Routines in
96830 ** If the SQL is a query, then for each row in the query result
96956 ** The author disclaims copyright to this source code. In place of
96969 #define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
96971 /************** Include sqlite3ext.h in the middle of loadext.c **************/
96976 ** The author disclaims copyright to this source code. In place of
96999 ** WARNING: In order to maintain backwards compatibility, add new
97001 ** interfaces in the middle of this structure, then older different
97461 /************** Continuing where we left off in loadext.c ********************/
97563 ** in order to preserve backwards compatibility.
97838 ** Attempt to load an SQLite extension library contained in the file
97839 ** zFile. The entry point is zProc. zProc may be 0 in which case a
97921 ** character in the filename after the last "/" upto the first ".",
97956 "no entry point [%s] in shared library [%s]", zEntry, zFile);
98003 ** Call this routine when the database connection is closing in order
98017 ** default so as not to open security holes in older applications.
98052 int nExt; /* Number of entries in aExt[] */
98058 ** we have to locate the state vector at run-time. In the more common
98164 ** If anything goes wrong, set an error in the database connection.
98206 ** The author disclaims copyright to this source code. In place of
98229 ** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun
98230 ** that script. Then copy/paste the output in place of the following:
98747 ** backed temporary databases, 2 for the Red-Black tree in memory database
98869 ** defined in pager.h. This function returns the associated lowercase
98930 ** index of the database this pragma is being applied to in db.aDb[]. */
98987 /* Locate the pragma in the lookup table */
99017 ** pages in the page cache. The second form sets both the current
99019 ** stored in the database file.
99069 ** database page size in bytes. The second form sets the
99122 ** maximum number of pages in the database file. The
99132 ** Return the number of pages in the specified database.
99168 ** of the PRAGMA command. In this case the locking-mode must be
99280 ** incr-vacuum flags. This is required in case this connection
99287 ** "incremental", write the value of meta[6] in the database
99344 ** number of pages in the cache. If N is negative, then the
99368 ** The parameter N is measured in bytes.
99593 ** in auto-commit mode. */
99844 Index *pIdx; /* Index in the parent table */
99847 HashElem *k; /* Loop counter: Next table in schema */
100007 ** In this case, the integrity of database iDb only is verified by
100011 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
100051 ** for all tables and indices in the database.
100078 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
100121 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
100176 "non-unique entry in index ", P4_STATIC);
100187 "wrong # of entries in index ", P4_STATIC);
100217 ** In its first form, this pragma returns the encoding of the main
100221 ** has not already been initialized. In this case it sets the default
100226 ** In all cases new databases created using the ATTACH command are
100231 ** In the second form this pragma sets the text encoding to be used in
100302 ** stored in the database header.
100369 ** Return the names of all compile-time options used in this build,
100418 ** after accumulating N frames in the log. Or query for the current value
100567 ** The author disclaims copyright to this source code. In place of
100809 ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
100874 /* Ticket #2804: When we open a database in the newer file format,
100916 ** the schema loaded, even if errors occurred. In this situation the
100951 ** bit is set in the flags field of the Db structure. If the database
100971 ** schema may contain references to objects in other databases.
101011 ** Check schema cookies in all databases. If any cookie is out
101041 ** value stored as part of the in-memory schema representation,
101059 ** which database file in db->aDb[] the schema refers to.
101067 /* If pSchema is NULL, then return -1000000. This happens when code in
101069 ** created by a sub-select). In this case the return value of this
101090 ** Free all memory allocations in the pParse object
101106 int nBytes, /* Length of zSql in bytes. */
101130 ** some other database connection is holding a write-lock, which in
101136 ** back and different changes are made in their place, then when this
101141 ** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
101266 int nBytes, /* Length of zSql in bytes. */
101329 ** Two versions of the official API. Legacy and new use. In the legacy
101330 ** version, the original SQL text is not saved in the prepared statement
101332 ** sqlite3_step(). In the new version, the original SQL text is retained
101339 int nBytes, /* Length of zSql in bytes. */
101351 int nBytes, /* Length of zSql in bytes. */
101369 int nBytes, /* Length of zSql in bytes. */
101376 ** tricky bit is figuring out the pointer to return in *pzTail.
101415 ** Two versions of the official API. Legacy and new use. In the legacy
101416 ** version, the original SQL text is not saved in the prepared statement
101418 ** sqlite3_step(). In the new version, the original SQL text is retained
101425 int nBytes, /* Length of zSql in bytes. */
101437 int nBytes, /* Length of zSql in bytes. */
101454 ** The author disclaims copyright to this source code. In place of
101463 ** to handle SELECT statements in SQLite.
101530 ExprList *pEList, /* which columns to include in the result */
101589 ** Return a pointer to the right-most SELECT statement in a compound.
101599 ** in terms of the following bit values:
101611 ** a join type, but put an error in the pParse structure.
101620 u8 i; /* Beginning of keyword text in zKeyText[] */
101621 u8 nChar; /* Length of the keyword in characters */
101671 ** Return the index of a column in a table. Return -1 if the column
101672 ** is not contained in the table.
101683 ** Search the first N tables in pSrc, from left to right, looking for a
101693 int N, /* Number of tables in pSrc->a[] to search */
101698 int i; /* For looping over tables in pSrc */
101722 ** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the
101728 SrcList *pSrc, /* List of tables in FROM clause */
101729 int iLeft, /* Index of first table to join in pSrc */
101730 int iColLeft, /* Index of column in first table */
101731 int iRight, /* Index of second table in pSrc */
101732 int iColRight, /* Index of column in second table */
101734 Expr **ppWhere /* IN/OUT: The WHERE clause to add to */
101761 ** And set the Expr.iRightJoinTable to iTable for every term in the
101766 ** join restriction specified in the ON or USING clause and not a part
101769 ** originated in the ON or USING clause.
101773 ** explicitly mentioned in the expression. That information is needed
101779 ** term until after the t2 loop of the join. In that way, a
101782 ** after the t1 loop and rows with t1.x!=5 will never appear in
101801 ** The terms of a FROM clause are contained in the Select.pSrc structure.
101802 ** The left most table is the first entry in Select.pSrc. The right-most
101803 ** table is the last entry. The join operator is held in the entry to
101811 SrcList *pSrc; /* All tables in the FROM clause */
101828 ** every column that the two tables have in common.
101837 char *zName; /* Name of column in the right table */
101839 int iLeftCol; /* Matching column in the left table */
101849 /* Disallow both ON and USING clauses in the same join
101853 "clauses in the same join");
101867 ** in the USING clause. Example: If the two tables to be joined are
101870 ** Report an error if any column mentioned in the USING clause is
101871 ** not contained in both tables to be joined.
101876 char *zName; /* Name of the term in the USING clause */
101887 "not present in both tables", zName);
101907 ** Insert code into "v" that will push the record in register regData
102003 ** seen combinations of the N values. A new entry is made in iTab
102030 ** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
102031 ** column. We do this in a subroutine because the error used to occur
102032 ** in multiple places. (The error only occurs in one place now, but we
102056 ** are evaluated in order to get the data for this row. If srcTab is
102098 ** there are columns in the table on the left. The error will be caught
102100 ** to avoid other spurious errors in the meantime. */
102180 /* In this mode, write each query result to the key of the temporary
102217 ** in the index, do not write it to the output. If not, add the
102240 /* If we are creating a set for an "expr IN (SELECT ...)" construct,
102250 ** ORDER BY in this case since the order of entries in the set
102251 ** does not matter. But there might be a LIMIT clause, in which
102264 /* If any row exist in the result set, record that fact and abort.
102273 ** store the results in the appropriate memory cell and break out
102308 ** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
102369 ** there is a sorter, in which case the sorter has already limited
102431 ** the collating sequence for each expression in that expression list.
102508 ** in sqlite3Select() to assign values to structure member variables that
102559 ** then the results were placed in a sorter. After the loop is terminated
102684 ** result in *pEstWidth.
102689 ** is considered a column can be complex in the presence of subqueries. The
102690 ** result-set expression in all of the following SELECT statements is
102733 ** extracted from in NameContext.pSrcList. This table may be real
102738 int iCol = pExpr->iColumn; /* Index of column in pTab */
102762 ** when columnType() is called on the expression "t1.col" in the
102763 ** sub-select. In this case, set the column type to NULL, even
102775 /* The "table" is actually a sub-select or a view in the FROM clause
102824 ** origin info for the single column in the result set of the SELECT
102854 ** in the result set.
102877 ** column specific strings, in case the schema is reset before this
102893 ** in the result set. This information is used to provide the
102894 ** azCol[] values in the callback.
102971 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
102983 int nCol; /* Number of columns in the result set */
102986 int nName; /* Size of name in zName[] */
103073 ** This routine requires that all identifiers in the SELECT
103149 ** If an error occurs, return NULL and leave a message in pParse.
103170 ** that appear in the original SQL statement after the LIMIT and OFFSET
103312 ** There is exactly one reference to the recursive-table in the FROM clause
103318 ** extracted row (now in the iCurrent table) becomes the content of the
103328 ** If the query has an ORDER BY, then entries in the Queue table are kept in
103345 int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
103385 ** the Distinct table must be exactly one greater than Queue in order
103416 /* Store the results of the setup-query in Queue. */
103422 /* Find the next row in the Queue and output that row */
103425 /* Transfer the next row in Queue over to Current */
103434 /* Output the single row in Current */
103445 /* Execute the recursive SELECT taking the single row in Current as
103446 ** the value for the recursive-table. Store the results in the Queue.
103481 ** in which case this routine will be called recursively.
103498 ** The arrows in the diagram above represent the Select.pPrior pointer.
103500 ** pPrior will be the t2 query. p->op will be TK_UNION in this case.
103522 ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
103554 /* Make sure all SELECTs in the statement have the same number of elements
103555 ** in their result sets.
103682 /* Query flattening in sqlite3Select() might refill p->pOrderBy.
103695 /* Convert the data in the temporary table into whatever form
103817 int nCol; /* Number of columns in result set */
103863 ** The data to be output is contained in pIn->iSdst. There are
103870 ** If regPrev>0 then it is the first register in a vector that
103876 ** If the LIMIT found in p->iLimit is reached, jump immediately to
103933 /* If we are creating a set for an "expr IN (SELECT ...)" construct,
103951 /* If any row exist in the result set, record that fact and abort.
103961 ** store the results in the appropriate memory cell and break out
103972 /* The results are stored in a sequence of registers
103989 ** For SRT_Output, results are stored in a sequence of registers.
104025 ** co-routines. Then run the co-routines in parallel and merge the results
104026 ** into the output. In addition to the two coroutines (called selectA and
104035 ** appears only in B.)
104063 ** In the AltB, AeqB, and AgtB subroutines, an EOF on A following nextA
104068 ** Duplicate removal in the UNION, EXCEPT, and INTERSECT cases is handled
104138 int nOrderBy; /* Number of terms in the ORDER BY clause */
104312 ** are exhausted and only data in select B remains.
104326 ** are exhausted and only data in select A remains.
104384 /* Jump to the this point in order to terminate the query.
104418 ** a column in table number iTable with a copy of the iColumn-th
104419 ** entry in pEList. (But leave references to the ROWID column
104423 ** whose result set is defined by pEList appears as entry in the
104431 Expr *pExpr, /* Expr in which substitution occurs */
104460 ExprList *pList, /* List to scan and in which to make substitutes */
104472 Select *p, /* SELECT statement in which to make substitutions */
104507 ** subquery first and store the results in a temporary table, then
104602 ** appear as unmodified result columns in the outer query. But we
104603 ** have other optimizations in mind to deal with that case.
104613 ** recursive queries in multiSelect().
104616 ** In this routine, the "p" parameter is a pointer to the outer query.
104629 int iFrom, /* Index in p->pSrc->a[] of the inner subquery */
104636 Select *pSub1; /* Pointer to the rightmost select in sub-query */
104778 ** using UNION ALL operators. In this case N is the number of simple
104779 ** select statements in the compound sub-query.
104831 ** in the outer query.
104865 /* The following loop runs once for each term in a compound-subquery
104872 ** the cursor number for the original outer query FROM element in
104876 ** elements we are now copying in.
104882 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
104898 ** query. If the subquery has more than one element in its FROM clause,
104906 ** The outer query has 3 slots in its FROM clause. One slot of the
104909 ** slot is expanded to two slots in order to make space for the
104910 ** two elements in the FROM clause of the subquery.
104930 ** references to the iParent in the outer query.
104938 ** We look at every expression in the outer query and every place we see
105085 ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
105125 ** there are COLLATE terms in the ORDER BY.
105211 ** WITH clause will never be popped from the stack. In this case it
105212 ** should be freed along with the Parse object. In other cases, when
105237 ** occurs. If an error does occur, an error message is stored in the
105261 ** recursive reference to CTE pCte. Leave an error in pParse and return
105263 ** In this case, proceed. */
105333 pCte->zErr = "recursive reference in a subquery: %s";
105373 ** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
105374 ** defines FROM clause. When views appear in the FROM clause,
105384 ** (4) Scan the list of columns in the result set (pEList) looking
105386 ** If found, expand each "*" to be every column in every table
105387 ** and TABLE.* to be every column in TABLE.
105411 /* Make sure cursor numbers have been assigned to all entries in
105416 /* Look up every table named in the FROM clause of the select. If
105440 /* A sub-query in the FROM clause of a SELECT */
105455 /* An ordinary table or view name in the FROM clause */
105489 /* For every "*" that occurs in the column list, insert the names of
105490 ** all columns in all tables. And for every TABLE.* insert the names
105491 ** of all columns in TABLE. The parser inserted a special expression
105492 ** with the TK_ALL operator for each "*" that it found in the column list.
105494 ** each one to the list of all columns in all tables.
105510 ** in the result set and expand them one by one.
105582 ** for virtual tables), do not include it in the expanded
105595 /* In a NATURAL join, omit the join columns from the
105600 /* In a join with a USING clause, omit columns in the
105656 sqlite3ErrorMsg(pParse, "too many columns in result set");
105669 ** subquery in the parser tree.
105681 ** Expanding a SELECT statement is the first step in processing a
105732 /* A sub-query in the FROM clause of a SELECT */
105747 ** the Table structures of all FROM-clause subqueries in a
105771 ** * Wildcards "*" and "TABLE.*" in result sets are expanded.
105772 ** * Identifiers in expression are matched to tables.
105798 ** routine generates code that stores NULLs in all of those memory
105840 ** in the AggInfo structure.
105913 ** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
105962 ** Generate code for the SELECT statement given in the p argument.
105965 ** See comments in sqliteInt.h for further information.
105968 ** encountered, then an appropriate error message is left in
105971 ** This routine does NOT free the Select structure passed in. The
106016 /* If ORDER BY makes no difference in the output then neither does
106047 /* Generate code for all sub-queries in the FROM clause
106059 ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
106060 ** for example. In that case, do not regenerate the code to manifest
106168 ** can be rewritten as a GROUP BY. In other words, this:
106196 ** extracted in pre-sorted order. If that is the case, then the
106290 int groupBySort; /* Rows come from source in GROUP BY order */
106301 struct ExprList_item *pItem; /* For looping over expression in a list */
106318 ** in the correct order. It also may not - the GROUP BY may use a
106330 /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
106331 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
106399 /* Begin a loop that will extract all source rows in GROUP BY order.
106400 ** This might involve two separate loops with an OP_Sort in between, or
106402 ** in the right order to begin with.
106410 /* The optimizer is able to deliver rows in group by order so
106416 /* Rows are coming out in undetermined order. We have to push
106418 ** then loop over the sorting index in order to get the output
106419 ** in sorted order
106476 ** will naturally deliver rows in the order required by the ORDER BY
106489 /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
106492 ** from the previous row currently stored in a0, a1, a2...
106514 ** Changes in the GROUP BY are detected by the previous code
106517 ** This code copies current group by terms in b0,b1,b2,...
106519 ** and resets the aggregate accumulator registers in preparation
106536 VdbeComment((v, "indicate data in accumulator"));
106561 ** increments the iAbortFlag memory location before returning in
106620 ** (2013-10-03) Do not count the entries in a partial index.
106622 ** In practice the KeyInfo structure will not be used. It is only
106656 ** If it is, then ask the code in where.c to attempt to sort results
106658 ** If where.c is able to produce results sorted in this order, then
106671 ** + The optimizer code in where.c (the thing that decides which
106673 ** satisfying the 'ORDER BY' clause than it does in other cases.
106674 ** Refer to code and comments in where.c for details.
106864 ** The author disclaims copyright to this source code. In place of
106876 ** These routines are in a separate files so that they will not be linked
106892 int nRow; /* Number of rows in the result */
106893 int nColumn; /* Number of columns in the result */
106894 int nData; /* Slots used in azResult[]. (nRow+1)*nColumn */
106899 ** This routine is called once for each row in the result table. Its job
106900 ** is to fill in the TabResult structure appropriately, allocating new
106905 int need; /* Slots needed in p->azResult[] */
106909 /* Make sure there is enough space in p->azResult to hold everything
106972 ** The result that is written to ***pazResult is held in memory obtained
106981 int *pnRow, /* Write the number of rows in the result here */
107062 ** The author disclaims copyright to this source code. In place of
107095 ** All of the triggers on pTab that are in the same database as pTab
107097 ** triggers on pTab in the TEMP schema. This routine prepends all
107103 ** pTab as well as the triggers lised in pTab->pTrigger.
107134 ** in pParse->pNewTrigger. After the trigger actions have been parsed, the
107154 int iDb; /* The database to store the trigger in */
107172 /* Figure out the db that the trigger will be created in */
107196 ** then set iDb to 1 to create the trigger in the temporary database.
107222 ** drop so the trigger cannot be dropped. This results in an
107327 ** in order to complete the process of building the trigger.
107366 /* Make an entry in the sqlite_master table */
107408 ** The parser calls this routine when it finds a SELECT statement in
107457 IdList *pColumn, /* List of columns in pTableName to insert into */
107678 ** in pEList is of the format <id>=<expr>. If any of the entries
107679 ** in pEList have an <id> which matches an identifier in pIdList,
107698 ** least one of the columns in pChanges is being modified.
107704 ExprList *pChanges, /* Columns that change in an UPDATE statement */
107731 ** forming the SrcList. This prevents a trigger in one database from
107732 ** referring to a target in another database. An exception is when the
107733 ** trigger is in TEMP in which case it can refer to any other database it
107836 ** program. It is not used in production code, only for debugging.
107996 /* It may be that this trigger has already been coded (or is in the
107999 ** in the Parse.pTriggerPrg list. Search for such an entry. */
108016 ** function are the same as those described in the header function for
108032 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
108061 ** The reg argument is the address of the first in an array of registers
108063 ** in the trigger program. If N is the number of columns in table pTab
108080 ** Similarly, for ON INSERT triggers the values stored in the OLD.* registers
108098 int reg, /* The first in an array of registers (see above) */
108111 ** always defined. The trigger must be in the same schema as the table
108129 ** Triggers may access values stored in the old.* or new.* pseudo-table.
108138 ** are more than 32 columns in the table, and at least one of the columns
108149 ** included in the returned mask if the TRIGGER_BEFORE bit is set in the
108151 ** included in the returned mask if the TRIGGER_AFTER bit is set in tr_tm.
108189 ** The author disclaims copyright to this source code. In place of
108207 ExprList *pChanges, /* The columns to change in the UPDATE statement */
108209 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
108220 ** The default value of a column is specified by a DEFAULT clause in the
108223 ** command. If the latter, then the row-records in the table btree on disk
108242 ** stored in place of an 8-byte floating point value in order to save
108275 SrcList *pTabList, /* The table in which we should change things */
108293 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
108297 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
108298 u8 chngRowid; /* Rowid changed in a normal table */
108302 NameContext sNC; /* The name-context to resolve expressions in */
108316 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
108323 int regNew; /* Content of the NEW.* table in triggers */
108324 int regOld = 0; /* Content of OLD.* table in triggers */
108368 ** allocate enough space, just in case.
108397 /* Resolve the column names in all the expressions of the
108399 ** for each column to be updated in the pChanges array. For each
108457 /* There is one entry in the aRegIdx[] array for each index on the table
108458 ** being updated. Fill in aRegIdx[] with a register number that will hold
108522 /* Resolve the column names in all the expressions in the
108702 ** a new.* reference in a trigger program.
108721 /* The row-trigger may have deleted the row being updated. In this
108724 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
108738 ** registers in case this has happened.
108789 ** handle rows (possibly in other tables) that refer via a foreign key
108855 ** thely may interfere with compilation of other functions in this file
108856 ** (or in another file, if this file becomes part of the amalgamation). */
108873 ** (C) The content of every column in the row.
108875 ** Then we loop over this ephemeral table and for each row in
108880 ** (note1) Actually, if we know in advance that (A) is always the same
108888 ExprList *pChanges, /* The columns to change in the UPDATE statement */
108890 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
108901 int iReg; /* First register in set passed to OP_VUpdate */
108965 ** The author disclaims copyright to this source code. In place of
108975 ** Most of the code in this file may be omitted by defining the
108982 ** text of the error message in *pzErrMsg. Return the result code.
109036 ** in PostgreSQL. The VACUUM command works as follows:
109051 ** Two writes per page are required in step (3) because the original
109059 ** And a power loss in between deleting the original and renaming the
109094 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
109191 ** in the temporary database.
109208 /* Loop through the tables in the main database. For each, do
109260 /* This array determines which meta meta values are preserved in the
109279 /* GetMeta() and UpdateMeta() cannot fail in this context because
109335 ** The author disclaims copyright to this source code. In place of
109365 sqlite3 *db, /* Database in which module is registered */
109409 sqlite3 *db, /* Database in which module is registered */
109421 sqlite3 *db, /* Database in which module is registered */
109477 ** Table p is a virtual table. This function moves all elements in the
109481 ** connection db is left in the p->pVTable list.
109492 ** database connection that may have an entry in the p->pVTable list.
109518 ** list in p->pVTab. It also decrements the VTable ref count. This is
109542 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
109549 ** 1) By this function. In this case, all BtShared mutexes and the mutex
109553 ** the sqlite3.pDisconnect list. In
109554 ** associated with the database the virtual table is stored in is held
109555 ** or, if the virtual table is stored in a non-sharable database, then
109589 ** in the list are moved to the sqlite3.pDisconnect list of the associated
109641 int iDb; /* The database the table is being created in */
109676 ** in pParse->zArg[] and appends it to the list of arguments on the
109677 ** virtual table currently under construction in pParse->pTable.
109702 ** first time (in other words if the virtual table is actually being
109705 ** in the sqlite_master table.
109719 /* A slot for the record has already been allocated in the
109724 ** entry in the sqlite_master table tht was created for this vtab
109749 /* If we are rereading the sqlite_master table create the in-memory
109751 ** the first time the virtual table is used in an SQL statement. This
109772 ** of an argument to the module name in a CREATE VIRTUAL TABLE statement.
109782 ** in an argument to the module name in a CREATE VIRTUAL TABLE statement.
109909 ** and an error left in pParse.
109977 ** of the virtual table named zTab in database iDb.
109981 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
110083 ** of the virtual table named zTab in database iDb. This occurs
110113 ** of each of the virtual tables in the sqlite3.aVTrans array. The method
110115 ** the offset of the method to call in the sqlite3_module structure.
110140 ** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
110144 ** If an error message is available, leave it in p->zErrMsg.
110165 ** Invoke the xRollback method of all virtual tables in the
110174 ** Invoke the xCommit method of all virtual tables in the
110188 ** in the sqlite3.aVTrans array.
110197 ** virtual module tables in this case, so return SQLITE_LOCKED.
110210 /* If pVtab is already in the aVTrans array, return early */
110281 ** If pExpr is a column in a virtual table, then let the virtual
110308 /* Check to see the left operand is a column in a virtual table */
110352 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
110354 ** array if it is missing. If pTab is already in the array, this routine
110377 ** Return the ON CONFLICT resolution mode in effect for the virtual
110378 ** table update operation currently in progress.
110434 ** The author disclaims copyright to this source code. In place of
110449 /************** Include whereInt.h in the middle of where.c ******************/
110454 ** The author disclaims copyright to this source code. In place of
110464 ** planner logic in "where.c". These definitions are broken out into
110499 ** loop in WHERE clause.
110507 ** each term in the FROM clause (which is to say, for each of the
110517 int addrNxt; /* Jump here to start the next IN combination */
110522 u8 iFrom; /* Which entry in the FROM clause */
110527 int nIn; /* Number of entries in aInLoop[] */
110529 int iCur; /* The VDBE cursor used by this IN operator */
110530 int addrInTop; /* Top of the IN loop */
110531 u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
110532 } *aInLoop; /* Information about each nested IN operator */
110533 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
110560 u8 iTab; /* Position in FROM clause of table for this loop */
110580 u16 nLTerm; /* Number of entries in aLTerm[] */
110585 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
110590 ** subquery on one operand of an OR operator in the WHERE clause.
110617 ** Think of each WhereLoop object as a node in a graph with arcs
110628 ** number of nodes in the FROM clause. The best (lowest cost) WherePath
110632 Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
110667 ** In this second case, wtFlag has the TERM_ORINFO bit set and eOperator==WO_OR
110671 ** If a term in the WHERE clause does not match either of the two previous
110674 ** but no other fields in the WhereTerm object are meaningful.
110678 ** cursor number into bits and the translated bit is stored in the prereq
110679 ** fields. The translation is used in order to maximize the number of
110680 ** bits that will fit in a Bitmask. The VDBE cursor numbers might be
110684 ** beginning with 0 in order to make the best possible use of the available
110685 ** bits in the Bitmask. So, in the example above, the cursor numbers
110688 ** The number of terms in a join is limited by the number of bits
110689 ** in prereqRight and prereqAll. The default is 64 bits, hence SQLite
110695 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
110697 int leftColumn; /* Column number of X in "X <op> <expr>" */
110728 ** terms in the WHERE clause that are useful to the query planner.
110735 unsigned char nEquiv; /* Number of entries in aEquiv[] */
110736 unsigned char iEquiv; /* Next unused slot in aEquiv[] */
110759 int nSlot; /* Number of entries in a[] */
110774 Bitmask indexable; /* Bitmask of all indexable tables in the clause */
110787 ** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
110789 ** The VDBE cursor numbers are small integers contained in
110792 ** contain gaps in the numbering sequence. But we want to make maximum
110793 ** use of the bits in our bitmasks. This structure provides a mapping
110804 ** Note that the mapping is not necessarily ordered. In the example
110828 int nRecValid; /* Number of valid fields currently in pRec */
110844 SrcList *pTabList; /* List of tables in the join */
110864 WhereLevel a[1]; /* Information about each nest loop in WHERE */
110890 ** These are definitions of bits in the WhereLoop.wsFlags field.
110891 ** The particular combination of bits in each WhereLoop help to
110896 #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
110906 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
110914 /************** Continuing where we left off in where.c **********************/
110932 ** Return TRUE if the WHERE clause returns rows in ORDER BY order.
110940 ** Return the VDBE address or label to jump to in order to continue
110949 ** Return the VDBE address or label to jump to in order to break
111083 ** The index in pWC->a[] of the new WhereTerm is returned on success.
111085 ** allocation error. The memory allocation failure will be recorded in
111134 ** This routine identifies subexpressions in the WHERE clause where
111136 ** operator specified in the op parameter. The WhereClause structure
111143 ** The original WHERE clause in pExpr is unaltered. All this routine
111146 ** In the previous sentence and in the diagram, "slot[]" refers to
111168 ** iCursor is not in the set.
111184 ** There is one cursor per table in the FROM clause. The number of
111185 ** tables in the FROM clause is limited by a test early in the
111196 ** a bitmask indicating which tables are used in that expression
111251 ** "=", "<", ">", "<=", ">=", "IN", and "IS NULL"
111458 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
111463 ** The term returned might by Y=<expr> if there is another constraint in
111465 ** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
111467 ** taking up two slots in aEquiv[]. The first slot is for the cursor number
111468 ** and the second is for the column number. There are 22 slots in aEquiv[]
111473 ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
111474 ** then try for the one with no dependencies on <expr> - in other words where
111476 ** the form "X <op> Y" where Y is a column in another table if no terms of
111509 ** Call exprAnalyze on all terms in a WHERE clause.
111527 ** In order for the operator to be optimizible, the RHS must be a string
111534 int *pisComplete, /* True if the only wildcard is % in the last character */
111540 int c; /* One character in z[] */
111648 ** If the pBase expression originated in the ON or USING clause of
111661 ** subterms. So in:
111666 ** This routine analyzes terms such as the middle term in the above example.
111686 ** a single table T (as shown in example B above) then create a new virtual
111687 ** term that is an equivalent IN expression. In other words, if the term
111694 ** x IN (expr1,expr2,expr3)
111705 ** <op> is one of "=", "<", "<=", ">", ">=", "IS NULL", or "IN".
111719 ** always prefer case 1, so in that case we pretend that case 2 is not
111728 ** to "bitmap indices" in other database engines.
111754 ** stored in a WhereClause structure containing within the WhereOrInfo
111837 ** IN operator because one or more terms in the OR clause contain
111838 ** something other than == on a column in the single table. The 1-bit
111844 ** might be possible to form an IN operator with either table1.column
111852 int okToChngToIN = 0; /* True if the conversion to IN is valid */
111853 int iColumn = -1; /* Column index on lhs of IN operator */
111858 ** other of the == operator in every subterm. That table and column
111859 ** will be recorded in iCursor and iColumn. There might not be any
111875 /* This term must be of the form t1.a==t2.b where t2 is in the
111899 ** table and column is common to every term in the OR clause */
111925 ** case 1. In that case, construct a new virtual term that is
111926 ** pTerm converted into an IN operator.
111930 ExprList *pList = 0; /* The RHS of the IN operator */
111931 Expr *pLeft = 0; /* The LHS of the IN operator */
111932 Expr *pNew; /* The complete IN operator */
111968 ** "pExpr" field filled in. The job of this routine is to analyze the
112290 ** If such an expression is found, its index in pList->a[] is returned. If
112337 /* If there is more than one table or sub-select in the FROM clause of
112358 ** 2. All of the columns in the index are either part of the pDistinct
112448 Bitmask notReady /* Tables in outer loops of the join */
112475 int nKeyCol; /* Number of columns in the constructed index */
112486 int mxBitCol; /* Maximum column in pSrc->colUsed */
112654 /* If the ORDER BY clause contains only columns in the current
112682 ** changing them. We have to do some funky casting in order to
112709 /* The direct assignment in the previous line is possible only because
112734 ** comes in as the 3rd argument to this function.
112779 ** Estimate the location of a particular key among all keys in an
112780 ** index. Store the results in aStat as follows:
112795 int iCol; /* Index of required stats in anEq[] etc. */
112911 ** extracted from pLower and pUpper with the corresponding column in each
112983 ** using the method described in the header comment for this function. */
113016 ** If either of the upper or lower bound is not present, then NULL is passed in
113019 ** The value in (pBuilder->pNew->u.btree.nEq) is the index of the index
113036 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
113039 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
113068 /* Variable iLower will be set to the estimate of the number of rows in
113072 ** columns of the index, and $L is the value in pLower.
113076 ** range is $P. Due to a quirk in the way whereKeyStats() works, even
113099 ** have been requested when testing key $P in whereEqualScanEst(). */
113167 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
113182 ** an equality constraint x=VALUE and where that VALUE occurs in
113195 ** in the pParse structure.
113200 Expr *pExpr, /* Expression for VALUE in the x=VALUE constraint */
113248 ** an IN constraint where the right-hand side of the IN operator
113251 ** WHERE x IN (1,2,3,4)
113260 ** in the pParse structure.
113265 ExprList *pList, /* The value list on the RHS of "x IN (v1,v2,v3,...)" */
113287 WHERETRACE(0x10,("IN row estimate: est=%g\n", nRowEst));
113295 ** Disable a term in the WHERE clause. Except, do not disable the term
113296 ** if it controls a LEFT OUTER JOIN and it did not originate in the ON
113299 ** Consider the term t2.z='ok' in the following queries:
113305 ** The t2.z='ok' is disabled in the in (2) because it originates
113306 ** in the ON clause. The term is disabled in (3) because it is not part
113307 ** of a LEFT OUTER JOIN. In (1), the term is not disabled.
113309 ** Disabling a term causes that term to not be tested in the inner loop
113311 ** by indices, we disable them to prevent redundant tests in the inner
113314 ** as we can without disabling too much. If we disabled in (1), we'd get
113338 ** beginning and end of zAff are ignored. If all entries in zAff are
113375 ** term can be either X=expr or X IN (...). pTerm is the term to be
113378 ** The current value for the constraint is left in register iReg.
113381 ** result is left on the stack. For constraints of the form X IN (...)
113389 int bRev, /* True for reverse-order IN operations */
113390 int iTarget /* Attempt to leave results in this register */
113430 if( pLevel->u.in.nIn==0 ){
113433 pLevel->u.in.nIn++;
113434 pLevel->u.in.aInLoop =
113435 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
113436 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
113437 pIn = pLevel->u.in.aInLoop;
113439 pIn += pLevel->u.in.nIn - 1;
113449 pLevel->u.in.nIn = 0;
113458 ** Generate code that will evaluate all == and IN constraints for an
113462 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
113463 ** The index has as many as three equality constraints, but in this
113466 ** a==5 and b IN (1,2,3). The current values for a and b will be stored
113467 ** in consecutive registers and the index of the first register is returned.
113469 ** In the example above nEq==2. But this subroutine works for any value
113475 ** are == or IN and are covered by the nEq. nExtraReg is 1 if there is
113476 ** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
113480 ** the index of the first memory cell in that range. The code that
113483 ** key value of the loop. If one or more IN operators appear, then
113489 ** sqlite3DbMalloc(). Except, entries in the copy of the string associated
113496 ** In the example above, the index on t1(a) has TEXT affinity. But since
113499 ** a key to search the index. Hence the first byte in the returned affinity
113500 ** string in this example would be set to SQLITE_AFF_NONE.
113505 int bRev, /* Reverse the order of IN operators */
113509 u16 nEq; /* The number of == or IN constraints to code */
113624 ** of the subset of table rows scanned by the strategy in the form of an
113683 ** record is added to the output to describe the table scan strategy in
113772 ** Generate code for the start of the iLevel-th loop in the WHERE clause
113782 int addrNxt; /* Where to jump to continue with the next IN case */
113784 int bRev; /* True if we need to scan in reverse order */
113795 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
113817 ** When there is an IN operator, we also have a "addrNxt" label that
113818 ** means to continue with the next IN value combination. When
113819 ** there are no IN operators in the constraints, the "addrNxt" label
113893 ** we reference multiple rows using a "rowid IN (...)"
114007 ** terms ("==" or "IN" operators) that refer to the N
114012 ** use the "==" and "IN" operators. For example, if the
114032 ** constraints but an index is selected anyway, in order
114051 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
114076 ** should not have a NULL value stored in 'x'. If column 'x' is
114077 ** the first one after the nEq equality constraints in the index,
114112 /* Generate code to evaluate all constraint terms using == or IN
114113 ** and store the values of those terms in an array of registers
114276 ** In the example, there are three indexed terms connected by OR.
114279 ** Null 1 # Zero the rowset in reg 1
114294 ** Null 1 # Zero the rowset in reg 1
114332 /* Set up a new SrcList in pOrTab containing the table being scanned
114333 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
114334 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
114356 ** capable of holding primary keys in the case of a WITHOUT ROWID.
114360 ** is required in a few obscure LEFT JOIN cases where control jumps
114361 ** over the top of the loop into the body of it. In this case the
114382 ** That way, terms in y that are factored into the disjunction will
114386 ** the "interesting" terms of z - terms that did not originate in the
114391 in the ON clause of a LEFT JOIN.
114440 ** row will be skipped in subsequent sub-WHERE clauses.
114462 ** the row has already been included in the result set and
114468 ** is zero, assume that the key cannot already be present in
114506 ** If the call to sqlite3WhereBegin() above resulted in a scan that
114554 /* Tables marked isRecursive have only a single row that is stored in
114704 ** expressions in the WhereLoop.aLTerm[] array.
114869 ** This adjustment is omitted for SKIPSCAN loops. In a SKIPSCAN loop, the
114871 ** clause terms covered, since some of the first nLTerm entries in aLTerm[]
114902 ** Search the list of WhereLoops in *ppPrev looking for one that can be
114906 ** pTemplate, in other words if pTemplate does not belong on the list.
114926 /* In the current implementation, the rSetup value is either zero
114988 ** information is gathered in the pBuilder->pOrSet object. This special
115100 ** In the current implementation, the first extra WHERE clause term reduces
115154 LogEst nInMul /* log(Number of iterations due to IN) */
115169 int iCol; /* Index of the column in the table */
115204 ** number of repeats in the left-most terms is at least 18.
115208 ** contains fewer than 2^17 rows we assume otherwise in other parts of
115232 LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
115261 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
115264 /* "x IN (value, value, ...)" */
115268 ** changes "x IN (?)" into "x=?". */
115299 ** values of nIn and nInMul. In other words, assuming that all
115300 ** "x IN(...)" terms are replaced with "x = ?". This block updates
115356 /* Set rCostIdx to the cost of visiting selected rows in index. Add
115359 ** visiting the rows in the main table. */
115399 ** Return True if it is possible that pIndex might be useful in
115400 ** implementing the ORDER BY clause in pBuilder.
115403 ** if there is no way for pIndex to be useful in implementing that
115447 ** in the current query. Return true if it can be and false if not.
115483 ** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when
115484 ** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans.
115489 ** log(nRow) factor is omitted from a non-covering index scan in order to
115490 ** bias the scoring in favor of using an index, since the worst-case
115509 LogEst rSize; /* number of rows in the table */
115510 LogEst rLogSize; /* Logarithm of the number of rows in the table */
115528 /* There is no INDEXED BY clause. Create a fake Index object in local
115530 ** fake index the first in a chain of Index objects with all of the real
115577 ** approximately 7*N*log2(N) where N is the number of rows in
115581 /* TUNING: Each index lookup yields 20 rows in the table. This
115702 int seenIn = 0; /* True if an IN operator is seen */
115704 int iPhase; /* 0: const w/o IN, 1: const, 2: no IN, 2: IN */
115741 case 0: /* Constants without IN operator */
115752 case 1: /* Constants with IN operators */
115756 case 2: /* Variables without IN */
115760 default: /* Variables with IN */
115807 /* Do not attempt to use an IN constraint if the virtual table
115810 ** repeated in the output. */
115813 /* A virtual table that is constrained by an IN clause may not
115814 ** consume the ORDER BY clause because (1) the order of IN terms
115816 ** (2) Multiple outputs from a single IN value will not merge
115974 /* Loop over the tables in the join, from left to right */
116001 ** parameters) to see if it outputs rows in the requested ORDER BY
116011 ** and DISTINCT do not require rows to appear in any particular order as long
116013 ** the pOrderBy terms can be matched in any order. With ORDER BY, the
116014 ** pOrderBy terms must be matched in strict left-to-right order.
116021 u16 nLoop, /* Number of entries in pPath->aLoop[] */
116023 Bitmask *pRevMask /* OUT: Mask of WhereLoops to run in reverse order */
116031 u16 nKeyCol; /* Number of key columns in pIndex */
116032 u16 nColumn; /* Total number of ordered columns in the index */
116033 u16 nOrderBy; /* Number terms in the ORDER BY clause */
116034 int iLoop; /* Index of WhereLoop in pPath being processed */
116055 ** Every one-row WhereLoop will have the WHERE_ONEROW bit set in wsFlags.
116058 ** that WhereLoop that are in the ORDER BY clause are different for every
116060 ** order-distinct. A WhereLoop that has no columns in the ORDER BY clause
116067 ** rowid appears in the ORDER BY clause, the corresponding WhereLoop is
116090 /* Mark off any ORDER BY term X that is a column in the table of
116091 ** the current loop for which there is term in the WHERE
116132 IN.
116151 /* Get the column number in the table (iColumn) and sort order
116197 /* Make sure the sort order is compatible in an ORDER BY clause.
116257 ** If the WHERE_GROUPBY flag is set in the mask passed to sqlite3WhereBegin(),
116262 ** Normally, in this case it is not possible for the caller to determine
116263 ** whether or not the rows are really being delivered in sorted order, or
116264 ** just in some other order that provides the required grouping. However,
116267 ** true if the rows really will be sorted in the specified order, or false
116299 ** nOrderby columns and that the first nSorted columns are already in
116342 ** will be nRowEst (in the 10*log2 representation). Or, ignore sorting
116350 int nLoop; /* Number of terms in the join */
116359 int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
116380 /* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
116408 ** the ORDER BY clause are already in order, where X is the array
116425 /* If nLoop is zero, then there are no FROM terms in the query. Since
116426 ** in this case the query may return a maximum of one row, the results
116427 ** are already in the requested order. Set isOrdered to nOrderBy to
116504 ** paths currently in the best-so-far buffer. So discard
116769 ** in order to complete the WHERE clause processing.
116773 ** The basic idea is to do a nested loop, one loop for each table in
116775 ** same as a SELECT with only a single table in the FROM clause.) For
116782 ** foreach row1 in t1 do \ Code generated
116783 ** foreach row2 in t2 do |-- by sqlite3WhereBegin()
116784 ** foreach row3 in t3 do /
116790 ** Note that the loops might not be nested in the order in which they
116791 ** appear in the FROM clause if a different order is better able to make
116792 ** use of indices. Note also that when the IN operator appears in
116793 ** the WHERE clause, it might result in additional nested loops for
116794 ** scanning through all values on the right-hand side of the IN.
116802 ** in pTabList pointing at their appropriate entries. The [...] code
116808 ** the tables have indices and there are terms in the WHERE clause that
116814 ** make it to the "..." in the middle of the loop. After each "foreach",
116815 ** terms of the WHERE clause that use only terms in that loop and outer
116824 ** foreach row1 in t1 do
116826 ** foreach row2 in t2 do
116840 ** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
116848 ** the first cursor in an array of cursors for all indices. iIdxCur should
116858 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
116862 int nTabList; /* Number of elements in pTabList */
116868 WhereLevel *pLevel; /* A single level in pWInfo->a[] */
116890 /* The number of tables in the FROM clause is limited by the number of
116891 ** bits in a Bitmask
116895 sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS);
116899 /* This function normally generates a nested loop for all tables in
116901 ** only generate code for the first table in pTabList and assume that
116966 /* Assign a bit from the bitmask to every term in the FROM clause.
116977 in
117142 /* Open all tables in the pTabList and any indices selected for
117296 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
117300 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
117308 sqlite3DbFree(db, pLevel->u.in.aInLoop);
117354 ** the co-routine into OP_SCopy of result contained in a register.
117399 ** from the index instead of from the table where possible. In some cases
117403 ** Calls to the code generator in between sqlite3WhereBegin and
117455 ** macros to disable tests that are needed in the case of a general
117456 ** LALR(1) grammar but which are always false in the
117460 ** in the input grammar file. */
117465 ** Disable all error recovery processing in the parser push-down
117582 /* Next is all token values, in a form suitable for use by makeheaders.
117590 ** Each symbol here is a terminal symbol in the grammar.
117605 ** number is used to fill in empty slots of the hash
117618 ** which is sqlite3ParserTOKENTYPE. The entry in the union
117627 ** YYNRULE the number of rules in the grammar
117676 ** Applications can choose to define yytestcase() in the %include section
117677 ** to a macro that can assist in verifying code coverage. For production
117704 ** slots in the yy_action[] table.
117713 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
117718 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
117719 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
117722 ** The following are the tables generated in this section:
117725 ** yy_lookahead[] A table containing the lookahead for each entry in
118197 ** appears in the grammar, then ID becomes a fallback token for X, Y,
118283 ** (In other words, the "major" token.)
118286 ** the information used by the action routines in the grammar.
118298 /* The state of the parser is completely contained in an instance of
118301 int yyidx; /* Index of top element in stack */
118370 "AND", "IS", "BETWEEN", "IN",
118644 /* 221 */ "in_op ::= IN",
118645 /* 222 */ "in_op ::= NOT IN",
118786 ** A pointer to a parser. This pointer is used in subsequent calls
118917 ** empty in SQLite. */
118949 /* In SQLite, we never try to destroy a parser that was not successfully
118950 ** created in the first place. */
119094 int yyNewState, /* The new state to shift in */
119095 int yyMajor, /* The major token to shift in */
119096 YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */
119140 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
119497 ** in some cases when it is copied into the stack after the following
119507 ** from wireshark this week. Clearly they are stressing Lemon in ways
119590 case 221: /* in_op ::= IN */ yytestcase(yyruleno==221);
119599 case 222: /* in_op ::= NOT IN */ yytestcase(yyruleno==222);
119841 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
120161 /* When doing a nested parse, one can include terms in an expression
120163 ** in the virtual machine. #N is the N-th register. */
120304 ** expr1 IN ()
120305 ** expr1 NOT IN ()
120315 ** expr1 IN (?1)
120316 ** expr1 NOT IN (?2)
120327 ** the semantics would be subtly different from IN or NOT IN.
120741 ** onto the stack here, and skip the stack overflow test in yy_shift().
120820 ** user wants (and specified in the grammar) and is available for
120993 ** The author disclaims copyright to this source code. In place of
121048 ** mkkeywordhash.h, located in the tool subdirectory of the distribution.
121053 /************** Include keywordhash.h in the middle of tokenize.c ************/
121057 ** The code in this file has been automatically generated by
121061 ** The code in this file implements a function that determines whether
121070 /* zText[] encodes 834 bytes of keywords in 554 bytes */
121289 testcase( i==93 ); /* IN */
121331 /************** Continuing where we left off in tokenize.c *******************/
121335 ** If X is a character that can be used in an identifier then
121339 ** allowed in an identifier. For 7-bit characters,
121345 ** Ticket #1066. the SQL standard does not allow '$' in the
121347 ** SQLite will allow '$' in identifiers for compatibility.
121375 ** Store the token type in *tokenType before returning.
121643 ** passed in. An SQLITE_ status code is returned. If an error occurs
121763 ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
121794 ** The author disclaims copyright to this source code. In place of
121812 ** This is defined in tokenize.c. We just have to import the definition.
121841 ** Return TRUE if the given SQL string ends in a semicolon.
121852 ** returns 1 if it ends in the START state and 0 if it ends
121853 ** in any other state.
121855 ** (2) NORMAL We are in the middle of statement which ends with a single
121865 ** (5) TRIGGER We are in the middle of a trigger definition that must be
121868 ** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at
121894 u8 state = 0; /* Current state, using numbers defined in header comment */
121962 case '[': { /* Microsoft-style identifiers in [...] */
122079 ** The author disclaims copyright to this source code. In place of
122087 ** Main file for the SQLite library. The routines in this file
122088 ** implement the programmer interface to the library. Routines in
122094 /************** Include fts3.h in the middle of main.c ***********************/
122099 ** The author disclaims copyright to this source code. In place of
122123 /************** Continuing where we left off in main.c ***********************/
122126 /************** Include rtree.h in the middle of main.c **********************/
122131 ** The author disclaims copyright to this source code. In place of
122155 /************** Continuing where we left off in main.c ***********************/
122158 /************** Include sqliteicu.h in the middle of main.c ******************/
122163 ** The author disclaims copyright to this source code. In place of
122188 /************** Continuing where we left off in main.c ***********************/
122340 ** the pInitMutex mutex. Return an error in either case. */
122355 ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
122430 ** while any part of SQLite is otherwise in use in any thread. This
122459 ** this function resulted in the heap subsystem actually being shutdown.
122487 ** the SQLite library is in use. */
122493 /* Mutex configuration options are only available in a threadsafe
122694 ** The sz parameter is the number of bytes in each lookaside slot.
122799 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
122871 ** Another built-in collating sequence: NOCASE.
122875 ** extends only to the 26 characters used in the English language.
122901 ** Return the number of changes in the most recent call to sqlite3_exec().
123006 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
123108 /* Tell the code in notify.c that the connection no longer holds any
123172 ** any open cursors are invalidated ("tripped" - as in "tripping a circuit
123183 ** This is important in case the transaction being rolled back has
123185 ** here, then another shared-cache connection might sneak in between
123187 ** corruption reports in some cases. */
123221 ** specified in the argument.
123329 ** Return a static string that describes the kind of error specified in the
123382 ** an integer number of milliseconds passed in as the first
123513 ** that if a malloc() fails in sqlite3_create_function(), an error code
123700 ** A global function must exist in order for name resolution to work
123819 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
123841 ** more frames in the log file. Passing zero or a negative value as the
123892 int *pnLog, /* OUT: Size of WAL log in frames */
123901 /* Initialize the output variables to -1 in case an error occurs. */
123942 ** not currently open in WAL mode.
124115 ** Return a string that describes the kind of error specified in the
124129 HashElem *k; /* For looping over tables in pDb */
124130 Table *pTab; /* A table in the database */
124229 ** initializer must be kept in sync with the SQLITE_LIMIT_*
124230 ** #defines in sqlite3.h.
124297 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
124337 ** the default flags to open the database handle with. The value stored in
124341 ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
124355 unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */
124423 /* This branch is taken when "%00" appears within the URI. In this
124424 ** case we ignore all text in the remainder of the path, name or
124584 /* Only allow sensible combinations of bits in the flags argument.
124587 ** assert() statements in deeper layers. Sensible combinations
124620 ** dealt with in the previous code block. Besides these, the only
124739 /* Register all built-in functions, but do not attempt to read the
124860 char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
125002 ** Test to see whether or not the database connection is in autocommit
125016 ** 1. Serve as a convenient place to set a breakpoint in a debugger
125059 ** See comment in sqlite3.h (sqlite.h.in) for details.
125093 /* Locate the table in question */
125120 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
125179 /* This function works in milliseconds, but the underlying OsSleep()
125321 ** Set the PENDING byte to the value in the argument, if X>0.
125325 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
125327 ** while any database connection is open results in undefined and
125430 ** is obtained in every case.
125444 ** This test feature is only available in the amalgamation since
125445 ** the SQLITE_N_KEYWORD macro is not defined in this file if SQLite
125504 ** testing causes certain assert() statements in the code to be activated
125629 ** The author disclaims copyright to this source code. In place of
125670 ** 1) Each entry in the list has a non-NULL value for either
125673 ** 2) All entries in the list that share a common value for
125676 ** 3) If the argument db is not NULL, then none of the entries in the
125755 ** (call it pOther) in the same process was busy using the same shared
125789 ** blocking transaction. In either case, invoke the notify callback
125835 ** This function loops through each entry in the blocked connections
125851 int nArg = 0; /* Number of entries in aArg[] */
125860 /* This loop runs once for each entry in the blocked-connections list. */
125962 ** The author disclaims copyright to this source code. In place of
125975 ** The code in this file is only compiled if:
125978 ** (in which case SQLITE_CORE is not defined), or
125981 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
125984 /* The full-text index is stored in a series of b+tree (-like)
125986 ** structures are like b+trees in layout, but are constructed from the
125987 ** bottom up in optimal fashion and are not updatable. Since trees
125994 ** varint. We encode variable-length integers in little-endian order
126006 ** This is similar in concept to how sqlite encodes "varints" but
126008 ** are are limited to 9 bytes in length whereas FTS3 varints are
126009 ** little-endian and can be up to 10 bytes in length (in theory).
126045 ** Here, array { X } means zero or more occurrences of X, adjacent in
126046 ** memory. A "position" is an index of a token in the token stream
126048 ** in the same logical place as the position element, and act as sentinals
126057 ** The 123 value is the first docid. For column zero in this document
126095 ** Here, array { X } means zero or more occurrences of X, adjacent in
126098 ** Leaf nodes are broken into blocks which are stored contiguously in
126099 ** the %_segments table in sorted order. This means that when the end
126100 ** of a node is reached, the next term is in the node with the next
126105 ** larger than STANDALONE_MIN (default 1024) is placed in a standalone
126141 ** means zero or more occurrences of X, adjacent in memory.
126163 ** The segment directory in table %_segdir stores meta-information for
126175 ** The meta-information in the segment directory is:
126190 ** merged in batches. Each increase in level represents exponentially
126201 ** A segment merge traverses all segments at a given level in
126203 ** leaf nodes are written in to the %_segments table in order, this
126211 ** a tiny bit slower (perhaps due to more overhead in merge-time
126249 /************** Include fts3Int.h in the middle of fts3.c ********************/
126254 ** The author disclaims copyright to this source code. In place of
126287 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
126325 ** implementation. The xCreate() function in turn returns an
126347 ** Create a new tokenizer. The values in the argv[] array are the
126401 ** of this buffer in bytes. The input text that generated the token is
126402 ** identified by the byte offsets returned in *piStartOffset and
126404 ** byte of the token in the input buffer. *piEndOffset should be set
126405 ** to the index of the first byte just past the end of the token in
126419 int *piStartOffset, /* OUT: Byte offset of token in input buffer */
126420 int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */
126451 /************** Continuing where we left off in fts3Int.h ********************/
126452 /************** Include fts3_hash.h in the middle of fts3Int.h ***************/
126457 ** The author disclaims copyright to this source code. In place of
126466 ** used in SQLite. We've modified it slightly to serve as a standalone
126488 int count; /* Number of entries in this table */
126490 int htsize; /* Number of buckets in the hash table */
126497 /* Each element in the hash table is an instance of the following
126504 Fts3HashElem *next, *prev; /* Next and previous elements in the table */
126514 ** is respected in comparisons.
126561 ** Number of entries in a hash table
126568 /************** Continuing where we left off in fts3Int.h ********************/
126590 ** This is the maximum amount of data (in bytes) to store in the
126592 ** populated as documents are inserted/updated/deleted in a transaction
126600 ** Macro to return the number of elements in an array. SQLite has a
126602 ** a collision when building an amalgamation with built-in FTS3.
126622 ** in the document set and zero or more prefix indexes. All indexes are stored
126623 ** as one or more b+-trees in the %_segments and %_segdir tables.
126626 ** value stored in the "%_segdir.level" column. Given this value L, the index
126627 ** that the b+-tree belongs to is (L<<10). In other words, all b+-trees with
126631 ** It is considered impossible for an index to use more than 1024 levels. In
126735 int nColumn; /* number of named columns in virtual table */
126756 u8 bDescIdx; /* True if doclists are in reverse order */
126766 ** The current language id is stored in variable iPrevLangid.
126769 ** there is an entry in the aIndex[] array. Index 0 is an index of all the
126770 ** terms that appear in the document set. Each subsequent index in aIndex[]
126816 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
126819 int nPhrase; /* Number of matchable phrases in query */
126825 u8 bDesc; /* True to sort in descending order */
126827 int nRowAvg; /* Average size of database rows, in pages */
126828 sqlite3_int64 nDoc; /* Documents in table */
126831 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
126833 int nMatchinfo; /* Number of elements in aMatchinfo[] */
126845 ** of the column to be searched. For example, in
126872 int nAll; /* Size of a[] in bytes */
126882 ** A "phrase" is a sequence of one or more tokens that must match in
126884 ** For a sequence of tokens contained in double-quotes (i.e. "one two three")
126885 ** nToken will be the number of tokens in the string.
126889 int n; /* Number of bytes in buffer z */
126894 ** parsed (by code in fts3_expr.c). Below this point the variables are
126909 int nToken; /* Number of tokens in the phrase */
126911 Fts3PhraseToken aToken[1]; /* One entry for each token in the phrase */
126919 ** of this phrase query in FTS3 doclist format. As usual, the initial
126920 ** "Length" field found in doclists stored on disk is omitted from this
126925 ** where nCol is the number of columns in the queried FTS table. The array
126954 ** four values is in order of precedence when parsing expressions. For
127036 char *aBuffer; /* Buffer to merge doclists in */
127037 int nBuffer; /* Allocated size of aBuffer[] in bytes */
127048 int nTerm; /* Size of zTerm in bytes */
127050 int nDoclist; /* Size of aDoclist[] in bytes */
127126 /************** Continuing where we left off in fts3.c ***********************/
127161 q[-1] &= 0x7f; /* turn off high bit in final byte */
127176 ** The value is stored in *v.
127235 ** the quote characters. The conversion is done in-place. If the
127300 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
127346 sqlite3 *db, /* Database in which to run SQL */
127396 ** Otherwise, if an error occurs, an SQLite error code is stored in *pRc
127513 ** Store the current database page-size in bytes in p->nPgsz.
127516 ** Otherwise, if an error occurs, an SQLite error code is stored in *pRc
127579 int *pRc, /* IN/OUT: Error code */
127580 char **pz, /* IN/OUT: Pointer to string buffer */
127602 ** Return a copy of input string zInput enclosed in double-quotes (") and
127632 ** could be used in a SELECT statement such as the following:
127636 ** to return the docid, followed by each column of text data in order
127692 ** of columns in the %_content table (one for the docid plus one for each
127769 ** the allocated array. *pnIndex is set to the number of elements in the
127776 const char *zParam, /* ABC in prefix=ABC parameter to parse */
127781 int nIndex = 1; /* Number of entries in array */
127829 ** the name of the corresponding column in table xxx. The array
127913 int argc, /* Number of elements in argv array */
127925 int nCol = 0; /* Number of columns in the FTS table */
127977 ** + If there is a tokenizer specification included in the arguments,
128185 /* Fill in the zName and zDb fields of the vtab structure. */
128194 /* Fill in the azColumn array */
128207 /* Fill in the abNotindexed array */
128231 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
128237 /* If this is an xCreate call, create the underlying tables in the
128251 /* Figure out the page-size for the database. This is required in order to
128284 ** work is done in function fts3InitVtab().
128289 int argc, /* Number of elements in argv array */
128299 int argc, /* Number of elements in argv array */
128310 ** support estimatedRows. In that case this function is a no-op.
128322 ** are three possible strategies, in order of preference:
128352 ** function MATCH in the requested context" error. To discourage
128377 ** it would lead to an "unable to use function MATCH in the requested
128428 /* Regardless of the strategy selected, FTS can deliver rows in rowid (or
128529 ** table is missing a row that is present in the full-text index.
128548 ** passed in zTerm/nTerm.
128561 int nTerm, /* Size of term zTerm in bytes */
128582 ** not make this guarantee explicitly, but in practice there are always
128667 ** left-most leaf node in the tree that may contain the specified term.
128683 int nTerm, /* Size of term zTerm in bytes */
128690 int iHeight; /* Height of this node in tree */
128700 int nBlob; /* Size of zBlob in bytes */
128729 char **pp, /* IN/OUT: Output pointer */
128730 sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
128744 ** a single document record of a doclist. So, in other words, this
128745 ** routine advances *ppPoslist so that it points to the next docid in
128764 ** last byte in the position-list.
128828 ** called, *pp may point to the start of the next varint in the position-list
128830 ** (in which case **pp will be a terminator bytes POS_END (0) or
128840 ** in the position-list. Because positions are delta-encoded, the value
128841 ** of the previous position is needed in order to compute the value of
128845 char **pp, /* IN/OUT: Pointer into position-list buffer */
128846 sqlite3_int64 *pi /* IN/OUT: Value read from position-list */
128878 ** into *pp contains all positions of both *pp1 and *pp2 in sorted
128881 ** that there is enough space in *pp to hold the complete output.
128893 int iCol1; /* The current column index in pp1 */
128894 int iCol2; /* The current column index in pp2 */
128966 ** each position in *pp2 for which there exists one or more positions in
128974 char **pp, /* IN/OUT: Preallocated output buffer */
128975 int nToken, /* Maximum difference in token positions */
128978 char **pp1, /* IN/OUT: Left input list */
128979 char **pp2 /* IN/OUT: Right input list */
129055 ** column-number in the position list.
129090 ** expression and *pp2 to the right. As usual, the indexes in the position
129091 ** lists are the offsets of the last token in each phrase (tokens "1" and "2"
129092 ** in the example above).
129095 ** entries that are not sufficiently NEAR entries in *pp1 removed.
129100 int nRight, /* Maximum difference in token positions */
129101 int nLeft, /* Maximum difference in token positions */
129102 char **pp1, /* IN/OUT: Left input list */
129103 char **pp2 /* IN/OUT: Right input list */
129139 int anOutput[16]; /* Size each output buffer in bytes */
129146 ** has been reached. In this case *pp is set to 0 and the function returns.
129156 char **pp, /* IN/OUT: Point to read varint from */
129159 sqlite3_int64 *pVal /* IN/OUT: Integer value */
129190 char **pp, /* IN/OUT: Output pointer */
129192 sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
129193 int *pbFirst, /* IN/OUT: True after first int written */
129217 ** sorted in either ascending or descending order.
129223 ** positions contained in either argument doclist). If the docids in the
129224 ** input doclists are sorted in ascending order, parameter bDescDoclist
129225 ** should be false. If they are sorted in ascending order, it should be
129229 ** containing the output doclist and SQLITE_OK is returned. In this case
129230 ** *pnOut is set to the number of bytes in the output doclist.
129233 ** are undefined in this case.
129256 ** are delta encoded. If they are in ascending order (bDescDoclist==0),
129257 ** then the first docid in each list is simply encoded as a varint. For
129259 ** current and previous docid (a positive number - since the list is in
129263 ** same number of bytes as it is in whichever of the input lists it is
129265 ** consumes either the same or less bytes as it did in the input (since
129266 ** the difference between it and the previous value in the output must
129274 ** be larger in the output than it was in the input (since the delta value
129281 ** A symetric argument may be made if the doclists are in descending
129316 ** This function does a "phrase" merge of two doclists. In a phrase merge,
129318 ** doclist for which there is a position in the left-hand input doclist
129321 ** If the docids in the input doclists are sorted in ascending order,
129322 ** parameter bDescDoclist should be false. If they are sorted in ascending
129331 char *aRight, int *pnRight /* IN/OUT: Right/output doclist */
129378 ** Argument pList points to a position list nList bytes in size. This
129380 ** a token in position 0 (of any column). If so, it writes argument iDelta
129388 int nList, /* Size of pList in bytes */
129429 ** Merge all doclists in the TermSelect.aaOutput[] array into a single
129430 ** doclist stored in TermSelect.aaOutput[0]. If successful, delete all
129433 ** If an OOM error occurs, return SQLITE_NOMEM. In this case it is
129434 ** the responsibility of the caller to free any doclists left in the
129442 /* Loop through the doclists in the aaOutput[] array. Merge them all
129495 int nDoclist /* Size of aDoclist in bytes */
129580 int nTerm, /* Size of zTerm in bytes */
129591 ** made by an fts4aux module, not an FTS table. In this case calling
129654 int nTerm, /* Size of zTerm in bytes */
129675 ** In addition to its current configuration, have the Fts3MultiSegReader
129684 int nTerm, /* Number of bytes in zTerm */
129708 int nTerm, /* Size of zTerm in bytes */
129820 ** This function counts the total number of docids in the doclist stored
129821 ** in buffer aList[], size nList bytes.
129844 ** Advance the cursor to the next row in the %_content table that
129847 ** simply the next row in the %_content table. For a docid lookup,
129908 ** in the %_content table.
129919 int nVal, /* Number of elements in apVal */
129949 /* In case the cursor has been used before, clear it now. */
130060 /* The column value supplied by SQLite must be in range. */
130118 ** in place to remove the entries that have already been merged. This
130144 int mxLevel = 0; /* Maximum relative level value in db */
130290 int nToken = 15; /* Default number of tokens in snippet */
130340 ** function merges all segments in the database to a single segment.
130453 ** PendingTermsFlush() in in case that changes.
130575 ** The fts3 built-in tokenizers - "simple", "porter" and "icu"- are
130576 ** implemented in files fts3_tokenizer1.c, fts3_porter.c and fts3_icu.c
130578 ** declared in these files used to retrieve the respective implementations.
130636 /* Load the built-in tokenizers into the hash table */
130695 ** Allocate an Fts3MultiSegReader for each token in the expression headed
130703 ** If the allocated Fts3MultiSegReader just seeks to a single entry in a
130706 ** and merged incrementally. Otherwise, it has to be merged into an in-memory
130712 int *pnToken, /* OUT: Total number of tokens in phrase. */
130713 int *pnOr, /* OUT: Total number of OR nodes in expr. */
130714 int *pRc /* IN/OUT: Error code */
130743 ** It is merged into the main doclist stored in p->doclist.aAll/nAll.
130754 int nList /* Number of bytes in pList */
130840 ** means that the phrase does not appear in the current row, doclist.pList
130848 int nPoslist = 0; /* Number of bytes in aPoslist */
130946 ** This function is called for each Fts3Phrase in a full-text query
130964 ** scanned in forward order, and the phrase consists of
131008 ** doclists in reverse and by the fts3_write.c module to iterate through
131011 ** The doclist may be sorted in ascending (parameter bDescIdx==0) or
131018 int nDoclist, /* Length of aDoclist in bytes */
131019 char **ppIter, /* IN/OUT: Iterator pointer */
131020 sqlite3_int64 *piDocid, /* IN/OUT: Docid pointer */
131074 int nDoclist, /* Length of aDoclist in bytes */
131075 char **ppIter, /* IN/OUT: Iterator pointer */
131076 sqlite3_int64 *piDocid, /* IN/OUT: Docid pointer */
131104 ** Advance the iterator pDL to the next entry in pDL->aAll/nAll. Set *pbEof
131138 ** edited in place by fts3EvalNearTrim(), then pIter may not actually
131163 ** multi-token phrase. Advance it to the next matching document in the
131212 ** Advance it to the next matching documnent in the database and populate
131233 ** one incremental token. In which case the bIncr flag is set. */
131254 /* Advance the iterator for each token in the phrase once. */
131354 ** each phrase in the expression (subject to deferred token processing).
131363 Fts3Expr *pExpr, /* Expression to initialize phrases in */
131364 int *pRc /* IN/OUT: Error code */
131386 ** of the xFilter() method). There is one element in the array for each
131387 ** token in the FTS expression.
131389 ** Tokens are divided into AND/NEAR clusters. All tokens in a cluster belong
131392 ** separately. The root of a tokens AND/NEAR cluster is stored in
131398 int iToken; /* Position of token in phrase */
131418 int *pRc /* IN/OUT: Error code */
131456 ** Determine the average document (row) size in pages. If successful,
131460 ** The average document size in pages is calculated by first calculating
131461 ** determining the average size in bytes, B. If B is less than the amount
131462 ** of data that will fit on a single leaf page of an intkey table in
131464 ** the number of overflow pages consumed by a record B bytes in size.
131473 ** varints, where nCol is the number of columns in the FTS3 table.
131474 ** The first varint is the number of documents currently stored in
131476 ** data stored in all rows of each column of the table, from left
131518 ** This function is called once for each AND/NEAR cluster in the
131531 int nTC /* Number of entries in aTC[] */
131538 int nToken = 0; /* Total number of tokens in cluster */
131552 /* Count the tokens in this AND/NEAR cluster. If none of the doclists
131554 ** only 1 token, exit early. No tokens to defer in this case. */
131563 /* Obtain the average docsize (in pages). */
131568 /* Iterate through all tokens in this AND/NEAR cluster, in ascending order
131573 ** a. The cheapest token in the entire query (i.e. the one visited by the
131580 ** contains. Set variable "nMinEst" to the smallest number of documents in
131585 ** Then, for each token, defer it if loading the doclist would result in
131616 ** overflowing the 32-bit integer it is stored in. */
131620 /* Either this is the cheapest token in the entire query, or it is
131646 ** the full-text query currently stored in pCsr->pExpr. To iterate through
131662 /* Allocate a MultiSegReader for each token in the expression. */
131665 /* Determine which, if any, tokens in the expression should be deferred. */
131722 ** Parameter nNear is passed the NEAR distance of the expression (5 in
131724 ** the position list, and *pnToken is the number of phrase tokens in, the
131729 ** All positions in the pPhrase position list that are not sufficiently
131730 ** close to a position in the *paPoslist position list are removed. If this
131734 ** associated with pPhrase. And *pnToken is set to the number of tokens in
131738 int nNear, /* NEAR distance. As in "NEAR/nNear". */
131740 char **paPoslist, /* IN/OUT: Position list */
131741 int *pnToken, /* IN/OUT: Tokens in phrase of *paPoslist */
131773 ** point to the next matching row in the database. Expressions iterate through
131774 ** matching rows in docid order. Ascending order if Fts3Cursor.bDesc is zero,
131778 ** successful, the following variables in pExpr are set:
131787 ** FTs3Expr.pPhrase->doclist.nList (length of pList in bytes)
131794 ** entirely of deferred tokens, it is assumed to match every row in
131795 ** the db. In this case the position-list is not populated at all.
131799 ** next possible match, considering only non-deferred tokens. In other
131802 ** where "*" may match any single token. The position list in this case
131814 int *pRc /* IN/OUT: Error code */
131926 ** expression, using the data currently stored in the position lists
131927 ** (Fts3Expr->pPhrase.doclist.pList/nList) for each phrase in the expression.
131930 ** phrase in the NEAR expression is edited in place to contain only those
131932 ** constraints. In this case it returns 1. If the NEAR expression does not
131944 ** which is represented in tree form as:
131957 ** no exceptions to this - it's the way the parser in fts3_expr.c works.
132019 ** the appropriate SQLite error code. In this case the returned value is
132025 int *pRc /* IN/OUT: Error code */
132039 ** all phrases involved in the NEAR. This is because the snippet(),
132115 ** * Up until this point, "NEAR" operators in the expression have been
132160 ** Advance to the next document that matches the FTS expression in
132239 ** After allocating the Fts3Expr.aMI[] array for each phrase in the
132242 ** the values in Fts3Expr.aMI[] according to the position-list currently
132243 ** found in Fts3Expr.pPhrase->doclist.pList for each of the phrase
132354 /* Caution: pRoot may iterate through docids in ascending or descending
132375 ** 1. The total number of occurrences of the phrase in each column of
132378 ** 2. For each column, the number of rows in the table for which the
132390 ** values are set to the number of documents in the table. In other
132391 ** words we assume that very common tokens occur exactly once in each
132399 ** that meet the NEAR constraint are included in the counts.
132435 ** a position-list indicating the occurrences of the phrase in column iCol
132439 ** occurrence of the phrase in the column, stored using the normal (delta+2)
132482 ** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the
132493 /* This is the descendent of an OR node. In this case we cannot use
132495 ** into memory in this case. */
132530 ** last entry in the doclist at pPhrase->doclist.aAll[]. Variable
132533 ** in the doclist.
132535 ** It would also be correct to set pIter and iDocid to zero. In
132537 ** would also move the iterator to point to the last entry in the
132639 ** The author disclaims copyright to this source code. In place of
132694 int argc, /* Number of elements in argv array */
132709 /* The user should invoke this in one of two forms:
132796 /* This vtab delivers always results in "ORDER BY term ASC" order. */
132940 /* State 0. In this state the integer just read was a docid. */
132947 /* State 1. In this state we are expecting either a 1, indicating
132952 ** integer encountered in state 1 is not 0 or 1, then we need to
132999 int nVal, /* Number of elements in apVal */
133008 int iEq = -1; /* Index of term=? value in apVal */
133009 int iGe = -1; /* Index of term>=? value in apVal */
133010 int iLe = -1; /* Index of term<=? value in apVal */
133011 int iLangid = -1; /* Index of languageid=? value in apVal */
133038 /* In case this cursor is being reused, close and zero it. */
133191 ** The author disclaims copyright to this source code. In place of
133231 ** operator in a similar format to that used by the lemon parser
133274 ** FTSQUERY_PHRASE with a unary "-" attached to it. i.e. "mysql" in the
133284 int nCol; /* Number of entries in azCol[] */
133352 ** and other information (column names etc.) in pParse. Create an Fts3Expr
133452 ** is included in the buffer. This function attempts to tokenize the entire
133482 ** The first pass, in the block below, uses a tokenizer cursor to iterate
133483 ** through the tokens in the expression. This pass uses fts3ReallocOrFree()
133484 ** to assemble data in two dynamic buffers:
133492 ** The second pass, in the block that begins "if( rc==SQLITE_DONE )" below,
133493 ** appends buffer zTemp to buffer p, and fills in the Fts3Expr and Fts3Phrase
133588 unsigned char parenOnly; /* Only valid in paren mode */
133670 ** a quote character embedded in a string.
133730 ** group more tightly). For example, in the C language, the == operator
133734 ** is defined), the order of the operators in precedence from highest to
133763 ** of pNew and the existing nodes of the tree. This may result in the head
133764 ** of the tree changing, in which case *ppHead is set to the new root node.
133788 ** Parse the fts3 query expression found in buffer z, length n. This function
133805 Fts3Expr *pNotBranch = 0; /* Only used in legacy parse mode */
133845 ** an expression contained in parenthesis is required. If a
133877 ** Return an error in either case.
133963 ** an equivalent but more balanced form. The tree is modified in place.
133976 int eType = pRoot->eType; /* Type of node in this tree */
133995 /* Set $p to point to the left-most leaf in the tree of eType nodes. */
134001 /* This loop runs once for each leaf in the tree of eType nodes. */
134042 /* Set $p to point to the next leaf in the tree of eType nodes */
134118 ** in this case.
134125 int nCol, /* Number of entries in azCol[] */
134174 ** of each column in the target fts3 table, in order from left to right.
134188 int nCol, /* Number of entries in azCol[] */
134476 ** The author disclaims copyright to this source code. In place of
134484 ** This is the implementation of generic hash-tables used in SQLite.
134490 ** The code in this file is only compiled if:
134493 ** (in which case SQLITE_CORE is not defined), or
134496 ** SQLite (in
134601 ** The C syntax in this function definition may be unfamilar to some
134622 ** For help in interpreted the obscure C code in the function definition,
134641 Fts3HashElem *pHead; /* First element already in pEntry */
134686 /* This function (for internal use only) locates an element in an
134789 ** The key is not copied in this instance. If a malloc fails, then
134798 int nKey, /* Number of bytes in the key */
134860 ** The author disclaims copyright to this source code. In place of
134873 ** The code in this file is only compiled if:
134876 ** (in which case SQLITE_CORE is not defined), or
134879 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
134903 int iOffset; /* current position in zInput */
134940 ** used to incrementally tokenize this string is returned in
134991 ** isConsonant() and isVowel() determine if their first character in
134997 ** in which case it is a vowel.
134999 ** In these routine, the letters are in reverse order. So the 'y' rule
135030 ** In prose: A word is an optional consonant followed by zero or
135035 ** Return true if the m-value for z is 1 or more. In other words,
135039 ** In this routine z[] is in reverse order. So we are really looking
135086 ** Return TRUE if the word ends in a double consonant.
135101 ** first three letters and the first one cannot be in [wxy].
135116 ** The input word *pz and zFrom are both in reverse order. zTo
135117 ** is in normal order.
135173 ** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
135177 ** Any upper-case characters in the US-ASCII character set ([A-Z])
135188 ** in [a-zA-Z] then no stemming is attempted and this routine just
135212 /* The use of a character not in [a-zA-Z] means that we fallback
135236 /* Do nothing. The work was all in the test */
135244 /* Do nothing. The work was all in the test */
135418 /* z[] is now the stemmed word in reverse order. Flip it back
135431 ** part of a token. In other words, delimiters all must have
135451 int *pnBytes, /* OUT: Number of bytes in token */
135508 ** tokenizer in *ppModule
135523 ** The author disclaims copyright to this source code. In place of
135537 ** The code in this file is only compiled if:
135540 ** (in which case SQLITE_CORE is not defined), or
135543 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
135563 ** the string <key-name> must already exist in the has table. Otherwise,
135729 ** designed to be used in concert with the Tcl testing framework. This
135739 ** list. For each token in the <input-string>, three elements are
135743 ** using the built-in "simple" tokenizer:
135808 zErr = "error in xCreate()";
135813 zErr = "error in xOpen()";
135826 zErr = "error in xClose()";
135830 zErr = "error in xDestroy()";
135895 ** This function is used for testing only, it is not included in the
135899 ** can be used as designed by the C-code in the queryTokenizer and
135901 ** in the README.tokenizer file as an example, so it is important to
135947 ** Set up SQL objects in database db used to access the contents of
135955 ** scalarFunc() in this file for details) and, if ENABLE_TABLE is
136013 ** The author disclaims copyright to this source code. In place of
136026 ** The code in this file is only compiled if:
136029 ** (in which case SQLITE_CORE is not defined), or
136032 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
136051 int iOffset; /* current position in pInput */
136080 ** track such information in the database, then we'd only want this
136117 ** used to incrementally tokenize this string is returned in
136167 int *pnBytes, /* OUT: Number of bytes in token */
136233 ** tokenizer in *ppModule
136248 ** The author disclaims copyright to this source code. In place of
136274 ** statement and returns one row for each token in the result. With
136311 int nToken; /* Size of zToken in bytes */
136348 ** in this case. Or, if an error occurs, an SQLite error code is returned.
136349 ** The final value of *pazDequote is undefined in this case.
136352 int argc, /* Number of elements in argv[] */
136404 int argc, /* Number of elements in argv array */
136579 int nVal, /* Number of elements in apVal */
136704 ** The author disclaims copyright to this source code. In place of
136717 ** code in fts3.c.
136732 ** of it. i.e. if a full-text index node is 900 bytes in size, then a buffer
136749 ** bytes and larger. Nodes are loaded in chunks of FTS3_NODE_CHUNKSIZE bytes.
136769 in
136779 ** debugging FTS only, it should not usually be turned on in production
136814 int iCol; /* Column token must occur in */
136815 Fts3DeferredToken *pNext; /* Next in list of deferred tokens */
136822 ** this structure are only manipulated by code in this file, opaque handles
136823 ** of type Fts3SegReader* are also used by code in fts3.c to iterate through
136843 sqlite3_int64 iEndBlock; /* Rowid of final block in segment (or 0) */
136858 int nTerm; /* Number of bytes in current term */
136862 int nDoclist; /* Size of doclist in current entry */
136876 ** An instance of this structure is used to create a segment b-tree in the
136886 sqlite3_int64 iFirst; /* First slot in %_segments written */
136887 sqlite3_int64 iFree; /* Next free slot in %_segments */
136889 int nTerm; /* Number of bytes in zTerm */
136893 int nData; /* Bytes of data in aData */
136911 ** the tree is assembled in memory and written out only once all leaves have
136922 int nTerm; /* Number of bytes in zTerm */
137006 /* Return segments in order from oldest to newest.*/
137032 ** of the oldest level in the db that contains at least ? segments. Or,
137033 ** if no level in the FTS index contains more than ? segments, the statement
137038 /* Estimate the upper limit on the number of leaf nodes in a new segment
137075 ** Return the largest relative level in the FTS index or indexes. */
137078 /* Return segments in order from oldest to newest.*/
137181 ** Similar to fts3SqlStmt(). Except, after binding the parameters in
137244 ** level within the index) are encoded in 64-bit integer values stored
137245 ** in the %_segdir table on disk. This function is used to convert three
137262 int iIndex, /* Index in p->aIndex[] */
137276 ** all rows in the %_segdir table, from oldest to newest. If successful,
137339 PendingList **pp, /* IN/OUT: Pointer to PendingList struct */
137379 ** Zero is always returned in this case. Otherwise, if no OOM error occurs,
137383 PendingList **pp, /* IN/OUT: PendingList structure */
137477 ** pending-terms hash-table. The docid used is that currently stored in
137487 u32 *pnWord /* IN/OUT: Incr. by number tokens inserted */
137507 ** zText==0. In this case, add zero token entries to the hash table and
137604 ** operation. It adds entries for each term in the new record to the
137671 ** defined columns in the FTS3 table, plus one for the docid field.
137689 ** In FTS3, this is an error. It is an error to specify non-NULL values
137750 ** The first element in the apVal[] array is assumed to contain the docid
137801 ** This function allocates a new level iLevel index in the segdir table.
137843 ** full, merge all segments in level iLevel into a single iLevel+1
137867 ** with the contents of the blob stored in the "block" column of the
137869 ** to the size of the blob in bytes before returning.
137876 ** This function may leave an open sqlite3_blob* handle in the
137889 char **paBlob, /* OUT: Blob data in malloc'd buffer */
137995 ** Move the iterator passed as the first argument to the next term in the
138006 int nPrefix; /* Number of bytes in term prefix */
138007 int nSuffix; /* Number of bytes in term suffix */
138103 ** Set the SegReader to point to the first docid in the doclist associated
138129 ** Advance the SegReader to point to the next docid in the doclist
138134 ** in the doclist entry (i.e. immediately past the docid varint).
138142 int *pnOffsetList /* OUT: Length of *ppOffsetList in bytes */
138152 ** Pending-terms doclists are always built up in ascending order, so
138199 /* List may have been edited in place by fts3EvalNearTrim() */
138202 /* If there are no more entries in the doclist, set pOffsetList to
138309 /* The entire segment is stored in the root node. */
138343 ** a subset of the terms stored in the Fts3Table.pendingTerms array.
138346 ** through each term in the pending-terms table. Or, if isPrefixIter is
138349 ** "firebird", then the iterator visits the following 'terms' (in the order
138402 ** objects in term order using qsort(). This uses the same comparison
138410 /* The query is a simple term lookup that matches at most one term in
138479 ** A different comparison function for SegReader structures. In this
138480 ** version, it is assumed that each SegReader points to an entry in
138483 ** 1) EOF (end of doclist in this case) is greater than not EOF.
138525 int nTerm /* Size of term zTerm in bytes */
138543 ** the final (nSegment-nSuspect) members are already in sorted order
138545 ** the array around until all entries are in sorted order.
138584 int n /* Size of buffer z in bytes */
138598 ** Find the largest relative level number in the table. If successful, set
138628 sqlite3_int64 nLeafData, /* Bytes of leaf data in segment */
138630 int nRoot /* Number of bytes in buffer zRoot */
138655 ** zNext, in bytes. For example,
138663 int nPrev, /* Size of buffer zPrev in bytes */
138665 int nNext /* Size of buffer zNext in bytes */
138679 SegmentNode **ppTree, /* IN/OUT: SegmentNode handle */
138682 int nTerm /* Size of term in bytes */
138692 int nData = pTree->nData; /* Current size of node in bytes */
138719 /* There is no prefix-length field for first term in a node */
138750 ** If this is the first node in the tree, the term is added to it.
138817 int iHeight, /* Height of this node in tree */
138819 sqlite3_int64 iFree, /* Block id of next free slot in %_segments */
138822 int *pnRoot /* OUT: Size of root node in bytes */
138879 ** and return it via the input/output variable *ppWriter in this case.
138885 SegmentWriter **ppWriter, /* IN/OUT: SegmentWriter handle */
138888 int nTerm, /* Size of term in bytes */
138890 int nDoclist /* Size of doclist in bytes */
138892 int nPrefix; /* Size of term prefix in bytes */
138893 int nSuffix; /* Size of term suffix in bytes */
138908 /* Allocate a buffer in which to accumulate data */
138913 /* Find the next free blockid in the %_segments table */
138947 ** to the database (still available in pWriter->zTerm), and
138952 ** In other words, it must be the prefix of zTerm 1 byte longer than
139071 ** The first value in the apVal[] array is assumed to contain an integer.
139100 ** Set *pnMax to the largest segment level in the database for the index
139103 ** Segment levels are stored in the 'level' column of the %_segdir table.
139167 ** Delete all entries in the %_segments table associated with the segment
139195 ** each of the SegReader objects in the array passed as the third
139254 ** If there are no entries in the input position list for column iCol, then
139263 char **ppList, /* IN/OUT: Pointer to position list */
139264 int *pnList /* IN/OUT: Size of buffer *ppList in bytes */
139299 ** Cache data in the Fts3MultiSegReader.aBuffer[] buffer (overwriting any
139327 int *pnPoslist /* OUT: Size of position list in bytes */
139394 int nTerm /* Length of zTerm in bytes */
139436 int nTerm /* Number of bytes in zTerm */
139477 ** have been made. Calling this function puts the MultiSegReader in such
139483 ** then the entire doclist for the term is available in
139532 /* Advance the first pCsr->nAdvance entries in the apSegment[] array
139533 ** forward. Then sort the list in order of current term again.
139556 ** required callbacks have been made. In this case exit early.
139595 sqlite3_int64 iPrev = 0; /* Previous docid stored in doclist */
139597 /* The current term of the first nMerge entries in the array
139707 ** by one or more space (0x20) characters. In the first case, set *piEndBlock
139708 ** to the integer value and *pnByte to zero before returning. In the second,
139759 /* Loop through all entries in the %_segdir table corresponding to
139760 ** segments in this index on levels greater than iAbsLevel. If there is
139762 ** such segments are smaller than nLimit bytes in size, they will be
139772 ** old version of FTS. In this case it is not possible to determine
139796 /* Loop through all %_segdir entries for segments in this index with
139799 ** oldest segment in the range, 1 for the next oldest, and so on.
139801 ** In other words, move all segments being promoted to level -1,
139802 ** setting the "idx" fields as appropriate to keep them in the same
139836 ** Merge all level iLevel segments in the database into a single
139839 ** currently present in the database.
139842 ** segment in the database, SQLITE_DONE is returned immediately.
139849 int iIndex, /* Index in p->aIndex[] to merge */
139877 /* This call is to merge all segments in the database to a single
139879 ** greatest segment level currently present in the database for this
140012 ** Insert the sizes (in tokens) for each column of the document
140019 u32 *aSz /* Sizes of each column, in tokens */
140022 int nBlob; /* Number of bytes in the BLOB */
140047 ** where N is the number of user defined columns in the fts3 table plus
140051 ** Varint 0: Total number of rows in the table.
140053 ** Varint 1..nCol: For each column, the total number of tokens stored in
140056 ** Varint 1+nCol: The total size, in bytes, of all text values in all
140065 int nChng /* Change in the number of documents */
140252 ** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute
140306 ** to build up nodes or other blobs of data in.
140312 int n; /* Number of valid bytes of data in a[] */
140334 int iIdx; /* Index of *output* segment in iAbsLevel+1 */
140359 int nDoclist; /* Size of doclist in bytes */
140365 ** bytes in size, extend (realloc) it to be so.
140437 ** Initialize a node-reader object to read the node in buffer aNode/nNode.
140466 ** The block id of the leaf node just written to disk may be found in
140499 ** bytes in size, write the key here. */
140548 ** stored in blob *pNode. The node need not contain any terms, but the
140558 ** If the size of the value in blob pPrev is zero, then this is the first
140574 int nTerm, /* Size of zTerm in bytes */
140576 int nDoclist /* Size of aDoclist in bytes */
140580 int nPrefix; /* Size of term prefix in bytes */
140581 int nSuffix; /* Size of term suffix in bytes */
140630 int nSpace; /* Total space in bytes required on leaf */
140654 ** to the database (still available in pLeaf->key), and
140659 ** In other words, it must be the prefix of zTerm 1 byte longer than
140708 int *pRc /* IN/OUT: Error code */
140711 int iRoot; /* Index of root in pWriter->aNodeWriter */
140715 /* Set iRoot to the index in pWriter->aNodeWriter[] of the output segment
140732 ** the node would be stored as a blob in the "root" column of the %_segdir
140733 ** table. However, this is not permitted in this case. The problem is that
140734 ** space has already been reserved in the %_segments table, and so the
140743 ** Todo: Better might be to defer allocating space in the %_segments
140788 ** Compare the term in buffer zLhs (size in bytes nLhs) with that in
140789 ** zRhs (size in bytes nRhs) using memcmp. If one term is a prefix of
140810 ** Query to see if the entry in the %_segments table with blockid iEnd is
140815 ** error code. The final value of *pbRes is undefined in this case.
140849 ** greater than the largest key currently stored in the potential
140857 int nKey, /* Number of bytes in nKey */
140869 int nRoot = 0; /* Size of aRoot[] in bytes */
140890 /* Check for the zero-length marker in the %_segments table */
140982 ** *piIdx is undefined in this case.
141007 ** In the %_segdir table, a segment is defined by the values in three
141017 ** of input segments, multiplied by two. This value is stored in stack
141026 ** In the actual code below, the value "16" is replaced with the
141054 /* Calculate the first block to use in the output segment */
141066 /* Insert the marker in the %_segments table to make sure nobody tries
141115 ** Update the 'idx' values of the remaining segments in the level so that
141124 int nIdx = 0; /* Valid entries in aIdx[] */
141189 ** This function creates a new node image in blob object *pNew by copying
141195 int nNode, /* Size of aNode in bytes */
141198 int nTerm, /* Size of zTerm in bytes */
141199 sqlite3_int64 *piBlock /* OUT: Block number in next layer down */
141240 ** Remove all terms smaller than zTerm/nTerm from segment iIdx in absolute
141242 ** table, and modifying existing entries in both the %_segments and %_segdir
141253 int nTerm /* Number of bytes in buffer zTerm */
141330 ** or modified in place so that it no longer contains those entries that
141331 ** have been duplicated in the output segment.
141348 ** somewhere in the pCsr->apSegment[] array. */
141364 ** segment to the upper level. The segment is modified in place
141382 ** Store an incr-merge hint in the database.
141401 ** exists, is stored in the rowid==1 row of the %_stat table.
141436 ** Otherwise, append an entry to the hint stored in blob *pHint. Each entry
141445 i64 iAbsLevel, /* First varint to store in hint */
141446 int nInput, /* Second varint to store in hint */
141447 int *pRc /* IN/OUT: Error code */
141461 ** If no error occurs, return SQLITE_OK. If the hint blob in *pHint does
141486 ** values for the _segdir.idx field) in the highest level that contains
141487 ** at least nMin segments. Multiple merges might occur in an attempt to
141513 int iIdx = 0; /* Largest idx in level (iAbsLevel+1) */
141532 ** last entry in it specifies a relative level smaller than or equal
141555 ** nMin segments and no hint in the %_stat table. No work to do.
141556 ** Exit early in this case. */
141562 ** segments available in level iAbsLevel. In this case, no work is
141731 int nTerm, /* Size of zTerm in bytes */
141751 ** Return a checksum of all entries in the FTS index that correspond to
141757 ** return value is undefined in this case.
141831 ** code. The final value of *pbOk is undefined in this case.
141884 int nToken = 0; /* Number of bytes in token */
141886 int iPos = 0; /* Position of token in zText */
141925 ** prefix in the document set, a 64-bit checksum is calculated (by code
141926 ** in fts3ChecksumEntry()) based on the following:
141931 ** + The language-id of the row it appears in,
141932 ** + The docid of the row it appears in,
141933 ** + The column it appears in, and
141936 ** The checksums for all entries in the index are XORed together to create
141939 ** The integrity-check code calculates the same checksum in two ways:
142014 ** Free all entries in the pCsr->pDeffered list. Entries are added to
142029 ** Generate deferred-doclists for all tokens in the pCsr->pDeferred list
142058 int nToken = 0; /* Number of bytes in token */
142060 int iPos = 0; /* Position of token in zText */
142122 int iCol /* Column that token must appear in (or -1) */
142144 ** present in the FTS3 table. If it is, delete it and adjust the contents
142150 int *pnChng, /* IN/OUT: Decrement if row is deleted */
142154 int bFound = 0; /* True if *pRowid really is in the table */
142162 /* Deleting this row means the whole table is empty. In this case
142164 ** data in the pendingTerms hash table. */
142207 int nChng = 0; /* Net change in number of documents */
142237 /* Allocate space to hold the change in document sizes */
142269 /* The new rowid is not NULL (in this case the rowid will be
142280 ** be losslessly converted to an integer. In this case, the eventual
142281 ** call to fts3InsertData() (either just below or further on in this
142338 ** Flush any data in the pending-terms hash table to disk. If successful,
142339 ** merge all segments in the database (including the new segment, if
142366 ** The author disclaims copyright to this source code. In place of
142382 ** Characters that may appear in the second argument to matchinfo().
142420 int nSnippet; /* Requested snippet length (in tokens) */
142421 int nPhrase; /* Number of phrases in query */
142427 int nToken; /* Number of tokens in phrase */
142429 int iHead; /* Next value in position list */
142431 int iTail; /* Next value in trailing position list */
142437 int iPos; /* Index of first token in snippet */
142449 int nCol; /* Number of columns in table */
142450 int nPhrase; /* Number of matchable phrases in query */
142451 sqlite3_int64 nDoc; /* Number of docs in database */
142465 int n; /* Length of z in bytes (excl. nul-term) */
142466 int nAlloc; /* Allocated size of buffer z in bytes */
142486 ** the list. *piPos contains the value of the previous entry in the list.
142522 ** Iterate through all phrase nodes in an FTS3 query, except those that
142559 ** Load the doclists for each phrase in the query associated with FTS3 cursor
142563 ** phrases in the expression (all phrases except those directly or
142565 ** pnToken is not NULL, then it is set to the number of tokens in all
142570 int *pnPhrase, /* OUT: Number of phrases in query */
142571 int *pnToken /* OUT: Number of tokens in query */
142679 u64 mHighlight = 0; /* Mask of tokens to highlight in snippet */
142753 ** (a) +1 point for each occurrence of a matchable phrase in the snippet.
142755 ** (b) +1000 points for the first occurrence of each matchable phrase in
142758 ** The selected snippet parameters are stored in structure *pFragment before
142759 ** returning. The score of the selected snippet is stored in *piScore
142767 u64 *pmSeen, /* IN/OUT: Mask of phrases seen */
142772 int nList; /* Number of phrases in expression */
142780 /* Iterate through the phrases in the expression to count them. The same
142799 ** the set of phrases in the expression to populate the aPhrase[] array.
142815 /* Loop through all candidate snippets. Store the best snippet in
142816 ** *pFragment. Store its associated 'score' in iBestScore.
142849 int nAppend /* Size of zAppend in bytes (or -1) */
142886 ** This function "shifts" the beginning of the snippet forward in the
142900 int iLangid, /* Language id to use in tokenizing */
142903 int nDoc, /* Size of buffer zDoc in bytes */
142904 int *piPos, /* IN/OUT: First token of snippet */
142905 u64 *pHlmask /* IN/OUT: Mask of tokens to highlight */
142918 /* Ideally, the start of the snippet should be pushed forward in the
142934 ** or more tokens in zDoc/nDoc.
142966 int isLast, /* True for final fragment in snippet */
142967 int nSnippet, /* Number of tokens in extracted snippet */
142976 int nDoc; /* Size of zDoc in bytes */
143005 int iBegin = 0; /* Offset in zDoc of start of token */
143006 int iFin = 0; /* Offset in zDoc of end of token */
143010 ** in the FTS code the variable that the third argument to xNext points to
143074 ** This function is used to count the entries in a column-list (a
143077 ** beginning of the first varint in the column-list (the varint that
143078 ** contains the position of the first matching term in the column data).
143080 ** the last varint in the column-list (either the 0x00 signifying the end
143082 ** the next column in the position-list).
143084 ** The number of elements in the column-list is returned.
143123 ** Y values are set to nDoc, where nDoc is the number of documents in the
143240 ** hits for a single phrase on a single row in order to calculate the
143294 ** array before returning. SQLITE_OK is returned in this case.
143307 ** contains one element for each matchable phrase in the query.
143322 int nLive = 0; /* Number of iterators in aIter not at EOF */
143382 ** pInfo->aMatchinfo[] buffer is left in is undefined.
143416 sqlite3_int64 nDoc; /* Number of rows in table */
143511 ** matchinfo function has been called for this query. In this case
143516 int nMatchinfo = 0; /* Number of u32 elements in match-info */
143517 int nArg; /* Bytes in zArg */
143520 in the query */
143524 /* Determine the number of integers in the buffer returned by this call. */
143562 int nToken /* Approximate number of tokens in snippet */
143570 ** the data in the current row. The first iteration of the for(...) loop
143571 ** below attempts to locate a single fragment of text nToken tokens in
143572 ** size that contains at least one instance of all phrases in the query
143573 ** expression that appear in the current row. If such a fragment of text
143577 int nSnippet = 0; /* Number of fragments in this snippet */
143579 int nFToken = -1; /* Number of tokens in each fragment */
143614 /* Find the best snippet of nFToken tokens in column iRead. */
143628 /* If all query phrases seen by fts3BestSnippet() are present in at least
143676 int nTerm; /* Number of tokens in phrase */
143679 int iPos = 0; /* First position in position-list */
143710 int nToken; /* Number of tokens in query */
143723 /* Count the number of terms in the query */
143757 /* Retreive the text stored in column iCol. If an SQL NULL is stored
143758 ** in column iCol, jump immediately to the next iteration of the loop.
143889 ** The author disclaims copyright to this source code. In place of
143976 int nInput; /* Size of aInput[] in bytes */
143999 ** all characters in string zIn/nIn to be separators (if bAlnum==0) or
144002 ** For each codepoint in the zIn/nIn string, this function checks if the
144007 ** codepoints in the aiException[] array.
144010 ** identifies as a diacritic) occurs in the zIn/nIn string it is ignored.
144018 int nIn /* Length of z in bytes */
144039 int nNew; /* Number of valid entries in array aNew[] */
144148 ** used to incrementally tokenize this string is returned in
144154 int nInput, /* Size of string aInput in bytes */
144283 ** The author disclaims copyright to this source code. In place of
144310 /* Each unsigned integer in the following array corresponds to a contiguous
144314 ** The most significant 22 bits in each 32-bit value contain the first
144315 ** codepoint in the range. The least significant 10 bits are used to store
144316 ** the size of the range (always at least 1). In other words, the value
144435 ** in the ASCII range with a diacritic added, return the codepoint
144511 /* Each entry in the following array defines a rule for folding a range
144515 ** If the least significant bit in flags is clear, then the rule applies
144518 ** every second codepoint in the range, starting with codepoint C.
144520 ** The 7 most significant bits in flags are an index into the aiOff[]
144651 ** The author disclaims copyright to this source code. In place of
144667 ** The data structure for a single virtual r-tree table is stored in three
144668 ** native SQLite tables declared as follows. In each case, the '%' character
144669 ** in the table name is replaced with the user-supplied name of the r-tree
144676 ** The data for each node of the r-tree structure is stored in the %_node
144678 ** an entry in the %_parent table associating the node with its parent.
144679 ** And for each row of data in the table, there is an entry in the %_rowid
144684 ** empty. The nodeno of the root node is always 1. All other nodes in the
144693 ** stored in the node.
144747 ** the number of rows in the virtual table to calculate the costs of
144762 int iNodeSize; /* Size in bytes of each node in the node table */
144770 i64 nRowEst; /* Estimated number of rows in this table */
144795 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
144824 ** represents is the iCell-th entry in the parent node.
144836 ** maximum. In Gutman's notation:
144858 ** Number of entries in
144872 int nConstraint; /* Number of entries in aConstraint */
144875 int nPoint; /* Number of slots used in aPoint[] */
144945 RtreeNode *pNext; /* Next node in this hash collision chain */
144948 /* Return the number of cells in a node */
144964 ** operators in order to constrain a search.
144971 ** This object is deleted automatically by the destructor mechanism in
144990 ** An instance of this structure (in the form of a BLOB) is returned by
145090 ** in the Rtree.aHash table.
145163 /* Check if the requested node is already in the hash table. If so,
145272 ** If there is not enough free space in pNode, return SQLITE_FULL.
145279 int nCell; /* Current number of cells in pNode */
145360 ** Return coordinate iCoord from cell iCell in node pNode.
145558 ** Store the results in "r".
145652 ** in a coordinate pair. But make pCellData point to the lower bound.
145684 ** The op is given by p->op. The xN is p->iCoord-th coordinate in
145710 ** One of the cells in node pNode is guaranteed to have a 64-bit
145733 ** in its parent. If pNode is the root node, return -1.
145750 ** iLevel values coming first. In this way, if rScore is the same for all
145766 ** Interchange to search points in a cursor.
146091 ** return SQLITE_OK. If there is no such record in the table, set
146181 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
146271 ** support estimatedRows. In that case this function is a no-op.
146283 ** table scan strategies to choose from (in order from most to
146295 ** the constraint in sqlite3_index_info.aConstraintUsage[] with
146298 ** The first of each pair of bytes in idxStr identifies the constraint
146385 ** Return the N-dimensional volumn of the cell stored in *p.
146398 ** of the objects size in each dimension.
146410 ** Store the union of cells p1 and p2 in p1.
146488 ** ChooseSubTree in r*tree terminology.
146547 ** the node pNode. This function updates the bounding box cells in
146602 ** (nIdx-1) in no particular order. This function sorts the values
146603 ** in aIdx according to the indexed values in aDistance. For
146674 ** (nIdx-1) in no particular order. This function sorts the values
146675 ** in aIdx according to dimension iDim of the cells in aCell. The
146924 ** In this case avoid the all to nodeWrite().
147045 /* Remove the entry in the parent cell. */
147074 /* Remove the node from the in-memory hash table and link it into
147122 ** the in-memory node image, so it cannot fail.
147128 ** cell in the parent node so that it tightly contains the updated
147225 /* Find a node to store this cell in. pNode->iNode currently contains
147294 /* Find a node to store this cell in. pNode->iNode currently contains
147329 int iCell; /* Index of iDelete cell in pLeaf */
147343 /* Delete the cell in question from the leaf node. */
147356 /* Delete the corresponding entry in the <rtree>_rowid table. */
147369 ** in this scenario).
147460 ** In the first case, if the conflict-handling mode is REPLACE, then
147461 ** the conflicting row can be removed before proceeding. In the second
147493 /* If a rowid value was supplied, check if it is already present in
147581 ** of the number of rows in the virtual table. If possible, this is based
147745 ** table already exists. In this case the node-size is determined by inspecting
147751 ** would fit in a single node, use a smaller node-size.
147900 ** entry for each cell in the r-tree node. Each entry is itself a
148002 ** or sqlite3_rtree_query_callback(). In other words, this routine is the
148120 ** The author disclaims copyright to this source code. In place of
148163 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
148190 int iPattern = 0; /* Current byte index in zPattern */
148191 int iString = 0; /* Current byte index in zString */
148214 ** MATCH_ALL. For each MATCH_ONE, skip one character in the
148262 ** the build-in LIKE operator. The first argument to the function is the
148283 ** of deep recursion and N*N behavior in patternCompare().
148625 ** The author disclaims copyright to this source code. In place of
148658 int nChar; /* Number of UChar elements in pInput */
148660 int *aOffset; /* Offsets of each character in utf-8 input */
148672 int argc, /* Number of entries in argv[] */
148710 ** used to incrementally tokenize this string is returned in
148716 int nInput, /* Length of zInput in bytes */
148799 int *pnBytes, /* OUT: Number of bytes in token */