Home | History | Annotate | Download | only in dist

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.
24236 ** cannot be closed immediately. In these cases, instances of the following
24286 ** transaction counter in bytes 24-27 of database files are updated
24294 unsigned char inNormalWrite; /* True if in a normal write operation */
24299 /* In test mode, increase the size of this structure a bit so that
24300 ** it is larger than the struct CrashFile defined in test6.c.
24332 /************** Include os_common.h in the middle of os_unix.c ***************/
24337 ** The author disclaims copyright to this source code. In place of
24357 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
24385 /************** Include hwtime.h in the middle of os_common.h ****************/
24390 ** The author disclaims copyright to this source code. In place of
24474 /************** Continuing where we left off in os_common.h ******************/
24540 /************** Continuing where we left off in os_unix.c ********************/
24581 ** Different Unix systems declare open() in different ways. Same use
24593 ** On some systems, calls to fchown() will trigger a message in a security
24831 ** Do not accept any file descriptor less than this value, in order to avoid
24851 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
25020 /* At one point this code was not commented out. In theory, this branch
25041 * introspection, in which it actually means what it says */
25059 * introspection, in which it actually means what it says */
25063 /* invalid fd, unless during file system support introspection, in which
25093 ** unique file ID in
25103 struct vxworksFileId *pNext; /* Next in a list of them all */
25124 ** Changes are made in-place. Return the new name length.
25126 ** The original filename is in z[0..n-1]. Return the number of
25127 ** characters in the simplified name.
25247 ** to synchronize access for threads in separate processes, but not
25253 ** st_dev and st_ino fields of the stat structure that fstat() fills in)
25261 ** canonical filename and implemented in the previous division.)
25300 ** in thread B. But there is no way to know at compile-time which
25309 ** per database file in the same process and (2) database connections
25365 ** It is invoked after an error occurs in an OS function and errno has been
25432 ** We assume that close() almost always works, since it is only in a
25450 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
25505 unixFile *pFile, /* Unix file with file desc used in the key */
25532 ** around this problem (we consider it a bug in OS X, not SQLite)
25536 ** in the header of every SQLite database. In this way, if there
25655 /* Check if a thread in this process holds such a lock */
25693 ** in order to coordinate access between separate database connections
25694 ** within this process, but all of that is handled in memory and the
25702 ** to fcntl() fails. In this case, errno is set appropriately (by fcntl()).
25742 ** are inserted in between. The locking might fail on one of the later
25758 ** lock transitions in terms of the POSIX advisory shared and exclusive
25761 ** slightly in order to be compatible with windows systems simultaneously
25762 ** accessing the same database file, in case that is ever required.
25764 ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved
25915 /* We are trying for an exclusive lock but another thread in this
26000 ** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
26038 ** the lock in 2 blocks, so that part of the range will be covered by a
26100 /* In theory, the call to unixFileLock() cannot fail because another
26104 ** SQLITE_BUSY would confuse the upper layer (in practice it causes
26126 ** OS call only when all threads in this same process have released
26265 ** corruption if this locking mode is used in situations where multiple
26310 ** Dotfile locking works by creating a subdirectory in the same directory as
26317 ** The file suffix added to the data base filename in order to create the
26328 ** In dotfile locking, either a lock exists or it does not. So in this
26341 /* Check if a thread in this process holds such a lock */
26343 /* Either this connection or some other connection in the same process
26366 ** are inserted in between. The locking might fail on one of the later
26496 ** flock() locking is like dot-file locking in that the various
26498 ** a single exclusive lock. In other words, SHARED, RESERVED, and
26537 /* Check if a thread in this process holds such a lock */
26591 ** are inserted in between. The locking might fail on one of the later
26603 ** lock states in the sqlite3_file structure, but all locks SHARED or
26707 ** Semaphore locking is like dot-lock and flock in that it really only
26729 /* Check if a thread in this process holds such a lock */
26744 /* someone else has the lock when we are in NO_LOCK */
26768 ** are inserted in between. The locking might fail on one of the later
26780 ** lock states in the sqlite3_file structure, but all locks SHARED or
26932 OSTRACE(("AFPSETLOCK [%s] for %d%s in range %llx:%llx\n",
26978 /* Check if a thread in this process holds such a lock */
26989 /* if we succeeded in taking the reserved lock, unlock it to restore
27018 ** are inserted in between. The locking might fail on one of the later
27145 /* We are trying for an exclusive lock but another thread in this
27283 ** OS call only when all threads in this same process have released
27378 ** methods were defined in divisions above (one locking method per
27463 ** file), the bytes in the locking range should never be read or written. */
27513 int nBuf, /* Size of buffer pBuf in bytes */
27549 ** Seek to the offset in id->offset then read cnt bytes into pBuf.
27576 ** file), the bytes in the locking range should never be read or written. */
27780 ** The ability to override this routine was added in support of the
27920 ** Determine the current size of a file in bytes
27935 ** writes a single byte into that file in order to work around a bug
27936 ** in the OS-X msdos filesystem. In order to avoid problems with upper
27948 ** Handler for proxy-locking file-control verbs. Defined below in the
27956 ** file-control operation. Enlarge the database to nBytes in size
27984 ** the last byte in each block within the extended region. This
28131 ** Return the sector size in bytes of the underlying block device for
28136 ** if two files are created in the same file-system directory (i.e.
28232 ** file system does not always provide powersafe overwrites. (In other
28235 ** very rare. And asserting PSOW makes a large reduction in the amount
28258 ** This function should not be called directly by other code in this file.
28278 ** of this unixShmNode object. In other words, each wal-index is opened
28283 ** every open file that does not use shared memory (in other words, most
28300 ** in this structure.
28428 ** to use 64KB pages - in this case each mapping must cover at least two
28474 ** The file used to implement shared-memory is in the same directory
28480 ** Another approach to is to use files in /dev/shm or /dev/tmp or an
28481 ** some other tmpfs mount. But if a file in a different directory
28486 ** in database corruption. Nevertheless, this tmpfs file usage
28489 ** option results in an incompatible build of SQLite; builds of SQLite
28493 ** "unsupported" and may go away in a future SQLite release.
28496 ** file are currently open, in this process or in other processes, then
28501 ** that no other processes are able to read or write the database. In
28511 in bytes */
28634 ** bytes in size.
28639 ** region has not been allocated (by any client, including one running in a
28708 ** last page in order to extend the file. But writing to all new
28782 ** different here than in posix. In xShmLock(), one can go from unlocked
28988 ** the three variables above are zeroed. In this case SQLite should
28999 i64 nOrig = pFd->mmapSizeActual; /* Size of pOrig region in bytes */
29059 ** in this case. */
29117 ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
29120 ** value of *pp is undefined in this case.
29222 ** to the METHOD object in the previous bullet.
29323 ** The proxy locking method is a "super-method" in the sense that it
29327 ** proxy locking is located much further down in the file. But we need
29494 ** exception is when opening the proxy "conch" file in builds that
29504 /* No locking occurs in temporary files */
29536 /* Cache zFilename in the locking context (AFP and dotlock override) for
29551 /* If an error occurred in findInodeInfo(), close the file descriptor
29553 ** in two scenarios:
29566 ** implicit assumption here is that if fstat() fails, things are in
29577 /* AFP locking uses the file path so it needs to be included in
29604 /* Dotfile locking uses the file path so it needs to be included in
29623 ** included in the semLockingContext
29664 ** Return the name of a directory in which to put temporary files.
29695 ** Create a temporary file name in zBuf. zBuf must be allocated
29739 ** Implementation in the proxy-lock division, but used by unixOpen()
29754 ** Refer to comments in the unixClose() function and the lengthy comment
29774 ** For this reason, if an error occurs in the stat() call here, it is
29810 ** In most cases cases, this routine sets *pMode to 0, which will become
29837 int nDb; /* Number of valid bytes in zDb */
29882 ** Previously, the SQLite OS layer used three functions in place of this
29904 sqlite3_file *pFile, /* The file descriptor to be filled in */
29939 ** a temporary file. Use this buffer to store the file name in.
30122 /* In theory, the close(fd) call is sub-optimal. If the file opened
30125 ** then the call to close() will cancel those locks. In practice,
30141 /* Use unixClose to clean up the resources added in fillInUnixFile
30256 ** is stored as a nul-terminated string in the buffer pointed to by
30260 ** (in this case, MAX_PATHNAME bytes). The full-path is written to
30266 int nOut, /* Size of output buffer in bytes */
30367 ** uninitialized space in zBuf - but valgrind errors tend to worry
30370 ** in the random seed.
30434 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
30438 ** Find the current time (in Universal Coordinated Time). Write into *piNow
30439 ** the current time and date as a Julian Day number times 86_400_000. In
30441 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
30477 ** Find the current time (in Universal Coordinated Time). Write the
30494 ** in the core. So this routine is never called. For now, it is merely
30512 ** Proxy locking is a "uber-locking-method" in this sense: It uses the
30516 ** until late in the file (here) after all of the other I/O methods have
30522 ** The default locking schemes in SQLite use byte-range locks on the
30530 ** address in the shared range is taken for a SHARED lock, the entire
30538 ** slowdown in read performance on AFP because the AFP client disables
30570 ** host ID in it, the proxy path in the conch file will be used, otherwise
30599 ** proxy path against the values stored in the conch. The conch file is
30600 ** stored in the same directory as the database file and the file name
30665 ** and local proxy files in it
30723 ** Creates the lock file and any missing directories in lockPath
30759 ** Create a new VFS file descriptor (stored in memory obtained from
30760 ** sqlite3_malloc) and open the file named "path" in the file descriptor.
30854 /* Not always defined in the headers as it ought to be */
31035 ** lockPath means that the lockPath in the conch file will be used if the
31084 /* if the host id matches and the lock path already exists in the conch
31088 do { /* in case we need to try again for an :auto: named lock file */
31096 ** use the local lock file path that's already in there
31140 /* We are trying for an exclusive lock but another thread in this
31251 } while (1); /* in case we need to retry the :auto: lock file -
31280 ** Store the conch filename in memory obtained from sqlite3_malloc().
31292 char *conchPath; /* buffer in which to construct conch name */
31357 ** is a string buffer at least MAXPATHLEN+1 characters in size.
31365 /* afp style keeps a reference to the db path in the filePath field
31385 ** Takes an already filled in unix file and alters it so all file locking
31387 ** are preserved in the locking context so that they can be restored and
31574 ** are inserted in between. The locking might fail on one of the later
31685 ** should be the only routines in this file that are visible from other
31740 ** All default VFSes for unix are contained in the following array.
31776 /* Register all VFSes defined in the aVfs[] array */
31786 ** Some operating systems might need to do some cleanup in this routine,
31801 ** The author disclaims copyright to this source code. In place of
31817 in the middle of os_win.c ****************/
31822 ** The author disclaims copyright to this source code. In place of
31842 ** At least two bugs have slipped in because we changed the MEMORY_DEBUG
31870 /************** Include hwtime.h in the middle of os_common.h ****************/
31875 ** The author disclaims copyright to this source code. In place of
31959 /************** Continuing where we left off in os_common.h ******************/
32025 /************** Continuing where we left off in os_win.c *********************/
32033 ** available in Windows platforms based on the NT kernel.
32079 ** target system. GetVersionEx was first deprecated in Win8.1.
32090 ** This constant should already be defined (in the "WinDef.h" SDK file).
32097 ** Maximum pathname length (in chars) for Win32. This should normally be
32105 ** This constant should already be defined (in the "WinNT.h" SDK file).
32112 ** Maximum pathname length (in chars) for WinNT. This should normally be
32120 ** Maximum pathname length (in bytes) for Win32. The MAX_PATH macro is in
32129 ** Maximum pathname length (in bytes) for WinNT. This should normally be
32138 ** Maximum error message length (in chars) for WinRT.
32169 ** mode (e.g. these APIs are available in the Windows CE SDK; however, they
32170 ** are not present in the header file)?
32318 * data will almost certainly result in an immediate access violation.
32341 * The extra flags to use in calls to the Win32 heap APIs. This value may be
32412 ** In order to facilitate testing on a WinNT system, the test fixture
33156 ** largest committed free block in the heap, in bytes.
33228 ** The Win32 native heap cannot be modified because it may be in use.
33421 ** Return the size of an outstanding allocation, in bytes.
33527 ** Populate the low-level memory allocation function pointers in
33528 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
33699 ** the provided arguments. The type argument must be 1 in order to set the
33700 ** data directory or 2 in order to set the temporary directory. The zValue
33736 ** is zero if the error message fits in the buffer, or non-zero
33819 ** This routine is invoked after an error occurs in an OS function.
33873 ** non-zero if the error code is transient in nature and the operation
33880 ** may be used to include additional error codes in the set that should
33881 ** result in the failing I/O operation being retried by the caller. If
33988 ** Create the mutex and shared memory used for locking in the file
34044 /* If we succeeded in making the shared memory handle, map it. */
34090 /* The following blocks should probably assert in debug mode, but they
34091 are to cleanup in case any locks remained open */
34750 ** Determine the current size of a file in bytes
34896 ** are inserted in between. The locking might fail on one of the later
35028 /* Update the state of the lock has held in the file descriptor then
35255 ** Return the sector size in bytes of the underlying block device for
35260 ** if two files are created in the same file-system directory (i.e.
35317 ** point to a single instance of this object. In other words, each
35333 ** in this structure.
35351 winShmNode *pNext; /* Next in list of all winShmNode objects */
35494 ** file are currently open, in this process or in other processes, then
35502 int nName; /* Size of zName in bytes */
35771 ** bytes in size.
35776 ** region has not been allocated (by any client, including one running in a
36065 ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
36068 ** value of *pp is undefined in this case.
36209 ** operating system wants filenames in. Space to hold the result
36250 ** The pointer returned in pzBuf must be freed via sqlite3_free().
36447 ** name in the following format:
36451 ** If not, return SQLITE_ERROR. The number 17 is used here in order to
36527 void *zConverted; /* Filename in OS encoding */
36528 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
36532 ** a temporary file. Use this buffer to store the file name in.
36794 ** will open a journal file shortly after it is created in order to do
37004 ** a legal UNC name, a volume relative path, or an absolute path name in the
37033 ** bytes in size.
37038 int nFull, /* Size of output buffer in bytes */
37344 SQLITE_API int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */
37348 ** Find the current time (in Universal Coordinated Time). Write into *piNow
37349 ** the current time and date as a Julian Day number times 86_400_000. In
37351 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
37366 /* 2^32 - to avoid use of LL and warnings in gcc */
37396 ** Find the current time (in Universal Coordinated Time). Write the
37422 ** is zero if the error message fits in the buffer, or non-zero
37425 ** in the output buffer.
37540 ** The author disclaims copyright to this source code. In place of
37556 ** or all of the pages in a database can get journalled. In those cases,
37569 ** Bitvec object is the number of pages in the database file at the
37574 /* Size of the Bitvec structure in bytes. */
37586 /* Size, in bits, of the bitmap element. */
37588 /* Number of elements in a bitmap array. */
37590 /* Number of bits in the bitmap array. */
37593 /* Number of u32 values in hash table. */
37595 /* Maximum number of entries in hash table before
37600 ** (an arbitrary prime)in the hash function provided
37731 /* in hash, if not, try to find a spot for it */
37737 /* we didn't find it in the hash. h points to the first */
37854 ** 5 N S X Set N bits from S increment X in array only, not in bitvec
37859 ** Opcode 5 is used to deliberately induce a fault in order to
37949 ** The author disclaims copyright to this source code. In place of
37964 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
37965 PgHdr *pSynced; /* Last synced page in dirty page list */
37968 int szPage; /* Size of every page in this cache */
37979 ** Some of the assert() macros in this code are too expensive to run
37996 ** non-zero. This is only used in debugging builds, as follows:
38078 ** being used for an in-memory database, this function is a no-op.
38098 ** built-in default page cache is used instead of the application defined
38112 ** Return the size in bytes of a PCache object.
38118 ** has already been allocated and is passed in as the p pointer.
38350 ** Make every page in the cache clean.
38435 ** Merge two lists of pages connected by pDirty and in pgno order.
38463 ** Sort the list of pages in accending order by pgno. Pages are
38467 ** Since there cannot be more than 2^31 distinct pages in a database,
38469 ** One extra bucket is added to catch overflow in case something
38491 /* To get here, there need to be 2^(N_SORT_BUCKET) elements in
38505 ** Return a list of all dirty pages in the cache, sorted by page number.
38530 ** Return the total number of pages in the cache.
38571 ** For all dirty pages currently in the cache, invoke the specified
38588 ** The author disclaims copyright to this source code. In place of
38615 ** This page cache implementation works in one of two modes:
38625 ** and is therefore often faster. Mode 2 requires a mutex in order to be
38642 ** open database file (including each in-memory database and each
38656 int szPage; /* Size of allocated pages in bytes */
38657 int szExtra; /* Size of extra space in bytes */
38667 unsigned int nRecyclable; /* Number of pages in the LRU list */
38668 unsigned int nPage; /* Total number of pages in apHash */
38669 unsigned int nHash; /* Number of slots in apHash[] */
38677 ** in memory.
38682 u8 isPinned; /* Page in use, not on the LRU list */
38683 PgHdr1 *pNext; /* Next in hash table chain */
38685 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
38686 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
38690 ** Free slots in the allocator used to divide up the buffer provided using
38725 ** All code in this file should access the global structure above via the
38772 ** such buffer exists or there is no space left in it, this function falls
38776 ** in pcache1 need to be protected via mutex.
38795 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
38949 ** allocating a new page cache entry in order to avoid stressing
39042 ** (PCache1.apHash structure) that it is currently stored in.
39128 ** Note that the static mutex allocated in xInit does
39149 ** PGroup. In other words, separateCache is true for mode (1) where no
39154 ** * Always use a unified cache in single-threaded applications
39252 ** For a non-purgeable cache (a cache used as the storage for an in-memory
39263 ** 2. If createFlag==0 and the page is not already in the cache, NULL is
39266 ** 3. If createFlag is 1, and the page is not already in the cache, then
39499 ** Discard all unpinned pages in the cache with a page number equal to
39562 ** held by the pager system. Memory in use by any SQLite pager allocated
39621 ** The author disclaims copyright to this source code. In place of
39633 ** are inserted into the RowSet in an arbitrary order. Inserts
39638 ** elements of the RowSet in sorted order. Once this extraction
39651 ** TEST checks to see if an element is already in the RowSet. SMALLEST
39655 ** allocated in chunks so most INSERTs do no allocation. There is an
39661 ** in the batch number. In other words, if an INSERT occurs between
39672 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
39694 ** Each entry in a RowSet is an instance of the following object.
39697 ** objects. In that alternative use, pRight points to the next entry
39698 ** in the list, pLeft points to the tree, and v is unused. The
39708 ** RowSetEntry objects are allocated in large chunks (instances of the
39719 ** A RowSet in an instance of the following structure.
39721 ** A typedef of this structure if found in sqliteInt.h.
39793 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
39846 ** assumed to each already be in sorted order.
39976 ** as deep as it needs to be in order to contain the entire list.
39998 ** Take all the entries on p->pEntry and on the trees in p->pForest and
40001 in the life of a RowSet.
40108 /* Test to see if the iRowid value appears anywhere in the forest.
40131 ** The author disclaims copyright to this source code. In place of
40149 /************** Include wal.h in the middle of pager.c ***********************/
40154 ** The author disclaims copyright to this source code. In place of
40164 ** the implementation of each function in log.c for further details.
40214 ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
40237 ** position in the WAL */
40240 /* Move the write position of the WAL back to iFrame. Called in
40256 int *pnLog, /* OUT: Number of frames in WAL */
40257 int *pnCkpt /* OUT: Number of backfilled frames in WAL */
40261 ** number of frames in the WAL at the point of the last commit since
40280 ** stored in each frame (i.e. the db page-size when the WAL was created).
40289 /************** Continuing where we left off in pager.c **********************/
40312 ** (c) The page number is greater than the largest page that existed in
40325 ** both the content in the database when the rollback journal was written
40326 ** and the content in the database at the beginning of the current
40330 ** in length and are aligned on a page boundary.
40333 ** an integer multiple of the page size in length or are taken from the
40344 ** all queries. Note in particular the content of freelist leaf
40355 ** the beginning of the transaction. (In some VFSes, the xTruncate
40359 ** (9) Whenever the database file is modified, at least one bit in the range
40364 ** (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
40402 ** pager may be in any one of the seven states shown in the following
40440 ** The pager starts up in this state. Nothing is guaranteed in this
40450 ** In this state all the requirements for reading the database in
40452 ** was) in exclusive-locking mode, a user-level read transaction is
40453 ** open. The database size is known in this state.
40458 ** running in locking_mode=exclusive (including temp databases) remains in
40470 ** there is no hot-journal in the file-system.
40475 ** is first opened on the database. In WRITER_LOCKED state, all locks
40479 ** In rollback mode, a RESERVED or (if the transaction was opened with
40482 ** to in this state. If the transaction is committed or rolled back while
40483 ** in WRITER_LOCKED state, all that is required is to unlock the database
40486 ** IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
40491 ** * If the connection is open in rollback-mode, a RESERVED or greater
40493 ** * If the connection is open in WAL-mode, a WAL write transaction
40504 ** first modified by the upper layer. In rollback mode the journal file
40534 ** database file. In this state the transaction may be committed simply
40535 ** by finalizing the journal file. Once in WRITER_FINISHED state, it is
40549 ** SQLITE_IOERR_NOMEM) occurs at a point in the code that makes it
40550 ** difficult to be sure that the in-memory pager state (cache contents,
40553 ** Temporary pager files may enter the ERROR state, but in-memory pagers
40557 ** the contents of the page-cache may be left in an inconsistent state.
40569 ** page-cache and any other in-memory state at the same time. Everything
40577 ** 1. An error occurs while attempting a rollback. This happens in
40581 ** following a commit in function sqlite3PagerCommitPhaseTwo().
40584 ** database file in function pagerStress() in order to free up
40587 ** In other cases, the error is returned to the b-tree layer. The b-tree
40592 ** statement executed within a transaction. In this case, if the error
40594 ** automatically attempt a rollback, as it assumes that an error in a
40595 ** read-only statement cannot leave the pager in an internally inconsistent
40601 ** * The pager is not an in-memory pager.
40606 ** * A pager is never in WRITER_DBMOD or WRITER_FINISHED state if the
40607 ** connection is open in WAL mode. A WAL connection is always in one
40610 ** * Normally, a connection open in exclusive mode is never in PAGER_OPEN
40634 ** the operation was successful. In these circumstances pagerLockDb() and
40647 ** in the file-system that needs to be rolled back (as part of a OPEN->SHARED
40656 ** doesn't know it because of a previous error in xUnlock). If this happens
40658 ** transaction in another process, causing SQLite to read from the database
40662 ** database in the ERROR state, Pager.eLock is set to UNKNOWN_LOCK. It
40670 ** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in
40699 ** savepoint and statement transaction in the system. All such structures
40700 ** are stored in the Pager.aSavepoint[] array, which is allocated and
40712 i64 iOffset; /* Starting offset in main journal */
40714 Bitvec *pInSavepoint; /* Set of pages in this savepoint */
40715 Pgno nOrig; /* Original number of pages in file */
40716 Pgno iSubRec; /* Index of first record in sub-journal */
40743 ** For a temporary or in-memory database (neither of which require any
40749 ** In some (obscure) circumstances, this variable may also be set to
40766 ** This mechanism means that when running in exclusive mode, a connection
40777 ** the way in which the journal file is finalized after the transaction is
40778 ** committed or rolled back when running in "journal_mode=PERSIST" mode.
40783 ** running in "journal_mode=truncate" mode.
40799 ** to the file-system in order to free up memory).
40803 ** The SPILLFLAG_ROLLBACK case is done in a very obscure case that
40806 ** while it is being traversed by code in pager_playback(). The SPILLFLAG_OFF
40812 ** the database page-size in order to prevent a journal sync from happening
40813 ** in between the journalling of two pages on the same sector.
40818 ** is opened as an in-memory journal file. If false, then in-memory
40819 ** sub-journals are only used for in-memory pager files.
40826 ** Variable dbSize is set to the number of pages in the database file.
40827 ** It is valid in PAGER_READER and higher states (all states except for
40833 ** is not an integer multiple of the page-size, the value stored in
40835 ** Except, any file that is greater than 0 bytes in size is considered
40840 ** dbSize are modified in the cache, dbSize is updated accordingly.
40844 ** Variables dbOrigSize and dbFileSize are valid in states
40851 ** the file on disk in pages. It is set to a copy of dbSize when the
40861 ** dbFileSize is not used when rolling back a transaction. In this case
40863 ** a call to xFilesize() that is not strictly required). In either case,
40880 ** The Pager.errCode variable is only ever used in PAGER_ERROR state. It
40881 ** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
40896 u8 noLock; /* Do not lock (except in WAL mode) */
40902 ** routine opertion. Class members not in this block are either fixed
40914 u8 subjInMemory; /* True to use in-memory sub-journals */
40915 Pgno dbSize; /* Number of pages in the database */
40917 Pgno dbFileSize; /* Number of pages in the database file */
40923 Bitvec *pInJournal; /* One bit for each page in the database file */
40927 i64 journalOff; /* Current write offset in the journal file */
40931 int nSavepoint; /* Number of elements in aSavepoint[] */
40942 u16 nExtra; /* Add this many bytes to each in-memory page */
40946 int pageSize; /* Number of bytes in a page */
40983 ** testing purposes only. These variables do not exist in
41003 ** written, semi-random garbage data might appear in the journal
41006 ** sanity checking data is an attempt to discover the garbage in the
41012 ** This cksum is initialized to a 32-bit random value that appears in the
41015 ** data that was once in other files that have now been deleted. If the
41025 ** The size of the of each page record in the journal is given by
41037 ** The macro MEMDB is true if we are dealing with an in-memory database.
41099 ** This function runs many asserts to try to find inconsistencies in
41128 in-memory journal. Since
41129 ** this means an in-memory pager performs no IO at all, it cannot encounter
41131 ** a journal file. (although the in-memory journal implementation may
41133 ** is therefore not possible for an in-memory pager to enter the ERROR
41219 ** in ERROR state. Otherwise the pager should have already dropped
41233 ** Return a pointer to a human readable string in a static buffer
41236 ** to "print *pPager" in gdb:
41288 ** * The bit corresponding to the page-number is not set in
41306 ** Return true if the page is already in the journal file.
41314 ** that is read in *pRes. Return SQLITE_OK if everything worked, or an
41329 ** Write a 32-bit integer into a string buffer in big-endian byte order.
41404 ** an error to call this function if pPager is opened on an in-memory
41488 ** name in the journal is longer than nMaster bytes (including a
41490 ** were present in the journal.
41505 u32 len; /* Length in bytes of master journal name */
41506 i64 szJ; /* Total size in bytes of journal file pJrnl */
41544 ** following the value in pPager->journalOff, assuming a sector
41576 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
41577 ** zero the 28-byte header at the start of the journal file. In either case,
41578 ** if the pager is not in no-sync mode, sync the journal file immediately
41583 ** journal file in bytes is larger than this value, then truncate the
41631 ** - 4 bytes: Number of records in journal, or -1 no-sync mode is on.
41668 ** if in full-sync mode), the zero is overwritten with the true number
41678 ** * When the pager is in no-sync mode. Corruption can follow a
41679 ** power failure in this case anyway.
41713 /* In theory, it is only necessary to write the 28 bytes that the
41716 ** record is written to the following sector (leaving a gap in the file
41717 ** that will be implicitly filled in by the OS).
41725 ** The loop is required here in case the sector-size is larger than the
41727 ** bytes in size, more than one call to sqlite3OsWrite() may be required
41742 ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
41743 ** file. The current location in the journal file is given by
41749 ** database before the transaction began, in pages. Also, pPager->cksumInit
41751 ** in this case.
41760 i64 journalSize, /* Size of the open journal file in bytes */
41780 /* Read in the first 8 bytes of the journal header. If they do not match
41818 ** journal header to zero. In this case, assume that the Pager.pageSize
41826 ** are within range. To be 'in range', both values need to be a power
41834 /* If the either the page-size or sector-size in the journal-header is
41836 ** crashed before the header was synced. In this case stop reading
41866 ** thing written to a journal file. If the pager is in full-sync mode, the
41871 ** + N bytes: Master journal filename in utf-8.
41872 ** + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
41876 ** The master journal page checksum is the sum of the bytes in the master
41885 i64 iHdrOff; /* Offset of header in journal file */
41901 /* Calculate the length in bytes and the checksum of zMaster */
41906 /* If in full-sync mode, advance to the next disk sector before writing
41907 ** the master journal name. This is in case the previous page written to
41928 /* If the pager is in peristent-journal mode, then the physical
41935 ** Easiest thing to do in this scenario is to truncate the journal
41947 ** Find a page in the hash table given its page number. Return
41949 ** already in memory.
41962 ** Discard the entire contents of the in-memory page-cache.
41970 ** Free all structures in the Pager.aSavepoint[] array and set both
41972 ** if it is open and the pager is not in exclusive mode.
41989 ** Set the bit number pgno in the PagerSavepoint.pInSavepoint
42009 ** This function is a no-op if the pager is in exclusive mode and not
42010 ** in
42013 ** If the pager is not in exclusive-access mode, the database file is
42018 ** If the pager is in ERROR state when this function is called, the
42020 ** the OPEN state. Regardless of whether the pager is in exclusive-mode
42021 ** or not, any journal file left in the file-system will be treated
42061 /* If the pager is in the ERROR state and the call to unlock the database
42073 ** code is cleared and the cache reset in the block below.
42082 ** it can safely move back to PAGER_OPEN state. This happens in both
42108 ** is stored in Pager.errCode. While the pager remains in the ERROR state,
42142 ** This routine is never called in PAGER_ERROR state. If it is called
42143 ** in PAGER_NONE or PAGER_SHARED state and the lock held is less
42152 ** depends on whether or not the pager is running in exclusive mode and
42157 ** in-memory journal.
42160 ** Journal file is truncated to zero bytes in size.
42164 ** the first journal header in the file, and hence the entire journal
42170 ** If the pager is running in exclusive mode, this method of finalizing
42172 ** DELETE and the pager is in exclusive mode, the method described under
42176 ** If running in non-exclusive rollback mode, the lock on the file is
42183 ** tries to unlock the database file if not in exclusive mode. If the
42234 ** a hot-journal was just rolled back. In this case the journal
42236 ** the database file, it will do so using an in-memory journal.
42268 /* Drop the WAL write-lock, if any. Also, if the connection was in
42275 /* This branch is taken when committing a transaction in rollback-journal
42308 ** call to pager_unlock() will discard all in-memory pages, unlock
42310 ** means that there is a hot-journal left in the file-system, the next
42344 ** Changing the formula used to compute this checksum results in an
42382 ** value is increased to the start of the next page in the journal.
42402 ** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
42423 PgHdr *pPg; /* An existing page in the cache */
42424 Pgno pgno; /* The page number of a page in journal */
42442 ** is in state OPEN and holds an EXCLUSIVE lock. Hot-journal rollback
42494 /* If the pager is in CACHEMOD state, then there must be a copy of this
42495 ** page in the pager cache. In this case just update the pager cache,
42496 ** not the database file. The page is left marked dirty in this case.
42498 ** An exception to the above rule: If the database is in no-sync mode
42500 ** not be in the pager cache. Later: if a malloc() or IO error occurs
42501 ** during a Movepage() call, then the page may not be in the cache
42502 ** either. So the condition described in the above paragraph is not
42505 ** If in WRITER_DBMOD, WRITER_FINISHED or OPEN state, then we update the
42507 ** not dirty. Since this code is only executed in PAGER_OPEN state for
42509 ** if the pager is in OPEN state.
42517 ** journal. Otherwise, a power loss might leave modified data in the
42518 ** database file without an entry in the rollback journal that can
42522 ** in the main journal either because the page is not in cache or else
42563 ** the database and the page is not in-memory, there is a potential
42569 ** obscure. When running in synchronous mode, this can only happen
42573 ** The solution is to add an in-memory page to the cache containing
42589 /* No page should ever be explicitly rolled back that is in use, except
42590 ** for page 1 which is held in use in order to keep the lock on the
42592 ** of an internal error resulting in an automatic call to
42602 ** transaction was first opened. In this case we can mark the page
42611 ** already in the journal file (recorded in Pager.pInJournal) and
42706 ** sufficient space (in zMasterPtr) to hold the names of master
42772 ** file in the file-system. This only happens when committing a transaction,
42775 ** If the main database file is not open, or the pager is not in either
42854 ** might change if a crash occurs while writing to a single byte in
42868 ** may not have been opened yet, in which case the OsSectorSize()
42878 ** the state it was in before we started making changes.
42884 ** in the journal. If this value is 0xffffffff, then compute the
42891 ** is this many bytes in size.
42900 ** Each entry in the journal is an instance of the 8th item.
42903 ** valid page entries in the journal. In most cases, you can compute the
42907 ** the extra entries had not yet made it safely to disk. In such a case,
42909 ** that reason, we always use the nRec value in the header.
42914 ** in this case. But for things like temporary table (which will be
42935 i64 szJ; /* Size of the journal file in bytes */
42936 u32 nRec; /* Number of Records in the journal */
42938 Pgno mxPg = 0; /* Size of the original file in pages */
42945 /* Figure out how many records are in the journal. Abort early if
42983 ** not enough bytes left in the journal file for a complete header, or
42996 ** working in no-sync mode. This means that the rest of the journal
43006 ** process and if this is the final header in the journal, then it means
43014 ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
43053 ** not completely written and synced prior to a crash. In that
43054 ** case, the database should have never been written in the
43073 /* Following a rollback, the database file should be back in its original
43087 ** modification may just have been reverted. If this happens in exclusive
43090 ** problems for other processes at some point in the future. So, just
43091 ** in case this has happened, clear the changeCountDone flag now.
43169 ** zero or the size of the database in page. Bytes 32..35 and 35..39
43196 ** Update the value of the change-counter at offsets 24 and 92 in
43210 /* Also store the SQLite version number in bytes 96..99 and in
43224 ** If page iPg is present in the cache, and has no outstanding references,
43273 /* For all pages in the cache that are currently dirty or have already
43308 int nList; /* Number of pages in pList */
43316 /* Verify that the page list is in accending order */
43324 /* If a WAL transaction is being committed, there is no point in writing
43368 ** makes a snapshot of the database at the current point in time and preserves
43369 ** that snapshot for use by the reader in spite of concurrently changes by
43380 ** transaction in locking_mode=EXCLUSIVE. So call it now. If we
43381 ** are in locking_mode=NORMAL and EndRead() was previously called,
43399 ** in pages (assuming the page size currently stored in Pager.pageSize).
43402 ** in pages is stored in *pnPage. Otherwise, an error code (perhaps
43422 ** bytes in size is considered to contain at least one page.
43425 i64 n = 0; /* Size of db file in bytes */
43436 /* If the current number of pages in the file is greater than the
43455 ** in WAL mode. If the database is empty or if no *-wal file exists and
43508 ** performed in the order specified:
43524 ** corresponding bit is set in a bitvec structure (variable pDone in the
43526 ** rolled back the first time it is encountered in either journal.
43529 ** journal file. There is no need for a bitvec in this case.
43531 ** In either case, before playback commences the Pager.dbSize variable
43564 ** journal. The actual file might be larger than this in
43573 ** There might be records in the main journal that have a page number
43603 ** test is related to ticket #2565. See the discussion in the
43619 ** previously rolled back out of the main journal (and are hence in pDone)
43645 ** Change the maximum number of in-memory pages that are allowed.
43682 ** Adjust settings of the pager to those specified in the pgFlags parameter.
43684 ** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness
43696 ** in a state which would cause damage to the database
43701 ** of the journal header - being written in between the two
43712 ** an ordinary commit in NORMAL mode with WAL. FULL means that the WAL
43713 ** file is synced following each commit operation, in addition to the
43842 ** is passed in *pPageSize.
43844 ** If the pager is in the error state when this function is called, it
43855 ** * the database is either not an in-memory database or it is
43856 ** an in-memory database that currently consists of zero pages.
43863 ** In all other cases, SQLITE_OK is returned.
43866 ** conditions above is not true, the pager was in error state when this
43877 ** At one point this function returned an error if the pager was in
43952 ** errors in places where we do not care about errors.
43978 ** opened on a file less than N bytes in size, the output buffer is
44010 ** the pager. It returns the total number of pages in the database.
44012 ** However, if the file is between 1 and <page-size> bytes in size, then
44057 ** following is true for all dirty pages currently in the page-cache:
44060 ** current database image, in pages, OR
44071 ** content of the page. However, since this content is not present in either
44090 ** Truncate the in-memory database file image to nPage pages. This
44107 ** if one or more savepoints are open, present in the savepoint
44205 ** Free all PgHdr objects stored in the Pager.pMmapFreelist list.
44220 ** If a transaction was in progress when this routine is called, that
44224 ** result in a coredump.
44228 ** a hot journal may be left in the filesystem but no error is returned
44301 ** Sync the journal. In other words, make sure all the pages that have
44303 ** disk and can be restored in the event of a hot-journal rollback.
44309 ** * If the journal file is an in-memory journal file, no action need
44315 ** been written following it. If the pager is operating in full-sync
44321 ** Or, in pseudo-code:
44323 ** if( NOT <in-memory journal> ){
44332 ** page currently held in memory before returning SQLITE_OK. If an IO
44355 ** that wrote to this database was operating in persistent-journal
44357 ** than Pager.journalOff bytes. If the next thing in the journal
44393 /* Write the nRec value into the journal file header. If in
44399 ** SAFE_APPEND property. Because in this case it is not possible
44436 /* Unless the pager is in noSync mode, the journal file was just
44447 ** The argument is the first in a linked list of dirty pages connected
44449 ** in-memory pages in the list to the database file. The argument may
44450 ** be NULL, representing an empty list. In this case this function is
44463 ** the pages are written out to the database file in list order. Writing
44471 ** in Pager.dbFileVers[] is updated to match the new value stored in
44481 /* This function is only called for rollback pagers in WRITER_DBMOD state. */
44511 /* If there are dirty pages in the page cache with page numbers greater
44533 ** the value now stored in the database file. If writing this
44586 ** If successful, set the bit corresponding to pPg->pgno in the bitvecs
44591 ** SQLITE_NOMEM if a malloc fails while setting a bit in a savepoint
44635 ** (cast as a void*). The pager is always 'purgeable' (not an in-memory
44667 ** Spilling is also prohibited when in an error state since that could
44668 ** lead to database corruption. In the current implementaton it
44670 ** while in the error state, hence it is impossible for this routine to
44671 ** be called in the error state. Nevertheless, we include a NEVER()
44706 ** actually write data to the file in this case.
44755 ** in *ppPager. The pager should eventually be freed by passing it
44762 ** all information is held in cache. It is never written to disk.
44763 ** This can be used to implement an in-memory database.
44787 int nExtra, /* Extra bytes append to each in-memory page */
44795 int tempFile = 0; /* True for temp files (incl. in-memory files) */
44796 int memDb = 0; /* True if this is an in-memory file */
44800 int nPathname = 0; /* Number of bytes in zPathname */
44809 ** is the maximum space required for an in-memory journal file handle
44812 ** file in memory to implement the atomic-write optimization (see
44821 /* Set the output variable to NULL in case an error occurs. */
44836 /* Compute and store the full pathname in an allocated buffer pointed
44860 ** bytes in length. This means the database cannot be opened,
44874 ** file name. The layout in memory is as follows:
44908 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
44937 ** choose a default page size in case we have to create the
44979 ** In this case we accept the default page size and delay actually
44982 ** This branch is also run for an in-memory database. An in-memory
44984 ** disk and uses an in-memory rollback journal.
44991 pPager->eLock = EXCLUSIVE_LOCK; /* Pretend we are in EXCLUSIVE locking mode */
45005 /* If an error occurred in either of the blocks above, free the
45105 ** PAGER_SHARED state. It tests if there is a hot journal present in
45110 ** * The journal file exists in the file system, and
45112 ** * The database file itself is greater than 0 bytes in size, and
45117 ** database with the same name. In this case the journal file is
45123 ** does not exist, then the journal file is not really hot. In this
45160 ** in fact there is none. This results in a false-positive which will
45165 Pgno nPage; /* Number of pages in database file */
45169 /* If the database is zero pages in size, that means that either (1) the
45173 ** In either case, the journal file can be deleted. However, take care
45206 /* If we cannot open the rollback journal file in order to see if
45208 ** it might be due to the race condition described above and in
45234 ** 1) If the pager is currently in PAGER_OPEN state (no lock held
45243 ** 2) If the pager is running in exclusive-mode, and there are currently
45244 ** no outstanding references to any pages, and is in the error state,
45258 ** be OPEN or READER. READER is only possible if the pager is or was in
45301 ** this point in the code and fail to obtain its own EXCLUSIVE lock
45304 ** Unless the pager is in locking_mode=exclusive mode, the lock is
45314 ** in exclusive-access mode the file descriptor will be kept open
45316 ** is usually required to finalize the journal in journal_mode=persist
45320 ** other connection managed to get in and roll it back before
45322 ** may mean that the pager was in the error-state when this
45370 ** In order to get pager_unlock() to do this, set Pager.eState to
45372 ** to ERROR state in the state diagram at the top of this file,
45376 ** to be in ERROR state when there are zero outstanding page
45395 ** and there are already pages in the cache (from a previous
45404 ** a codec is in use.
45432 ** In this case there may exist a Pager.pMap mapping that appears
45441 /* If there is a WAL file in the file-system, open this database in WAL
45474 ** Except, in locking_mode=EXCLUSIVE when there is nothing to in
45485 ** Acquire a reference to page number pgno in pager pPager (a page
45489 ** If the requested page is already in the cache, it is returned.
45491 ** read from the database file. In some cases, the pcache module may
45497 ** already in the cache when this function is called, then the extra
45502 ** requested page is not already stored in the cache, then no
45503 ** actual disk read occurs. In this case the memory image of the
45507 ** of the page. This occurs in two scenarios:
45517 ** to pgno in Pager.pInJournal (bitvec of pages already written to the
45520 ** point in the future, using a call to sqlite3PagerWrite(), its contents
45523 ** The acquisition might fail for several reasons. In all cases,
45527 ** to find a page in the in-memory cache first. If the page is not already
45528 ** in memory, this routine goes to disk to read it in whereas Lookup()
45548 ** temporary or in-memory database. */
45564 /* If the pager is in the error state, return an error immediately.
45607 ** pager was already in the error-state when this function was called.
45616 /* In this case the pcache already contains an initialized copy of
45642 /* Failure to set the bits in the InJournal bit-vectors is benign.
45646 ** a bit in a bit vector.
45688 ** Acquire a page if it is already in the in-memory cache. Do
45690 ** or 0 if the page is not in cache.
45694 ** in the page if the page is not already in cache. This routine
45695 ** returns NULL if the page is not in cache or if a disk I/O error
45742 ** If the journal file is already open (as it may be in exclusive mode),
45761 /* If already in the error state, this function is a no-op. But on
45762 ** the other hand, this routine is never called if we are already in
45835 ** within this transaction will be opened as an in-memory file. This
45837 ** running in exclusive mode) or if the transaction does not require a
45839 ** sub-journal is implemented in-memory if pPager is an in-memory database,
45887 ** This is because in those states the code to roll back savepoint
45889 ** file as well as into the page cache. Which would be incorrect in
45911 ** one of the journals, the corresponding bit is set in the
45922 ** It is never called in the ERROR state.
45940 ** an error might occur and the pager would end up in WRITER_LOCKED state
45941 ** with pages marked as dirty in the cache.
45980 ** page in the block above, set the need-sync flag for the page.
45981 ** Otherwise, when the transaction is rolled back, the logic in
45983 ** in the database file. And if an IO error occurs while doing so,
46023 /* If the statement journal is open and the page is not in it,
46026 ** in that it omits the checksums and the header.
46049 ** fit on a single disk sector. In this case all co-resident pages
46067 Pgno nPageCount; /* Total number of pages in database file */
46148 ** Return TRUE if the page given in the argument was previously passed
46149 ** to sqlite3PagerWrite(). In other words, return TRUE if it is ok
46195 ** page data. In this case the file will be updated when the current
46199 ** with the SQLITE_ENABLE_ATOMIC_WRITE macro defined. In this case,
46213 ** atomic-write optimization is enabled in this build, then isDirect
46219 ** 'isDirect' below, as well as the block enclosed in the
46240 ** operating in direct-mode, make page 1 writable. When not in
46241 ** direct mode, page 1 is always held in cache and hence the PagerGet()
46252 /* If running in direct mode, write the contents of page 1 to the file. */
46281 ** Sync the database file to disk. This is a no-op for in-memory databases
46303 ** This function may only be called while a write-transaction is active in
46304 ** rollback. If the connection is in WAL mode, this call is a no-op.
46309 ** successful, or the connection is in WAL mode, SQLITE_OK is returned.
46350 ** journal file in this case.
46376 /* If this is an in-memory db, or no pages have been written to, or this
46378 ** backup in progress needs to be restarted.
46409 ** * Exactly one page has been modified and store in the journal file.
46413 ** counter in 'indirect-mode'. If the optimization is compiled in but
46416 ** pager_incr_changecounter() to update the change-counter in indirect
46421 ** in 'direct' mode. In this case the journal file will never be
46436 ** following call will modify the in-memory representation of page 1
46466 ** journal requires a sync here. However, in locking_mode=exclusive
46468 ** not the case. In this case it is likely enough that the redundant
46484 ** last page in the db image moved to the free-list. In this case the
46513 ** synced to disk. The journal file still exists in the file-system
46529 ** But if (due to a coding error elsewhere in the system) it does get
46540 ** this transaction, the pager is running in exclusive-mode and is
46547 ** header. Since the pager is in exclusive mode, there is no need
46570 ** If the pager is already in PAGER_ERROR state when this function is called,
46571 ** it returns Pager.errCode immediately. No work is performed in this case.
46573 ** Otherwise, in rollback mode, this function performs two functions:
46576 ** in-memory cache pages to the state they were in when the transaction
46580 ** rollback at any point in the future.
46585 ** In WAL mode, all cache-entries containing data modified within the
46594 /* PagerRollback() is a no-op if called in READER or OPEN state. If
46595 ** the pager is already in the ERROR state, the rollback is not
46637 ** if the database is (in theory) writable.
46715 ** Return true if this is an in-memory pager.
46743 ** if the allocation fails. Otherwise, zero the new portion in case a
46744 ** malloc failure occurs while populating it in the for(...) loop below.
46802 ** In any case, all savepoints with an index greater than iSavepoint
46821 ** operation. Store this value in nNew. Then free resources associated
46831 ** the sub-journal to zero bytes in size. */
46834 /* Only truncate if it is an in-memory sub-journal. */
46844 ** not yet been opened. In this case there have been no changes to
46860 ** Except, if the pager is in-memory only, then return an empty string if
46864 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
46865 ** participate in shared-cache.
46947 ** Move the page pPg to location pgno in the file.
46951 ** in cache. If the page previously located at pgno is not already
46952 ** in the rollback journal, it is not put there by by this routine.
46955 ** meta-data associated with pPg (i.e. data stored in the nExtra bytes
46965 ** is being committed. In this case, it is guaranteed that the database page
46983 /* In order to be able to rollback, an in-memory database must journal
46996 ** <journal page X, then modify it in memory>
47021 ** be written to, store pPg->pgno in local variable needSyncPgno.
47045 /* Do not discard pages from an in-memory database since we might
47057 /* For an in-memory database, make sure the original page continues
47058 ** to exist, in case the transaction needs to roll back. Use pPgOld
47070 ** Currently, no such page exists in the page-cache and the
47076 ** to a malloc() or IO failure), clear the bit in the pInJournal[]
47077 ** array. Otherwise, if the page is loaded and written again in
47079 ** it is synced into the journal file. This way, it may end up in
47152 ** * An in-memory database can only have its journal_mode set to _OFF
47183 /* Do allow the journalmode of an in-memory database to be set to
47200 ** mode except WAL, unless the pager is in locking_mode=exclusive mode,
47213 /* In this case we would like to delete the journal file. If it is
47219 ** while it is in use by some other client.
47260 ** Return TRUE if the pager is in a state where it is OK to change the
47287 ** in backup.c maintains the content of this variable. This module
47297 ** Unless this is an in-memory or temporary database, clear the pager cache.
47356 ** Call sqlite3WalOpen() to open the WAL handle. If the pager is in
47359 ** in. Otherwise, use the normal shared-memory.
47367 /* If the pager is already in exclusive-mode, the WAL module will use
47396 ** file (not a temp file or an in-memory database), and the WAL file
47400 ** not modified in either case.
47402 ** If the pager is open on a temp-file (or in-memory database), or if
47450 /* If the log file is not already open, but does exist in the file-system,
47487 ** the pager is in WAL mode and the WAL file currently contains one or more
47488 ** frames, return the size in bytes of the page images stored within the
47505 ** The author disclaims copyright to this source code. In place of
47514 ** This file contains the implementation of a write-ahead log (WAL) used in
47525 ** transferred back into the database file in an operation called a
47528 ** A single WAL file can be used multiple times. In other words, the
47535 ** The WAL header is 32 bytes in size and consists of the following eight
47553 ** 4: For commit records, the size of the database image in pages
47563 ** (1) The salt-1 and salt-2 values in the frame-header match
47564 ** salt values in the wal-header
47566 ** (2) The checksum values in the final 8 bytes of the frame-header
47572 ** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
47574 ** The checksum values are always stored in the frame header in a
47586 ** in reverse order (the largest fibonacci weight occurs on the first element
47597 ** value is randomized. This prevents old and new frames in the WAL from
47612 ** valid frame in the WAL. The reader uses this recorded "mxFrame" value
47616 ** of the database from a single point in time. This technique allows
47620 ** The reader algorithm in the previous paragraphs works correctly, but
47637 ** be) reconstructed from the original WAL file. In fact, the VFS is required
47642 ** as big endian, the wal-index can store multi-byte values in the native
47647 ** last frame in the wal before frame M for page P in the WAL, or return
47648 ** NULL if there are no frames for page P in the WAL prior to M.
47654 ** in the mxFrame field.
47660 ** first index block are the same size as all other index blocks in the
47667 ** for the first index block) 32-bit page numbers. The first entry in the
47669 ** first frame in the WAL file. The first entry in the second index block
47670 ** in the WAL file corresponds to the (HASHTABLE_NPAGE_ONE+1)th frame in
47673 ** The last index block in a wal-index usually contains less than the full
47687 ** HASHTABLE_NSLOT = 2*HASHTABLE_NPAGE, and there is one entry in the
47688 ** hash table for each page number in the mapping section, so the hash
47691 ** 1-based index of an entry in the mapping section of the same
47692 ** index block. Let K be the 1-based index of the largest entry in
47698 ** To look for page P in the hash table, first compute a hash iKey on
47711 ** no hash slot such that aHash[i]==p) then page P is not in the
47718 ** average, only two or three slots in each index block need to be
47719 ** examined in order to either find the last entry for page P, or to
47720 ** establish that no such entry exists in the block. Each index block
47723 ** comparisons (on average) suffice to either locate a frame in the
47724 ** WAL or to establish that the frame does not exist in the WAL. This
47727 ** Note that entries are added in order of increasing K. Hence, one
47732 ** the correct result. There may be entries in the hash table with
47734 ** slots in the hash table and so the first reader will get an answer as
47736 ** in the first place - which is what reader one wants. Meanwhile, the
47762 ** values in the wal-header are correct and (b) the version field is not
47794 ** The actual header in the wal-index consists of two copies of this
47799 ** added in 3.7.1 when support for 64K pages was added.
47806 u8 bigEndCksum; /* True if checksums in WAL are big-endian */
47807 u16 szPage; /* Database page size in bytes. 1==64K */
47808 u32 mxFrame; /* Index of last valid frame in the WAL */
47809 u32 nPage; /* Size of database in pages */
47810 u32 aFrameCksum[2]; /* Checksum of last frame in log */
47816 ** A copy of the following object occurs in the wal-index immediately
47820 ** nBackfill is the number of frames in the WAL that have been written
47828 ** There is one entry in aReadMark[] for each reader lock. If a reader
47829 ** holds read-lock K, then the value in aReadMark[K] is no greater than
47844 ** in use (that is, every aReadMark[j] for which there is a corresponding
47849 ** in the WAL has been backfilled into the database) then new readers
47857 ** (in other words, if there are no WAL_READ_LOCK(i) where i>0) then
47861 ** We assume that 32-bit loads are atomic and so no locks are needed in
47880 /* Size of header before each frame in wal */
47888 ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
47889 ** big-endian format in the first 4 bytes of a WAL file.
47899 ** Return the offset of frame iFrame in the write-ahead log file,
47919 volatile u32 **apWiData; /* Pointer to wal-index content in memory */
47923 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
47924 u8 writeLock; /* True if in a write transaction */
47932 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
47960 ** all frames in the WAL in database page order. Where two or more frames
47962 ** frame most recently written to the WAL (in other words, the frame with
47975 int nSegment; /* Number of entries in aSegment[] */
47977 int iNext; /* Next slot in aIndex[] not yet returned */
47978 ht_slot *aIndex; /* i0, i1, i2... such that aPgno[iN] ascend */
47980 int nEntry; /* Nr. of entries in aPgno[] and aIndex[] */
47982 } aSegment[1]; /* One for every 32KB page in the wal-index */
47986 ** Define the parameters of the hash tables in the wal-index file. There
47987 ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
47998 ** The block of page numbers associated with the first hash-table in a
48058 ** Return a pointer to the WalCkptInfo structure in the wal-index.
48066 ** Return a pointer to the WalIndexHdr structure in the wal-index.
48086 ** Generate or extend an 8 byte checksum based on the data in
48097 int nByte, /* Bytes of content in a[]. Must be a multiple of 8. */
48139 ** Write the header information in pWal->hdr into the wal-index.
48162 ** 4: For commit records, the size of the database image in pages
48192 ** Check to see if the frame with header in aFrame[] and content
48193 ** in aData[] is valid. If it is a valid frame, fill *piPage and
48208 /* A frame is only valid if the salt values in the frame-header
48209 ** match the salt values in the wal-header.
48224 ** and the frame-data matches the checksum in the last 8
48273 ** In locking_mode=EXCLUSIVE, all of these routines become no-ops.
48312 ** the hash to the next value in the event of a collision.
48329 ** in the wal-index file. Set *piZero to one less than the frame
48331 ** slot in the hash table is set to N, it refers to frame number
48332 ** (*piZero+N) in the log.
48387 ** Return the page number associated with frame iFrame in this WAL.
48414 int nByte; /* Number of bytes to zero in aPgno[] */
48443 /* Zero the entries in the aPgno array that correspond to frames with
48450 /* Verify that the every entry in the mapping region is still reachable
48468 ** Set an entry in the wal-index that will map database page number
48498 /* If the entry in aPgno[] is already set, then the previous writer
48499 ** must have exited unexpectedly in the middle of a transaction (after
48518 /* Verify that the number of entries in the hash table exactly equals
48519 ** the number of entries in the mapping region.
48523 int nEntry = 0; /* Number of entries in the hash table */
48528 /* Verify that the every entry in the mapping region is reachable
48567 /* Obtain an exclusive lock on all byte in the locking range not already
48595 int szFrame; /* Number of bytes in buffer aFrame[] */
48604 /* Read in the WAL header. */
48757 int bNoShm, /* True to run in heap-memory mode */
48768 /* In the amalgamation, the os_unix.c and os_win.c source files come before
48770 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
48828 ** Find the smallest page number out of all pages held in the WAL that
48834 ** Return 0 on success. If there are no pages in the WAL with a page
48878 ** of indices such that the aRight[] contains every index that appears in
48891 const u32 *aContent, /* Pages in wal - keys for the sort */
48892 ht_slot *aLeft, /* IN: Left hand input list */
48893 int nLeft, /* IN: Elements in array *paLeft */
48894 ht_slot **paRight, /* IN/OUT: Right hand input list */
48895 int *pnRight, /* IN/OUT: Elements in *paRight */
48898 int iLeft = 0; /* Current index in aLeft */
48899 int iRight = 0; /* Current index in aRight */
48900 int iOut = 0; /* Current index in output buffer */
48931 ** Sort the elements in list aList using aContent[] as the sort key.
48935 ** The aList[] entries are indices into aContent[]. The values in
48948 const u32 *aContent, /* Pages in wal */
48950 ht_slot *aList, /* IN/OUT: List to sort */
48951 int *pnList /* IN/OUT: Number of elements in aList[] */
48954 int nList; /* Number of elements in aList */
48959 int nMerge = 0; /* Number of elements in list aMerge */
49012 ** pages in the WAL in ascending order. The caller must hold the checkpoint
49025 u32 iLast; /* Last frame in log */
49032 ** it only runs if there is actually content in the log (mxFrame>0).
49067 int nEntry; /* Number of entries in this segment */
49120 ** Return the page-size in bytes used by the database.
49128 ** in response to an sqlite3_wal_checkpoint() request or the equivalent.
49134 ** All I/O barrier operations (a.k.a fsyncs) occur in this routine when
49135 ** SQLite is in WAL-mode in synchronous=NORMAL. That means that if
49141 ** in the WAL and can be recovered following a power-loss or hard reset.
49145 ** it safe to delete the WAL since the new content will persist in the
49154 ** checkpoint is running (in any other thread or process) at the same
49191 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
49193 ** overwrite database pages that are in use by active readers and thus
49302 ** If the WAL file is currently larger than nMax bytes in size, truncate
49335 ** the database. In this case checkpoint the database and unlink both
49355 ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
49360 ** completed and fsynced (rc==SQLITE_OK) and we are in persistent
49388 ** The wal-index is in shared memory. Another thread or process might
49390 ** read it, which might result in inconsistency. A dirty read is detected
49404 WalIndexHdr volatile *aHdr; /* Header in shared memory */
49410 ** same area of shared memory on a different CPU in a SMP,
49415 ** When reading, read [0] first then [1]. Writes are in the reverse order.
49452 ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
49557 ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1)
49572 ** update values of the aReadMark[] array in the header, but if it does
49577 volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */
49592 ** during the few nanoseconds that it is holding the lock. In that case,
49603 int nDelay = 1; /* Pause time in microseconds */
49615 /* If there is not a recovery running in another thread or process
49627 ** modules may return SQLITE_BUSY due to a race condition in the
49664 ** it finished. Leaving a corrupt image in the database file.
49718 ** value in the aReadMark[] array or the contents of the wal-index
49725 ** that occur later in the log than pWal->hdr.mxFrame may have been
49756 ** instant in time. The current thread will continue to use this snapshot.
49793 ** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
49805 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
49813 ** in this case as an optimization. Likewise, if pWal->readLock==0,
49826 ** This code might run concurrently to the code in walIndexAppend()
49836 ** For the reasons above, the if(...) condition featured in the inner
49895 ** (which is nOut bytes in size). Return SQLITE_OK if successful, or an
49901 int nOut, /* Size of buffer pOut in bytes */
49916 ** Return the size of the database in pages (or zero, if unknown).
49935 ** returns SQLITE_BUSY in that case and no write transaction is started.
50004 ** was in before the client began writing to the database.
50013 ** is passed as the second argument is (a) in the cache and
50036 ** point in the event of a savepoint rollback (via WalSavepointUndo()).
50048 ** the values in the aWalData[] array. aWalData must point to an array
50102 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
50107 ** In theory it would be Ok to update the cache of the header only
50161 ** In other words, if iSyncPoint is in between iOffset and iOffset+iAmt,
50198 u8 aFrame[WAL_FRAME_HDRSIZE]; /* Buffer to assemble frame-header in */
50218 int szPage, /* Database page-size in bytes */
50227 PgHdr *pLast = 0; /* Last frame in list */
50230 i64 iOffset; /* Next byte to write in WAL file */
50260 u8 aWalHdr[WAL_HDRSIZE]; /* Buffer to assemble wal-header in */
50287 ** an out-of-order write following a WAL restart could result in
50349 /* If this frame set completes the first transaction in the WAL and
50365 ** be in use by existing readers is being overwritten.
50407 ** callback. In this case this function runs a blocking checkpoint.
50417 int *pnLog, /* OUT: Number of frames in WAL */
50418 int *pnCkpt /* OUT: Number of backfilled frames in WAL */
50444 ** there is no point in blocking waiting for any readers. Assuming no
50499 ** number of frames in the WAL at the point of the last commit since
50518 ** on the pWal->readLock byte. If the WAL is already in locking_mode=NORMAL
50527 ** WAL is already in exclusive-locking mode - meaning that this
50543 ** happen if the connection is actually in exclusive mode (as no xShmLock
50544 ** locks are taken in this case). Nor should the pager attempt to
50558 /* Already in locking_mode=NORMAL */
50601 ** The author disclaims copyright to this source code. In place of
50611 ** This code really belongs in btree.c. But btree.c is getting too
50615 /************** Include btreeInt.h in the middle of btmutex.c ****************/
50620 ** The author disclaims copyright to this source code. In place of
50649 ** disk where M is the number of entries in the tree.
50651 ** In this implementation, a single file can hold one or more separate
50675 ** 16 2 Page size in bytes. (1 means 65536)
50685 ** 36 4 Number of freelist pages in the file
50707 ** space in a page that can be consumed by a single cell for standard
50718 ** except that it applies to leaf nodes in a LEAFDATA tree. The maximum
50720 ** not specified in the header.
50755 ** which is stored in the key size entry of the cell header rather than in
50760 ** offsets from the beginning of the page to the cell content in the cell
50761 ** content area. The cell pointers occur in sorted order. The system strives
50769 ** freeblocks. Each freeblock is at least 4 bytes in size. The byte offset
50770 ** to the first freeblock is given in the header. Freeblocks occur in
50771 ** increasing order. Because a freeblock must be at least 4 bytes in size,
50772 ** any group of 3 or fewer unused bytes in the cell content area cannot
50774 ** a fragment. The total number of bytes in all fragments is recorded.
50775 ** in the page header at offset 7.
50779 ** 2 Bytes in this freeblock
50781 ** Cells are of variable length. Cells are stored in the cell content area at
50782 ** the end of the page. Pointers to the cells are in the cell pointer array
50784 ** contiguous or in order, but cell pointers are contiguous and in order.
50792 ** allows a 64-bit integer to be encoded in 9 bytes.
50803 ** bytes of key and data in a btree cell.
50822 ** Freelist pages come in two subtypes: trunk pages and leaf pages. The
50823 ** file header points to the first in a linked list of trunk page. Each trunk
50841 ** plus 2 bytes for the index to the cell in the page header). Such
50852 ** SQLite database in order to identify the file as a real database.
50886 ** stored in MemPage.pBt->mutex.
50890 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
50899 u16 cellOffset; /* Index in aData of first cell pointer */
50915 ** The in-memory image of a disk page has the auxiliary information appended
50932 BtLock *pNext; /* Next in BtShared.pLock list */
50948 ** shared between multiple connections. In that case, each connection
50954 ** All fields in this structure are accessed under sqlite3.mutex.
50956 ** in the referenced BtShared that point back to this Btree since those
50989 ** A single database file can be in use at the same time by two
50996 ** Fields in this structure are accessed under the BtShared.mutex
51016 ** while in the 'pending-lock' state, no connection may start a new
51035 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
51036 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
51037 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
51038 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
51042 u32 nPage; /* Number of pages in the database */
51069 ** about a cell. The parseCellPtr() function fills in this structure
51074 i64 nKey; /* The key for INTKEY tables, or number of bytes in key */
51078 u16 nHeader; /* Size of the cell content header in bytes */
51099 ** The entry is identified by its MemPage and the index in
51106 ** Fields in this structure are accessed under the BtShared.mutex
51124 i16 iPage; /* Index of current page in apPage */
51125 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
51157 ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
51164 ** cursor. The error has left the cache in an inconsistent state.
51166 ** should return the error code stored in BtCursor.skip
51183 ** page number to look up in the pointer map.
51200 ** each child page in the database file. The parent page is the page that
51201 ** contains a pointer to the child. Every page in the database contains
51202 ** 0 or 1 parent pages. (In this context 'database page' refers
51208 ** position in the file to another as part of autovacuum. When a page
51209 ** is moved, the pointer in its parent must be updated to point to the
51213 ** used in this case.
51216 ** is not used in this case.
51218 ** PTRMAP_OVERFLOW1: The database page is the first page in a list of
51222 ** PTRMAP_OVERFLOW2: The database page is the second or later page in a list of
51224 ** page in the overflow page list.
51227 ** identifies the parent page in the btree.
51259 ** in order to keep track of some global state information.
51261 ** The aRef[] array is allocated so that there is 1 bit for each page in
51262 ** the database. As the integrity-check proceeds, for each page used in
51271 u8 *aPgRef; /* 1 bit per page in the db (see above) */
51272 Pgno nPage; /* Number of pages in the database */
51288 /************** Continuing where we left off in btmutex.c ********************/
51327 ** But we keep a reference count in Btree.wantToLock so the behavior
51330 ** To avoid deadlocks, multiple Btrees are locked in the same order
51342 ** connected by pNext and pPrev should be in sorted order by
51366 /* In most cases, we should be able to acquire the lock we
51378 ** the other BtShared locks that we used to hold in ascending
51452 ** Enter the mutexes in accending order by BtShared pointer address
51454 ** two or more btrees in common both try to lock all their btrees
51536 ** in single threaded applications that use shared cache. Except for
51537 ** these two routines, all mutex operations are no-ops in that case and
51538 ** are null #defines in btree.h.
51541 ** the ones below, are no-ops and are null #defines in btree.h.
51564 ** The author disclaims copyright to this source code. In place of
51627 ** in shared cache. This variable has file scope during normal builds,
51660 ** manipulate entries in the BtShared.pLock linked list used to store
51688 ** When writing to an index that resides in a sharable database, the
51830 /* The condition (pIter->eLock!=eLock) in the following if(...)
51836 ** may hold a WRITE_LOCK on any table in this file (since there can
51883 ** by a connection in read-uncommitted mode is on the sqlite_master
51884 ** table, and that lock is obtained in BtreeBeginTrans(). */
51967 ** than the writer must be about to drop to zero. In this case
51971 ** be zero already. So this next line is harmless in that case.
52033 ** table is about to be deleted. In this case invalidate all incrblob
52037 ** rowid iRow is being replaced or deleted. In this case invalidate
52085 ** may be lost. In the event of a rollback, it may not be possible
52090 ** set in the bitvec. Whenever a leaf page is extracted from the free-list,
52092 ** set in BtShared.pHasContent. The contents of the bitvec are cleared
52145 ** Save the current cursor position in the variables BtCursor.nKey
52162 ** stores the integer key in pCur->nKey. In this case this value is
52227 ** In this version of BtreeMoveto, pKey is a packed index record
52265 ** Restore the cursor to the position it was in (or as close to as possible)
52370 int offset; /* Offset in pointer map page */
52422 int offset; /* Offset of entry in pointer map */
52488 ** Parse a cell content block and fill in the CellInfo structure. There
52499 CellInfo *pInfo /* Fill in this structure */
52501 u16 n; /* Number bytes in cell content header */
52540 ** in between minLocal and maxLocal.
52542 ** Warning: changing the way overflow payload is distributed in any
52543 ** way will result in an incompatible file format.
52568 CellInfo *pInfo /* Fill in this structure */
52574 ** Compute the total number of bytes that a Cell needs in the cell
52663 ** big FreeBlk that occurs in between the header and cell
52705 /* These conditions have already been verified in btreeInitPage()
52750 ** allocation. This routine might need to defragment in order to bring
52753 ** allocation is being made in order to insert a new cell, so we will
52790 in
52822 /* Check to make sure there is enough space in the gap to satisfy
52834 /* Allocate memory from the gap in between the cell pointer array
52852 ** Most of the effort here is involved in coalesing adjacent
52877 ** cell content area exceeds the value in the page header. If these
53067 /* Free blocks must be in ascending order. And the last byte of
53147 ** to fetch the content. Just fill in the content with zeros for now.
53148 ** If in the future we call sqlite3PagerWrite() on this page, that
53155 MemPage **ppPage, /* Return the page in this parameter */
53171 ** already in the pager cache return NULL. Initialize the MemPage.pBt and
53185 ** Return the size of the database file in pages. If there is any kind of
53265 ** or ptrmap page or a free page. In those cases, the following
53269 ** the call for every page that comes in for re-initing. */
53290 ** be exclusively in memory, or it might use a disk-based memory cache.
53294 ** If zFilename is ":memory:" then an in-memory database is created
53300 ** If the database is already opened in the same database connection
53301 ** and we are in shared cache mode, then the open will fail with an
53303 ** objects in the same database connection since doing so will lead
53324 /* Set the variable isMemdb to true for an in-memory database, or
53338 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
53420 /* In debug mode, we mark all persistent databases as sharable
53472 /* If the magic name ":memory:" will create an in-memory database, then
53476 ** regular file-name. In this case the auto-vacuum applies as per normal.
53523 ** The list is kept in ascending order by pBt address.
53627 ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
53706 ** Change the limit on the number of pages allowed in the cache.
53716 ** could be left in an inconsistent and unrecoverable state.
53745 ** Change the way data is synced to disk in order to increase or decrease
53767 ** Return TRUE if the given btree is set to safety level 1. In other
53841 ** This is useful in one special case in the backup API code where it is
53843 ** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
53958 int nPage; /* Number of pages in the database */
53959 int nPageFile = 0; /* Number of pages in the database file */
53960 int nPageHeader; /* Number of pages in the database according to hdr */
54002 ** in WAL mode. If the log is not already open, open it now. Then
54005 ** required as the version of page 1 currently in the page1 buffer
54006 ** may not be the latest version - there may be a newer one in the log
54105 ** in assert() expressions, so it is only compiled if NDEBUG is not
54127 ** If there are no outstanding cursors and we are not in the middle
54132 ** If there is a transaction in progress, this routine is a no-op.
54229 ** returned when there is already a read-lock in order to avoid a deadlock.
54247 /* If the btree is already in a write-transaction, or it
54248 ** is already in a read-transaction and a read-transaction
54300 ** file is not pBt->pageSize. In this case lockBtree() will update
54386 int nCell; /* Number of cells in page pPage */
54432 ** overflow page in the list.
54438 /* The pointer is always the first 4 bytes of the page in this case. */
54486 ** Move the open database page pDbPage to location iFreePage in the
54572 ** SQLITE_OK. If there is no work to do (and therefore no point in
54577 ** that the last page of the file currently in use is no longer in use.
54614 ** if bCommit is non-zero. In that case, the free-list will be
54680 ** nOrig pages in size containing nFree free pages. Return the expected
54681 ** size of the database in pages following an auto-vacuum operation.
54749 ** pages are in use.
54760 Pgno nFin; /* Number of pages in database after autovacuuming */
54894 ** Commit the transaction currently in progress.
54901 ** routine has to do is delete or truncate or zero the header in the
54909 ** transaction. In this case, the transaction has already been committed
54911 ** functions return code. So, even if an error occurs in the pager layer,
54996 ** Rollback the transaction in progress. All cursors will be
54999 ** in an error.
55094 ** SAVEPOINT_ROLLBACK, then iSavepoint may also be -1. In this case the
55134 ** are the conditions that must be met in order for writing to
55140 ** but which are not in the READ_UNCOMMITTED state may not have
55143 ** the read cursors in the other database connection.
55188 /* Now that no other errors can occur, finish filling in the BtCursor
55220 ** Return the size of a BtCursor object in bytes.
55274 ** Make sure the BtCursor* given in the argument has a valid
55276 ** btreeParseCell() to fill it in.
55278 ** BtCursor.info is a cache of the information in the current cell.
55281 ** 2007-06-25: There is a bug in some versions of MSVC that cause the
55300 /* Use a real function in MSVC to work around bugs in that compiler. */
55311 /* Use a macro in all other compilers so that the function is inlined */
55325 ** that is currently pointing to a row in a (non-empty) table.
55339 ** itself, not the number of bytes in the key.
55358 ** Set *pSize to the number of bytes of data in the entry the
55362 ** valid entry. In other words, the calling procedure must guarantee
55378 ** Given the page number of an overflow page in the database (parameter
55379 ** ovfl), this function finds the page number of the next page in the
55385 ** The page number of the next overflow page in the linked list is
55386 ** written to *pPgnoNext. If page ovfl is the last page in its linked
55392 ** on *ppPage to free the reference. In no reference was obtained (because
55410 /* Try to find the next page in the overflow list using the
55411 ** autovacuum pointer-map pages. Guess that the next page in
55508 ** the cursor is moved to a different row. Additionally, in auto-vacuum
55512 ** * A commit in auto_vacuum="full" mode,
55576 ** in the overflow chain. The page number of the first overflow page is
55577 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
55619 ** number for the next page in the overflow chain. The page
55708 ** in the table.
55797 ** in the common case where no overflow pages are used.
55848 ** cell in page pParent. Or, if iIdx is equal to the total number of
55849 ** cells in pParent, that page number iChild is the right-child of
55882 ** into more than one b-tree structure in a corrupt database. */
55960 ** in such a way that page pRoot is linked into a second b-tree table
55990 ** in ascending order.
56015 ** key in ascending order.
56037 /* Move the cursor to the first entry in the table. Return SQLITE_OK
56060 /* Move the cursor to the last entry in the table. Return SQLITE_OK
56074 ** to the last entry in the b-tree. */
56191 u8 *pCell; /* Pointer to current cell in pPage */
56267 /* The record flows over onto one or more overflow pages. In
56337 ** past the last entry in the table or sqlite3BtreePrev() moves past
56341 /* TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
56349 ** Advance the cursor to the next entry in the database. If
56351 ** was already pointing to the last entry in the database before
56402 ** only happen if the database is corrupt in such a way as to link the
56446 ** Step the cursor to the back to the previous entry in the database. If
56448 ** was already pointing to the first entry in the database before
56530 ** The new page is marked as dirty. (In other words, sqlite3PagerWrite()
56536 ** an error. *ppPage and *pPgno are undefined in the event of an error.
56540 ** locate a page close to the page number "nearby". This can be used in an
56541 ** attempt to keep related pages close to each other in the database file,
56542 ** which in turn can make database access faster.
56678 ** page in this case.
56789 ** that is required in the event of a rollback. In this case, do
56906 /* If the database supports auto-vacuum, write an entry in the pointer-map
56916 ** trunk page in the free-list is full, then this page will become a
56918 ** first trunk page in the current free-list. This block tests if it
56937 /* In this case there is room on the trunk page to insert the page
56942 ** coded. But due to a coding error in versions of SQLite prior to
56944 ** usableSize/4 - 8 entries will be reported as corrupt. In order
56947 ** for now. At some point in the future (once everyone has upgraded
56966 ** the page being freed as a leaf page of the first trunk in the free-list.
56968 ** first trunk in the free-list is full. Either way, the page being freed
56969 ** will become the new first trunk page in the free-list.
57045 ** caller is iterating through or using in some other way, this
57065 ** allocated and filled in as necessary. The calling procedure
57071 ** be constructed in this temporary area then copied into pPage->aData
57102 /* Fill in the header. */
57118 /* Fill in the payload */
57157 ** then the optimistic overflow chain processing in clearCell()
57230 ** "sz" must be the number of bytes in the cell.
57273 ** in pPage->apOvfl[] and make it point to the cell content (either
57274 ** in pTemp or the original pCell) and also record its index.
57275 ** Allocating a new entry in pPage->aCell[] implies that
57287 int sz, /* Bytes of content in pCell */
57292 int idx = 0; /* Where to write new cell content in data[] */
57294 int end; /* First byte past the last cell pointer in data[] */
57295 int ins; /* Index in data[] where new cell pointer is inserted */
57296 int cellOffset; /* Address of first cell pointer in data[] */
57312 ** the term after the || in the following assert(). */
57407 ** in a balancing operation. NN is the number of neighbors on either side
57408 ** of the page that participate in the balancing operation. NB is the
57413 ** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
57414 ** in exchange for a larger degradation in INSERT and UPDATE performance.
57418 #define NB (NN*2+1) /* Total pages involved in the balance */
57425 ** tree, in other words, when the new entry will become the largest
57426 ** entry in the tree.
57429 ** a new page to the right-hand side and put the one new entry in
57435 ** pPage is the leaf page which is the right-most page in the tree.
57441 ** byte page number followed by a variable length integer. In other
57443 ** least 13 bytes in size.
57499 ** record-length (a variable length integer at most 32-bits in size)
57572 ** parent page stored in the pointer map is page pTo. If pFrom contained
57576 ** If pFrom is currently carrying any overflow cells (entries in the
57630 ** page are used in the balancing, though both siblings might come from one
57634 ** participate in the balancing.
57637 ** one or two in an effort to keep pages nearly full but not over full.
57640 ** might not actually be stored in MemPage.aData[]. This can happen
57644 ** In the course of balancing the page and its siblings, cells may be
57651 ** in a corrupted state. So if this routine fails, the database should
57671 int iParentIdx, /* Index of "the page" in pParent */
57677 int nCell = 0; /* Number of cells in apCell[] */
57679 int nNew = 0; /* Number of pages in apNew[] */
57680 int nOld; /* Number of pages in apOld[] */
57682 int nxDiv; /* Next divider slot in pParent->aCell[] */
57686 int usableSpace; /* Bytes in pPage beyond the header */
57688 int subtotal; /* Subtotal of bytes in cells on one page */
57695 u8 *pRight; /* Location in parent of right-sibling pointer */
57696 u8 *apDiv[NB-1]; /* Divider cells in pParent */
57697 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
57700 u16 *szCell; /* Local size of all cells in apCell[] */
57702 Pgno pgno; /* Temp var to store a page number in */
57724 /* Find the sibling pages to balance. Also locate the cells in pParent
57732 ** overflow cells in the parent page, since if any existed they will
57783 ** But not if we are in secure-delete mode. In secure-delete mode,
57785 ** In this case, temporarily copy the cell into the aOvflSpace[]
57805 /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
57835 ** into aSpace1[]. In this way, all cells in apCell[] are without
57836 ** child pointers. If siblings are not leaves, then all cell in
57837 ** apCell[] include child pointers. Either way, all cells in apCell[]
57850 ** that the original pages since the original pages will be in the
57908 ** Store this number in "k". Also compute szNew[] which is the total
57910 ** in apCell[] of the cell that divides page i from page i+1.
57917 ** cntNew[i]: Index in apCell[] and szCell[] for the first cell to
57952 int r; /* Index of right-most cell in left sibling */
57978 ** in this procedure so there is no need to act upon it now.
58034 ** Put the new pages in accending order. This helps to
58035 ** keep entries in the disk file in order so that a scan
58037 ** in turn helps the operating system to deliver pages
58074 ** Evenly distribute the data in apCell[] across the new pages.
58106 ** then there is no divider cell in apCell[]. Instead, the divider
58125 ** Note that this can never happen in an SQLite data file, as all
58126 ** cells are at least 4 bytes. It only happens in b-trees used
58127 ** to evaluate "IN (SELECT ...)" and similar clauses.
58158 ** sub-algorithm in some documentation.
58187 ** page in any overflow chains used by new divider cells. These
58319 ** page and SQLITE_OK is returned. In this case the caller is required
58371 ** The page that pCur currently points to has just been modified in
58395 /* The root page of the b-tree is overfull. In this case call the
58431 ** happens, the overflow cell is stored in the aBalanceQuickSpace[]
58437 ** of the aBalanceQuickSpace[] might sneak in.
58444 /* In this case, call balance_nonroot() to redistribute cells
58451 ** are stored in the pSpace buffer allocated immediately below.
58552 ** In some cases, the call to btreeMoveto() below is a no-op. For
58556 ** data into the intkey B-Tree. In this case btreeMoveto() recognizes
58637 ** is advantageous to leave the cursor pointing to the last entry in
58639 ** entry in the table, and the next row inserted has an integer key
58693 ** the cursor to the largest entry in the tree that is smaller than
58726 ** is currently pointing to the largest entry in the sub-tree headed
58750 ** then the cursor still points to that page. In this case the first
58758 ** be either under or overfull. In this case run the balancing algorithm
58760 ** tree that we can be sure that any problem in the internal node has
58783 ** following values of flags are currently in use. Other values for
58811 ** to make room for the new tables root page. In case this page turns
58852 /* Save the positions of any open cursors. This is required in
58903 /* When the new root page was allocated, page 1 was made writable in
58991 ** Delete all information from a single table in the database. iTable is
59001 ** entries in the table.
59032 ** Erase all information in a table and add the root of the table to
59040 ** root page in the database file, then the last root page
59041 ** in the database file is moved into the slot formerly occupied by
59043 ** is added to the freelist instead of iTable. In this say, all
59046 ** page number that used to be the last root page in the file before
59048 ** The last root page is recorded in meta[3] and the value of
59060 ** database. This is because in auto-vacuum mode the backend may
59093 ** number in the database, put the root page on the free list.
59102 ** number in the database. So move the page that does into the
59126 /* Set the new 'max-root-page' value in the database header. This
59146 ** This really never should happen except in a corrupt
59168 ** is the number of free pages currently in the database. Meta[1]
59187 /* If auto-vacuum is disabled in this build and this is an auto-vacuum
59229 ** number of entries in the b-tree and write the result to *pnEntry.
59236 i64 nEntry = 0; /* Value to return in *pnEntry */
59246 ** page in the B-Tree structure (not including overflow pages).
59249 int iIdx; /* Index of child node in parent */
59263 ** the next page in the tree that has not yet been visited. The
59265 ** of the page, or to the number of cells in the page if the next page
59268 ** If all pages in the tree have been visited, return SQLITE_OK to the
59341 ** Return non-zero if the bit in the IntegrityCk.aPgRef[] array that
59350 ** Set the bit in the IntegrityCk.aPgRef[] array that corresponds to page iPg.
59364 ** Also check that the page number is in bounds.
59382 ** Check that the entry in the pointer-map for page iChild maps to
59419 int iPage, /* Page number for first page in the list */
59420 int N, /* Expected number of pages in the list */
59468 ** page in this overflow list, check that the pointer-map entry for
59493 ** NO 2. Make sure cell keys are in order.
59535 /* Clear MemPage.isInit to make sure the corruption detection code in
59562 /* For intKey pages, check that the keys are in order.
59615 /* For intKey leaf pages, check that the min/max keys are in order
59674 "Corruption detected in cell %d on page %d",i,iPage);
59716 ** a table. nRoot is the number of entries in aRoot.
59721 ** Write the number of error seen in *pnErr. Except for some memory
59722 ** allocation errors, an error message held in memory obtained from
59729 int nRoot, /* Number of entries in aRoot[] */
59782 /* Make sure every page in the file is referenced
59832 ** an empty string if the database is in-memory or a TEMP database.
60002 ** required in case any of them are holding references to an xFetch
60041 ** "write version" (single byte at byte offset 19) fields in the database
60096 ** The author disclaims copyright to this source code. In place of
60114 u32 iDestSchema; /* Original schema cookie in destination */
60142 ** structure, in that order.
60145 ** invoked by the pager layer to report various state changes in
60159 ** Non-sharable Btrees (in-memory databases for example), do not have
60165 ** in connection handle pDb. If such a database cannot be found, return
60217 ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
60221 ** stored in database handle pDestDb.
60232 ** handle is not locked in this routine, but it is locked in
60236 ** database connection while a backup is in progress may cause
60327 /* Catch the case where the destination is an in-memory database and the
60336 ** and a codec is in use.
60438 int nSrcPage = -1; /* Size of source db in pages */
60441 /* If the source pager is currently in a write-transaction, return
60467 /* Do not allow backup if the destination database is in WAL mode
60477 ** source pager for the number of pages in the database.
60504 /* Update the schema version field in the destination database. This
60505 ** is to make sure that the schema-version really does change in
60527 /* Set nDestTruncate to the final number of pages in the destination
60532 ** round up. In this case the call to sqlite3OsTruncate() below will
60534 ** sqlite3PagerTruncateImage() here so that any pages in the
60559 ** pending-byte page in the source database may need to be
60577 ** database has been stored in the journal for pDestPager and the
60579 ** the database file in any way, knowing that if a power failure
60720 ** Return the total number of pages in the source database as of the most
60764 ** connection. In this case there is no way of knowing which of the
60816 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
60845 ** The author disclaims copyright to this source code. In place of
60855 ** stores a single value in the VDBE. Mem is an opaque structure visible
60877 ** (1) Memory in Mem.zMalloc and managed by the Mem object
60942 ** in pMem->z is discarded.
60985 ** Make the given Mem object MEM_Dyn. In other words, make it so
60986 ** that any TEXT or BLOB content is stored in memory obtained from
60987 ** malloc(). In this way, we know that the memory is safe to be
61015 ** blob stored in dynamically allocated space.
61070 ** keys are strings. In the former case a NULL pointer is returned the
61161 ** Release any memory held by the Mem. This may leave the Mem in an
61251 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
61256 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
61279 ** The second and third terms in the following conditional enforces
61343 ** Delete any previous value and set the value stored in *pMem to NULL.
61382 ** Delete any previous value and set the value stored in *pMem to val,
61393 ** Delete any previous value and set the value stored in *pMem to val,
61513 ** Transfer the contents of pFrom to pTo. Any existing value in pTo is
61542 ** is required to store the string, then value of pMem is unchanged. In
61548 int n, /* Bytes in string, or negative */
61582 ** also sets a flag in local variable "flags" to indicate the memory
61636 ** to read from the disk) then the pMem is left in an inconsistent state.
61643 Mem *pMem /* OUT: Return data in this Mem structure. */
61686 ** external API. It works in a similar way to sqlite3_value_text(),
61687 ** except the data returned is in the encoding specified by the second
61807 ** Extract a value from the supplied expression in the manner described
61814 ** in all cases.
61838 /* Handle negative integers in a single step. This is needed in the
61944 ** This is used to convert the value stored in the 'sample' column of the
61980 ** Register built-in functions used to help read ANALYZE data.
62001 ** A value is extracted in the following cases:
62003 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
62059 ** in the sqlite_stat4 table.
62065 ** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
62089 UnpackedRecord **ppRec, /* IN/OUT: Probe record */
62118 ** is undefined in this case.
62130 ** Extract the iCol-th column from the nRec-byte record in pRec. Write
62140 int nRec, /* Size of buffer pRec in bytes */
62145 int nHdr; /* Size of the header in the record */
62220 ** Return the number of bytes in the sqlite3_value object assuming
62240 ** The author disclaims copyright to this source code. In place of
62326 ** SQLITE_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain
62370 ** Add a new instruction to the list of instructions current in the
62547 ** in a Vdbe main program and each of the sub-programs (triggers) it may
62565 int nSub; /* Number of entries in apSub */
62614 ** Check if the program stored in the VM associated with pParse may
62629 ** part of an assert statement in the compiler. Similar to:
62658 ** true for this case to prevent the assert() in the callers frame
62770 ** Before returning, *pnOp is set to the number of entries in the returned
62772 ** the number of entries in the Vdbe.apArg[] array required to execute the
63015 ** the Vdbe. In these cases we can just copy the pointer.
63085 ** in a production build.
63169 ** The Synopsis: field in comments in the vdbe.c source file gets converted
63170 ** to an extra string that is appended to the sqlite3OpcodeName(). In the
63183 int nTemp /* Space available in zTemp[] */
63357 ** The prepared statements need to know in advance the complete set of
63359 ** is maintained in p->btreeMask. The p->lockMask value is the subset of
63375 ** that may be accessed by the VM passed as an argument. In doing so it also
63388 ** statement p will ever use. Let N be the number of bits in p->btreeMask
63507 ** allocated by the OP_Program opcode in sqlite3VdbeExec().
63522 ** Give a listing of the program in the virtual machine.
63530 ** are shown in a different format. p->explain==2 is used to implement
63568 ** nRow is the sum of the number of rows in the main program, plus
63569 ** the sum of the number of rows in all trigger subprograms encountered
63606 /* The output line number is small enough that we are still in the
63633 ** kept in p->aMem[9].z to hold the new program - assuming this subprogram
63778 ** to allocate. If there is insufficient space in *ppFrom to satisfy the
63784 u8 **ppFrom, /* IN/OUT: Allocate from *ppFrom */
63801 ** Rewind the VDBE back to the beginning in preparation for
63866 int nArg; /* Number of arguments in subprograms */
63885 if( nOnce==0 ) nOnce = 1; /* Ensure at least one byte in p->aOnceFlag[] */
63891 ** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
63899 ** an array to marshal SQL function arguments in.
63914 /* Memory for registers, parameters, cursor, etc, is allocated in two
63918 ** pass will fill in the rest using a fresh allocation.
63994 ** Copy the values stored in the VdbeFrame structure to its Vdbe. This
64016 ** Also release any dynamic memory held by the VM in the Vdbe.aMem memory
64018 ** pointers to VdbeFrame objects, which may in turn contain pointers to
64059 ** variables in the aVar[] array.
64155 ** virtual module tables written in this transaction. This has to
64195 ** string, it means the main database is :memory: or a temp file. In
64212 ** but could happen. In this case abandon processing and return the error.
64278 /* Write the name of each database file in the transaction into the new
64319 /* Sync all the db files involved in the transaction. The same call
64320 ** sets the master journal pointer in each individual journal. If
64326 ** in case the master journal file name was written into the journal
64380 ** matches the number of vdbe's in the list sqlite3.pVdbe that are
64427 ** In this case (db->nStatement==0), and there is nothing to do.
64502 ** has made changes and is in autocommit mode, then commit those
64507 ** call this on a VM that is in the SQLITE_MAGIC_HALT state.
64528 ** Then the internal cache might have been left in an inconsistent
64567 ** pagerStress() in pager.c), the rollback is required to restore
64708 ** in p->rc. This routine sets that result back to SQLITE_OK.
64795 ** called), set the database error in this case as well.
64874 ** * the corresponding bit in argument mask is clear (where the first
65001 ** encapsulate the code that serializes values for storage in SQLite
65006 ** In an SQLite index record, the serial type is stored directly before
65007 ** the blob of data that it corresponds to. In a table record, all serial
65030 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
65035 ** Return the serial-type for the value stored in pMem.
65099 ** float in the wrong order. And that error has been propagated
65124 static u64 floatSwap(u64 in){
65131 u.r = in;
65143 ** Write the serialized data blob for the value stored in pMem into
65147 ** nBuf is the amount of space left in buf[]. The caller is responsible
65152 ** of bytes in the zero-filled tail is included in the return value only
65153 ** if those bytes were zeroed in buf[].
65200 ** and store the result in pMem. Return the number of bytes read.
65312 int szSpace, /* Size of pSpace[] in bytes */
65342 ** Given the nKey-byte encoding of a record in pKey[], populate the
65354 u32 idx; /* Offset in aKey[] to read from */
65382 ** This function compares two index or table record keys in the same way
65386 ** in assert() statements to ensure that the optimized code in
65395 u32 szHdr1; /* Number of bytes in header */
65410 ** But in fact, mem1.u.i will never actually be used uninitialized, and doing
65426 /* Read the serial types for the next element in each key. */
65433 ** sqlite3VdbeSerialTypeLen() in the common case.
65475 ** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
65483 /* The strings are already in the correct encoding. Call the
65654 ** fields that appear in both keys are equal, then pPKey2->default_rc is
65667 u32 szHdr1; /* Size of record header in bytes */
65668 u32 idx1; /* Offset of first type in header */
65676 ** two elements in the keys are equal. Fix the various stack variables so
65848 ** size-of-header varint at the start of (pKey1/nKey1) fits in a single
65934 ** fields. Return pPKey2->default_rc in this case. */
65950 ** at the start of (pKey1/nKey1) fits in a single byte.
66019 ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
66024 ** limit the size of the header to 64 bytes in cases where the first field
66056 ** Read the rowid (the last field in the record) and store it in *rowid.
66074 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
66082 /* Read in the complete content of the index entry */
66133 ** the key string in pUnpacked. Write into *pRes a number
66182 ** Set a flag in the vdbe to update the change counter when it is finalised
66240 ** in a better query plan.
66254 ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
66255 ** in memory obtained from sqlite3DbMalloc).
66271 ** The author disclaims copyright to this source code. In place of
66288 ** execution environment changes in a way that would alter the program
66373 ** Set all the parameters in the compiled SQL statement to NULL.
66487 int n, /* Bytes in string, or negative */
66653 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
66744 ** be one of the values in the first assert() below. Variable p->rc
66754 ** error has occurred, then return the error code in p->rc to the
66755 ** caller. Set the error code in the database handle to the same value.
66852 ** fails with an error message stating that the function is used in the
66867 "unable to use function %s in the requested context", zName);
66977 ** Return the number of columns in the result set for the statement pStmt.
67045 ** column value (i.e. a value returned by evaluating an SQL expression in the
67077 ** in the result set.
67281 ** Routines used to attach values to wildcards in a compiled SQL statement.
67284 ** Unbind the value bound to variable i in virtual machine p. This is the
67291 ** The error code stored in database p->db is overwritten with the return
67292 ** value in any case.
67318 /* If the bit corresponding to this variable in Vdbe.expmask is set, then
67322 ** parameter in the WHERE clause might influence the choice of query plan
67570 ** in the argument belongs. This is the same database handle that was
67572 ** the statement in the first place.
67587 ** Return true if the prepared statement is in need of being reset.
67627 ** The author disclaims copyright to this source code. In place of
67646 ** bytes in this text up to but excluding the first character in
67648 ** the total number of bytes in the text.
67670 ** This function returns a pointer to a nul-terminated string in memory
67685 ** ALGORITHM: Scan the input string looking for host parameters in any of
67690 ** parameter index is known, locate the value in p->aVar[]. Then render
67691 ** the value as a literal in place of the host parameter name.
67753 int nOut; /* Number of bytes of the string text to include in output */
67784 int nOut; /* Number of bytes of the blob to include in output */
67928 ** The author disclaims copyright to this source code. In place of
67936 ** The code in this file implements the function that runs the
67939 ** Various scripts scan this source file in order to generate HTML
67941 ** of the code in this file is, therefore, important. See other comments
67942 ** in this file for details. If in doubt, do not deviate from existing
67951 ** is changed while the copy is still in use, the string or blob might
67974 ** each instruction in the VDBE. When it reaches zero, the u1.isInterrupted
67975 ** field of the sqlite3 structure is set in order to simulate an interrupt.
67978 ** in an ordinary build.
68044 ** source code is in a single file (the amalgamation). Special values 1
68082 ** string that the register itself controls. In other words, it
68099 int nField, /* Number of fields in the table or index */
68109 ** purposes in a vdbe program. The different uses might require
68150 ** do so without loss of information. In other words, if the string
68392 /************** Include hwtime.h in the middle of vdbe.c *********************/
68397 ** The author disclaims copyright to this source code. In place of
68481 /************** Continuing where we left off in vdbe.c ***********************/
68489 ** the number of non-transaction savepoints currently in the
68623 ** an undefined integer. Opcodes will either fill in the integer
68675 ** separate instruction in the virtual machine. If we follow the usual
68679 ** big comment (similar to this one) will mark the point in the code where
68691 ** Other keywords in the comment that follows each case are used to
68698 ** comment lines are used in the generation of the opcode.html documentation
68704 ** Do not deviate from the formatting style currently in use.
68774 ** Jump to the next instruction after the address in register P1. After
68810 ** The instruction at the address in register P1 is a Yield.
68831 ** Swap the program counter with the value in register P1. This
68857 ** Check the value in register P3. If it is NULL then Halt using
68859 ** value in register P3 is not NULL, then this routine is a no-op.
68914 ** an IGNORE exception. In this case jump to the address specified
68939 zLogFmt = "abort at %d in [%s]: %s";
69038 ** The string value P4 of length P1 (bytes) is stored in register P2.
69054 ** NULL into register P3 and every register in between P2 and P3. If P3
69097 ** blob in register P2.
69112 ** If the parameter is named, then its name appears in P4.
69132 ** Move the P3 values in register P1..P1+P3-1 over into
69265 /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
69270 ** In case this is such a statement, close any statement transaction
69314 ** Add the text in register P1 onto the end of the text in
69315 ** register P2 and store the result in register P3.
69316 ** If either the P1 or P2 text are NULL then store NULL in P3.
69362 ** Add the value in register P1 to the value in register P2
69363 ** and store the result in register P3.
69370 ** Multiply the value in register P1 by the value in register P2
69371 ** and store the result in register P3.
69377 ** Subtract the value in register P1 from the value in register P2
69378 ** and store the result in register P3.
69384 ** Divide the value in register P1 by the value in register P2
69385 ** and store the result in register P3 (P3=P2/P1). If the value in
69393 ** register P1 and store the result in register P3.
69394 ** If the value in register P1 is zero the result is NULL.
69451 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
69490 ** be returned. This is used by the built-in min(), max() and nullif()
69499 ** publicly, only to user functions defined in func.c.
69514 ** successors. The result of the function is stored in register P3.
69556 ** the pointer to ctx.s so in case the user-function can use
69619 ** Take the bit-wise AND of the values in register P1 and P2 and
69620 ** store the result in register P3.
69626 ** Take the bit-wise OR of the values in register P1 and P2 and
69627 ** store the result in register P3.
69633 ** Shift the integer value in register P2 to the left by the
69634 ** number of bits specified by the integer in register P1.
69635 ** Store the result in register P3.
69641 ** Shift the integer value in register P2 to the right by the
69642 ** number of bits specified by the integer in register P1.
69643 ** Store the result in register P3.
69672 /* If shifting by a negative amount, shift in the other direction */
69701 ** Add the constant P2 to the value in register P1.
69716 ** Force the value in register P1 to be an integer. If the value
69717 ** in P1 is not an integer and cannot be converted into an integer
69762 ** Force the value in register P1 to be text.
69785 ** Force the value in register P1 to be a BLOB.
69808 ** Force the value in register P1 to be numeric (either an
69825 ** Force the value in register P1 to be an integer. If
69843 ** Force the value in register P1 to be a floating point number.
69863 ** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
69881 ** are text, then the appropriate collating function specified in
69889 ** store a boolean result (either 0, or 1, or NULL) in register P2.
69891 ** If the SQLITE_NULLEQ bit is set in P5, then NULL values are considered
69899 ** the operands in registers P1 and P3 are not equal. See the Lt opcode for
69902 ** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
69912 ** the operands in registers P1 and P3 are equal.
69915 ** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
70036 ** of integers in P4.
70039 ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should
70052 ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
70053 ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
70058 ** OPFLAG_PERMUTE bit is clear, then register are compared in sequential
70119 ** in the most recent OP_Compare instruction the P1 vector was less than
70136 ** Take the logical AND of the values in registers P1 and P2 and
70146 ** Take the logical OR of the values in register P1 and P2 and
70147 ** store the answer in register P3.
70190 ** Interpret the value in register P1 as a boolean value. Store the
70191 ** boolean complement in register P2. If the value in register P1 is
70192 ** NULL, then a NULL is stored in P2.
70210 ** a NULL then store a NULL in P2.
70227 ** In other words, this opcode causes all following opcodes up through P2
70247 ** Jump to P2 if the value in register P1 is true. The value
70249 ** in P1 is NULL then take the jump if and only if P3 is non-zero.
70253 ** Jump to P2 if the value in register P1 is False. The value
70255 ** in P1 is NULL then take the jump if and only if P3 is non-zero.
70281 ** Jump to P2 if the value in register P1 is NULL.
70295 ** Jump to P2 if the value in register P1 is not NULL.
70313 ** values in the record, extract a NULL.
70315 ** The value extracted is stored in register P3.
70332 i64 payloadSize64; /* Number of bytes in the record */
70346 u32 szField; /* Number of bytes in the content of a field */
70441 ** parsed and valid information is in aOffset[] and aType[].
70444 /* If there is more header available for parsing in the record, try
70461 /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
70491 /* If we have read more header data than was contained in the header,
70542 ** for text and blob and whatever is in the payloadSize64 variable
70558 /* If we dynamically allocated space to hold the data (in the
70589 ** memory cell in the range.
70612 ** use as a data record in a database table or as a key
70613 ** in an index. The OP_Column opcode can decode the record later.
70620 ** macros defined in sqliteInt.h.
70631 int nVarint; /* Number of bytes in a varint */
70635 int nField; /* Number of fields in the record */
70638 int i; /* Space used in zNewRecord[] header */
70639 int j; /* Space used in zNewRecord[] content */
70754 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
70763 ** Store the number of entries (an integer value) in the table or index
70764 ** opened by cursor P1 in register P2
70814 "SQL statements in progress");
70872 "cannot release savepoint - SQL statements in progress"
70926 ** constraint violations present in the database to the value stored
70979 "SQL statements in progress");
70988 "SQL statements in progress");
71042 ** connection is currently not in autocommit mode, or if there are other
71053 ** cookie in P3 differs from the schema cookie in the database header or
71054 ** if the schema generation counter in P4 differs from the current
71118 ** stored with the in-memory representation of the schema, do
71121 ** If virtual-tables are in use, this is not just an optimization.
71122 ** Often, v-tables store their data in other SQLite tables, which
71197 /* Record changes in the file format */
71213 ** P2 in a database file. The database file is determined by P3.
71236 ** value, it is set to the number of columns in the table.
71245 ** number of P2 and if it is this opcode becomes a no-op. In other words,
71265 ** value, it is set to the number of columns in the table, or to the
71269 ** in read/write mode. For a given table, there can be one or more read-only
71385 ** P2 is the number of columns in the ephemeral table.
71388 ** that defines the format of keys in the index.
71391 ** in btree.h. These flags control aspects of the operation of
71401 ** indices in joins.
71473 ** Synopsis: P3 columns in r[P2]
71477 ** register P2. In other words, cursor P1 becomes an alias for the
71478 ** MEM_Blob content contained in register P2.
71485 ** P3 is the number of fields in the records that will be stored by
71518 ** use the value in register P3 as the key. If cursor P1 refers
71519 ** to an SQL index, then P3 is the first in an array of P4 registers
71526 ** This opcode leaves the cursor configured to move in forward order,
71527 ** from the beginning toward the end. In other words, the cursor is
71536 ** use the value in register P3 as a key. If cursor P1 refers
71537 ** to an SQL index, then P3 is the first in an array of P4 registers
71544 ** This opcode leaves the cursor configured to move in forward order,
71545 ** from the beginning toward the end. In other words, the cursor is
71554 ** use the value in register P3 as a key. If cursor P1 refers
71555 ** to an SQL index, then P3 is the first in an array of P4 registers
71562 ** This opcode leaves the cursor configured to move in reverse order,
71563 ** from the end toward the beginning. In other words, the cursor is
71572 ** use the value in register P3 as a key. If cursor P1 refers
71573 ** to an SQL index, then P3 is the first in an array of P4 registers
71580 ** This opcode leaves the cursor configured to move in reverse order,
71581 ** from the end toward the beginning. In other words, the cursor is
71613 /* The input value in P3 might be of any type: integer, real, string,
71764 ** is a prefix of any entry in P1 then a jump is made to P2 and
71767 ** This operation leaves the cursor in a state where it can be
71768 ** advanced in the forward direction. The Next instruction will work,
71781 ** is not the prefix of any entry in P1 then a jump is made to P2. If P1
71786 ** This operation leaves the cursor in a state where it cannot be
71787 ** advanced in either direction. In other words, the Next and Prev
71801 ** record are not-NULL then a check is done to determine if any row in the
71809 ** This operation leaves the cursor in a state where it cannot be
71810 ** advanced in either direction. In other words, the Next and Prev
71909 ** This opcode leaves the cursor in a state where it cannot be advanced
71910 ** in either direction. In other words, the Next and Prev opcodes will
71970 ** The record number is not previously used as a key in the database
71974 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds
71998 ** thing) is obtained in a two-step algorithm.
72006 ** it already exists in the table. If it does not exist, we have
72076 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
72116 ** entry is overwritten. The data is the value MEM_Blob stored in register
72117 ** number P2. The key is stored in register P3. The key must
72155 ** integer value P3, not the value of the integer stored in register P3.
72229 ** record in the table. If it is left pointing at the next record, then
72294 ** record blob in register P3 against a prefix of the entry that
72298 ** If either P3 or the sorter contains a NULL in one of their significant
72345 ** it is found in the database file.
72356 ** it is found in the database file.
72387 ** a no-op and can never fail. But we leave it in place as a safety.
72418 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
72427 ** Store in register P2 an integer which is the key of the table entry that
72496 ** will refer to the last entry in the database table or index.
72501 ** This opcode leaves the cursor configured to move in reverse order,
72502 ** from the end toward the beginning. In other words, the cursor is
72556 ** will refer to the first entry in the database table or index.
72561 ** This opcode leaves the cursor configured to move in forward order,
72562 ** from the beginning toward the end. In other words, the cursor is
72599 ** Advance cursor P1 so that it points to the next key/data pair in its
72620 ** number P5-1 in the prepared statement is incremented.
72631 ** Back up cursor P1 so that it points to the previous key/data pair in its
72653 ** number P5-1 in the prepared statement is incremented.
72811 ** Write into register P2 an integer which is the last entry in the record at
72936 ** Delete an entire database table or index whose root page in the database
72939 ** The table being destroyed is in the main database file if P3==0. If
72940 ** P3==1 then the table to be clear is in the auxiliary database file
72944 ** might be moved into the newly deleted root page in
72947 ** is stored in register P2. If no page
72949 ** the last one in the database) then a zero is stored in register P2.
72950 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
73000 ** in the database file is given by P1. But, unlike Destroy, do not
73003 ** The table being clear is in the main database file if P2==0. If
73004 ** P2==1 then the table to be clear is in the auxiliary database file
73008 ** intkey table (an SQL table, not an index). In this case the row change
73009 ** count is incremented by the number of rows in the table being cleared.
73010 ** If P3 is greater than zero, then the value stored in register P3 is
73011 ** also incremented by the number of rows in the table being cleared.
73061 ** Allocate a new table in the main database file if P1==0 or in the
73062 ** auxiliary database file if P1==1 or in an attached database if
73075 ** Allocate a new index in the main database file if P1==0 or in the
73076 ** auxiliary database file if P1==1 or in an attached database if
73176 ** Remove the internal (in-memory) data structures that describe
73177 ** the table named P4 in database P1. This is called after a table
73178 ** is dropped from disk (using the Destroy opcode) in order to keep
73189 ** Remove the internal (in-memory) data structures that describe
73190 ** the index named P4 in database P1. This is called after an index
73192 ** in order to keep the internal representation of the
73202 ** Remove the internal (in-memory) data structures that describe
73203 ** the trigger named P4 in database P1. This is called after a trigger
73204 ** is dropped from disk (using the Destroy opcode) in order to keep
73217 ** Do an analysis of the currently open database. Store in
73219 ** If no problems are found, store a NULL in register P1.
73223 ** In other words, the analysis stops as soon as reg(P1) errors are
73226 ** The root page numbers of all tables in the database are integer
73227 ** stored in reg(P1), reg(P1+1), reg(P1+2), .... There are P2 tables
73281 ** held in register P1.
73324 ** Synopsis: if r[P3] in rowset(P1) goto P2
73328 ** the value held in P3, jump to register P2. Otherwise, insert the
73329 ** integer in P3 into the RowSet and continue on to the
73356 /* If there is anything other than a rowset object in memory cell P1,
73388 ** cell in an array of values used as arguments to the sub-program. P2
73391 ** of a memory cell in this (the parent) VM that is used to allocate the
73403 Mem *pEnd; /* Last memory cell in new array */
73404 VdbeFrame *pFrame; /* New vdbe frame to execute in */
73418 ** disabled. In some cases a single trigger may generate more than one
73441 ** program stored in SubProgram.aOp. As well as these, one memory
73506 ** This opcode is only ever present in sub-programs called via the
73507 ** OP_Program instruction. Copy a value currently stored in a memory
73508 ** cell of the calling (parent) frame to cell P2 in the current frames
73512 ** The address of the cell in the parent frame is determined by adding
73575 ** P1 is a register in the root frame of this VM (the root frame is
73578 ** its current value and the value in register P2.
73623 ** Register P1 must contain an integer. Add literal P3 to the value in
73641 ** value in register P1. If the result is exactly 0, jump to P2.
73750 ** Checkpoint database P1. This is a no-op if P1 is not currently in
73753 ** SQLITE_BUSY or not, respectively. Write the number of pages in the
73755 ** in the WAL that have been checkpointed after the checkpoint
73826 ** in temporary storage or if the VFS does not support shared memory
73953 ** P1 is the index of the database in sqlite3.aDb[] of the database
74001 ** P4 is the name of a virtual table in database P1. Call the xCreate method
74013 ** P4 is the name of a virtual table in database P1. Call the xDestroy method
74029 ** table and stores that cursor in P1.
74074 ** by P1. The integer query plan parameter to xFilter is stored in register
74165 ** the current contents to sContext.s so in case the user-function
74180 ** dynamic allocation in sContext.s (a Mem struct) is released.
74197 ** Advance virtual table P1 to the next row in its result set and
74244 ** in register P1 is passed as the zName argument to the xRename method.
74277 ** invocation. The value in register (P3+P2-1) corresponds to the
74285 ** rowid for itself. The subsequent elements in the array are
74286 ** the values of columns in the new row.
74296 ** apply in the case of a constraint failure on an insert or update.
74350 ** Write the current number of pages in database P1 to memory cell P2.
74362 ** Try to set the maximum page count for database P1 to the value in P3.
74366 ** Store the maximum page count after the change in register P2.
74391 ** the UTF-8 string contained in P4 is emitted on the trace callback.
74443 ** the same as a no-op. This opcodesnever appears in a real VM program.
74558 ** The author disclaims copyright to this source code. In place of
74579 int nByte; /* Size of open blob, in bytes */
74580 int iOffset; /* Byte offset of blob in cursor data */
74595 ** contain a value of type TEXT or BLOB in the column nominated when the
74669 int iCol; /* Index of zColumn in row-record */
74842 ** we can invoke OP_Column to fill in the vdbe cursors type
74929 ** already been invalidated. Return SQLITE_ABORT in this case.
74999 ** already been invalidated. Return SQLITE_ABORT in this case.
75025 ** The author disclaims copyright to this source code. In place of
75033 ** This file contains code for the VdbeSorter object, used in concert with
75035 ** example, by CREATE INDEX statements on tables too large to fit in main
75048 ** As keys are added to the sorter, they are written to disk in a series
75050 ** the same as the cache-size allowed for temporary databases. In order
75051 in sorted order,
75054 ** merging any number of arrays in a single pass with no redundant comparison
75060 ** N elements in size, where N is the smallest power of 2 greater to or equal
75064 ** The aTree[] array is also N elements in size. The value of N is stored in
75096 ** be advanced to the next key in its segment. Say the next key is
75110 ** In other words, each time we advance to the next sorter element, log2(N)
75119 int nPMA; /* Number of PMAs stored in pTemp1 */
75120 int mnPmaSize; /* Minimum PMA size, in bytes */
75121 int mxPmaSize; /* Maximum PMA size, in bytes. 0==no limit */
75125 SorterRecord *pRecord; /* Head of in-memory record list */
75130 ** The following type is an iterator for a PMA. It caches the current key in
75137 int nKey; /* Number of bytes in key */
75142 int nBuffer; /* Size of read buffer in bytes */
75148 ** blocks. Doing all I/O in aligned page-sized blocks helps I/O to go
75152 int eFWErr; /* Non-zero if in an error state */
75154 int nBuffer; /* Size of write buffer in bytes */
75157 i64 iWriteOff; /* Offset of start of buffer in file */
75162 ** A structure to store a single record. All in-memory records are connected
75175 /* Maximum number of segments to merge in a single pass. */
75204 int nAvail; /* Bytes of data available in buffer */
75209 ** than p->nBuffer bytes remaining in the PMA, read all remaining data. */
75231 /* The requested data is available in the in-memory buffer. In this
75237 /* The requested data is not all available in the in-memory buffer.
75238 ** In this case, allocate space at p->aAlloc[] to copy the requested
75251 /* Copy as much data as is available in the buffer into the start of
75305 ** Advance iterator pIter to the next key in its PMA. Return SQLITE_OK if
75313 u64 nRec = 0; /* Size of record in bytes */
75331 ** Initialize iterator pIter to scan through the PMA stored in file pFile
75333 ** leaves the iterator pointing to the first key in the PMA (or EOF if the
75339 i64 iStart, /* Start offset in pFile */
75341 i64 *pnByte /* IN/OUT: Increment this value by PMA size */
75375 u64 nByte; /* Size of PMA in bytes */
75397 ** If the bOmitRowid argument is non-zero, assume both keys end in a rowid
75467 assert( pCsr->pSorter->pUnpacked!=0 ); /* allocated in vdbeSorterMerge() */
75737 ** Write the current contents of the in-memory linked-list to a PMA. Return
75743 ** in the PMA (not including the varint itself).
75745 ** * One or more records packed end-to-end in order of ascending keys.
75747 ** key). The varint is the number of bytes in the blob of data.
75820 ** * The total memory allocated for the in-memory list is greater
75823 ** * The total memory allocated for the in-memory list is greater
75849 i64 *pnByte /* Sum of bytes in all opened PMAs */
75854 i64 nByte = 0; /* Total bytes in all opened PMAs */
75876 ** for iterating through its contents in sorted order.
75891 ** from the in-memory list. */
75898 /* Write the current in-memory list to a PMA. */
75922 i64 nWrite; /* Number of bytes in new PMA */
75926 /* If there are SORTER_MAX_MERGE_COUNT or less PMAs in file pTemp1,
75985 ** Advance to the next element in the sorter.
76001 ** advanced (iPrev) and the one next to it in the array. */
76007 /* Compare pIter1 and pIter2. Store the result in variable iRes. */
76020 ** Then set pIter2 to the next iterator to compare to pIter1. In this
76021 ** case there is no cache of pIter2 in pSorter->pUnpacked, so set
76059 int *pnKey /* OUT: Size of current key in bytes */
76093 ** Compare the key in memory cell pVal with the key that the sorter cursor
76099 ** key in pVal is smaller than, equal to or larger than the current sorter
76121 ** The author disclaims copyright to this source code. In place of
76136 ** the caller specifies a buffer size for an in-memory buffer to
76140 ** 1) The in-memory representation grows too large for the allocated
76153 int nBuf; /* Size of zBuf[] in bytes */
76180 ** returning. This way, SQLite uses the in-memory journal data to
76280 ** Query the size of the file in bytes.
76379 ** The author disclaims copyright to this source code. In place of
76388 ** This file contains code use to implement an in-memory rollback journal.
76389 ** The in-memory rollback journal is used to journal transactions for
76398 /* Space to hold the rollback journal is allocated in increments of
76403 ** a power-of-two allocation. This mimimizes wasted space in power-of-two
76412 FileChunk *pNext; /* Next chunk in the journal */
76431 FileChunk *pFirst; /* Head of in-memory chunk-list */
76437 ** Read data from the in-memory journal file. This is the implementation
76495 /* An in-memory journal file should only ever be appended to. Random
76562 ** Syncing an in-memory journal is a no-op. And, in fact, this routine
76563 ** is never called in a working implementation. This implementation
76564 ** exists purely as a contingency, in case some malfunction in some other
76573 ** Query the size of the file in bytes.
76618 ** an in-memory journal
76636 ** The author disclaims copyright to this source code. In place of
76653 ** of the expression, while decending. (In other words, the callback
76690 ** Call sqlite3WalkExpr() for every expression in list p or until
76722 ** Walk the parse trees associated with all subqueries in the
76725 ** and on any subqueries further down in the tree. Return
76745 ** Call sqlite3WalkExpr() for every expression in Select statement p.
76746 ** Invoke sqlite3WalkSelect() for subqueries in the FROM clause and
76792 ** The author disclaims copyright to this source code. In place of
76833 ** result set in pEList.
76846 ** that in a GROUP BY clause, the expression is evaluated twice. Hence:
76854 ** The result of random()%5 in the GROUP BY clause is probably different
76855 ** from the result in the result-set. On the other hand Standard SQL does
76857 ** So this should never come up in well-formed queries.
76877 int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
76927 ** Return TRUE if the name zCol occurs anywhere in the USING clause.
76944 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
76974 ** that name in the set of source tables in pSrcList and make the pExpr
76978 ** pExpr->iDb Set the index in db->aDb[] of the database X
76997 ** in pParse and return WRC_Abort. Return WRC_Prune on success.
77014 NameContext *pTopNC = pNC; /* First namecontext in the list */
77021 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
77029 /* Translate the schema name in zDb into a pointer to the corresponding
77031 in an appropriate error message toward the end of this routine
77092 ** is for the right-hand table of a NATURAL JOIN or is in a
77182 ** we are resolving names in the WHERE clause of the following command:
77186 ** In cases like this, replace pExpr with a copy of the expression that
77187 ** forms the result set entry ("a+b" in the example) and return immediately.
77188 ** Note that the expression in the result set should have already been
77191 ** The ability to use an output result-set column in the WHERE, GROUP BY,
77192 ** or HAVING clauses, or as part of a larger expression in the ORDRE BY
77232 ** If X and Y are NULL (in other words if only the column name Z is
77233 ** supplied) and the value of Z is enclosed in double-quotes, then
77234 ** Z is a string literal if it doesn't match any column names. In that
77239 ** fields are not changed in any context.
77265 /* If a column from a table in pSrcList is referenced, then record
77266 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
77268 ** column number is greater than the number of bits in the bitmask
77310 ** from datasource iSrc in SrcList pSrc.
77341 sqlite3ErrorMsg(pParse, "%s prohibited in partial index WHERE clauses",
77356 sqlite3ErrorMsg(pParse,"%s prohibited in CHECK constraints", zMsg);
77381 ** node in the expression tree. Return 0 to continue the search down
77412 ** column in the FROM clause. This is used by the LIMIT and ORDER BY
77468 int nId; /* Number of characters in function name */
77584 ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
77588 ** elements in pEList, corresponding to the matching entry. If there is
77616 ** pE is a pointer to an expression which is a single term in the
77624 ** Attempt to match pE against result set columns in the left-most
77627 ** The left-most column is 1. In other words, the value returned is the
77628 ** same integer value that would be used in the SQL statement to indicate
77648 /* Resolve all names in the ORDER BY term expression
77664 ** in the result set. Return an 1-based index of the matching
77692 ** Analyze the ORDER BY clause in a compound SELECT statement. Modify
77694 ** and N where N is the number of columns in the compound SELECT.
77721 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
77785 "column in the result set", i+1);
77793 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
77816 sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType);
77835 ** pOrderBy is an ORDER BY or GROUP BY clause in SELECT statement pSelect.
77841 ** number of columns in the result set of the SELECT) then the expression
77842 ** in the resolution is a copy of the I-th result-set expression. If
77845 ** result-set expression. Otherwise, the expression is resolved in
77849 ** an appropriate error message might be left in pParse. (OOM errors
77862 int nResult; /* Number of terms in the result set */
77908 ** Resolve names in the SELECT statement p and all of its descendents.
77937 ** this routine in the correct order.
77952 /* Resolve the expressions in the LIMIT and OFFSET clauses. These
77962 /* Recursively resolve names in all subqueries
77972 ** parent contexts. After resolving references to expressions in
77996 /* Resolve names in the result set. */
78006 /* If there are no aggregate functions in the result-set, and no GROUP BY
78007 ** expression, do not allow aggregates in any of the other expressions.
78025 ** other expressions in the SELECT statement. This is so that
78026 ** expressions in the WHERE clause (etc.) can refer to expressions by
78027 ** aliases in the result set.
78036 /* The ORDER BY and GROUP BY clauses may not refer to terms in
78065 sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
78100 ** Y: The name of a table in a FROM clause. Or in a trigger
78103 ** Z: The name of a column in table Y.
78109 ** Expr.iColumn The column index in X.Y. -1 for the rowid.
78115 ** size of an AS clause in the result-set of a SELECT. The Z expression
78118 ** tree. For example, in:
78133 ** An error message is left in pParse if anything is amiss. The number
78137 NameContext *pNC, /* Namespace to resolve expressions in. */
78177 ** Resolve all names in all expressions of a SELECT and in all
78179 ** subqueries in expressions, and subqueries used as FROM clause
78205 ** Resolve names in expressions that can only reference a single table:
78213 ** Any errors cause an error message to be set in pParse.
78251 ** The author disclaims copyright to this source code. In place of
78260 ** for generating VDBE code that evaluates expressions in SQLite.
78271 ** i.e. the WHERE clause expresssions in the following statements all
78298 ** a TK_COLUMN but was previously evaluated and cached in a register */
78312 ** If a memory allocation error occurs, that fact is recorded in pParse->db
78386 ** a TK_COLUMN but was previously evaluated and cached in a register */
78460 ** pExpr is a comparison expression, eg. '=', '<', IN(...) etc.
78463 ** the comparison in pExpr.
78496 ** Argument pRight (but not pLeft) may be a null pointer. In this case,
78546 ** expression depth allowed. If it is not, leave an error message in
78599 ** Set the Expr.nHeight variable in the structure passed as an
78620 ** leave an error in pParse.
78656 ** stored in u.zToken. Instead, the integer values is written
78724 ** In that case, delete the subtrees pLeft and pRight.
78785 ** boolean values in different circumstances (a false positive.)
78849 ** in the original SQL statement.
78968 ** to store a copy of an expression or expression tree. They differ in
79023 ** This function returns the space in bytes required to store the copy
79044 ** space to duplicate all Expr nodes in the tree formed by Expr.pLeft
79120 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
79128 /* Fill in pNew->pLeft and pNew->pRight. */
79192 ** part of the in-memory representation of the database schema.
79425 ** leave an error message in pParse.
79436 sqlite3ErrorMsg(pParse, "too many columns in %s", zObject);
79557 ** to fit in a 32-bit integer, return 1 and put the value of the integer
79558 ** in *pValue. If the expression is not an integer or if it is too big
79559 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
79564 /* If an expression is an integer literal that fits in a signed 32-bit
79600 ** (returning TRUE when in fact the expression can never be NULL) might
79603 ** will likely result in an incorrect answer. So when in doubt, return
79627 ** unchanged by OP_Affinity with the affinity given in the second
79631 ** can be omitted. When in doubt return FALSE. A false negative
79632 ** is harmless. A false positive, however, can result in the wrong
79676 ** Return true if we are able to the IN operator optimization on a
79679 ** x IN (SELECT ...)
79684 ** The Select object passed in has already been preprocessed and no
79692 if( p==0 ) return 0; /* right-hand side of IN is SELECT */
79705 if( pSrc->nSrc!=1 ) return 0; /* Single term in FROM clause */
79712 if( pEList->nExpr!=1 ) return 0; /* One column in the result set */
79746 ** The argument is an IN operator with a list (not a subquery) on the
79762 ** This function is used by the implementation of the IN (...) operator.
79763 ** The pX parameter is the expression on the RHS of the IN operator, which
79767 ** be used either to test for membership in the RHS set or to iterate through
79770 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
79780 ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be
79788 ** If the RHS of the IN operator is a list or a more complex subquery, then
79797 ** IN index will be used to loop over all values of the RHS of the
79798 ** IN operator.
79812 ** if the RHS of the IN operator is a list (not a subquery) then this
79814 ** testing is too expensive and return IN_INDEX_NOOP. In that case, the
79815 ** calling routine should implement the IN operator using a sequence
79819 ** might need to know whether or not the RHS side of the IN operator
79826 ** If a register is allocated and its location stored in *prRhsHasNull, then
79827 ** the value in that register will be NULL if the b-tree contains one or more
79833 Select *p; /* SELECT to the right of IN operator */
79867 /* This function is only called from two places. In both cases the vdbe
79884 ** be used in place of a temp-table, it must be ordered according
79916 /* If no preexisting index is available for the IN clause
79918 ** and the RHS of the IN operator is a list, not a subquery
79921 ** the IN operator so return IN_INDEX_NOOP.
79958 ** or IN operators. Examples:
79962 ** x IN (4,5,11) -- IN operator with list on right-hand side
79963 ** x IN (SELECT a FROM b) -- IN operator with subquery on the right
79965 ** The pExpr parameter describes the expression that contains the IN
79969 ** to be of the form "<rowid> IN (?, ?, ?)", where <rowid> is a reference
79970 ** to some integer key column of a table B-Tree. In this case, use an
79971 ** intkey B-Tree to store the set of IN(...) values instead of the usual
79974 ** If rMayHaveNull is non-zero, that means that the operation is an IN
79981 ** result. For IN operators or if an error occurs, the return value is 0.
79986 Expr *pExpr, /* The IN, SELECT, or EXISTS operator */
79987 int rHasNullFlag, /* Register that records whether NULLs exist in RHS */
79988 int isRowid /* If true, LHS of IN operator is a rowid */
79996 /* This code must be run in its entirety every time it is encountered
80022 char affinity; /* Affinity of the LHS of the IN */
80024 Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
80029 /* Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)'
80047 /* Case 1: expr IN (SELECT ...)
80063 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
80076 /* Case 2: expr IN (exprlist)
80079 ** store it in the temporary table. If <expr> is a column, then use
80096 /* Loop through each expression in <exprlist>. */
80144 ** value of this select in a memory cell and record the number
80145 ** of the memory cell in iColumn. If this is an EXISTS, write
80147 ** and record that memory cell in iColumn.
80196 ** Generate code for an IN expression.
80198 ** x IN (SELECT ...)
80199 ** x IN (value, value, ...)
80209 ** is contained in the RHS then jump to destIfNull. If the LHS is contained
80214 Expr *pExpr, /* The IN expression */
80215 int destIfFalse, /* Jump here if LHS is not contained in the RHS */
80229 VdbeNoopComment((v, "begin IN expr"));
80240 /* Code the LHS, the <expr> from "<expr> IN (...)".
80247 ** suitable for evaluating the IN operator, then evaluate using a
80307 /* In this case, the RHS is the ROWID of table b-tree
80313 /* In this case, the RHS is an index b-tree.
80318 ** "x IN (...)" expression must be either 0 or NULL. If the set
80327 ** of a "NOT NULL" constraint in the database schema.
80330 ** for this particular IN operator.
80335 /* In this branch, the RHS of the IN might contain a NULL and
80336 ** the presence of a NULL on the RHS makes a difference in the
80341 /* First check to see if the LHS is contained in the RHS. If so,
80342 ** then the answer is TRUE the presence of NULLs in the RHS does
80343 ** not matter. If the LHS is not contained in the RHS, then the
80358 VdbeComment((v, "end IN expr"));
80365 static char *dup8bytes(Vdbe *v, const char *in){
80368 memcpy(out, in, 8);
80451 ** Record in the column cache that a particular column from a
80452 ** particular table is stored in a particular register.
80472 ** that the object will never already be in cache. Verify this guarantee.
80547 ** the previous sqlite3ExprCachePush operation. In other words, restore
80548 ** the cache to the state it was in prior the most recent Push.
80571 ** register might be in the cache in multiple places, so be sure to
80611 ** table pTab and store the column value in a register. An effort
80612 ** is made to store the column value in register iReg, but this is
80615 ** There must be an open cursor to pTab in iTable when this routine
80694 ** Return true if any register in the range iFrom..iTo (inclusive)
80698 ** and does not appear in a normal build.
80723 ** expression. Attempt to store the results in register "target".
80727 ** be stored in target. The result might be stored in some other
80735 int inReg = target; /* Results stored in register inReg */
80995 int nId; /* Length of the function name in bytes */
81018 /* Attempt a direct implementation of the built-in COALESCE() and
81096 ** see if it is a column in a virtual table. This is done because
81100 ** "glob(B,A). We want to use the A in "A glob B" to test
81101 ** for function overloading. But we use the B term in "glob(B,A)".
81150 ** X is stored in pExpr->pLeft.
81151 ** Y is stored in pExpr->pList->a[0].pExpr.
81152 ** Z is stored in pExpr->pList->a[1].pExpr.
81187 ** to a column in the new.* or old.* pseudo-tables available to
81188 ** trigger programs. In this case Expr.iTable is set to 1 for the
81197 ** set to (n+1), where n is the number of columns in each pseudo-table.
81198 ** For a reference to any other column in the new.* pseudo-table, p1
81250 ** X (if it exists) is in pExpr->pLeft.
81251 ** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
81252 ** odd. The Y is also optional. If the number of elements in x.pList
81254 ** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
81287 ** The value in regFree1 might get SCopy-ed into the file result.
81361 int regDest, /* Store the value in this register */
81387 ** code to fill the register in the initialization section of the
81388 ** VDBE program, in order to factor it out of the evaluation loop.
81425 ** results in register target. The results are guaranteed to appear
81426 ** in register target.
81445 ** results in register target. The results are guaranteed to appear
81446 ** in register target. If the expression is constant, then this routine
81459 ** in register target.
81636 sqlite3ExplainPrintf(pOut, "IN(");
81656 ** X is stored in pExpr->pLeft.
81657 ** Y is stored in pExpr->pList->a[0].pExpr.
81658 ** Z is stored in pExpr->pList->a[1].pExpr.
81675 ** to a column in the new.* or old.* pseudo-tables available to
81676 ** trigger programs. In this case Expr.iTable is set to 1 for the
81822 Expr exprAnd; /* The AND operator in x>=y AND x<=z */
81868 ** operation. Special comments in vdbe.c and the mkopcodeh.awk script in
81869 ** the make process cause these values to align. Assert()s in the code
82151 ** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
82161 ** can be sure the expressions are the same. In the places where
82163 ** just might result in some slightly slower code. But returning
82209 ** non-zero if they differ in any way.
82212 ** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
82252 ** When in doubt, return false. Returning true might give a performance
82277 ** to count references to table columns in the arguments of an
82278 ** aggregate function, in order to implement the
82282 SrcList *pSrc; /* One particular FROM clause in a nested query */
82283 int nThis; /* Number of references to columns in pSrcList */
82284 int nOther; /* Number of references to columns in other FROM clauses */
82294 ** sqlite3FunctionUsesThisSrc() is used differently in the future, the
82316 ** references columns but not columns of tables found in pSrcList.
82381 /* Check to see if the column is in one of the tables in the FROM
82390 ** that is in the FROM clause of the aggregate query.
82392 ** Make an entry for the column in pAggInfo->aCol[] if there
82431 /* There is now an entry for pExpr in pAggInfo->aCol[] (either
82451 ** function that is already in the pAggInfo structure
82460 /* pExpr is original. Make a new entry in pAggInfo->aFunc[]
82520 ** Call sqlite3ExprAnalyzeAggregates() for every expression in an
82605 ** The author disclaims copyright to this source code. In place of
82618 ** The code in this file only exists if we are not omitting the
82627 ** CREATE INDEX command. The second is a table name. The table name in
82655 /* The principle used to locate the table name in the CREATE TABLE
82666 /* Store the token that zCsr points to in tname. */
82670 /* Advance zCsr to the next token. Store that token type in 'token',
82671 ** and its length in 'len' (to be used next iteration of this loop).
82753 ** statement. The second is a table name. The table name in the CREATE
82776 /* The principle used to locate the table name in the CREATE TRIGGER
82789 /* Store the token that zCsr points to in tname. */
82793 /* Advance zCsr to the next token. Store that token type in 'token',
82794 ** and its length in 'len' (to be used next iteration of this loop).
82818 ** in the CREATE TRIGGER statement.
82828 ** Register built-in functions used to help implement ALTER TABLE
82862 ** In this case zWhere is passed to sqlite3DbFree() before returning.
82896 ** table pTab has no temporary triggers, or is itself stored in the
82904 /* If the table is not located in the temp-db (in which case NULL is
82907 ** expression being built up in zWhere.
82928 ** Argument zName is the name of the table in the database schema at
82965 /* Now, if the table is not stored in the temp database, reload any temp
82966 ** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.
82978 ** in pParse->zErr (system tables may not be altered) and returns non-zero.
83004 int nTabName; /* Number of UTF-8 characters in zTabName */
83029 ** in database iDb. If so, this is an error.
83099 /* figure out how many UTF-8 characters are in zName */
83144 /* If the sqlite_sequence table exists in this database, then update
83156 ** table. Don't do this if the table being ALTERed is itself located in
83335 ** This function is called by the parser after the table-name in
83384 /* Put a copy of the Table struct in Parse.pNewTable for the
83435 ** The author disclaims copyright to this source code. In place of
83456 ** Additional tables might be added in future releases of SQLite.
83465 ** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is
83475 ** name in the idx column. The tbl column is the name of the table to
83476 ** which the index belongs. In each such row, the stat column will be
83477 ** a string consisting of a list of integers. The first integer in this
83478 ** list is the number of rows in the index. (This is the same as the
83479 ** number of rows in the table, except for partial indices.) The second
83480 ** integer is the average number of rows in the index that have the same
83481 ** value in the first column of the index. The third integer is the average
83482 ** number of rows in the index that have the same value for the first two
83483 ** columns. The N-th integer (for N>1) is the average number of rows in
83485 ** a K-column index, there will be K+1 integers in the stat column. If
83488 ** The list of integers in the stat column can optionally be followed
83496 ** rows in the table identified by sqlite_stat1.tbl.
83505 ** the index belongs. There are usually 10 rows in the sqlite_stat2
83509 ** inclusive are samples of the left-most key value in the index taken at
83511 ** (10 in the standard build) and let C be the number of rows in the index.
83533 ** to aid the query planner in choosing good indices based on the values
83534 ** that indexed columns are compared against in the WHERE clauses of
83543 ** of entries in the index whose left-most column exactly matches
83544 ** the left-most column of the sample. The second integer in nEq
83545 ** is the approximate number of entries in the index where the
83549 ** integer in nLt contains the number of entries in the index where the
83551 ** The K-th integer in the nLt entry is the number of index entries
83554 ** number of distinct entries in the index that are less than the
83568 ** of a blob encoding of the complete index key as is found in
83571 ** integer in the equivalent columns in sqlite_stat4.
83598 ** or it may be a NULL pointer. If it is not NULL, then all entries in
83604 int iDb, /* The database we are looking in */
83647 ** of the new table in register pParse->regRoot. This is important
83703 i64 iRowid; /* Rowid in main table of the key */
83713 tRowcnt nRow; /* Number of rows in the entire table */
83715 int nCol; /* Number of columns in index + pk/rowid */
83721 int iMin; /* Index in a[] of entry with minimum score */
83804 ** N: The number of columns in the index including the rowid/pk (note 1)
83805 ** K: The number of columns in the index excluding the rowid/pk.
83806 ** C: The number of rows in the index (note 2)
83808 ** Note 1: In the special case of the covering index that implements a
83810 ** total number of columns in the table.
83815 ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
83819 ** This routine allocates the Stat4Accum object in heap memory. The return
83829 int nCol; /* Number of columns in index being sampled */
83921 ** In other words, if we assume that the cardinalities of the selected
83989 /* This sample is being added because the prefix that ends in column
83990 ** iCol occurs many times in the table. However, if we have already
84030 ** for the last sample in the p->a[] array. Otherwise, the samples would
84042 /* Zero the first nEqZero entries in the anEq[] array. */
84103 in this case too. */
84128 ** statistical data and/or samples in the Stat4Accum object about the
84254 /* Return the value to store in the "stat" column of the sqlite_stat1
84258 ** the index. The first integer in the list is the total number of
84259 ** entries in the index. There is one additional integer in the list
84262 ** a key with the corresponding number of fields. In other words,
84446 int nCol; /* Number of columns in pIdx. "N" */
84514 ** (1) the number of columns in the index including the rowid
84516 ** (2) the number of columns in the key without the rowid/pk
84517 ** (3) the number of rows in the index,
84739 ** Generate code that will do an analysis of a single table in
84741 ** in pTab that should be analyzed.
84770 ** Form 1 causes all indices in all attached databases to be analyzed.
84785 ** and code in pParse and return NULL. */
84851 int nOut, /* Number of slots in aOut[] */
84914 ** Entries for which argv[1]==NULL simply record the number of rows in
84986 ** stored in pIdx->aSample[].
85010 ** occur in the stat4 table for this index before pFinal. Set
85069 Index *pPrevIdx = 0; /* Previous index in the loop */
85070 IndexSample *pSample; /* A slot in pIdx->aSample[] */
85082 int nIdxCol = 1; /* Number of columns in stat4 records */
85097 ** loaded from the stat4 table. In this case ignore stat3 data. */
85140 int nCol = 1; /* Number of columns in index */
85147 ** the sqlite_stat4 table. In this case ignore stat3 data. */
85160 ** This is in case the sample record is corrupted. In that case, the
85213 ** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
85214 ** is returned. In this case, even if SQLITE_ENABLE_STAT3/4 was defined
85219 ** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
85220 ** returned. However, in this case, data is read from the sqlite_stat1
85289 ** The author disclaims copyright to this source code. In place of
85387 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
85392 /* Allocate the new entry in the db->aDb[] array and initialize the schema
85723 ** was left unspecified in the original SQL statement. The pFix structure
85727 ** view in one database does not refer to objects in a different database.
85728 ** (Exception: indices, triggers, and views in the TEMP database are
85730 ** to an object in a different database, an error message is added to
85748 "%s %T cannot reference objects in database %s",
85865 ** The author disclaims copyright to this source code. In place of
85880 ** All of the code in this file may be omitted by defining a single
85954 ** table zTab in database zDb. This function assumes that an authorization
85959 ** is treated as SQLITE_DENY. In this case an error is left in pParse.
85987 ** is in pTabList or else it is the NEW or OLD table of a trigger.
86003 int iSrc; /* Index in pTabList->a[] of table being read */
86005 int iCol; /* Index of column in table */
86048 ** is returned, then the error count and error message in pParse are
86116 ** The author disclaims copyright to this source code. In place of
86125 ** when syntax rules are reduced. The routines in this file handle the
86162 ** The table to be locked has root page iTab and is found in database iDb.
86348 ** Run the parser and code generator recursively in order to generate
86386 ** Locate the in-memory structure that describes a particular database
86416 ** Locate the in-memory structure that describes a particular database
86419 ** error message in pParse->zErrMsg.
86422 ** routine leaves an error message in pParse->zErrMsg where
86426 Parse *pParse, /* context in which to report errors */
86434 ** and code in pParse and return NULL. */
86478 ** Locate the in-memory structure that describes
86522 ** For the index called zIdxName which is found in the database iDb,
86555 ** Look through the list of open database files in db->aDb[] and if
86600 ** since TEMP might be holding triggers that reference tables in the
86667 ** contains lookaside memory. (Table objects in the schema do not use
86682 /* Record the number of outstanding lookaside allocations in schema Tables
86769 ** Open the sqlite_master table stored in database number iDb for
86784 ** function returns the index of the named database in db->aDb[], or
86805 ** index of the named database in db->aDb[], or -1 if the named db
86835 Token *pName1, /* The "xxx" in the name "xxx.yyy" or "xxx" */
86836 Token *pName2, /* The "yyy" in the name "xxx.yyy" */
86867 ** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
86902 ** Begin constructing a new table representation in memory. This is
86903 ** the first of several action routines that get called in response
86904 ** to a CREATE TABLE statement. In particular, this routine is called
86906 ** flag is true if the table should be stored in the auxiliary database
86907 ** file instead of in the main database file. This is normally the case
86908 ** when the "TEMP" or "TEMPORARY" keyword occurs in between
86911 ** The new table record is initialized and put in pParse->pNewTable.
86930 int iDb; /* Database number to create the table in */
86948 ** created in.
86995 ** index or table name in the same database. Issue an error message if
86997 ** to an sqlite3_declare_vtab() call. In that case only the column names
87038 ** then record a pointer to this table in the main database structure
87049 ** the SQLITE_MASTER table. Note in particular that we must go ahead
87068 /* If the file format and encoding in the database have not been set,
87085 /* This just creates a place-holder record in the sqlite_master table.
87087 ** by the real entry in code generated at sqlite3EndTable().
87089 ** The rowid for the new entry is left in register pParse->regRowid.
87090 ** The root page number of the new table is left in reg pParse->regRoot.
87120 in a case-insensitive manner.
87136 ** in a CREATE TABLE statement. sqlite3StartTable() gets called
87185 ** This routine is called by the parser while in the middle of
87202 ** substrings in the following table. If one of the substrings is
87219 ** If none of the substrings in the above table are found,
87285 ** This routine is called by the parser while in the middle of
87287 ** token in the sequence of tokens that describe the type of the
87289 ** in the sequence. Use this information to construct a string
87291 ** in zType.
87312 ** This routine is called by the parser while in the middle of
87490 ** in the database native encoding, the collation factory is invoked to
87492 ** and the sequence is available in another text encoding, then that is
87534 ** 1 chance in 2^32. So we're safe enough.
87567 ** to the specified offset in the buffer and updates *pIdx to refer
87741 ** (3) Set the Index.tnum of the PRIMARY KEY Index object in the
87807 /* Update the in-memory representation of all UNIQUE indices by converting
87860 ** An entry for the table is made in the master table on disk, unless
87864 ** recently changed, so the entry for this table already exists in
87875 Token *pEnd, /* The ')' before options in the CREATE TABLE */
87881 int iDb; /* Database in which the table lives */
87920 /* Resolve names in all CHECK constraint expressions.
87934 ** in the SQLITE_MASTER table of the database.
87968 ** new table is in register pParse->regRoot.
87970 ** Once the SELECT has been coded by sqlite3Select(), it is in a
88014 /* A slot for the record has already been allocated in the
88055 /* Add the table to the in-memory representation of the database.
88088 ** The parser calls this routine in order to create a new VIEW
88109 sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
88163 ** The Table structure pTable is really a VIEW. Fill in the names of
88164 ** the columns of the view in the pTable structure. Return the number
88165 ** of errors. If an error is seen leave an error message in pParse->zErrMsg.
88199 ** in the following:
88213 ** "*" elements in the results set of the view and will assign cursors
88260 ** Clear the column names from every VIEW in database idx.
88283 ** root-page of a table or index in database iDb has changed from iFrom
88295 ** in order to be certain that we got the right one.
88334 /* OP_Destroy stores an in integer r1. If this integer
88339 ** The "#NNN" in the SQL is a special constant that means whatever value
88340 ** is in register NNN. See grammar rules associated with the TK_REGISTER
88353 ** in case a root-page belonging to another table is moved by the btree layer
88367 ** table and index root-pages in order, starting with the numerically
88376 ** and root page 5 happened to be the largest root-page number in the
88411 ** Remove entries from the sqlite_statN tables (for N in (1,2,3))
88468 ** at the btree level, in case the sqlite_sequence table needs to
88469 ** move as a result of the drop (can happen in auto-vacuum mode).
88483 ** created in the temp database that refers to a table in another
88609 ** in the current table point to the foreign key. If pFromCol==0 then
88612 ** of tables in the parent pTo table. flags contains all
88614 ** in the ON DELETE, ON UPDATE and ON INSERT clauses.
88617 ** under construction in the pParse->pNewTable field.
88624 ExprList *pFromCol, /* Columns in this table that point to other table */
88626 ExprList *pToCol, /* Columns in the other table */
88653 "number of columns in foreign key does not match the number of "
88654 "columns in the referenced table");
88691 "unknown column \"%s\" in foreign key definition",
88756 ** content of an index in response to a REINDEX command.
88768 int iSorter; /* Cursor opened by OpenSorter (if in use) */
88848 ** pointer to this extra space in *ppExtra.
88852 i16 nCol, /* Total number of columns in the index */
88910 int nName; /* Number of characters in zName */
88913 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
88919 const Column *pTabCol; /* A column in the table */
89212 ** the constraint occur in different orders, then the constraints are
89213 ** considered distinct and both result in separate indices.
89234 ** constraint specified somewhere in the CREATE TABLE statement.
89254 ** in-memory database structures.
89276 ** the index in the sqlite_master table and populate the index with
89282 ** or UNIQUE index in a CREATE TABLE statement. Since the table
89315 /* Add an entry in sqlite_master for this index
89342 ** processing (in sqlite3GenerateConstraintChecks()) as part of
89376 ** aiRowEst[0] is suppose to contain the number of elements in the index.
89378 ** number of rows in the table that match any particular value of the
89388 ** are based on typical values found in actual indices.
89397 /* Set the first entry (number of rows in the index) to the estimated
89398 ** number of rows in the table. Or 10, if the estimated number of rows
89399 ** in the table is less than that. */
89483 ** pArray is a pointer to an array of objects. Each object in the
89484 ** array is szEntry bytes in size. This routine uses sqlite3DbRealloc()
89488 ** the array (in entries - so the allocation is ((*pnEntry) * szEntry) bytes
89489 ** in total).
89494 ** returned. *pIdx is set to the index of the new array entry in this case.
89502 int szEntry, /* Size of each object in the array */
89503 int *pnEntry, /* Number of objects currently in use */
89565 ** Return the index in pList of the identifier named zId. Return -1
89600 int iStart /* Index in pSrc->a[] of first new slot */
89646 ** need be. A new entry is created in the SrcList even if pTable is NULL.
89661 ** In other words, if call like this:
89671 ** then so is B. In other words, we never have a case where:
89711 ** Assign VdbeCursor index numbers to all tables in a SrcList
89753 ** are the name of the table and database named in the FROM clause term.
89770 Select *pSubquery, /* A subquery used in place of a table name */
89824 ** When building up a FROM clause in the parser, the join operator
89835 ** in p->a[0] and p->a[1], respectively. The parser initially stores the
89931 ** the number of errors. Leave any error messages in the pParse structure.
90023 ** inserting multiple rows in a table, or inserting a row and index entries.)
90034 ** possible to abort a statement prior to completion. In order to
90043 ** makes it more difficult to prove that the code is correct (in
90165 ** Recompute all indices of all tables in all databases where the
90174 HashElem *k; /* For looping over tables in pDb */
90175 Table *pTab; /* A table in the database */
90196 ** Form 1 causes all indices in all attached databases to be rebuilt.
90197 ** Form 2 rebuilds all indices in all databases that use the named
90206 Table *pTab; /* A table in the database */
90213 ** and code in pParse and return NULL. */
90259 ** The KeyInfo structure for an index is cached in the Index object.
90320 ** not, store an error in the Parse structure. */
90378 ** The author disclaims copyright to this source code. In place of
90394 ** in the encoding enc of name zName, length nName.
90420 ** collation function in the best encoding but there may be other versions
90444 ** requested collation sequence is not available in the desired encoding.
90449 ** The return value is either the collation sequence to be used in database
90516 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an
90521 ** the collation sequence name. A pointer to this string is stored in
90547 /* If a malloc() failure occurred in sqlite3HashInsert(), it will
90597 ** matches the request for a function with nArg arguments in a system
90602 ** is also -1. In other words, we are searching for a function that
90663 int nFunc /* Number of bytes in zFunc */
90721 int nName, /* Number of characters in the name */
90747 /* If no match is found, search the built-in functions.
90749 ** If the SQLITE_PreferBuiltin flag is set, then search the built-in
90751 ** priority to built-in functions.
90756 ** new function. But the FuncDefs for built-in functions are read-only.
90857 ** The author disclaims copyright to this source code. In place of
90866 ** in order to generate code for DELETE FROM statements.
90870 ** While a SrcList can in general represent multiple tables and subqueries
90871 ** (as in the FROM clause of a SELECT statement) in this case it contains
90872 ** the name of a single table, as one might find in an INSERT, DELETE,
90873 ** or UPDATE statement. Look up that table in the symbol table and
90877 ** The following fields are initialized appropriate in pSrc:
90913 ** In either case leave an error message in pParse and return non-zero.
90937 ** Evaluate a view and store its result in an ephemeral table. The
90939 ** set of rows in the view that are to be added to the ephemeral table.
90987 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
91013 ** DELETE FROM table_a WHERE rowid IN (
91036 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
91086 NameContext sNC; /* Name context to resolve expressions in */
91095 i16 nPk = 1; /* Number of columns in the PRIMARY KEY */
91097 i16 nKey; /* Number of memory cells in the row key */
91118 ** put in an SrcList structure because some of the subroutines we
91192 /* Resolve the column names in the WHERE clause.
91278 ** one, so just keep it in its register(s) and fall through to the
91301 /* Get the rowid of the row to be deleted and remember it in the RowSet */
91327 /* Set up a loop over the rowids/primary-keys that were found in the
91410 ** thely may interfere with compilation of other functions in this file
91411 ** (or in another file, if this file becomes part of the amalgamation). */
91428 ** in the case of a rowid table, or the PRIMARY KEY index in the case
91434 ** 3. The primary key for the row to be deleted must be stored in a
91436 ** that a search record formed from OP_MakeRecord is contained in the
91452 int iOld = 0; /* First register in OLD.* array */
91473 ** use for the old.* references in the triggers. */
91475 u32 mask; /* Mask of OLD.* columns in use */
91523 ** a view (in which case the only effect of the DELETE statement is to
91534 ** handle rows (possibly in other tables) that refer via a foreign key
91600 ** Generate code that will assemble an index key and stores it in register
91606 ** Return a register number which is the first in a block of
91611 ** If *piPartIdxLabel is not NULL, fill it in with a label and jump
91624 ** a column in common, then the register corresponding to that column already
91665 ** might be stored in the table as an integer (using a compact
91696 ** The author disclaims copyright to this source code. In place of
91705 ** functions of SQLite. (Some function, and in particular the date and
91862 ** in haystack and returns the number of previous characters plus 1,
91866 ** the number of bytes in haystack prior to the first occurrence of needle,
91867 ** or 0 if needle never occurs in haystack.
92045 /* If Y==0 and X will fit in a 64-bit int,
92137 ** routines in the function table. The noopFunc macro provides this.
92158 ** in a way that is testable, mask the sign bit off of negative
92159 ** values, resulting in a positive value. Then take the
92254 ** character is exactly one byte in size. Also, all characters are
92255 ** able to participate in upper-case-to-lower-case mappings in EBCDIC
92256 ** whereas only characters less than 0x80 do in ASCII.
92287 ** [^...] Matches one character not in the enclosed list.
92290 ** in the list by making it the first character after '[' or '^'. A
92293 ** it the last character in the list.
92295 ** This routine is usually quick, but can be N**2 in the worst case.
92297 ** Hints: to match '*' or '?', put them in "[]". Like this:
92428 ** the build-in LIKE operator. The first argument to the function is the
92452 ** of deep recursion and N*N behavior in patternCompare().
92606 ** "NULL". Otherwise, the argument is enclosed in single quotes with
92885 int nIn; /* Number of bytes in input */
92888 unsigned char *aLen = 0; /* Length of each character in zCharSet */
92889 unsigned char **azChar = 0; /* Individual characters in zCharSet */
92890 int nChar; /* Number of characters in zCharSet */
93060 ** 0.0 in that case. In addition, TOTAL always returns a float where
93109 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
93251 ** of the built-in functions above are part of the global function set.
93275 ** Register the built-in LIKE and GLOB functions. The caseSensitive
93319 ** the first three statements in the compareInfo structure. The
93331 ** All all of the FuncDef structures in the aBuiltinFunc[] array above
93340 ** defined in this file.
93444 ** The author disclaims copyright to this source code. In place of
93463 ** Foreign keys in SQLite come in two flavours: deferred and immediate.
93498 ** row in the parent table. Decrement the counter for each row
93505 ** deleted row in the child table. If such a row is not found,
93510 ** in the parent table. For each found increment the counter.
93533 ** statement that inserts a single row only (no triggers). In this case,
93584 ** A foreign key constraint requires that the key columns in the parent
93596 ** N is the number of columns in the parent key. The first element of the
93598 ** constraint to the parent table column stored in the left-most column
93616 ** consists of a a different number of columns to the child key in
93624 Parse *pParse, /* Parse context to store any error in */
93628 int **paiCol /* OUT: Map of index columns in pFKey */
93632 int nCol = pFKey->nCol; /* Number of columns in parent key */
93686 ** map to an explicit list of columns in table pParent. Check if this
93691 i16 iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
93697 ** unusable. Bail out early in this case. */
93740 ** row in the parent table that corresponds to the row being inserted into
93743 ** found in the parent table:
93755 ** These operations are identified in the comment at the top of this file
93762 Index *pIdx, /* Unique index on parent key columns in pTab */
93778 ** Check if any of the key columns in the child table row are NULL. If
93780 ** search for a matching row in the parent table. */
93952 ** The code generated by this function scans through the rows in the child
93970 ** These operations are identified in the comment at the top of this file
94013 i16 iCol; /* Index of column in child table */
94014 const char *zCol; /* Name of column in child table */
94034 ** for WITHOUT ROWID tables. In the second form, the primary key is
94061 /* Resolve the references in the WHERE clause. */
94067 /* Create VDBE to loop through the entries in pSrc that match the WHERE
94136 ** constraint violations in the database,
94195 ** actually updated, the corresponding element in the aChange[] array
94222 ** actually updated, the corresponding element in the aChange[] array
94260 ** first register in an array of (pTab->nCol+1) registers containing the
94263 ** zero in this case.
94301 Index *pIdx = 0; /* Index on key columns in pTo */
94316 ** on the parent key columns in the parent table. If either of these
94317 ** schema items cannot be located, set an error in pParse and return
94328 /* If isIgnoreErrors is true, then a table is being dropped. In this
94330 ** before actually dropping it in order to check FK constraints.
94372 ** in the parent table. */
94407 ** foreign key violation. So do nothing in this case. */
94450 ** row contained in table pTab.
94477 ** row contained in table pTab. If the operation is a DELETE, then
94479 ** to an array of size N, where N is the number of columns in table pTab.
94481 ** entry in the aChange[] array is set to -1. If the column is modified,
94498 ** table in question is either the child or parent table for any
94533 ** For example, if pFKey is the foreign key and pTab is table "p" in
94566 int nFrom; /* Length in bytes of zFrom */
94582 Token tFromCol; /* Name of column in child table */
94583 Token tToCol; /* Name of column in parent table */
94584 int iFromCol; /* Idx of column in child table */
94678 sizeof(TriggerStep) + /* Single step in trigger program */
94788 /* EV: R-30323-21917 Each foreign key constraint in SQLite is
94810 ** The author disclaims copyright to this source code. In place of
94819 ** to handle INSERT statements in SQLite.
94834 int iDb, /* The database index in sqlite3.aDb[] */
94859 ** pIdx. A column affinity string has one character for each column in
94871 ** rowid that appears as the last column in every index.
94955 ** Return non-zero if the table pTab in database iDb or any of its indices
94956 ** have been opened at any point in the VDBE program. This is used to see if
94997 ** which is in database iDb. Return the register number for the register
95010 ** (3) Register to hold the rowid in sqlite_sequence of pTab
95036 pToplevel->nMem++; /* Rowid in sqlite_sequence */
95087 ** larger than the maximum rowid in the memId memory cell, then the
95155 ** appears in the pColumn parameter. pColumn is NULL if IDLIST is omitted.
95157 ** The pList parameter holds EXPRLIST in the first form of the INSERT
95177 ** in other words if the SELECT pulls all columns from a single table
95187 ** transfer all records in <table2> over to <table>
95203 ** loop over the rows in the SELECT
95217 ** that is also read as part of the SELECT. In the third form,
95224 ** loop over the tables in the SELECT
95255 int nColumn; /* Number of columns in the data */
95263 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
95267 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
95270 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
95377 /* If this is an AUTOINCREMENT table, look up the sequence number in the
95378 ** sqlite_sequence table and store it in memory cell regAutoinc.
95398 ** is named in the IDLIST, then record in the ipkColumn variable
95400 ** the index of the primary key as it appears in IDLIST, not as
95401 ** is appears in the original table. (The index of the INTEGER
95402 ** PRIMARY KEY in the original table is pTab->iPKey.)
95466 ** temp table in the case of row triggers.
95519 ** column index in the original table definition.
95525 /* Make sure the number of columns in the source data matches the number
95718 ** in its place. Hence, fill this column with a NULL to avoid
95835 ** thely may interfere with compilation of other functions in this file
95836 ** (or in another file, if this file becomes part of the amalgamation). */
95851 ** The regNewData parameter is the first register in a range that contains
95853 ** pTab->nCol+1 registers in this range. The first register (the one
95854 ** that regNewData points to) will contain the new rowid, or NULL in the
95855 ** case of a WITHOUT ROWID table. The second register in the range will
95878 ** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
95887 ** for the first index in the pTab->pIndex list. Cursors for other indices
95911 ** any IGNORE The attempt in insert or update the current
95923 ** CHECK REPLACE Illegal. The results in an exception.
95936 int regNewData, /* First register in a range holding values to insert */
95953 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
95968 in the
95969 ** pPk index or 1 for a rowid table. In other words, nPkField is the
95970 ** number of fields in the true primary key of the table. */
96056 ** exist in the table.
96061 /* Figure out what action to take in case of a rowid collision */
96092 /* Check to see if the new rowid already exists in the table. Skip
96191 ** the insert or update. Store that record in the aRegIdx[ix] register
96198 if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
96211 /* In an UPDATE operation, if this index is the PRIMARY KEY index
96220 /* Find out what action to take in case there is a uniqueness conflict */
96252 ** store it in registers regR..regR+nPk-1 */
96408 ** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
96409 ** ROWID table) is returned in *piDataCur. The first index cursor is
96410 ** returned in *piIdxCur. The number of indices is returned.
96417 ** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
96500 ** for index pDest in an insert transfer optimization. The rules
96545 ** performance. Raw index records are transferred in the same way.
96549 ** embedded in the code for details.
96553 ** is empty - a factor that can only be determined at run-time. In that
96556 ** xfer optimization code if the test fails. In that case, this routine
96571 Table *pSrc; /* The table in the FROM clause of SELECT */
96645 ** correct syntactic form to participate in this optimization. Now
96668 return 0; /* Number of columns must be the same in tab1 and tab2 */
96701 return 0; /* pDestIdx has no corresponding index in pSrc */
96746 /* In some circumstances, we are able to run the xfer optimization
96830 ** The author disclaims copyright to this source code. In place of
96838 ** Main file for the SQLite library. The routines in this file
96839 ** implement the programmer interface to the library. Routines in
96850 ** If the SQL is a query, then for each row in the query result
96976 ** The author disclaims copyright to this source code. In place of
96989 #define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
96991 /************** Include sqlite3ext.h in the middle of loadext.c **************/
96996 ** The author disclaims copyright to this source code. In place of
97019 ** WARNING: In order to maintain backwards compatibility, add new
97021 ** interfaces in the middle of this structure, then older different
97481 /************** Continuing where we left off in loadext.c ********************/
97583 ** in order to preserve backwards compatibility.
97858 ** Attempt to load an SQLite extension library contained in the file
97859 ** zFile. The entry point is zProc. zProc may be 0 in which case a
97941 ** character in the filename after the last "/" upto the first ".",
97976 "no entry point [%s] in shared library [%s]", zEntry, zFile);
98023 ** Call this routine when the database connection is closing in order
98037 ** default so as not to open security holes in older applications.
98072 int nExt; /* Number of entries in aExt[] */
98078 ** we have to locate the state vector at run-time. In the more common
98184 ** If anything goes wrong, set an error in the database connection.
98226 ** The author disclaims copyright to this source code. In place of
98249 ** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun
98250 ** that script. Then copy/paste the output in place of the following:
98767 ** backed temporary databases, 2 for the Red-Black tree in memory database
98889 ** defined in pager.h. This function returns the associated lowercase
98950 ** index of the database this pragma is being applied to in db.aDb[]. */
99007 /* Locate the pragma in the lookup table */
99037 ** pages in the page cache. The second form sets both the current
99039 ** stored in the database file.
99089 ** database page size in bytes. The second form sets the
99142 ** maximum number of pages in the database file. The
99152 ** Return the number of pages in the specified database.
99188 ** of the PRAGMA command. In this case the locking-mode must be
99300 ** incr-vacuum flags. This is required in case this connection
99307 ** "incremental", write the value of meta[6] in the database
99364 ** number of pages in the cache. If N is negative, then the
99388 ** The parameter N is measured in bytes.
99613 ** in auto-commit mode. */
99864 Index *pIdx; /* Index in the parent table */
99867 HashElem *k; /* Loop counter: Next table in schema */
100027 ** In this case, the integrity of database iDb only is verified by
100031 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
100071 ** for all tables and indices in the database.
100098 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
100141 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
100196 "non-unique entry in index ", P4_STATIC);
100207 "wrong # of entries in index ", P4_STATIC);
100237 ** In its first form, this pragma returns the encoding of the main
100241 ** has not already been initialized. In this case it sets the default
100246 ** In all cases new databases created using the ATTACH command are
100251 ** In the second form this pragma sets the text encoding to be used in
100322 ** stored in the database header.
100389 ** Return the names of all compile-time options used in this build,
100438 ** after accumulating N frames in the log. Or query for the current value
100587 ** The author disclaims copyright to this source code. In place of
100829 ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
100894 /* Ticket #2804: When we open a database in the newer file format,
100936 ** the schema loaded, even if errors occurred. In
100971 ** bit is set in the flags field of the Db structure. If the database
100991 ** schema may contain references to objects in other databases.
101031 ** Check schema cookies in all databases. If any cookie is out
101061 ** value stored as part of the in-memory schema representation,
101079 ** which database file in db->aDb[] the schema refers to.
101087 /* If pSchema is NULL, then return -1000000. This happens when code in
101089 ** created by a sub-select). In this case the return value of this
101110 ** Free all memory allocations in the pParse object
101126 int nBytes, /* Length of zSql in bytes. */
101150 ** some other database connection is holding a write-lock, which in
101156 ** back and different changes are made in their place, then when this
101161 ** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
101286 int nBytes, /* Length of zSql in bytes. */
101349 ** Two versions of the official API. Legacy and new use. In the legacy
101350 ** version, the original SQL text is not saved in the prepared statement
101352 ** sqlite3_step(). In the new version, the original SQL text is retained
101359 int nBytes, /* Length of zSql in bytes. */
101371 int nBytes, /* Length of zSql in bytes. */
101389 int nBytes, /* Length of zSql in bytes. */
101396 ** tricky bit is figuring out the pointer to return in *pzTail.
101435 ** Two versions of the official API. Legacy and new use. In the legacy
101436 in the prepared statement
101438 ** sqlite3_step(). In the new version, the original SQL text is retained
101445 int nBytes, /* Length of zSql in bytes. */
101457 int nBytes, /* Length of zSql in bytes. */
101474 ** The author disclaims copyright to this source code. In place of
101483 ** to handle SELECT statements in SQLite.
101550 ExprList *pEList, /* which columns to include in the result */
101609 ** Return a pointer to the right-most SELECT statement in a compound.
101619 ** in terms of the following bit values:
101631 ** a join type, but put an error in the pParse structure.
101640 u8 i; /* Beginning of keyword text in zKeyText[] */
101641 u8 nChar; /* Length of the keyword in characters */
101691 ** Return the index of a column in a table. Return -1 if the column
101692 ** is not contained in the table.
101703 ** Search the first N tables in pSrc, from left to right, looking for a
101713 int N, /* Number of tables in pSrc->a[] to search */
101718 int i; /* For looping over tables in pSrc */
101742 ** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the
101748 SrcList *pSrc, /* List of tables in FROM clause */
101749 int iLeft, /* Index of first table to join in pSrc */
101750 int iColLeft, /* Index of column in first table */
101751 int iRight, /* Index of second table in pSrc */
101752 int iColRight, /* Index of column in second table */
101754 Expr **ppWhere /* IN/OUT: The WHERE clause to add to */
101781 ** And set the Expr.iRightJoinTable to iTable for every term in the
101786 ** join restriction specified in the ON or USING clause and not a part
101789 ** originated in the ON or USING clause.
101793 ** explicitly mentioned in the expression. That information is needed
101799 ** term until after the t2 loop of the join. In that way, a
101802 ** after the t1 loop and rows with t1.x!=5 will never appear in
101821 ** The terms of a FROM clause are contained in the Select.pSrc structure.
101822 ** The left most table is the first entry in Select.pSrc. The right-most
101823 ** table is the last entry. The join operator is held in the entry to
101831 SrcList *pSrc; /* All tables in the FROM clause */
101848 ** every column that the two tables have in common.
101857 char *zName; /* Name of column in the right table */
101859 int iLeftCol; /* Matching column in the left table */
101869 /* Disallow both ON and USING clauses in the same join
101873 "clauses in the same join");
101887 ** in the USING clause. Example: If the two tables to be joined are
101890 ** Report an error if any column mentioned in the USING clause is
101891 ** not contained in both tables to be joined.
101896 char *zName; /* Name of the term in the USING clause */
101907 "not present in both tables", zName);
101927 ** Insert code into "v" that will push the record in register regData
102023 ** seen combinations of the N values. A new entry is made in iTab
102050 ** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
102051 ** column. We do this in a subroutine because the error used to occur
102052 ** in multiple places. (The error only occurs in one place now, but we
102076 ** are evaluated in order to get the data for this row. If srcTab is
102118 ** there are columns in the table on the left. The error will be caught
102120 ** to avoid other spurious errors in the meantime. */
102200 /* In this mode, write each query result to the key of the temporary
102237 ** in the index, do not write it to the output. If not, add the
102260 /* If we are creating a set for an "expr IN (SELECT ...)" construct,
102270 ** ORDER BY in this case since the order of entries in the set
102271 ** does not matter. But there might be a LIMIT clause, in which
102284 /* If any row exist in the result set, record that fact and abort.
102293 ** store the results in the appropriate memory cell and break out
102328 ** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
102389 ** there is a sorter, in which case the sorter has already limited
102451 ** the collating sequence for each expression in that expression list.
102528 ** in sqlite3Select() to assign values to structure member variables that
102579 ** then the results were placed in a sorter. After the loop is terminated
102704 ** result in *pEstWidth.
102709 ** is considered a column can be complex in the presence of subqueries. The
102710 ** result-set expression in all of the following SELECT statements is
102753 ** extracted from in NameContext.pSrcList. This table may be real
102758 int iCol = pExpr->iColumn; /* Index of column in pTab */
102782 ** when columnType() is called on the expression "t1.col" in the
102783 ** sub-select. In this case, set the column type to NULL, even
102795 /* The "table" is actually a sub-select or a view in the FROM clause
102844 ** origin info for the single column in the result set of the SELECT
102874 ** in the result set.
102897 ** column specific strings, in case the schema is reset before this
102913 ** in the result set. This information is used to provide the
102914 ** azCol[] values in the callback.
102991 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
103003 int nCol; /* Number of columns in the result set */
103006 int nName; /* Size of name in zName[] */
103093 ** This routine requires that all identifiers in the SELECT
103169 ** If an error occurs, return NULL and leave a message in pParse.
103190 ** that appear in the original SQL statement after the LIMIT and OFFSET
103332 ** There is exactly one reference to the recursive-table in the FROM clause
103338 ** extracted row (now in the iCurrent table) becomes the content of the
103348 ** If the query has an ORDER BY, then entries in the Queue table are kept in
103365 int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
103405 ** the Distinct table must be exactly one greater than Queue in order
103436 /* Store the results of the setup-query in Queue. */
103442 /* Find the next row in the Queue and output that row */
103445 /* Transfer the next row in Queue over to Current */
103454 /* Output the single row in Current */
103465 /* Execute the recursive SELECT taking the single row in Current as
103466 ** the value for the recursive-table. Store the results in the Queue.
103501 ** in which case this routine will be called recursively.
103518 ** The arrows in the diagram above represent the Select.pPrior pointer.
103520 ** pPrior will be the t2 query. p->op will be TK_UNION in this case.
103542 ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
103574 /* Make sure all SELECTs in the statement have the same number of elements
103575 ** in their result sets.
103702 /* Query flattening in sqlite3Select() might refill p->pOrderBy.
103715 /* Convert the data in the temporary table into whatever form
103837 int nCol; /* Number of columns in result set */
103883 ** The data to be output is contained in pIn->iSdst. There are
103890 ** If regPrev>0 then it is the first register in a vector that
103896 ** If the LIMIT found in p->iLimit is reached, jump immediately to
103953 /* If we are creating a set for an "expr IN (SELECT ...)" construct,
103971 /* If any row exist in the result set, record that fact and abort.
103981 ** store the results in the appropriate memory cell and break out
103992 /* The results are stored in a sequence of registers
104009 ** For SRT_Output, results are stored in a sequence of registers.
104045 ** co-routines. Then run the co-routines in parallel and merge the results
104046 ** into the output. In addition to the two coroutines (called selectA and
104055 ** appears only in B.)
104083 ** In the AltB, AeqB, and AgtB subroutines, an EOF on A following nextA
104088 ** Duplicate removal in the UNION, EXCEPT, and INTERSECT cases is handled
104158 int nOrderBy; /* Number of terms in the ORDER BY clause */
104332 ** are exhausted and only data in select B remains.
104346 ** are exhausted and only data in select A remains.
104404 /* Jump to the this point in order to terminate the query.
104438 ** a column in table number iTable with a copy of the iColumn-th
104439 ** entry in pEList. (But leave references to the ROWID column
104443 ** whose result set is defined by pEList appears as entry in the
104451 Expr *pExpr, /* Expr in which substitution occurs */
104480 ExprList *pList, /* List to scan and in which to make substitutes */
104492 Select *p, /* SELECT statement in which to make substitutions */
104527 ** subquery first and store the results in a temporary table, then
104622 ** appear as unmodified result columns in the outer query. But we
104623 ** have other optimizations in mind to deal with that case.
104633 ** recursive queries in multiSelect().
104636 ** In this routine, the "p" parameter is a pointer to the outer query.
104649 int iFrom, /* Index in p->pSrc->a[] of the inner subquery */
104656 Select *pSub1; /* Pointer to the rightmost select in sub-query */
104798 ** using UNION ALL operators. In this case N is the number of simple
104799 ** select statements in the compound sub-query.
104851 ** in the outer query.
104885 /* The following loop runs once for each term in a compound-subquery
104892 ** the cursor number for the original outer query FROM element in
104896 ** elements we are now copying in.
104902 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
104918 ** query. If the subquery has more than one element in its FROM clause,
104926 ** The outer query has 3 slots in its FROM clause. One slot of the
104929 ** slot is expanded to two slots in order to make space for the
104930 ** two elements in the FROM clause of the subquery.
104950 ** references to the iParent in the outer query.
104958 ** We look at every expression in the outer query and every place we see
105105 ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
105145 ** there are COLLATE terms in the ORDER BY.
105231 ** WITH clause will never be popped from the stack. In this case it
105232 ** should be freed along with the Parse object. In other cases, when
105257 ** occurs. If an error does occur, an error message is stored in the
105281 ** recursive reference to CTE pCte. Leave an error in pParse and return
105283 ** In this case, proceed. */
105353 pCte->zErr = "recursive reference in a subquery: %s";
105393 ** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
105394 ** defines FROM clause. When views appear in the FROM clause,
105404 ** (4) Scan the list of columns in the result set (pEList) looking
105406 ** If found, expand each "*" to be every column in every table
105407 ** and TABLE.* to be every column in TABLE.
105431 /* Make sure cursor numbers have been assigned to all entries in
105436 /* Look up every table named in the FROM clause of the select. If
105460 /* A sub-query in the FROM clause of a SELECT */
105475 /* An ordinary table or view name in the FROM clause */
105509 /* For every "*" that occurs in the column list, insert the names of
105510 ** all columns in all tables. And for every TABLE.* insert the names
105511 ** of all columns in TABLE. The parser inserted a special expression
105512 ** with the TK_ALL operator for each "*" that it found in the column list.
105514 ** each one to the list of all columns in all tables.
105530 ** in the result set and expand them one by one.
105602 ** for virtual tables), do not include it in the expanded
105615 /* In a NATURAL join, omit the join columns from the
105620 /* In a join with a USING clause, omit columns in the
105676 sqlite3ErrorMsg(pParse, "too many columns in result set");
105689 ** subquery in the parser tree.
105701 ** Expanding a SELECT statement is the first step in processing a
105752 /* A sub-query in the FROM clause of a SELECT */
105767 ** the Table structures of all FROM-clause subqueries in a
105791 ** * Wildcards "*" and "TABLE.*" in result sets are expanded.
105792 ** * Identifiers in expression are matched to tables.
105818 ** routine generates code that stores NULLs in all of those memory
105860 ** in the AggInfo structure.
105933 ** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
105982 ** Generate code for the SELECT statement given in the p argument.
105985 ** See comments in sqliteInt.h for further information.
105988 ** encountered, then an appropriate error message is left in
105991 ** This routine does NOT free the Select structure passed in. The
106036 /* If ORDER BY makes no difference in the output then neither does
106067 /* Generate code for all sub-queries in the FROM clause
106079 ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
106080 ** for example. In that case, do not regenerate the code to manifest
106188 ** can be rewritten as a GROUP BY. In other words, this:
106216 ** extracted in pre-sorted order. If that is the case, then the
106310 int groupBySort; /* Rows come from source in GROUP BY order */
106321 struct ExprList_item *pItem; /* For looping over expression in a list */
106338 ** in the correct order. It also may not - the GROUP BY may use a
106350 /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
106351 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
106419 /* Begin a loop that will extract all source rows in GROUP BY order.
106420 ** This might involve two separate loops with an OP_Sort in between, or
106422 ** in the right order to begin with.
106430 /* The optimizer is able to deliver rows in group by order so
106436 /* Rows are coming out in undetermined order. We have to push
106438 ** then loop over the sorting index in order to get the output
106439 ** in sorted order
106496 ** will naturally deliver rows in the order required by the ORDER BY
106509 /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
106512 ** from the previous row currently stored in a0, a1, a2...
106534 ** Changes in the GROUP BY are detected by the previous code
106537 ** This code copies current group by terms in b0,b1,b2,...
106539 ** and resets the aggregate accumulator registers in preparation
106556 VdbeComment((v, "indicate data in accumulator"));
106581 ** increments the iAbortFlag memory location before returning in
106640 ** (2013-10-03) Do not count the entries in a partial index.
106642 ** In practice the KeyInfo structure will not be used. It is only
106676 ** If it is, then ask the code in where.c to attempt to sort results
106678 ** If where.c is able to produce results sorted in this order, then
106691 ** + The optimizer code in where.c (the thing that decides which
106693 ** satisfying the 'ORDER BY' clause than it does in other cases.
106694 ** Refer to code and comments in where.c for details.
106884 ** The author disclaims copyright to this source code. In place of
106896 ** These routines are in a separate files so that they will not be linked
106912 int nRow; /* Number of rows in the result */
106913 int nColumn; /* Number of columns in the result */
106914 int nData; /* Slots used in azResult[]. (nRow+1)*nColumn */
106919 ** This routine is called once for each row in the result table. Its job
106920 ** is to fill in the TabResult structure appropriately, allocating new
106925 int need; /* Slots needed in p->azResult[] */
106929 /* Make sure there is enough space in p->azResult to hold everything
106992 ** The result that is written to ***pazResult is held in memory obtained
107001 int *pnRow, /* Write the number of rows in the result here */
107082 ** The author disclaims copyright to this source code. In place of
107115 ** All of the triggers on pTab that are in the same database as pTab
107117 ** triggers on pTab in the TEMP schema. This routine prepends all
107123 ** pTab as well as the triggers lised in pTab->pTrigger.
107154 ** in pParse->pNewTrigger. After the trigger actions have been parsed, the
107174 int iDb; /* The database to store the trigger in */
107192 /* Figure out the db that the trigger will be created in */
107216 ** then set iDb to 1 to create the trigger in the temporary database.
107242 ** drop so the trigger cannot be dropped. This results in an
107347 ** in order to complete the process of building the trigger.
107386 /* Make an entry in the sqlite_master table */
107428 ** The parser calls this routine when it finds a SELECT statement in
107477 IdList *pColumn, /* List of columns in pTableName to insert into */
107698 ** in pEList is of the format <id>=<expr>. If any of the entries
107699 ** in pEList have an <id> which matches an identifier in pIdList,
107718 ** least one of the columns in pChanges is being modified.
107724 ExprList *pChanges, /* Columns that change in an UPDATE statement */
107751 ** forming the SrcList. This prevents a trigger in one database from
107752 ** referring to a target in another database. An exception is when the
107753 ** trigger is in TEMP in which case it can refer to any other database it
107856 ** program. It is not used in production code, only for debugging.
108016 /* It may be that this trigger has already been coded (or is in the
108019 ** in the Parse.pTriggerPrg list. Search for such an entry. */
108036 ** function are the same as those described in the header function for
108052 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
108081 ** The reg argument is the address of the first in an array of registers
108083 ** in the trigger program. If N is the number of columns in table pTab
108100 ** Similarly, for ON INSERT triggers the values stored in the OLD.* registers
108118 int reg, /* The first in an array of registers (see above) */
108131 ** always defined. The trigger must be in the same schema as the table
108149 ** Triggers may access values stored in the old.* or new.* pseudo-table.
108158 ** are more than 32 columns in the table, and at least one of the columns
108169 ** included in the returned mask if the TRIGGER_BEFORE bit is set in the
108171 ** included in the returned mask if the TRIGGER_AFTER bit is set in tr_tm.
108209 ** The author disclaims copyright to this source code. In place of
108227 ExprList *pChanges, /* The columns to change in the UPDATE statement */
108229 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
108240 ** The default value of a column is specified by a DEFAULT clause in the
108243 ** command. If the latter, then the row-records in the table btree on disk
108262 ** stored in place of an 8-byte floating point value in order to save
108295 SrcList *pTabList, /* The table in which we should change things */
108313 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
108317 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
108318 u8 chngRowid; /* Rowid changed in a normal table */
108322 NameContext sNC; /* The name-context to resolve expressions in */
108336 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
108343 int regNew; /* Content of the NEW.* table in triggers */
108344 int regOld = 0; /* Content of OLD.* table in triggers */
108388 ** allocate enough space, just in case.
108417 /* Resolve the column names in all the expressions of the
108419 ** for each column to be updated in the pChanges array. For each
108477 /* There is one entry in the aRegIdx[] array for each index on the table
108478 ** being updated. Fill in aRegIdx[] with a register number that will hold
108542 /* Resolve the column names in all the expressions in the
108722 ** a new.* reference in a trigger program.
108741 /* The row-trigger may have deleted the row being updated. In this
108744 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
108758 ** registers in case this has happened.
108809 ** handle rows (possibly in other tables) that refer via a foreign key
108875 ** thely may interfere with compilation of other functions in this file
108876 ** (or in another file, if this file becomes part of the amalgamation). */
108893 ** (C) The content of every column in the row.
108895 ** Then we loop over this ephemeral table and for each row in
108900 ** (note1) Actually, if we know in advance that (A) is always the same
108908 ExprList *pChanges, /* The columns to change in the UPDATE statement */
108910 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
108921 int iReg; /* First register in set passed to OP_VUpdate */
108985 ** The author disclaims copyright to this source code. In place of
108995 ** Most of the code in this file may be omitted by defining the
109002 ** text of the error message in *pzErrMsg. Return the result code.
109056 ** in PostgreSQL. The VACUUM command works as follows:
109071 ** Two writes per page are required in step (3) because the original
109079 ** And a power loss in between deleting the original and renaming the
109114 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
109211 ** in the temporary database.
109228 /* Loop through the tables in the main database. For each, do
109280 /* This array determines which meta meta values are preserved in the
109299 /* GetMeta() and UpdateMeta() cannot fail in this context because
109355 ** The author disclaims copyright to this source code. In place of
109385 sqlite3 *db, /* Database in which module is registered */
109429 sqlite3 *db, /* Database in which module is registered */
109441 sqlite3 *db, /* Database in which module is registered */
109497 ** Table p is a virtual table. This function moves all elements in the
109501 ** connection db is left in the p->pVTable list.
109512 ** database connection that may have an entry in the p->pVTable list.
109538 ** list in p->pVTab. It also decrements the VTable ref count. This is
109562 ** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
109569 ** 1) By this function. In this case, all BtShared mutexes and the mutex
109573 ** the sqlite3.pDisconnect list. In this case either the BtShared mutex
109574 ** associated with the database the virtual table is stored in is held
109575 ** or, if the virtual table is stored in a non-sharable database, then
109609 ** in the list are moved to the sqlite3.pDisconnect list of the associated
109661 int iDb; /* The database the table is being created in */
109696 ** in pParse->zArg[] and appends it to the list of arguments on the
109697 ** virtual table currently under construction in pParse->pTable.
109722 ** first time (in other words if the virtual table is actually being
109725 ** in the sqlite_master table.
109739 /* A slot for the record has already been allocated in the
109744 ** entry in the sqlite_master table tht was created for this vtab
109769 /* If we are rereading the sqlite_master table create the in-memory
109771 ** the first time the virtual table is used in an SQL statement. This
109792 ** of an argument to the module name in a CREATE VIRTUAL TABLE statement.
109802 ** in an argument to the module name in a CREATE VIRTUAL TABLE statement.
109929 ** and an error left in pParse.
109997 ** of the virtual table named zTab in database iDb.
110001 ** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
110103 ** of the virtual table named zTab in database iDb. This occurs
110133 ** of each of the virtual tables in the sqlite3.aVTrans array. The method
110135 ** the offset of the method to call in the sqlite3_module structure.
110160 ** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
110164 ** If an error message is available, leave it in p->zErrMsg.
110185 ** Invoke the xRollback method of all virtual tables in the
110194 ** Invoke the xCommit method of all virtual tables in the
110208 ** in the sqlite3.aVTrans array.
110217 ** virtual module tables in this case, so return SQLITE_LOCKED.
110230 /* If pVtab is already in the aVTrans array, return early */
110301 ** If pExpr is a column in a virtual table, then let the virtual
110328 /* Check to see the left operand is a column in a virtual table */
110372 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
110374 ** array if it is missing. If pTab is already in the array, this routine
110397 ** Return the ON CONFLICT resolution mode in effect for the virtual
110398 ** table update operation currently in progress.
110454 ** The author disclaims copyright to this source code. In place of
110469 /************** Include whereInt.h in the middle of where.c ******************/
110474 ** The author disclaims copyright to this source code. In place of
110484 ** planner logic in "where.c". These definitions are broken out into
110519 ** loop in WHERE clause.
110527 ** each term in the FROM clause (which is to say, for each of the
110537 int addrNxt; /* Jump here to start the next IN combination */
110542 u8 iFrom; /* Which entry in the FROM clause */
110547 int nIn; /* Number of entries in aInLoop[] */
110549 int iCur; /* The VDBE cursor used by this IN operator */
110550 int addrInTop; /* Top of the IN loop */
110551 u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
110552 } *aInLoop; /* Information about each nested IN operator */
110553 } in
110580 u8 iTab; /* Position in FROM clause of table for this loop */
110600 u16 nLTerm; /* Number of entries in aLTerm[] */
110605 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
110610 ** subquery on one operand of an OR operator in the WHERE clause.
110637 ** Think of each WhereLoop object as a node in a graph with arcs
110648 ** number of nodes in the FROM clause. The best (lowest cost) WherePath
110652 Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
110687 ** In this second case, wtFlag has the TERM_ORINFO bit set and eOperator==WO_OR
110691 ** If a term in the WHERE clause does not match either of the two previous
110694 ** but no other fields in the WhereTerm object are meaningful.
110698 ** cursor number into bits and the translated bit is stored in the prereq
110699 ** fields. The translation is used in order to maximize the number of
110700 ** bits that will fit in a Bitmask. The VDBE cursor numbers might be
110704 ** beginning with 0 in order to make the best possible use of the available
110705 ** bits in the Bitmask. So, in the example above, the cursor numbers
110708 ** The number of terms in a join is limited by the number of bits
110709 ** in prereqRight and prereqAll. The default is 64 bits, hence SQLite
110715 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
110717 int leftColumn; /* Column number of X in "X <op> <expr>" */
110748 ** terms in the WHERE clause that are useful to the query planner.
110755 unsigned char nEquiv; /* Number of entries in aEquiv[] */
110756 unsigned char iEquiv; /* Next unused slot in aEquiv[] */
110779 int nSlot; /* Number of entries in a[] */
110794 Bitmask indexable; /* Bitmask of all indexable tables in the clause */
110807 ** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
110809 ** The VDBE cursor numbers are small integers contained in
110812 ** contain gaps in the numbering sequence. But we want to make maximum
110813 ** use of the bits in our bitmasks. This structure provides a mapping
110824 ** Note that the mapping is not necessarily ordered. In the example
110848 int nRecValid; /* Number of valid fields currently in pRec */
110864 SrcList *pTabList; /* List of tables in the join */
110884 WhereLevel a[1]; /* Information about each nest loop in WHERE */
110910 ** These are definitions of bits in the WhereLoop.wsFlags field.
110911 ** The particular combination of bits in each WhereLoop help to
110916 #define WHERE_COLUMN_IN 0x00000004 /* x IN (...) */
110926 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
110934 /************** Continuing where we left off in where.c **********************/
110952 ** Return TRUE if the WHERE clause returns rows in ORDER BY order.
110960 ** Return the VDBE address or label to jump to in order to continue
110969 ** Return the VDBE address or label to jump to in order to break
111103 ** The index in pWC->a[] of the new WhereTerm is returned on success.
111105 ** allocation error. The memory allocation failure will be recorded in
111154 ** This routine identifies subexpressions in the WHERE clause where
111156 ** operator specified in the op parameter. The WhereClause structure
111163 ** The original WHERE clause in pExpr is unaltered. All this routine
111166 ** In the previous sentence and in the diagram, "slot[]" refers to
111188 ** iCursor is not in the set.
111204 ** There is one cursor per table in the FROM clause. The number of
111205 ** tables in the FROM clause is limited by a test early in the
111216 ** a bitmask indicating which tables are used in that expression
111271 ** "=", "<", ">", "<=", ">=", "IN", and "IS NULL"
111478 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
111483 ** The term returned might by Y=<expr> if there is another constraint in
111485 ** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
111487 ** taking up two slots in aEquiv[]. The first slot is for the cursor number
111488 ** and the second is for the column number. There are 22 slots in aEquiv[]
111493 ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
111494 ** then try for the one with no dependencies on <expr> - in other words where
111496 ** the form "X <op> Y" where Y is a column in another table if no terms of
111529 ** Call exprAnalyze on all terms in a WHERE clause.
111547 ** In order for the operator to be optimizible, the RHS must be a string
111554 int *pisComplete, /* True if the only wildcard is % in the last character */
111560 int c; /* One character in z[] */
111668 ** If the pBase expression originated in the ON or USING clause of
111681 ** subterms. So in:
111686 ** This routine analyzes terms such as the middle term in the above example.
111706 ** a single table T (as shown in example B above) then create a new virtual
111707 ** term that is an equivalent IN expression. In other words, if the term
111714 ** x IN (expr1,expr2,expr3)
111725 ** <op> is one of "=", "<", "<=", ">", ">=", "IS NULL", or "IN".
111739 ** always prefer case 1, so in that case we pretend that case 2 is not
111748 ** to "bitmap indices" in other database engines.
111774 ** stored in a WhereClause structure containing within the WhereOrInfo
111857 ** IN operator because one or more terms in the OR clause contain
111858 ** something other than == on a column in the single table. The 1-bit
111864 ** might be possible to form an IN operator with either table1.column
111872 int okToChngToIN = 0; /* True if the conversion to IN is valid */
111873 int iColumn = -1; /* Column index on lhs of IN operator */
111878 ** other of the == operator in every subterm. That table and column
111879 ** will be recorded in iCursor and iColumn. There might not be any
111895 /* This term must be of the form t1.a==t2.b where t2 is in the
111919 ** table and column is common to every term in the OR clause */
111945 ** case 1. In that case, construct a new virtual term that is
111946 ** pTerm converted into an IN operator.
111950 ExprList *pList = 0; /* The RHS of the IN operator */
111951 Expr *pLeft = 0; /* The LHS of the IN operator */
111952 Expr *pNew; /* The complete IN operator */
111988 ** "pExpr" field filled in. The job of this routine is to analyze the
112310 ** If such an expression is found, its index in pList->a[] is returned. If
112357 /* If there is more than one table or sub-select in the FROM clause of
112378 ** 2. All of the columns in the index are either part of the pDistinct
112468 Bitmask notReady /* Tables in outer loops of the join */
112495 int nKeyCol; /* Number of columns in the constructed index */
112506 int mxBitCol; /* Maximum column in pSrc->colUsed */
112674 /* If the ORDER BY clause contains only columns in the current
112702 ** changing them. We have to do some funky casting in order to
112729 /* The direct assignment in the previous line is possible only because
112754 ** comes in as the 3rd argument to this function.
112799 ** Estimate the location of a particular key among all keys in an
112800 ** index. Store the results in aStat as follows:
112815 int iCol; /* Index of required stats in anEq[] etc. */
112931 ** extracted from pLower and pUpper with the corresponding column in each
113003 ** using the method described in the header comment for this function. */
113036 ** If either of the upper or lower bound is not present, then NULL is passed in
113039 ** The value in (pBuilder->pNew->u.btree.nEq) is the index of the index
113056 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
113059 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
113088 /* Variable iLower will be set to the estimate of the number of rows in
113092 ** columns of the index, and $L is the value in pLower.
113096 ** range is $P. Due to a quirk in the way whereKeyStats() works, even
113119 ** have been requested when testing key $P in whereEqualScanEst(). */
113187 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
113202 ** an equality constraint x=VALUE and where that VALUE occurs in
113215 ** in the pParse structure.
113220 Expr *pExpr, /* Expression for VALUE in the x=VALUE constraint */
113268 ** an IN constraint where the right-hand side of the IN operator
113271 ** WHERE x IN (1,2,3,4)
113280 ** in the pParse structure.
113285 ExprList *pList, /* The value list on the RHS of "x IN (v1,v2,v3,...)" */
113307 WHERETRACE(0x10,("IN row estimate: est=%g\n", nRowEst));
113315 ** Disable a term in the WHERE clause. Except, do not disable the term
113316 ** if it controls a LEFT OUTER JOIN and it did not originate in the ON
113319 ** Consider the term t2.z='ok' in the following queries:
113325 ** The t2.z='ok' is disabled in the in (2) because it originates
113326 ** in the ON clause. The term is disabled in (3) because it is not part
113327 ** of a LEFT OUTER JOIN. In (1), the term is not disabled.
113329 ** Disabling a term causes that term to not be tested in the inner loop
113331 ** by indices, we disable them to prevent redundant tests in the inner
113334 ** as we can without disabling too much. If we disabled in (1), we'd get
113358 ** beginning and end of zAff are ignored. If all entries in zAff are
113395 ** term can be either X=expr or X IN (...). pTerm is the term to be
113398 ** The current value for the constraint is left in register iReg.
113401 ** result is left on the stack. For constraints of the form X IN (...)
113409 int bRev, /* True for reverse-order IN operations */
113410 int iTarget /* Attempt to leave results in this register */
113450 if( pLevel->u.in.nIn==0 ){
113453 pLevel->u.in.nIn++;
113454 pLevel->u.in.aInLoop =
113455 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop,
113456 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
113457 pIn = pLevel->u.in.aInLoop;
113459 pIn += pLevel->u.in.nIn - 1;
113469 pLevel->u.in.nIn = 0;
113478 ** Generate code that will evaluate all == and IN constraints for an
113482 ** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
113483 ** The index has as many as three equality constraints, but in this
113486 ** a==5 and b IN (1,2,3). The current values for a and b will be stored
113487 ** in consecutive registers and the index of the first register is returned.
113489 ** In the example above nEq==2. But this subroutine works for any value
113495 ** are == or IN and are covered by the nEq. nExtraReg is 1 if there is
113496 ** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
113500 ** the index of the first memory cell in that range. The code that
113503 ** key value of the loop. If one or more IN operators appear, then
113509 ** sqlite3DbMalloc(). Except, entries in the copy of the string associated
113516 ** In the example above, the index on t1(a) has TEXT affinity. But since
113519 ** a key to search the index. Hence the first byte in the returned affinity
113520 ** string in this example would be set to SQLITE_AFF_NONE.
113525 int bRev, /* Reverse the order of IN operators */
113529 u16 nEq; /* The number of == or IN constraints to code */
113644 ** of the subset of table rows scanned by the strategy in the form of an
113703 ** record is added to the output to describe the table scan strategy in
113792 ** Generate code for the start of the iLevel-th loop in the WHERE clause
113802 int addrNxt; /* Where to jump to continue with the next IN case */
113804 int bRev; /* True if we need to scan in reverse order */
113815 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
113837 ** When there is an IN operator, we also have a "addrNxt" label that
113838 ** means to continue with the next IN value combination. When
113839 ** there are no IN operators in the constraints, the "addrNxt" label
113913 ** we reference multiple rows using a "rowid IN (...)"
114027 ** terms ("==" or "IN" operators) that refer to the N
114032 ** use the "==" and "IN" operators. For example, if the
114052 ** constraints but an index is selected anyway, in order
114071 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
114096 ** should not have a NULL value stored in 'x'. If column 'x' is
114097 ** the first one after the nEq equality constraints in the index,
114132 /* Generate code to evaluate all constraint terms using == or IN
114133 ** and store the values of those terms in an array of registers
114296 ** In the example, there are three indexed terms connected by OR.
114299 ** Null 1 # Zero the rowset in reg 1
114314 ** Null 1 # Zero the rowset in reg 1
114352 /* Set up a new SrcList in pOrTab containing the table being scanned
114353 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
114354 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
114376 ** capable of holding primary keys in the case of a WITHOUT ROWID.
114380 ** is required in a few obscure LEFT JOIN cases where control jumps
114381 ** over the top of the loop into the body of it. In this case the
114402 ** That way, terms in y that are factored into the disjunction will
114406 ** the "interesting" terms of z - terms that did not originate in the
114411 ** is not contained in the ON clause of a LEFT JOIN.
114460 ** row will be skipped in subsequent sub-WHERE clauses.
114482 ** the row has already been included in the result set and
114488 ** is zero, assume that the key cannot already be present in
114526 ** If the call to sqlite3WhereBegin() above resulted in a scan that
114574 /* Tables marked isRecursive have only a single row that is stored in
114724 ** expressions in the WhereLoop.aLTerm[] array.
114889 ** This adjustment is omitted for SKIPSCAN loops. In a SKIPSCAN loop, the
114891 ** clause terms covered, since some of the first nLTerm entries in aLTerm[]
114922 ** Search the list of WhereLoops in *ppPrev looking for one that can be
114926 ** pTemplate, in other words if pTemplate does not belong on the list.
114946 /* In the current implementation, the rSetup value is either zero
115008 ** information is gathered in the pBuilder->pOrSet object. This special
115120 ** In the current implementation, the first extra WHERE clause term reduces
115174 LogEst nInMul /* log(Number of iterations due to IN) */
115189 int iCol; /* Index of the column in the table */
115224 ** number of repeats in the left-most terms is at least 18.
115228 ** contains fewer than 2^17 rows we assume otherwise in other parts of
115252 LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
115281 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
115284 /* "x IN (value, value, ...)" */
115288 ** changes "x IN (?)" into "x=?". */
115319 ** values of nIn and nInMul. In other words, assuming that all
115320 ** "x IN(...)" terms are replaced with "x = ?". This block updates
115376 /* Set rCostIdx to the cost of visiting selected rows in index. Add
115379 ** visiting the rows in the main table. */
115419 ** Return True if it is possible that pIndex might be useful in
115420 ** implementing the ORDER BY clause in pBuilder.
115423 ** if there is no way for pIndex to be useful in implementing that
115467 ** in the current query. Return true if it can be and false if not.
115503 ** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when
115504 ** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans.
115509 ** log(nRow) factor is omitted from a non-covering index scan in order to
115510 ** bias the scoring in favor of using an index, since the worst-case
115529 LogEst rSize; /* number of rows in the table */
115530 LogEst rLogSize; /* Logarithm of the number of rows in the table */
115548 /* There is no INDEXED BY clause. Create a fake Index object in local
115550 ** fake index the first in a chain of Index objects with all of the real
115597 ** approximately 7*N*log2(N) where N is the number of rows in
115601 /* TUNING: Each index lookup yields 20 rows in the table. This
115722 int seenIn = 0; /* True if an IN operator is seen */
115724 int iPhase; /* 0: const w/o IN, 1: const, 2: no IN, 2: IN */
115761 case 0: /* Constants without IN operator */
115772 case 1: /* Constants with IN operators */
115776 case 2: /* Variables without IN */
115780 default: /* Variables with IN */
115827 /* Do not attempt to use an IN constraint if the virtual table
115830 ** repeated in the output. */
115833 /* A virtual table that is constrained by an IN clause may not
115834 ** consume the ORDER BY clause because (1) the order of IN terms
115836 ** (2) Multiple outputs from a single IN value will not merge
115994 /* Loop over the tables in the join, from left to right */
116021 ** parameters) to see if it outputs rows in the requested ORDER BY
116031 ** and DISTINCT do not require rows to appear in any particular order as long
116033 ** the pOrderBy terms can be matched in any order. With ORDER BY, the
116034 ** pOrderBy terms must be matched in strict left-to-right order.
116041 u16 nLoop, /* Number of entries in pPath->aLoop[] */
116043 Bitmask *pRevMask /* OUT: Mask of WhereLoops to run in reverse order */
116051 u16 nKeyCol; /* Number of key columns in pIndex */
116052 u16 nColumn; /* Total number of ordered columns in the index */
116053 u16 nOrderBy; /* Number terms in the ORDER BY clause */
116054 int iLoop; /* Index of WhereLoop in pPath being processed */
116075 ** Every one-row WhereLoop will have the WHERE_ONEROW bit set in wsFlags.
116078 ** that WhereLoop that are in the ORDER BY clause are different for every
116080 ** order-distinct. A WhereLoop that has no columns in the ORDER BY clause
116087 ** rowid appears in the ORDER BY clause, the corresponding WhereLoop is
116110 /* Mark off any ORDER BY term X that is a column in the table of
116111 ** the current loop for which there is term in the WHERE
116152 ** that are not constrained by == or IN.
116171 /* Get the column number in the table (iColumn) and sort order
116217 /* Make sure the sort order is compatible in an ORDER BY clause.
116277 ** If the WHERE_GROUPBY flag is set in the mask passed to sqlite3WhereBegin(),
116282 ** Normally, in this case it is not possible for the caller to determine
116283 ** whether or not the rows are really being delivered in sorted order, or
116284 ** just in some other order that provides the required grouping. However,
116287 ** true if the rows really will be sorted in the specified order, or false
116319 ** nOrderby columns and that the first nSorted columns are already in
116362 ** will be nRowEst (in the 10*log2 representation). Or, ignore sorting
116370 int nLoop; /* Number of terms in the join */
116379 int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
116400 /* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
116428 ** the ORDER BY clause are already in order, where X is the array
116445 /* If nLoop is zero, then there are no FROM terms in the query. Since
116446 ** in this case the query may return a maximum of one row, the results
116447 ** are already in the requested order. Set isOrdered to nOrderBy to
116524 ** paths currently in the best-so-far buffer. So discard
116789 ** in order to complete the WHERE clause processing.
116793 ** The basic idea is to do a nested loop, one loop for each table in
116795 ** same as a SELECT with only a single table in the FROM clause.) For
116802 ** foreach row1 in t1 do \ Code generated
116803 ** foreach row2 in t2 do |-- by sqlite3WhereBegin()
116804 ** foreach row3 in t3 do /
116810 ** Note that the loops might not be nested in the order in which they
116811 ** appear in the FROM clause if a different order is better able to make
116812 ** use of indices. Note also that when the IN operator appears in
116813 ** the WHERE clause, it might result in additional nested loops for
116814 ** scanning through all values on the right-hand side of the IN.
116822 ** in pTabList pointing at their appropriate entries. The [...] code
116828 ** the tables have indices and there are terms in the WHERE clause that
116834 ** make it to the "..." in the middle of the loop. After each "foreach",
116835 ** terms of the WHERE clause that use only terms in that loop and outer
116844 ** foreach row1 in t1 do
116846 ** foreach row2 in t2 do
116860 ** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
116868 ** the first cursor in an array of cursors for all indices. iIdxCur should
116878 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
116882 int nTabList; /* Number of elements in pTabList */
116888 WhereLevel *pLevel; /* A single level in pWInfo->a[] */
116910 /* The number of tables in the FROM clause is limited by the number of
116911 ** bits in a Bitmask
116915 sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS);
116919 /* This function normally generates a nested loop for all tables in
116921 ** only generate code for the first table in pTabList and assume that
116986 /* Assign a bit from the bitmask to every term in the FROM clause.
116997 ** Note that bitmasks are created for all pTabList->nSrc tables in
117162 /* Open all tables in the pTabList and any indices selected for
117316 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
117320 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
117328 sqlite3DbFree(db, pLevel->u.in.aInLoop);
117374 ** the co-routine into OP_SCopy of result contained in a register.
117419 ** from the index instead of from the table where possible. In some cases
117423 ** Calls to the code generator in between sqlite3WhereBegin and
117475 ** macros to disable tests that are needed in the case of a general
117476 ** LALR(1) grammar but which are always false in the
117480 ** in the input grammar file. */
117485 ** Disable all error recovery processing in the parser push-down
117602 /* Next is all token values, in a form suitable for use by makeheaders.
117610 ** Each symbol here is a terminal symbol in the grammar.
117625 ** number is used to fill in empty slots of the hash
117638 ** which is sqlite3ParserTOKENTYPE. The entry in the union
117647 ** YYNRULE the number of rules in the grammar
117696 ** Applications can choose to define yytestcase() in the %include section
117697 ** to a macro that can assist in verifying code coverage. For production
117724 ** slots in the yy_action[] table.
117733 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
117738 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
117739 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
117742 ** The following are the tables generated in this section:
117745 ** yy_lookahead[] A table containing the lookahead for each entry in
118217 ** appears in the grammar, then ID becomes a fallback token for X, Y,
118303 ** (In other words, the "major" token.)
118306 ** the information used by the action routines in the grammar.
118318 /* The state of the parser is completely contained in an instance of
118321 int yyidx; /* Index of top element in stack */
118390 "AND", "IS", "BETWEEN", "IN",
118664 /* 221 */ "in_op ::= IN",
118665 /* 222 */ "in_op ::= NOT IN",
118806 ** A pointer to a parser. This pointer is used in subsequent calls
118937 ** empty in SQLite. */
118969 /* In SQLite, we never try to destroy a parser that was not successfully
118970 ** created in the first place. */
119114 int yyNewState, /* The new state to shift in */
119115 int yyMajor, /* The major token to shift in */
119116 YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */
119160 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
119517 ** in some cases when it is copied into the stack after the following
119527 ** from wireshark this week. Clearly they are stressing Lemon in ways
119610 case 221: /* in_op ::= IN */ yytestcase(yyruleno==221);
119619 case 222: /* in_op ::= NOT IN */ yytestcase(yyruleno==222);
119861 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
120181 /* When doing a nested parse, one can include terms in an expression
120183 ** in the virtual machine. #N is the N-th register. */
120324 ** expr1 IN ()
120325 ** expr1 NOT IN ()
120335 ** expr1 IN (?1)
120336 ** expr1 NOT IN (?2)
120347 ** the semantics would be subtly different from IN or NOT IN.
120761 ** onto the stack here, and skip the stack overflow test in yy_shift().
120840 ** user wants (and specified in the grammar) and is available for
121013 ** The author disclaims copyright to this source code. In place of
121068 ** mkkeywordhash.h, located in the tool subdirectory of the distribution.
121073 /************** Include keywordhash.h in the middle of tokenize.c ************/
121077 ** The code in this file has been automatically generated by
121081 ** The code in this file implements a function that determines whether
121090 /* zText[] encodes 834 bytes of keywords in 554 bytes */
121309 testcase( i==93 ); /* IN */
121351 /************** Continuing where we left off in tokenize.c *******************/
121355 ** If X is a character that can be used in an identifier then
121359 ** allowed in an identifier. For 7-bit characters,
121365 ** Ticket #1066. the SQL standard does not allow '$' in the
121367 ** SQLite will allow '$' in identifiers for compatibility.
121395 ** Store the token type in *tokenType before returning.
121663 ** passed in. An SQLITE_ status code is returned. If an error occurs
121783 ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
121814 ** The author disclaims copyright to this source code. In place of
121832 ** This is defined in tokenize.c. We just have to import the definition.
121861 ** Return TRUE if the given SQL string ends in a semicolon.
121872 ** returns 1 if it ends in the START state and 0 if it ends
121873 ** in any other state.
121875 ** (2) NORMAL We are in the middle of statement which ends with a single
121885 ** (5) TRIGGER We are in
121888 ** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at
121914 u8 state = 0; /* Current state, using numbers defined in header comment */
121982 case '[': { /* Microsoft-style identifiers in [...] */
122099 ** The author disclaims copyright to this source code. In place of
122107 ** Main file for the SQLite library. The routines in this file
122108 ** implement the programmer interface to the library. Routines in
122114 /************** Include fts3.h in the middle of main.c ***********************/
122119 ** The author disclaims copyright to this source code. In place of
122143 /************** Continuing where we left off in main.c ***********************/
122146 /************** Include rtree.h in the middle of main.c **********************/
122151 ** The author disclaims copyright to this source code. In place of
122175 /************** Continuing where we left off in main.c ***********************/
122178 /************** Include sqliteicu.h in the middle of main.c ******************/
122183 ** The author disclaims copyright to this source code. In place of
122208 /************** Continuing where we left off in main.c ***********************/
122360 ** the pInitMutex mutex. Return an error in
122375 ** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
122450 ** while any part of SQLite is otherwise in use in any thread. This
122479 ** this function resulted in the heap subsystem actually being shutdown.
122507 ** the SQLite library is in use. */
122513 /* Mutex configuration options are only available in a threadsafe
122714 ** The sz parameter is the number of bytes in each lookaside slot.
122819 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
122891 ** Another built-in collating sequence: NOCASE.
122895 in the English language.
122921 ** Return the number of changes in the most recent call to sqlite3_exec().
123026 ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
123128 /* Tell the code in notify.c that the connection no longer holds any
123192 ** any open cursors are invalidated ("tripped" - as in "tripping a circuit
123203 ** This is important in case the transaction being rolled back has
123205 ** here, then another shared-cache connection might sneak in between
123207 ** corruption reports in some cases. */
123241 ** specified in the argument.
123349 ** Return a static string that describes the kind of error specified in the
123402 ** an integer number of milliseconds passed in as the first
123533 ** that if a malloc() fails in sqlite3_create_function(), an error code
123720 ** A global function must exist in order for name resolution to work
123839 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
123861 ** more frames in the log file. Passing zero or a negative value as the
123912 int *pnLog, /* OUT: Size of WAL log in frames */
123921 /* Initialize the output variables to -1 in case an error occurs. */
123962 ** not currently open in WAL mode.
124135 ** Return a string that describes the kind of error specified in the
124149 HashElem *k; /* For looping over tables in pDb */
124150 Table *pTab; /* A table in the database */
124249 ** initializer must be kept in sync with the SQLITE_LIMIT_*
124250 ** #defines in sqlite3.h.
124317 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
124357 ** the default flags to open the database handle with. The value stored in
124361 ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
124375 unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */
124443 /* This branch is taken when "%00" appears within the URI. In this
124444 ** case we ignore all text in the remainder of the path, name or
124604 /* Only allow sensible combinations of bits in the flags argument.
124607 ** assert() statements in deeper layers. Sensible combinations
124640 ** dealt with in the previous code block. Besides these, the only
124759 /* Register all built-in functions, but do not attempt to read the
124880 char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
125022 ** Test to see whether or not the database connection is in autocommit
125036 ** 1. Serve as a convenient place to set a breakpoint in a debugger
125079 ** See comment in sqlite3.h (sqlite.h.in) for details.
125113 /* Locate the table in question */
125140 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
125199 /* This function works in milliseconds, but the underlying OsSleep()
125341 ** Set the PENDING byte to the value in the argument, if X>0.
125345 ** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
125347 ** while any database connection is open results in undefined and
125450 ** is obtained in every case.
125464 ** This test feature is only available in the amalgamation since
125465 ** the SQLITE_N_KEYWORD macro is not defined in this file if SQLite
125524 ** testing causes certain assert() statements in the code to be activated
125649 ** The author disclaims copyright to this source code. In place of
125690 ** 1) Each entry in the list has a non-NULL value for either
125693 ** 2) All entries in the list that share a common value for
125696 ** 3) If the argument db is not NULL, then none of the entries in the
125775 ** (call it pOther) in the same process was busy using the same shared
125809 ** blocking transaction. In either case, invoke the notify callback
125855 ** This function loops through each entry in the blocked connections
125871 int nArg = 0; /* Number of entries in aArg[] */
125880 /* This loop runs once for each entry in the blocked-connections list. */
125982 ** The author disclaims copyright to this source code. In place of
125995 ** The code in this file is only compiled if:
125998 ** (in which case SQLITE_CORE is not defined), or
126001 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
126004 /* The full-text index is stored in a series of b+tree (-like)
126006 ** structures are like b+trees in layout, but are constructed from the
126007 ** bottom up in optimal fashion and are not updatable. Since trees
126014 ** varint. We encode variable-length integers in little-endian order
126026 ** This is similar in concept to how sqlite encodes "varints" but
126028 ** are are limited to 9 bytes in length whereas FTS3 varints are
126029 ** little-endian and can be up to 10 bytes in length (in theory).
126065 ** Here, array { X } means zero or more occurrences of X, adjacent in
126066 ** memory. A "position" is an index of a token in the token stream
126068 ** in the same logical place as the position element, and act as sentinals
126077 ** The 123 value is the first docid. For column zero in this document
126115 ** Here, array { X } means zero or more occurrences of X, adjacent in
126118 ** Leaf nodes are broken into blocks which are stored contiguously in
126119 ** the %_segments table in sorted order. This means that when the end
126120 ** of a node is reached, the next term is in the node with the next
126125 ** larger than STANDALONE_MIN (default 1024) is placed in a standalone
126161 ** means zero or more occurrences of X, adjacent in memory.
126183 ** The segment directory in table %_segdir stores meta-information for
126195 ** The meta-information in the segment directory is:
126210 ** merged in batches. Each increase in level represents exponentially
126221 ** A segment merge traverses all segments at a given level in
126223 ** leaf nodes are written in to the %_segments table in order, this
126231 ** a tiny bit slower (perhaps due to more overhead in merge-time
126269 /************** Include fts3Int.h in the middle of fts3.c ********************/
126274 ** The author disclaims copyright to this source code. In place of
126307 /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
126345 ** implementation. The xCreate() function in turn returns an
126367 ** Create a new tokenizer. The values in the argv[] array are the
126421 ** of this buffer in bytes. The input text that generated the token is
126422 ** identified by the byte offsets returned in *piStartOffset and
126424 ** byte of the token in the input buffer. *piEndOffset should be set
126425 ** to the index of the first byte just past the end of the token in
126439 int *piStartOffset, /* OUT: Byte offset of token in input buffer */
126440 int *piEndOffset, /* OUT: Byte offset of end of token in input buffer */
126471 /************** Continuing where we left off in fts3Int.h ********************/
126472 /************** Include fts3_hash.h in the middle of fts3Int.h ***************/
126477 ** The author disclaims copyright to this source code. In place of
126486 ** used in SQLite. We've modified it slightly to serve as a standalone
126508 int count; /* Number of entries in this table */
126510 int htsize; /* Number of buckets in the hash table */
126517 /* Each element in the hash table is an instance of the following
126524 Fts3HashElem *next, *prev; /* Next and previous elements in the table */
126534 ** is respected in comparisons.
126581 ** Number of entries in a hash table
126588 /************** Continuing where we left off in fts3Int.h ********************/
126610 ** This is the maximum amount of data (in bytes) to store in the
126612 ** populated as documents are inserted/updated/deleted in a transaction
126620 ** Macro to return the number of elements in an array. SQLite has a
126622 ** a collision when building an amalgamation with built-in FTS3.
126642 ** in the document set and zero or more prefix indexes. All indexes are stored
126643 ** as one or more b+-trees in the %_segments and %_segdir tables.
126646 ** value stored in the "%_segdir.level" column. Given this value L, the index
126647 ** that the b+-tree belongs to is (L<<10). In other words, all b+-trees with
126651 ** It is considered impossible for an index to use more than 1024 levels. In
126755 int nColumn; /* number of named columns in virtual table */
126776 u8 bDescIdx; /* True if doclists are in reverse order */
126786 ** The current language id is stored in variable iPrevLangid.
126789 ** there is an entry in the aIndex[] array. Index 0 is an index of all the
126790 ** terms that appear in the document set. Each subsequent index in aIndex[]
126836 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
126839 int nPhrase; /* Number of matchable phrases in query */
126845 u8 bDesc; /* True to sort in descending order */
126847 int nRowAvg; /* Average size of database rows, in pages */
126848 sqlite3_int64 nDoc; /* Documents in table */
126851 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
126853 int nMatchinfo; /* Number of elements in aMatchinfo[] */
126865 ** of the column to be searched. For example, in
126892 int nAll; /* Size of a[] in bytes */
126902 ** A "phrase" is a sequence of one or more tokens that must match in
126904 ** For a sequence of tokens contained in double-quotes (i.e. "one two three")
126905 ** nToken will be the number of tokens in the string.
126909 int n; /* Number of bytes in buffer z */
126914 ** parsed (by code in fts3_expr.c). Below this point the variables are
126929 int nToken; /* Number of tokens in the phrase */
126931 Fts3PhraseToken aToken[1]; /* One entry for each token in the phrase */
126939 ** of this phrase query in FTS3 doclist format. As usual, the initial
126940 ** "Length" field found in doclists stored on disk is omitted from this
126945 ** where nCol is the number of columns in the queried FTS table. The array
126974 ** four values is in order of precedence when parsing expressions. For
127056 char *aBuffer; /* Buffer to merge doclists in */
127057 int nBuffer; /* Allocated size of aBuffer[] in bytes */
127068 int nTerm; /* Size of zTerm in bytes */
127070 int nDoclist; /* Size of aDoclist[] in bytes */
127146 /************** Continuing where we left off in fts3.c ***********************/
127181 q[-1] &= 0x7f; /* turn off high bit in final byte */
127196 ** The value is stored in *v.
127255 ** the quote characters. The conversion is done in-place. If the
127320 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
127366 sqlite3 *db, /* Database in which to run SQL */
127416 ** Otherwise, if an error occurs, an SQLite error code is stored in *pRc
127533 ** Store the current database page-size in bytes in p->nPgsz.
127536 ** Otherwise, if an error occurs, an SQLite error code is stored in *pRc
127599 int *pRc, /* IN/OUT: Error code */
127600 char **pz, /* IN/OUT: Pointer to string buffer */
127622 ** Return a copy of input string zInput enclosed in double-quotes (") and
127652 ** could be used in a SELECT statement such as the following:
127656 ** to return the docid, followed by each column of text data in order
127712 ** of columns in the %_content table (one for the docid plus one for each
127789 ** the allocated array. *pnIndex is set to the number of elements in the
127796 const char *zParam, /* ABC in prefix=ABC parameter to parse */
127801 int nIndex = 1; /* Number of entries in array */
127849 ** the name of the corresponding column in table xxx. The array
127933 int argc, /* Number of elements in argv array */
127945 int nCol = 0; /* Number of columns in the FTS table */
127997 ** + If there is a tokenizer specification included in the arguments,
128205 /* Fill in the zName and zDb fields of the vtab structure. */
128214 /* Fill in the azColumn array */
128227 /* Fill in the abNotindexed array */
128251 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
128257 /* If this is an xCreate call, create the underlying tables in the
128271 /* Figure out the page-size for the database. This is required in order to
128304 ** work is done in function fts3InitVtab().
128309 int argc, /* Number of elements in argv array */
128319 int argc, /* Number of elements in argv array */
128330 ** support estimatedRows. In that case this function is a no-op.
128342 ** are three possible strategies, in order of preference:
128372 ** function MATCH in the requested context" error. To discourage
128397 ** it would lead to an "unable to use function MATCH in the requested
128448 /* Regardless of the strategy selected, FTS can deliver rows in rowid (or
128549 ** table is missing a row that is present in the full-text index.
128568 ** passed in zTerm/nTerm.
128581 int nTerm, /* Size of term zTerm in bytes */
128602 ** not make this guarantee explicitly, but in practice there are always
128687 ** left-most leaf node in the tree that may contain the specified term.
128703 int nTerm, /* Size of term zTerm in bytes */
128710 int iHeight; /* Height of this node in tree */
128720 int nBlob; /* Size of zBlob in bytes */
128749 char **pp, /* IN/OUT: Output pointer */
128750 sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
128764 ** a single document record of a doclist. So, in other words, this
128765 ** routine advances *ppPoslist so that it points to the next docid in
128784 ** last byte in the position-list.
128848 ** called, *pp may point to the start of the next varint in the position-list
128850 ** (in which case **pp will be a terminator bytes POS_END (0) or
128860 ** in the position-list. Because positions are delta-encoded, the value
128861 ** of the previous position is needed in order to compute the value of
128865 char **pp, /* IN/OUT: Pointer into position-list buffer */
128866 sqlite3_int64 *pi /* IN/OUT: Value read from position-list */
128898 ** into *pp contains all positions of both *pp1 and *pp2 in sorted
128901 ** that there is enough space in *pp to hold the complete output.
128913 int iCol1; /* The current column index in pp1 */
128914 int iCol2; /* The current column index in pp2 */
128986 ** each position in *pp2 for which there exists one or more positions in
128994 char **pp, /* IN/OUT: Preallocated output buffer */
128995 int nToken, /* Maximum difference in token positions */
128998 char **pp1, /* IN/OUT: Left input list */
128999 char **pp2 /* IN/OUT: Right input list */
129075 ** column-number in the position list.
129110 ** expression and *pp2 to the right. As usual, the indexes in the position
129111 ** lists are the offsets of the last token in each phrase (tokens "1" and "2"
129112 ** in the example above).
129115 ** entries that are not sufficiently NEAR entries in *pp1 removed.
129120 int nRight, /* Maximum difference in token positions */
129121 int nLeft, /* Maximum difference in token positions */
129122 char **pp1, /* IN/OUT: Left input list */
129123 char **pp2 /* IN/OUT: Right input list */
129159 int anOutput[16]; /* Size each output buffer in bytes */
129166 ** has been reached. In this case *pp is set to 0 and the function returns.
129176 char **pp, /* IN/OUT: Point to read varint from */
129179 sqlite3_int64 *pVal /* IN/OUT: Integer value */
129210 char **pp, /* IN/OUT: Output pointer */
129212 sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */
129213 int *pbFirst, /* IN/OUT: True after first int written */
129237 ** sorted in either ascending or descending order.
129243 ** positions contained in either argument doclist). If the docids in the
129244 ** input doclists are sorted in ascending order, parameter bDescDoclist
129245 ** should be false. If they are sorted in ascending order, it should be
129249 ** containing the output doclist and SQLITE_OK is returned. In this case
129250 ** *pnOut is set to the number of bytes in the output doclist.
129253 ** are undefined in this case.
129276 ** are delta encoded. If they are in ascending order (bDescDoclist==0),
129277 ** then the first docid in each list is simply encoded as a varint. For
129279 ** current and previous docid (a positive number - since the list is in
129283 ** same number of bytes as it is in whichever of the input lists it is
129285 ** consumes either the same or less bytes as it did in the input (since
129286 ** the difference between it and the previous value in the output must
129294 ** be larger in the output than it was in the input (since the delta value
129301 ** A symetric argument may be made if the doclists are in descending
129336 ** This function does a "phrase" merge of two doclists. In a phrase merge,
129338 ** doclist for which there is a position in the left-hand input doclist
129341 ** If the docids in the input doclists are sorted in ascending order,
129342 ** parameter bDescDoclist should be false. If they are sorted in ascending
129351 char *aRight, int *pnRight /* IN/OUT: Right/output doclist */
129398 ** Argument pList points to a position list nList bytes in size. This
129400 ** a token in position 0 (of any column). If so, it writes argument iDelta
129408 int nList, /* Size of pList in bytes */
129449 ** Merge all doclists in the TermSelect.aaOutput[] array into a single
129450 ** doclist stored in TermSelect.aaOutput[0]. If successful, delete all
129453 ** If an OOM error occurs, return SQLITE_NOMEM. In this case it is
129454 ** the responsibility of the caller to free any doclists left in the
129462 /* Loop through the doclists in the aaOutput[] array. Merge them all
129515 int nDoclist /* Size of aDoclist in bytes */
129600 int nTerm, /* Size of zTerm in bytes */
129611 ** made by an fts4aux module, not an FTS table. In this case calling
129674 int nTerm, /* Size of zTerm in bytes */
129695 ** In addition to its current configuration, have the Fts3MultiSegReader
129704 int nTerm, /* Number of bytes in zTerm */
129728 int nTerm, /* Size of zTerm in bytes */
129840 ** This function counts the total number of docids in the doclist stored
129841 ** in buffer aList[], size nList bytes.
129864 ** Advance the cursor to the next row in the %_content table that
129867 ** simply the next row in the %_content table. For a docid lookup,
129928 ** in the %_content table.
129939 int nVal, /* Number of elements in apVal */
129969 /* In case the cursor has been used before, clear it now. */
130080 /* The column value supplied by SQLite must be in range. */
130138 ** in place to remove the entries that have already been merged. This
130164 int mxLevel = 0; /* Maximum relative level value in db */
130310 int nToken = 15; /* Default number of tokens in snippet */
130360 ** function merges all segments in the database to a single segment.
130473 ** PendingTermsFlush() in in case that changes.
130595 ** The fts3 built-in tokenizers - "simple", "porter" and "icu"- are
130596 ** implemented in files fts3_tokenizer1.c, fts3_porter.c and fts3_icu.c
130598 ** declared in these files used to retrieve the respective implementations.
130656 /* Load the built-in tokenizers into the hash table */
130727 ** Allocate an Fts3MultiSegReader for each token in the expression headed
130735 ** If the allocated Fts3MultiSegReader just seeks to a single entry in a
130738 ** and merged incrementally. Otherwise, it has to be merged into an in-memory
130744 int *pnToken, /* OUT: Total number of tokens in phrase. */
130745 int *pnOr, /* OUT: Total number of OR nodes in expr. */
130746 int *pRc /* IN/OUT: Error code */
130775 ** It is merged into the main doclist stored in p->doclist.aAll/nAll.
130786 int nList /* Number of bytes in pList */
130872 ** means that the phrase does not appear in the current row, doclist.pList
130880 int nPoslist = 0; /* Number of bytes in aPoslist */
130978 ** This function is called for each Fts3Phrase in a full-text query
130996 ** scanned in forward order, and the phrase consists of
131040 ** doclists in reverse and by the fts3_write.c module to iterate through
131043 ** The doclist may be sorted in ascending (parameter bDescIdx==0) or
131050 int nDoclist, /* Length of aDoclist in bytes */
131051 char **ppIter, /* IN/OUT: Iterator pointer */
131052 sqlite3_int64 *piDocid, /* IN/OUT: Docid pointer */
131106 int nDoclist, /* Length of aDoclist in bytes */
131107 char **ppIter, /* IN/OUT: Iterator pointer */
131108 sqlite3_int64 *piDocid, /* IN/OUT: Docid pointer */
131136 ** Advance the iterator pDL to the next entry in pDL->aAll/nAll. Set *pbEof
131170 ** edited in place by fts3EvalNearTrim(), then pIter may not actually
131195 ** multi-token phrase. Advance it to the next matching document in the
131244 ** Advance it to the next matching documnent in the database and populate
131265 ** one incremental token. In which case the bIncr flag is set. */
131286 /* Advance the iterator for each token in the phrase once. */
131386 ** each phrase in the expression (subject to deferred token processing).
131395 Fts3Expr *pExpr, /* Expression to initialize phrases in */
131396 int *pRc /* IN/OUT: Error code */
131418 ** of the xFilter() method). There is one element in the array for each
131419 ** token in the FTS expression.
131421 ** Tokens are divided into AND/NEAR clusters. All tokens in a cluster belong
131424 ** separately. The root of a tokens AND/NEAR cluster is stored in
131430 int iToken; /* Position of token in phrase */
131450 int *pRc /* IN/OUT: Error code */
131488 ** Determine the average document (row) size in pages. If successful,
131492 ** The average document size in pages is calculated by first calculating
131493 ** determining the average size in bytes, B. If B is less than the amount
131494 ** of data that will fit on a single leaf page of an intkey table in
131496 ** the number of overflow pages consumed by a record B bytes in size.
131505 ** varints, where nCol is the number of columns in the FTS3 table.
131506 ** The first varint is the number of documents currently stored in
131508 ** data stored in all rows of each column of the table, from left
131550 ** This function is called once for each AND/NEAR cluster in the
131563 int nTC /* Number of entries in aTC[] */
131570 int nToken = 0; /* Total number of tokens in cluster */
131584 /* Count the tokens in this AND/NEAR cluster. If none of the doclists
131586 ** only 1 token, exit early. No tokens to defer in this case. */
131595 /* Obtain the average docsize (in pages). */
131600 /* Iterate through all tokens in this AND/NEAR cluster, in ascending order
131605 ** a. The cheapest token in the entire query (i.e. the one visited by the
131612 ** contains. Set variable "nMinEst" to the smallest number of documents in
131617 ** Then, for each token, defer it if loading the doclist would result in
131648 ** overflowing the 32-bit integer it is stored in. */
131652 /* Either this is the cheapest token in the entire query, or it is
131678 ** the full-text query currently stored in pCsr->pExpr. To iterate through
131694 /* Allocate a MultiSegReader for each token in the expression. */
131697 /* Determine which, if any, tokens in the expression should be deferred. */
131754 ** Parameter nNear is passed the NEAR distance of the expression (5 in
131756 ** the position list, and *pnToken is the number of phrase tokens in, the
131761 ** All positions in the pPhrase position list that are not sufficiently
131762 ** close to a position in the *paPoslist position list are removed. If this
131766 ** associated with pPhrase. And *pnToken is set to the number of tokens in
131770 int nNear, /* NEAR distance. As in "NEAR/nNear". */
131772 char **paPoslist, /* IN/OUT: Position list */
131773 int *pnToken, /* IN/OUT: Tokens in phrase of *paPoslist */
131805 ** point to the next matching row in the database. Expressions iterate through
131806 ** matching rows in docid order. Ascending order if Fts3Cursor.bDesc is zero,
131810 ** successful, the following variables in pExpr are set:
131819 ** FTs3Expr.pPhrase->doclist.nList (length of pList in bytes)
131826 ** entirely of deferred tokens, it is assumed to match every row in
131827 ** the db. In this case the position-list is not populated at all.
131831 ** next possible match, considering only non-deferred tokens. In other
131834 ** where "*" may match any single token. The position list in this case
131846 int *pRc /* IN/OUT: Error code */
131958 ** expression, using the data currently stored in the position lists
131959 ** (Fts3Expr->pPhrase.doclist.pList/nList) for each phrase in the expression.
131962 ** phrase in the NEAR expression is edited in place to contain only those
131964 ** constraints. In this case it returns 1. If the NEAR expression does not
131976 ** which is represented in tree form as:
131989 ** no exceptions to this - it's the way the parser in fts3_expr.c works.
132051 ** the appropriate SQLite error code. In this case the returned value is
132057 int *pRc /* IN/OUT: Error code */
132071 ** all phrases involved in the NEAR. This is because the snippet(),
132147 ** * Up until this point, "NEAR" operators in the expression have been
132192 ** Advance to the next document that matches the FTS expression in
132271 ** After allocating the Fts3Expr.aMI[] array for each phrase in the
132274 ** the values in Fts3Expr.aMI[] according to the position-list currently
132275 ** found in Fts3Expr.pPhrase->doclist.pList for each of the phrase
132386 /* Caution: pRoot may iterate through docids in ascending or descending
132407 ** 1. The total number of occurrences of the phrase in each column of
132410 ** 2. For each column, the number of rows in the table for which the
132422 ** values are set to the number of documents in the table. In other
132423 ** words we assume that very common tokens occur exactly once in each
132431 ** that meet the NEAR constraint are included in the counts.
132467 ** a position-list indicating the occurrences of the phrase in column iCol
132471 ** occurrence of the phrase in the column, stored using the normal (delta+2)
132514 ** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the
132525 /* This is the descendent of an OR node. In this case we cannot use
132527 ** into memory in this case. */
132562 ** last entry in the doclist at pPhrase->doclist.aAll[]. Variable
132565 ** in the doclist.
132567 ** It would also be correct to set pIter and iDocid to zero. In
132569 ** would also move the iterator to point to the last entry in the
132671 ** The author disclaims copyright to this source code. In place of
132726 int argc, /* Number of elements in argv array */
132741 /* The user should invoke this in one of two forms:
132828 /* This vtab delivers always results in "ORDER BY term ASC" order. */
132972 /* State 0. In this state the integer just read was a docid. */
132979 /* State 1. In this state we are expecting either a 1, indicating
132984 ** integer encountered in state 1 is not 0 or 1, then we need to
133031 int nVal, /* Number of elements in apVal */
133040 int iEq = -1; /* Index of term=? value in apVal */
133041 int iGe = -1; /* Index of term>=? value in apVal */
133042 int iLe = -1; /* Index of term<=? value in apVal */
133043 int iLangid = -1; /* Index of languageid=? value in apVal */
133070 /* In case this cursor is being reused, close and zero it. */
133223 ** The author disclaims copyright to this source code. In place of
133263 ** operator in a similar format to that used by the lemon parser
133306 ** FTSQUERY_PHRASE with a unary "-" attached to it. i.e. "mysql" in the
133316 int nCol; /* Number of entries in azCol[] */
133384 ** and other information (column names etc.) in pParse. Create an Fts3Expr
133484 ** is included in the buffer. This function attempts to tokenize the entire
133514 ** The first pass, in the block below, uses a tokenizer cursor to iterate
133515 ** through the tokens in the expression. This pass uses fts3ReallocOrFree()
133516 ** to assemble data in two dynamic buffers:
133524 ** The second pass, in the block that begins "if( rc==SQLITE_DONE )" below,
133525 ** appends buffer zTemp to buffer p, and fills in the Fts3Expr and Fts3Phrase
133620 unsigned char parenOnly; /* Only valid in paren mode */
133702 ** a quote character embedded in a string.
133762 ** group more tightly). For example, in the C language, the == operator
133766 ** is defined), the order of the operators in precedence from highest to
133795 ** of pNew and the existing nodes of the tree. This may result in the head
133796 ** of the tree changing, in which case *ppHead is set to the new root node.
133820 ** Parse the fts3 query expression found in buffer z, length n. This function
133837 Fts3Expr *pNotBranch = 0; /* Only used in legacy parse mode */
133877 ** an expression contained in parenthesis is required. If a
133909 ** Return an error in either case.
133995 ** an equivalent but more balanced form. The tree is modified in place.
134008 int eType = pRoot->eType; /* Type of node in this tree */
134027 /* Set $p to point to the left-most leaf in the tree of eType nodes. */
134033 /* This loop runs once for each leaf in the tree of eType nodes. */
134074 /* Set $p to point to the next leaf in the tree of eType nodes */
134150 ** in this case.
134157 int nCol, /* Number of entries in azCol[] */
134206 ** of each column in the target fts3 table, in order from left to right.
134220 int nCol, /* Number of entries in azCol[] */
134508 ** The author disclaims copyright to this source code. In place of
134516 ** This is the implementation of generic hash-tables used in SQLite.
134522 ** The code in this file is only compiled if:
134525 ** (in which case SQLITE_CORE is not defined), or
134528 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
134633 ** The C syntax in this function definition may be unfamilar to some
134654 ** For help in interpreted the obscure C code in the function definition,
134673 Fts3HashElem *pHead; /* First element already in pEntry */
134718 /* This function (for internal use only) locates an element in an
134821 ** The key is not copied in this instance. If a malloc fails, then
134830 int nKey, /* Number of bytes in the key */
134892 ** The author disclaims copyright to this source code. In place of
134905 ** The code in this file is only compiled if:
134908 ** (in which case SQLITE_CORE is not defined), or
134911 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
134935 int iOffset; /* current position in zInput */
134972 ** used to incrementally tokenize this string is returned in
135023 ** isConsonant() and isVowel() determine if their first character in
135029 ** in which case it is a vowel.
135031 ** In these routine, the letters are in reverse order. So the 'y' rule
135062 ** In prose: A word is an optional consonant followed by zero or
135067 ** Return true if the m-value for z is 1 or more. In other words,
135071 ** In this routine z[] is in reverse order. So we are really looking
135118 ** Return TRUE if the word ends in a double consonant.
135133 ** first three letters and the first one cannot be in [wxy].
135148 ** The input word *pz and zFrom are both in reverse order. zTo
135149 ** is in normal order.
135205 ** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
135209 ** Any upper-case characters in the US-ASCII character set ([A-Z])
135220 ** in [a-zA-Z] then no stemming is attempted and this routine just
135244 /* The use of a character not in [a-zA-Z] means that we fallback
135268 /* Do nothing. The work was all in the test */
135276 /* Do nothing. The work was all in the test */
135450 /* z[] is now the stemmed word in reverse order. Flip it back
135463 ** part of a token. In other words, delimiters all must have
135483 int *pnBytes, /* OUT: Number of bytes in token */
135540 ** tokenizer in *ppModule
135555 ** The author disclaims copyright to this source code. In place of
135569 ** The code in this file is only compiled if:
135572 ** (in which case SQLITE_CORE is not defined), or
135575 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
135595 ** the string <key-name> must already exist in the has table. Otherwise,
135761 ** designed to be used in concert with the Tcl testing framework. This
135771 ** list. For each token in the <input-string>, three elements are
135775 ** using the built-in "simple" tokenizer:
135840 zErr = "error in xCreate()";
135845 zErr = "error in xOpen()";
135858 zErr = "error in xClose()";
135862 zErr = "error in xDestroy()";
135927 ** This function is used for testing only, it is not included in the
135931 ** can be used as designed by the C-code in the queryTokenizer and
135933 ** in the README.tokenizer file as an example, so it is important to
135979 ** Set up SQL objects in database db used to access the contents of
135987 ** scalarFunc() in this file for details) and, if ENABLE_TABLE is
136045 ** The author disclaims copyright to this source code. In place of
136058 ** The code in this file is only compiled if:
136061 ** (in which case SQLITE_CORE is not defined), or
136064 ** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
136083 int iOffset; /* current position in pInput */
136112 ** track such information in the database, then we'd only want this
136149 ** used to incrementally tokenize this string is returned in
136199 int *pnBytes, /* OUT: Number of bytes in token */
136265 ** tokenizer in *ppModule
136280 ** The author disclaims copyright to this source code. In place of
136306 ** statement and returns one row for each token in the result. With
136343 int nToken; /* Size of zToken in bytes */
136380 ** in this case. Or, if an error occurs, an SQLite error code is returned.
136381 ** The final value of *pazDequote is undefined in this case.
136384 int argc, /* Number of elements in argv[] */
136436 int argc, /* Number of elements in argv array */
136611 int nVal, /* Number of elements in apVal */
136736 ** The author disclaims copyright to this source code. In place of
136749 ** code in fts3.c.
136764 ** of it. i.e. if a full-text index node is 900 bytes in size, then a buffer
136781 ** bytes and larger. Nodes are loaded in chunks of FTS3_NODE_CHUNKSIZE bytes.
136801 ** The two values that may be meaningfully bound to the :1 parameter in
136811 ** debugging FTS only, it should not usually be turned on in production
136846 int iCol; /* Column token must occur in */
136847 Fts3DeferredToken *pNext; /* Next in list of deferred tokens */
136854 ** this structure are only manipulated by code in this file, opaque handles
136855 ** of type Fts3SegReader* are also used by code in fts3.c to iterate through
136875 sqlite3_int64 iEndBlock; /* Rowid of final block in segment (or 0) */
136890 int nTerm; /* Number of bytes in current term */
136894 int nDoclist; /* Size of doclist in current entry */
136908 ** An instance of this structure is used to create a segment b-tree in the
136918 sqlite3_int64 iFirst; /* First slot in %_segments written */
136919 sqlite3_int64 iFree; /* Next free slot in %_segments */
136921 int nTerm; /* Number of bytes in zTerm */
136925 int nData; /* Bytes of data in aData */
136943 ** the tree is assembled in memory and written out only once all leaves have
136954 int nTerm; /* Number of bytes in zTerm */
137038 /* Return segments in order from oldest to newest.*/
137064 ** of the oldest level in the db that contains at least ? segments. Or,
137065 ** if no level in the FTS index contains more than ? segments, the statement
137070 /* Estimate the upper limit on the number of leaf nodes in a new segment
137107 ** Return the largest relative level in the FTS index or indexes. */
137110 /* Return segments in order from oldest to newest.*/
137213 ** Similar to fts3SqlStmt(). Except, after binding the parameters in
137276 ** level within the index) are encoded in 64-bit integer values stored
137277 ** in the %_segdir table on disk. This function is used to convert three
137294 int iIndex, /* Index in p->aIndex[] */
137308 ** all rows in the %_segdir table, from oldest to newest. If successful,
137371 PendingList **pp, /* IN/OUT: Pointer to PendingList struct */
137411 ** Zero is always returned in this case. Otherwise, if no OOM error occurs,
137415 PendingList **pp, /* IN/OUT: PendingList structure */
137509 ** pending-terms hash-table. The docid used is that currently stored in
137519 u32 *pnWord /* IN/OUT: Incr. by number tokens inserted */
137539 ** zText==0. In this case, add zero token entries to the hash table and
137636 ** operation. It adds entries for each term in the new record to the
137703 ** defined columns in the FTS3 table, plus one for the docid field.
137721 ** In FTS3, this is an error. It is an error to specify non-NULL values
137782 ** The first element in the apVal[] array is assumed to contain the docid
137833 ** This function allocates a new level iLevel index in the segdir table.
137875 ** full, merge all segments in level iLevel into a single iLevel+1
137899 ** with the contents of the blob stored in the "block" column of the
137901 ** to the size of the blob in bytes before returning.
137908 ** This function may leave an open sqlite3_blob* handle in the
137921 char **paBlob, /* OUT: Blob data in malloc'd buffer */
138027 ** Move the iterator passed as the first argument to the next term in the
138038 int nPrefix; /* Number of bytes in term prefix */
138039 int nSuffix; /* Number of bytes in term suffix */
138135 ** Set the SegReader to point to the first docid in the doclist associated
138161 ** Advance the SegReader to point to the next docid in the doclist
138166 ** in the doclist entry (i.e. immediately past the docid varint).
138174 int *pnOffsetList /* OUT: Length of *ppOffsetList in bytes */
138184 ** Pending-terms doclists are always built up in ascending order, so
138231 /* List may have been edited in place by fts3EvalNearTrim() */
138234 /* If there are no more entries in the doclist, set pOffsetList to
138341 /* The entire segment is stored in the root node. */
138375 ** a subset of the terms stored in the Fts3Table.pendingTerms array.
138378 ** through each term in the pending-terms table. Or, if isPrefixIter is
138381 ** "firebird", then the iterator visits the following 'terms' (in the order
138434 ** objects in term order using qsort(). This uses the same comparison
138442 /* The query is a simple term lookup that matches at most one term in
138511 ** A different comparison function for SegReader structures. In this
138512 ** version, it is assumed that each SegReader points to an entry in
138515 ** 1) EOF (end of doclist in this case) is greater than not EOF.
138557 int nTerm /* Size of term zTerm in bytes */
138575 ** the final (nSegment-nSuspect) members are already in sorted order
138577 ** the array around until all entries are in sorted order.
138616 int n /* Size of buffer z in bytes */
138630 ** Find the largest relative level number in the table. If successful, set
138660 sqlite3_int64 nLeafData, /* Bytes of leaf data in segment */
138662 int nRoot /* Number of bytes in buffer zRoot */
138687 ** zNext, in bytes. For example,
138695 int nPrev, /* Size of buffer zPrev in bytes */
138697 int nNext /* Size of buffer zNext in bytes */
138711 SegmentNode **ppTree, /* IN/OUT: SegmentNode handle */
138714 int nTerm /* Size of term in bytes */
138724 int nData = pTree->nData; /* Current size of node in bytes */
138751 /* There is no prefix-length field for first term in a node */
138782 ** If this is the first node in the tree, the term is added to it.
138849 int iHeight, /* Height of this node in tree */
138851 sqlite3_int64 iFree, /* Block id of next free slot in %_segments */
138854 int *pnRoot /* OUT: Size of root node in bytes */
138911 ** and return it via the input/output variable *ppWriter in this case.
138917 SegmentWriter **ppWriter, /* IN/OUT: SegmentWriter handle */
138920 int nTerm, /* Size of term in bytes */
138922 int nDoclist /* Size of doclist in bytes */
138924 int nPrefix; /* Size of term prefix in bytes */
138925 int nSuffix; /* Size of term suffix in bytes */
138940 /* Allocate a buffer in which to accumulate data */
138945 /* Find the next free blockid in the %_segments table */
138979 ** to the database (still available in pWriter->zTerm), and
138984 ** In other words, it must be the prefix of zTerm 1 byte longer than
139103 ** The first value in the apVal[] array is assumed to contain an integer.
139132 ** Set *pnMax to the largest segment level in the database for the index
139135 ** Segment levels are stored in the 'level' column of the %_segdir table.
139199 ** Delete all entries in the %_segments table associated with the segment
139227 ** each of the SegReader objects in the array passed as the third
139286 ** If there are no entries in the input position list for column iCol, then
139295 char **ppList, /* IN/OUT: Pointer to position list */
139296 int *pnList /* IN/OUT: Size of buffer *ppList in bytes */
139331 ** Cache data in the Fts3MultiSegReader.aBuffer[] buffer (overwriting any
139359 int *pnPoslist /* OUT: Size of position list in bytes */
139426 int nTerm /* Length of zTerm in bytes */
139468 int nTerm /* Number of bytes in zTerm */
139509 ** have been made. Calling this function puts the MultiSegReader in such
139515 ** then the entire doclist for the term is available in
139564 /* Advance the first pCsr->nAdvance entries in the apSegment[] array
139565 ** forward. Then sort the list in order of current term again.
139588 ** required callbacks have been made. In this case exit early.
139627 sqlite3_int64 iPrev = 0; /* Previous docid stored in doclist */
139629 /* The current term of the first nMerge entries in the array
139739 ** by one or more space (0x20) characters. In the first case, set *piEndBlock
139740 ** to the integer value and *pnByte to zero before returning. In the second,
139791 /* Loop through all entries in the %_segdir table corresponding to
139792 ** segments in this index on levels greater than iAbsLevel. If there is
139794 ** such segments are smaller than nLimit bytes in size, they will be
139804 ** old version of FTS. In this case it is not possible to determine
139828 /* Loop through all %_segdir entries for segments in this index with
139831 ** oldest segment in the range, 1 for the next oldest, and so on.
139833 ** In other words, move all segments being promoted to level -1,
139834 ** setting the "idx" fields as appropriate to keep them in the same
139868 ** Merge all level iLevel segments in the database into a single
139871 ** currently present in the database.
139874 ** segment in the database, SQLITE_DONE is returned immediately.
139881 int iIndex, /* Index in p->aIndex[] to merge */
139909 /* This call is to merge all segments in the database to a single
139911 ** greatest segment level currently present in the database for this
140044 ** Insert the sizes (in tokens) for each column of the document
140051 u32 *aSz /* Sizes of each column, in tokens */
140054 int nBlob; /* Number of bytes in the BLOB */
140079 ** where N is the number of user defined columns in the fts3 table plus
140083 ** Varint 0: Total number of rows in the table.
140085 ** Varint 1..nCol: For each column, the total number of tokens stored in
140088 ** Varint 1+nCol: The total size, in bytes, of all text values in all
140097 int nChng /* Change in the number of documents */
140284 ** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute
140338 ** to build up nodes or other blobs of data in.
140344 int n; /* Number of valid bytes of data in a[] */
140366 int iIdx; /* Index of *output* segment in iAbsLevel+1 */
140391 int nDoclist; /* Size of doclist in bytes */
140397 ** bytes in size, extend (realloc) it to be so.
140469 ** Initialize a node-reader object to read the node in buffer aNode/nNode.
140498 ** The block id of the leaf node just written to disk may be found in
140531 ** bytes in size, write the key here. */
140580 ** stored in blob *pNode. The node need not contain any terms, but the
140590 ** If the size of the value in blob pPrev is zero, then this is the first
140606 int nTerm, /* Size of zTerm in bytes */
140608 int nDoclist /* Size of aDoclist in bytes */
140612 int nPrefix; /* Size of term prefix in bytes */
140613 int nSuffix; /* Size of term suffix in bytes */
140662 int nSpace; /* Total space in bytes required on leaf */
140686 ** to the database (still available in pLeaf->key), and
140691 ** In other words, it must be the prefix of zTerm 1 byte longer than
140740 int *pRc /* IN/OUT: Error code */
140743 int iRoot; /* Index of root in pWriter->aNodeWriter */
140747 /* Set iRoot to the index in pWriter->aNodeWriter[] of the output segment
140764 ** the node would be stored as a blob in the "root" column of the %_segdir
140765 ** table. However, this is not permitted in this case. The problem is that
140766 ** space has already been reserved in the %_segments table, and so the
140775 ** Todo: Better might be to defer allocating space in the %_segments
140820 ** Compare the term in buffer zLhs (size in bytes nLhs) with that in
140821 ** zRhs (size in bytes nRhs) using memcmp. If one term is a prefix of
140842 ** Query to see if the entry in the %_segments table with blockid iEnd is
140847 ** error code. The final value of *pbRes is undefined in this case.
140881 ** greater than the largest key currently stored in the potential
140889 int nKey, /* Number of bytes in nKey */
140901 int nRoot = 0; /* Size of aRoot[] in bytes */
140922 /* Check for the zero-length marker in the %_segments table */
141014 ** *piIdx is undefined in this case.
141039 ** In the %_segdir table, a segment is defined by the values in three
141049 ** of input segments, multiplied by two. This value is stored in stack
141058 ** In the actual code below, the value "16" is replaced with the
141086 /* Calculate the first block to use in the output segment */
141098 /* Insert the marker in the %_segments table to make sure nobody tries
141147 ** Update the 'idx' values of the remaining segments in the level so that
141156 int nIdx = 0; /* Valid entries in aIdx[] */
141221 ** This function creates a new node image in blob object *pNew by copying
141227 int nNode, /* Size of aNode in bytes */
141230 int nTerm, /* Size of zTerm in bytes */
141231 sqlite3_int64 *piBlock /* OUT: Block number in next layer down */
141272 ** Remove all terms smaller than zTerm/nTerm from segment iIdx in absolute
141274 ** table, and modifying existing entries in both the %_segments and %_segdir
141285 int nTerm /* Number of bytes in buffer zTerm */
141362 ** or modified in place so that it no longer contains those entries that
141363 ** have been duplicated in the output segment.
141380 ** somewhere in the pCsr->apSegment[] array. */
141396 ** segment to the upper level. The segment is modified in place
141414 ** Store an incr-merge hint in the database.
141433 ** exists, is stored in the rowid==1 row of the %_stat table.
141468 ** Otherwise, append an entry to the hint stored in blob *pHint. Each entry
141477 i64 iAbsLevel, /* First varint to store in hint */
141478 int nInput, /* Second varint to store in hint */
141479 int *pRc /* IN/OUT: Error code */
141493 ** If no error occurs, return SQLITE_OK. If the hint blob in *pHint does
141518 ** values for the _segdir.idx field) in the highest level that contains
141519 ** at least nMin segments. Multiple merges might occur in an attempt to
141545 int iIdx = 0; /* Largest idx in level (iAbsLevel+1) */
141564 ** last entry in it specifies a relative level smaller than or equal
141587 ** nMin segments and no hint in the %_stat table. No work to do.
141588 ** Exit early in this case. */
141594 ** segments available in level iAbsLevel. In this case, no work is
141763 int nTerm, /* Size of zTerm in bytes */
141783 ** Return a checksum of all entries in the FTS index that correspond to
141789 ** return value is undefined in this case.
141863 ** code. The final value of *pbOk is undefined in this case.
141916 int nToken = 0; /* Number of bytes in token */
141918 int iPos = 0; /* Position of token in zText */
141957 ** prefix in the document set, a 64-bit checksum is calculated (by code
141958 ** in fts3ChecksumEntry()) based on the following:
141963 ** + The language-id of the row it appears in,
141964 ** + The docid of the row it appears in,
141965 ** + The column it appears in, and
141968 ** The checksums for all entries in the index are XORed together to create
141971 ** The integrity-check code calculates the same checksum in two ways:
142046 ** Free all entries in the pCsr->pDeffered list. Entries are added to
142061 ** Generate deferred-doclists for all tokens in the pCsr->pDeferred list
142090 int nToken = 0; /* Number of bytes in token */
142092 int iPos = 0; /* Position of token in zText */
142154 int iCol /* Column that token must appear in (or -1) */
142176 ** present in the FTS3 table. If it is, delete it and adjust the contents
142182 int *pnChng, /* IN/OUT: Decrement if row is deleted */
142186 int bFound = 0; /* True if *pRowid really is in the table */
142194 /* Deleting this row means the whole table is empty. In this case
142196 ** data in the pendingTerms hash table. */
142239 int nChng = 0; /* Net change in number of documents */
142269 /* Allocate space to hold the change in document sizes */
142301 /* The new rowid is not NULL (in this case the rowid will be
142312 ** be losslessly converted to an integer. In this case, the eventual
142313 ** call to fts3InsertData() (either just below or further on in this
142370 ** Flush any data in the pending-terms hash table to disk. If successful,
142371 ** merge all segments in the database (including the new segment, if
142398 ** The author disclaims copyright to this source code. In place of
142414 ** Characters that may appear in the second argument to matchinfo().
142452 int nSnippet; /* Requested snippet length (in tokens) */
142453 int nPhrase; /* Number of phrases in query */
142459 int nToken; /* Number of tokens in phrase */
142461 int iHead; /* Next value in position list */
142463 int iTail; /* Next value in trailing position list */
142469 int iPos; /* Index of first token in snippet */
142481 int nCol; /* Number of columns in table */
142482 int nPhrase; /* Number of matchable phrases in query */
142483 sqlite3_int64 nDoc; /* Number of docs in database */
142497 int n; /* Length of z in bytes (excl. nul-term) */
142498 int nAlloc; /* Allocated size of buffer z in bytes */
142518 ** the list. *piPos contains the value of the previous entry in the list.
142554 ** Iterate through all phrase nodes in an FTS3 query, except those that
142591 ** Load the doclists for each phrase in the query associated with FTS3 cursor
142595 ** phrases in the expression (all phrases except those directly or
142597 ** pnToken is not NULL, then it is set to the number of tokens in all
142602 int *pnPhrase, /* OUT: Number of phrases in query */
142603 int *pnToken /* OUT: Number of tokens in query */
142711 u64 mHighlight = 0; /* Mask of tokens to highlight in snippet */
142785 ** (a) +1 point for each occurrence of a matchable phrase in the snippet.
142787 ** (b) +1000 points for the first occurrence of each matchable phrase in
142790 ** The selected snippet parameters are stored in structure *pFragment before
142791 ** returning. The score of the selected snippet is stored in *piScore
142799 u64 *pmSeen, /* IN/OUT: Mask of phrases seen */
142804 int nList; /* Number of phrases in expression */
142812 /* Iterate through the phrases in the expression to count them. The same
142831 ** the set of phrases in the expression to populate the aPhrase[] array.
142847 /* Loop through all candidate snippets. Store the best snippet in
142848 ** *pFragment. Store its associated 'score' in iBestScore.
142881 int nAppend /* Size of zAppend in bytes (or -1) */
142918 ** This function "shifts" the beginning of the snippet forward in the
142932 int iLangid, /* Language id to use in tokenizing */
142935 int nDoc, /* Size of buffer zDoc in bytes */
142936 int *piPos, /* IN/OUT: First token of snippet */
142937 u64 *pHlmask /* IN/OUT: Mask of tokens to highlight */
142950 /* Ideally, the start of the snippet should be pushed forward in the
142966 ** or more tokens in zDoc/nDoc.
142998 int isLast, /* True for final fragment in snippet */
142999 int nSnippet, /* Number of tokens in extracted snippet */
143008 int nDoc; /* Size of zDoc in bytes */
143037 int iBegin = 0; /* Offset in zDoc of start of token */
143038 int iFin = 0; /* Offset in zDoc of end of token */
143042 ** in the FTS code the variable that the third argument to xNext points to
143106 ** This function is used to count the entries in a column-list (a
143109 ** beginning of the first varint in the column-list (the varint that
143110 ** contains the position of the first matching term in the column data).
143112 ** the last varint in the column-list (either the 0x00 signifying the end
143114 ** the next column in the position-list).
143116 ** The number of elements in the column-list is returned.
143155 ** Y values are set to nDoc, where nDoc is the number of documents in the
143272 ** hits for a single phrase on a single row in order to calculate the
143326 ** array before returning. SQLITE_OK is returned in this case.
143339 ** contains one element for each matchable phrase in the query.
143354 int nLive = 0; /* Number of iterators in aIter not at EOF */
143414 ** pInfo->aMatchinfo[] buffer is left in is undefined.
143448 sqlite3_int64 nDoc; /* Number of rows in table */
143543 ** matchinfo function has been called for this query. In this case
143548 int nMatchinfo = 0; /* Number of u32 elements in match-info */
143549 int nArg; /* Bytes in zArg */
143552 /* Determine the number of phrases in the query */
143556 /* Determine the number of integers in the buffer returned by this call. */
143594 int nToken /* Approximate number of tokens in snippet */
143602 ** the data in the current row. The first iteration of the for(...) loop
143603 ** below attempts to locate a single fragment of text nToken tokens in
143604 ** size that contains at least one instance of all phrases in the query
143605 ** expression that appear in the current row. If such a fragment of text
143609 int nSnippet = 0; /* Number of fragments in this snippet */
143611 int nFToken = -1; /* Number of tokens in each fragment */
143646 /* Find the best snippet of nFToken tokens in column iRead. */
143660 /* If all query phrases seen by fts3BestSnippet() are present in at least
143708 int nTerm; /* Number of tokens in phrase */
143711 int iPos = 0; /* First position in position-list */
143742 int nToken; /* Number of tokens in query */
143755 /* Count the number of terms in the query */
143789 /* Retreive the text stored in column iCol. If an SQL NULL is stored
143790 ** in column iCol, jump immediately to the next iteration of the loop.
143921 ** The author disclaims copyright to this source code. In place of
144008 in bytes */
144031 ** all characters in string zIn/nIn to be separators (if bAlnum==0) or
144034 ** For each codepoint in the zIn/nIn string, this function checks if the
144039 ** codepoints in the aiException[] array.
144042 ** identifies as a diacritic) occurs in the zIn/nIn string it is ignored.
144050 int nIn /* Length of z in bytes */
144071 int nNew; /* Number of valid entries in array aNew[] */
144180 ** used to incrementally tokenize this string is returned in
144186 int nInput, /* Size of string aInput in bytes */
144315 ** The author disclaims copyright to this source code. In place of
144342 /* Each unsigned integer in the following array corresponds to a contiguous
144346 ** The most significant 22 bits in each 32-bit value contain the first
144347 ** codepoint in the range. The least significant 10 bits are used to store
144348 ** the size of the range (always at least 1). In other words, the value
144467 ** in the ASCII range with a diacritic added, return the codepoint
144543 /* Each entry in the following array defines a rule for folding a range
144547 ** If the least significant bit in flags is clear, then the rule applies
144550 ** every second codepoint in the range, starting with codepoint C.
144552 ** The 7 most significant bits in flags are an index into the aiOff[]
144683 ** The author disclaims copyright to this source code. In place of
144699 ** The data structure for a single virtual r-tree table is stored in three
144700 ** native SQLite tables declared as follows. In each case, the '%' character
144701 ** in the table name is replaced with the user-supplied name of the r-tree
144708 ** The data for each node of the r-tree structure is stored in the %_node
144710 ** an entry in the %_parent table associating the node with its parent.
144711 ** And for each row of data in the table, there is an entry in the %_rowid
144716 ** empty. The nodeno of the root node is always 1. All other nodes in the
144725 ** stored in the node.
144779 ** the number of rows in the virtual table to calculate the costs of
144794 int iNodeSize; /* Size in bytes of each node in the node table */
144802 i64 nRowEst; /* Estimated number of rows in this table */
144827 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
144856 in the parent node.
144868 ** maximum. In Gutman's notation:
144890 ** Number of entries in the cursor RtreeNode cache. The first entry is
144904 int nConstraint; /* Number of entries in aConstraint */
144907 int nPoint; /* Number of slots used in aPoint[] */
144977 RtreeNode *pNext; /* Next node in this hash collision chain */
144980 /* Return the number of cells in a node */
144996 ** operators in order to constrain a search.
145003 ** This object is deleted automatically by the destructor mechanism in
145022 ** An instance of this structure (in the form of a BLOB) is returned by
145122 ** in the Rtree.aHash table.
145195 /* Check if the requested node is already in the hash table. If so,
145304 ** If there is not enough free space in pNode, return SQLITE_FULL.
145311 int nCell; /* Current number of cells in pNode */
145392 in node pNode.
145590 ** Store the results in "r".
145684 ** in a coordinate pair. But make pCellData point to the lower bound.
145716 ** The op is given by p->op. The xN is p->iCoord-th coordinate in
145742 ** One of the cells in node pNode is guaranteed to have a 64-bit
145765 ** in its parent. If pNode is the root node, return -1.
145782 ** iLevel values coming first. In this way, if rScore is the same for all
145798 ** Interchange to search points in a cursor.
146123 ** return SQLITE_OK. If there is no such record in the table, set
146213 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
146303 ** support estimatedRows. In that case this function is a no-op.
146315 ** table scan strategies to choose from (in order from most to
146327 ** the constraint in sqlite3_index_info.aConstraintUsage[] with
146330 ** The first of each pair of bytes in idxStr identifies the constraint
146417 ** Return the N-dimensional volumn of the cell stored in *p.
146430 ** of the objects size in each dimension.
146442 ** Store the union of cells p1 and p2 in p1.
146520 ** ChooseSubTree in r*tree terminology.
146579 ** the node pNode. This function updates the bounding box cells in
146634 ** (nIdx-1) in no particular order. This function sorts the values
146635 ** in aIdx according to the indexed values in aDistance. For
146706 ** (nIdx-1) in no particular order. This function sorts the values
146707 ** in aIdx according to dimension iDim of the cells in aCell. The
146956 ** In this case avoid the all to nodeWrite().
147077 /* Remove the entry in the parent cell. */
147106 /* Remove the node from the in-memory hash table and link it into
147154 ** the in-memory node image, so it cannot fail.
147160 ** cell in the parent node so that it tightly contains the updated
147257 /* Find a node to store this cell in. pNode->iNode currently contains
147326 /* Find a node to store this cell in. pNode->iNode currently contains
147361 int iCell; /* Index of iDelete cell in pLeaf */
147375 /* Delete the cell in question from the leaf node. */
147388 /* Delete the corresponding entry in the <rtree>_rowid table. */
147401 ** in this scenario).
147492 ** In the first case, if the conflict-handling mode is REPLACE, then
147493 ** the conflicting row can be removed before proceeding. In the second
147525 /* If a rowid value was supplied, check if it is already present in
147613 ** of the number of rows in the virtual table. If possible, this is based
147777 ** table already exists. In this case the node-size is determined by inspecting
147783 ** would fit in a single node, use a smaller node-size.
147932 ** entry for each cell in the r-tree node. Each entry is itself a
148034 ** or sqlite3_rtree_query_callback(). In other words, this routine is the
148152 ** The author disclaims copyright to this source code. In place of
148195 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
148222 int iPattern = 0; /* Current byte index in zPattern */
148223 int iString = 0; /* Current byte index in zString */
148246 ** MATCH_ALL. For each MATCH_ONE, skip one character in the
148294 ** the build-in LIKE operator. The first argument to the function is the
148315 ** of deep recursion and N*N behavior in patternCompare().
148657 ** The author disclaims copyright to this source code. In place of
148690 int nChar; /* Number of UChar elements in pInput */
148692 int *aOffset; /* Offsets of each character in utf-8 input */
148704 int argc, /* Number of entries in argv[] */
148742 ** used to incrementally tokenize this string is returned in
148748 int nInput, /* Length of zInput in bytes */
148831 int *pnBytes, /* OUT: Number of bytes in token */